From: Peter Zijlstra <peterz@infradead.org>
To: Jason Low <jason.low2@hp.com>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
Scott J Norton <scott.norton@hpe.com>,
Waiman Long <Waiman.Long@hpe.com>,
peter@hurleysoftware.com, jason.low2@hpe.com
Subject: Re: [PATCH] locking/rwsem: Optimize write lock slowpath
Date: Wed, 11 May 2016 20:38:09 +0200 [thread overview]
Message-ID: <20160511183809.GJ3192@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1462991162.2488.23.camel@j-VirtualBox>
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!
next prev parent reply other threads:[~2016-05-11 18:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 19:16 Jason Low
2016-05-10 2:25 ` Waiman Long
2016-05-11 11:49 ` Peter Zijlstra
2016-05-11 18:26 ` Jason Low
2016-05-11 18:38 ` Peter Zijlstra [this message]
2016-05-11 18:33 ` Davidlohr Bueso
2016-05-11 18:49 ` Jason Low
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160511183809.GJ3192@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Waiman.Long@hpe.com \
--cc=dave@stgolabs.net \
--cc=jason.low2@hp.com \
--cc=jason.low2@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peter@hurleysoftware.com \
--cc=scott.norton@hpe.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome