From: Waiman Long <waiman.long@hp.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org, Jason Low <jason.low2@hp.com>,
Scott J Norton <scott.norton@hp.com>,
Douglas Hatch <doug.hatch@hp.com>
Subject: Re: [PATCH v3] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write
Date: Mon, 27 Apr 2015 16:25:09 -0400 [thread overview]
Message-ID: <553E9B25.4060802@hp.com> (raw)
In-Reply-To: <1429907956.10273.65.camel@stgolabs.net>
On 04/24/2015 04:39 PM, Davidlohr Bueso wrote:
> On Fri, 2015-04-24 at 13:54 -0400, Waiman Long wrote:
>> This patch also checks one more time in __rwsem_do_wake() to see if
>> the rwsem was stolen just before doing the expensive wakeup operation
>> which will be unnecessary if the lock was stolen.
> It strikes me that this should be another patch, as the optimization is
> independent of the wake_lock (comments below).
>
> [...]
>
I could separate that into a separate patch.
>> +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
> Could you please reuse the CONFIG_RWSEM_SPIN_ON_OWNER ifdefiry we
> already have? Just add these where we define rwsem_spin_on_owner().
I can move the rwsem_has_spinner() down there, but
rwsem_has_active_writer() has to be on top or I will need to add a
forward reference to it.
> [...]
>
>> /*
>> * handle the lock release when processes blocked on it that can now run
>> * - if we come here from up_xxxx(), then:
>> @@ -125,6 +154,14 @@ __rwsem_do_wake(struct rw_semaphore *sem, enum rwsem_wake_type wake_type)
>> struct list_head *next;
>> long oldcount, woken, loop, adjustment;
>>
>> + /*
>> + * up_write() cleared the owner field before calling this function.
>> + * If that field is now set, a writer must have stolen the lock and
>> + * the wakeup operation should be aborted.
>> + */
>> + if (rwsem_has_active_writer(sem))
>> + goto out;
> We currently allow small races between rwsem owner and counter checks.
> And __rwsem_do_wake() can be called by checking the former -- and lock
> stealing is done with the counter as well. Please see below how we back
> out of such cases, as it is very much considered when granting the next
> reader. So nack to this as is, sorry.
If the first one in the queue is a writer, wake_up_process() may be
called directly which can be quite expensive if the lock has already
been stolen as the task will have to sleep again. Even for reader, the
counter check is by mean of an atomic instruction which can cost
hundreds of CPU cycles, the rwsem_has_active_writer() check, however, is
just a few additional cycles on top of the rwsem cacheline read which is
needed by the next list_entry() function call anyway. I consider this a
low-cost way to save hundreds of wasted CPU cycles in case the lock is
stolen and the owner set.
Cheers,
Longman
next prev parent reply other threads:[~2015-04-27 20:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 17:54 [PATCH v3] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write Waiman Long
2015-04-24 20:39 ` Davidlohr Bueso
2015-04-27 20:25 ` Waiman Long [this message]
2015-04-28 18:17 ` Davidlohr Bueso
2015-04-29 19:58 ` Waiman Long
2015-04-30 14:12 ` Davidlohr Bueso
2015-04-30 20:25 ` Waiman Long
2015-04-28 16:52 ` Peter Zijlstra
2015-04-28 17:17 ` Peter Zijlstra
2015-04-28 17:50 ` Jason Low
2015-04-28 17:59 ` Jason Low
2015-04-28 18:05 ` Davidlohr Bueso
2015-04-30 21:34 ` Waiman Long
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=553E9B25.4060802@hp.com \
--to=waiman.long@hp.com \
--cc=dave@stgolabs.net \
--cc=doug.hatch@hp.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hp.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;
as well as URLs for NNTP newsgroup(s).