From: Davide Libenzi <davidel@xmailserver.org>
To: Anton Blanchard <anton@linuxcare.com.au>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@suse.de>
Subject: Re: sys_sched_yield fast path
Date: Mon, 12 Mar 2001 01:10:30 +0100 (CET) [thread overview]
Message-ID: <XFMail.20010312011030.davidel@xmailserver.org> (raw)
In-Reply-To: <20010312005448.A5439@linuxcare.com>
On 11-Mar-2001 Anton Blanchard wrote:
>
>> This is the linux thread spinlock acquire :
>>
>>
>> static void __pthread_acquire(int * spinlock)
>> {
>> int cnt = 0;
>> struct timespec tm;
>>
>> while (testandset(spinlock)) {
>> if (cnt < MAX_SPIN_COUNT) {
>> sched_yield();
>> cnt++;
>> } else {
>> tm.tv_sec = 0;
>> tm.tv_nsec = SPIN_SLEEP_DURATION;
>> nanosleep(&tm, NULL);
>> cnt = 0;
>> }
>> }
>> }
>>
>>
>> Yes, it calls sched_yield() but this is not a std wait for mutex but for
>> spinlocks that are hold a very short time. Real wait are implemented using
>> signals. More, with the new implementation of sys_sched_yield() the task
>> release all its time quantum so, even in a case where a task repeatedly
>> calls
>> sched_yield() the call rate is not so high if there is at least one process
>> to spin. And if there isn't one task with goodness() > 0, nobody cares
>> about
>> sched_yield() performance.
>
> The problem I found with sched_yield is that things break down with high
> levels of contention. If you have 3 processes and one has a lock then
> the other two can ping pong doing sched_yield() until their priority drops
> below the process with the lock. eg in a run I just did then where 2
> has the lock:
>
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 1
> 0
> 2
>
> Perhaps we need something like sched_yield that takes off some of
> tsk->counter so the task with the spinlock will run earlier.
2.4.x has changed the scheduler behaviour so that the task that call
sched_yield() is not rescheduled by the incoming schedule().
A flag is set ( under certain conditions in SMP ) and the goodness()
calculation assign the lower value to the exiting task ( this flag is cleared
in schedule_tail() ).
This could give the task owning the lock the opportunity to complete the locked
code.
But yes, if the locked code is rescheduled for some reason ( timeslice or I/O )
the yielding task will run again.
But this is a software design problem, not a sched_yield() one coz, if the time
path between lock ans unlock can be high the use of sched_yield() is not the
best way to wait.
Wait queue or user space equivalences are a better choice to do this.
- Davide
next prev parent reply other threads:[~2001-03-11 22:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-10 0:47 sys_sched_yield fast path Mike Kravetz
2001-03-10 11:30 ` Davide Libenzi
2001-03-10 16:59 ` Andi Kleen
2001-03-11 14:12 ` Davide Libenzi
2001-03-11 13:54 ` Anton Blanchard
2001-03-11 19:17 ` Dave Zarzycki
2001-03-12 0:18 ` Davide Libenzi
2001-03-11 23:46 ` Davide Libenzi
2001-03-12 0:10 ` Davide Libenzi [this message]
2001-03-12 1:24 ` Anton Blanchard
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=XFMail.20010312011030.davidel@xmailserver.org \
--to=davidel@xmailserver.org \
--cc=ak@suse.de \
--cc=anton@linuxcare.com.au \
--cc=linux-kernel@vger.kernel.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.