From: Waiman Long <waiman.long@hp.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Davidlohr Bueso <davidlohr@hp.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Darren Hart <dvhart@linux.intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Mike Galbraith <efault@gmx.de>,
jeffm@suse.com, "Norton, Scott J" <scott.norton@hp.com>,
tom.vaden@hp.com, "Chandramouleeswaran, Aswin" <aswin@hp.com>,
Jason Low <jason.low2@hp.com>
Subject: Re: [PATCH 4/5] futex: Avoid taking hb lock if nothing to wakeup
Date: Fri, 22 Nov 2013 23:05:55 -0500 [thread overview]
Message-ID: <529029A3.4080009@hp.com> (raw)
In-Reply-To: <CA+55aFz9o2K-CEp+ECEaTgmP2fU=Eh7_o58VGmM1sOhKhu_n=w@mail.gmail.com>
On 11/22/2013 08:25 PM, Linus Torvalds wrote:
> On Fri, Nov 22, 2013 at 4:56 PM, Davidlohr Bueso<davidlohr@hp.com> wrote:
>> In futex_wake() there is clearly no point in taking the hb->lock if
>> we know beforehand that there are no tasks to be woken. This comes
>> at the smaller cost of doing some atomic operations to keep track of
>> the list's size.
> Hmm. Why? Afaik, you only care about "empty or not". And if you don't
> need the serialization from locking, then afaik you can just do a
> "plist_head_empty()" without holding the lock.
>
> NOTE!
>
> The "list_empty()" function is very much designed to work even without
> holding a lock (as long as the head itself exists reliably, of course)
> BUT you have to then guarantee yourself that your algorithm doesn't
> have any races wrt other CPU's adding an entry to the list at the same
> time. Not holding a lock obviously means that you are not serialized
> against that.. We've had problems with people doing
>
> if (!list_empty(waiters))
> wake_up_list(..)
>
> because they wouldn't wake people up who just got added.
>
> But considering that your atomic counter checking has the same lack of
> serialization, at least the plist_head_empty() check shouldn't be any
> worse than that counter thing.. And doesn't need any steenking atomic
> ops or a new counter field.
>
> Linus
Before the patch, a waker will wake up one or waiters who call
spin_lock() before the waker. If we just use plist_head_empty(), we will
miss waiters who have called spin_lock(), but have not yet got the lock
or inserted itself into the wait list. By adding atomic counter for
checking purpose, we again has a single point where any waiters who pass
that point (inc atomic counter) can be woken up by a waiter who check
the atomic counter after they inc it. This acts sort of like
serialization without using a lock.
-Longman
next prev parent reply other threads:[~2013-11-23 4:06 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-23 0:56 [PATCH 0/5] futex: Wakeup optimizations Davidlohr Bueso
2013-11-23 0:56 ` [PATCH 1/5] futex: Misc cleanups Davidlohr Bueso
2013-11-23 6:52 ` Darren Hart
2013-11-23 0:56 ` [PATCH 2/5] futex: Check for pi futex_q only once Davidlohr Bueso
2013-11-23 6:33 ` Darren Hart
2013-11-24 5:19 ` Davidlohr Bueso
2013-11-23 0:56 ` [PATCH 3/5] futex: Larger hash table Davidlohr Bueso
2013-11-23 6:52 ` Darren Hart
2013-11-23 0:56 ` [PATCH 4/5] futex: Avoid taking hb lock if nothing to wakeup Davidlohr Bueso
2013-11-23 1:25 ` Linus Torvalds
2013-11-23 3:03 ` Jason Low
2013-11-23 3:19 ` Davidlohr Bueso
2013-11-23 7:23 ` Darren Hart
2013-11-23 13:16 ` Thomas Gleixner
2013-11-24 3:46 ` Linus Torvalds
2013-11-24 5:15 ` Davidlohr Bueso
2013-11-25 12:01 ` Thomas Gleixner
2013-11-25 16:23 ` Thomas Gleixner
2013-11-25 16:36 ` Peter Zijlstra
2013-11-25 17:32 ` Thomas Gleixner
2013-11-25 17:38 ` Peter Zijlstra
2013-11-25 18:55 ` Davidlohr Bueso
2013-11-25 19:52 ` Thomas Gleixner
2013-11-25 19:47 ` Thomas Gleixner
2013-11-25 20:03 ` Darren Hart
2013-11-25 20:26 ` Thomas Gleixner
2013-11-26 13:53 ` Thomas Gleixner
2013-11-23 4:05 ` Waiman Long [this message]
2013-11-23 5:40 ` Darren Hart
2013-11-23 5:42 ` Hart, Darren
2013-11-23 7:20 ` Darren Hart
2013-11-23 0:56 ` [PATCH 5/5] sched,futex: Provide delayed wakeup list Davidlohr Bueso
2013-11-23 11:48 ` Peter Zijlstra
2013-11-23 12:01 ` Peter Zijlstra
2013-11-24 5:25 ` Davidlohr Bueso
2013-11-23 5:55 ` [PATCH 0/5] futex: Wakeup optimizations Darren Hart
2013-11-23 6:35 ` Mike Galbraith
2013-11-23 6:38 ` Davidlohr Bueso
-- strict thread matches above, loose matches on Subject: below --
2014-01-12 23:31 [PATCH v6 " Davidlohr Bueso
2014-01-12 23:31 ` [PATCH 4/5] futex: Avoid taking hb lock if nothing to wakeup Davidlohr Bueso
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=529029A3.4080009@hp.com \
--to=waiman.long@hp.com \
--cc=aswin@hp.com \
--cc=davidlohr@hp.com \
--cc=dvhart@linux.intel.com \
--cc=efault@gmx.de \
--cc=jason.low2@hp.com \
--cc=jeffm@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hp.com \
--cc=tglx@linutronix.de \
--cc=tom.vaden@hp.com \
--cc=torvalds@linux-foundation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.