public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Helge Hafting <helge.hafting@aitel.hist.no>
To: Bodo Eggert <7eggert@gmx.de>
Cc: Leon Woestenberg <leon.woestenberg@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jakub Jozwicki <jozwicki@aster.pl>,
	linux-kernel@vger.kernel.org, Robert Hancock <hancockr@shaw.ca>
Subject: Re: sched_yield() on 2.6.25
Date: Fri, 13 Jun 2008 10:37:58 +0200	[thread overview]
Message-ID: <485231E6.30101@aitel.hist.no> (raw)
In-Reply-To: <Pine.LNX.4.58.0806130006530.8419@be10.lrz>

Bodo Eggert wrote:
> On Thu, 12 Jun 2008, Leon Woestenberg wrote:
>   
[...]
>>
>> As the code after sched_yield() has to be executed the thread will be
>> rescheduled soon (or even immediately) anyway.
>>     
>
> The code after yield() is most likely to not run successfully (and as a
> result will return to the yield call) unless some time passes, and this
> time can pass while another process gets the CPU. It might even depend on
> another process to change the system state.
>
> Besides that, "Schedule another process, if you can" is part of the 
> semantics of yield. The code after yield should therefore be expected to 
> NOT be the very next code to run.
>
> If you can't do that, it's fine, the process will abuse some more innocent 
> electrons for busy waiting, but if you can support this yield() semantics, 
> the system will perform much better. Won't it?
>   
The system as a whole will perform better if the busy-wait is avoided - yes.
A multithreaded app actually using yield this way may suffer badly though.

Consider a case where two threads use yield() for synchronization, and 
there is
some contention. Ideally, the two threads want to ping-pong the cpu between
them. In the precence of other processes, they want to use up their fair 
amount of
cpu in this manner. If they busy-wait, then both the app and the system 
overall gets
slower.

Now, consider what happens if yield() really do lower the priority, or 
does something
like "sleep(1)  unless there really is nothing else to run". 
Busy-waiting will disappear,
and the overall performance will be fine. The app running alone will 
also seem fine.

The app running with some contention - massive use of yield - on a machine
with some other load will almost stop. Every yield will wait for all the 
other
processes on the system, not only the process/thread we needed to wait for.

Ideally, yield() from a non-realtime process should cause a segfault, 
that would
crash all software abusing it, forcing a change. Too drastic though. :-/

>> The users not understanding the limited scope where sched_yield()
>> behaves deterministicly, seem to think that _yield() will yield() AND
>> lower the thread's dynamic priority for SCHED_OTHER. Is downgrading
>> the dynamic priority a behavioral option?
>>     
>
> I expect it to be. It may cause lower-nice-level processes to run,
> but the (lack of) definition allows it.
>   
And this is the problem - suddenly those niced cpu hogs trumps an
interactive process that seems hopelessly stuck.

Helge Hafting

  reply	other threads:[~2008-06-13  8:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <aCBfw-3Cv-23@gated-at.bofh.it>
     [not found] ` <aCBfw-3Cv-21@gated-at.bofh.it>
     [not found]   ` <aCJd6-3IF-11@gated-at.bofh.it>
     [not found]     ` <aCRaM-8cM-33@gated-at.bofh.it>
2008-06-11 15:28       ` sched_yield() on 2.6.25 Bodo Eggert
2008-06-11 22:45         ` Leon Woestenberg
2008-06-12  8:09           ` Helge Hafting
2008-06-12 22:33           ` Bodo Eggert
2008-06-13  8:37             ` Helge Hafting [this message]
     [not found] <fa.5iKTy3xTJkKWZLGio+GIHXi3+0o@ifi.uio.no>
2008-06-08 22:09 ` Robert Hancock
2008-06-09  6:37   ` Jakub Jozwicki
2008-06-09  9:03     ` Helge Hafting
2008-06-09 15:04     ` Peter Zijlstra
2008-06-08 11:34 Jakub W. Jozwicki
2008-06-09  9:35 ` Andrew Morton

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=485231E6.30101@aitel.hist.no \
    --to=helge.hafting@aitel.hist.no \
    --cc=7eggert@gmx.de \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hancockr@shaw.ca \
    --cc=jozwicki@aster.pl \
    --cc=leon.woestenberg@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox