From: Eric Dumazet <dada1@cosmosbay.com>
To: Pierre PEIFFER <pierre.peiffer@bull.net>
Cc: Ulrich Drepper <drepper@gmail.com>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
jakub@redhat.com
Subject: Re: [PATCH] 2.6.16 - futex: small optimization (?)
Date: Wed, 29 Mar 2006 17:26:00 +0200 [thread overview]
Message-ID: <442AA708.3030802@cosmosbay.com> (raw)
In-Reply-To: <442A8933.6090408@bull.net>
Pierre PEIFFER a écrit :
> Ulrich Drepper a écrit :
>>
>> There are no such situations anymore in an optimal userlevel
>> implementation. The last problem (in pthread_cond_signal) was fixed
>> by the addition of FUTEX_WAKE_OP. The userlevel code you're looking
>> at is simply not optimized for the modern kernels.
>>
>
> I think there is a misunderstanding here.
>
Hum... maybe Ulrich was answering to my own message (where I stated that most
existing multithreaded pay the price of context switches)
(To Ulrich : Most existing applications use glibc <= 2.3.6, where
FUTEX_WAKE_OP is not used yet AFAIK)
I think your analysis is correct Pierre, but you speak of 'task-switches',
where there is only a spinlock involved :
On UP case : a wake_up_all() wont preempt current thread : it will task-switch
only when current thread exits kernel mode.
On PREEMPT case : wake_up_all() wont preempt current thread (because current
thread is holding bh->lock).
On SMP : the awaken thread will spin some time on bh->lock, but not
task-switch again.
On RT kernel, this might be different of course...
> FUTEX_WAKE_OP is implemented to handle simultaneously more than one
> futex in some specific situations (such as pthread_cond_signal).
>
> The scenario I've described occurred in futex_wake, futex_wake_op and
> futex_requeue and is _independent_ of the userlevel code.
>
> All these functions call wake_futex, and then wake_up_all, with the
> futex_hash_bucket lock still held.
>
> If the woken thread is immediately scheduled (in wake_up_all), and only
> in this case (because of a higher priority, etc), it will try to take
> this lock too (because of the "if (lock_ptr != 0)" statement in
> unqueue_me), causing two task-switches to take this lock for nothing.
>
> Otherwise, it will not: lock_ptr is set to NULL just after the
> wake_up_all call)
>
> This scenario happens at least in pthread_cond_signal,
> pthread_cond_broadcast and probably all pthread_*_unlock functions.
>
> The patch I've proposed should, at least in theory, solve this. But I'm
> not sure of the correctness...
>
next prev parent reply other threads:[~2006-03-29 15:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-28 7:37 [PATCH] 2.6.16 - futex: small optimization (?) Pierre PEIFFER
2006-03-28 10:05 ` Eric Dumazet
2006-03-28 15:02 ` Ulrich Drepper
2006-03-28 22:46 ` Bill Davidsen
2006-03-29 15:26 ` Ingo Molnar
2006-03-30 20:27 ` Bill Davidsen
2006-03-31 6:01 ` Ingo Molnar
2006-03-31 14:50 ` Bill Davidsen
2006-03-31 18:15 ` Ingo Molnar
2006-03-29 13:18 ` Pierre PEIFFER
2006-03-29 15:26 ` Eric Dumazet [this message]
2006-03-30 14:51 ` Pierre PEIFFER
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=442AA708.3030802@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=drepper@gmail.com \
--cc=jakub@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pierre.peiffer@bull.net \
/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