Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1399415

Re: [PATCH] locking/rwsem: Optimize write lock slowpath

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH] locking/rwsem: Optimize write lock slowpath
Date 2016-05-11 20:40 +0200
Message-ID <rxHd8-5ub-31@gated-at.bofh.it> (permalink)
References <rwYSJ-3gz-1@gated-at.bofh.it> <rxAOn-7sm-33@gated-at.bofh.it> <rxHd7-5ub-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, May 11, 2016 at 11:26:02AM -0700, Jason Low wrote:
> On Wed, 2016-05-11 at 13:49 +0200, Peter Zijlstra wrote:

> > >  static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem)
> > >  {
> > >  	/*
> > > +	 * Avoid trying to acquire write lock if count isn't RWSEM_WAITING_BIAS.
> > >  	 */
> > > +	if (count != RWSEM_WAITING_BIAS)
> > > +		return false;
> > > +
> > > +	/*
> > > +	 * Acquire the lock by trying to set it to ACTIVE_WRITE_BIAS. If there
> > > +	 * are other tasks on the wait list, we need to add on WAITING_BIAS.
> > > +	 */
> > > +	count = list_is_singular(&sem->wait_list) ?
> > > +			RWSEM_ACTIVE_WRITE_BIAS :
> > > +			RWSEM_ACTIVE_WRITE_BIAS + RWSEM_WAITING_BIAS;
> > > +
> > > +	if (cmpxchg_acquire(&sem->count, RWSEM_WAITING_BIAS, count) == RWSEM_WAITING_BIAS) {
> > >  		rwsem_set_owner(sem);
> > >  		return true;
> > >  	}
> > 
> > Right; so that whole thing works because we're holding sem->wait_lock.
> > Should we clarify that someplace?
> 
> Yup, we can mention that the rwsem_try_write_lock() function must be
> called with the wait_lock held.

Also try to explain _why_ it must be held.

Thanks!

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] locking/rwsem: Optimize write lock slowpath Jason Low <jason.low2@hp.com> - 2016-05-09 21:20 +0200
  Re: [PATCH] locking/rwsem: Optimize write lock slowpath Waiman Long <waiman.long@hpe.com> - 2016-05-10 04:30 +0200
  Re: [PATCH] locking/rwsem: Optimize write lock slowpath Peter Zijlstra <peterz@infradead.org> - 2016-05-11 13:50 +0200
    Re: [PATCH] locking/rwsem: Optimize write lock slowpath Jason Low <jason.low2@hp.com> - 2016-05-11 20:40 +0200
      Re: [PATCH] locking/rwsem: Optimize write lock slowpath Peter Zijlstra <peterz@infradead.org> - 2016-05-11 20:40 +0200
    Re: [PATCH] locking/rwsem: Optimize write lock slowpath Davidlohr Bueso <dave@stgolabs.net> - 2016-05-11 20:40 +0200
      Re: [PATCH] locking/rwsem: Optimize write lock slowpath Jason Low <jason.low2@hp.com> - 2016-05-11 21:00 +0200

csiph-web