public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: jw schultz <jw@pegasys.ws>
To: linux-kernel@vger.kernel.org
Subject: Re: Question about sched_yield()
Date: Tue, 18 Jun 2002 19:10:59 -0700	[thread overview]
Message-ID: <20020618191059.C1001@pegasys.ws> (raw)
In-Reply-To: <20020618004630.AAA28082@shell.webmaster.com@whenever>; from davids@webmaster.com on Mon, Jun 17, 2002 at 05:46:29PM -0700

Lets back up a moment please.

On Mon, Jun 17, 2002 at 05:46:29PM -0700, David Schwartz wrote:
> 
> On Sat, 15 Jun 2002 15:15:32 -0700, mgix@mgix.com wrote:
> >
> >Hello,
> >
> >I am seeing some strange linux scheduler behaviours,
> >and I thought this'd be the best place to ask.
> >
> >I have two processes, one that loops forever and
> >does nothing but calling sched_yield(), and the other
> >is basically benchmarking how fast it can compute
> >some long math calculation.
> [snip]
> 
> 	You seem to have a misconception about what sched_yield is for. It is not a 
> replacement for blocking or a scheduling priority adjustment. It simply lets 
> other ready-to-run tasks be scheduled before returning to the current task.
> 
> 	Here's a quote from SuS3:
> 
> "The sched_yield() function shall force the running thread to relinquish the 
> processor until it again becomes the head of its thread list. It takes no 
> arguments."

.From this description it sounds like sched_yield was
intended to deal with scheduling of threads within a
process not the between processes.  Namely that there is a
"thread list" within a single process context.

This would be used for yielding to another thread within the
same list (context) when the current thread needs a
contended-for resource (an inter-thread/intra-context lock)
or the result of another thread's calculation.  Or simply to
allow switching, round-robin style, between a set of compute
intensive threads by salting the compute loops with
sched_yield.

Am i right?

Linux, as we know, treats threads and independent processes
as equals.  Therefore, the process scheduler now becomes
responsible for dealing with sched_yield and somehow
translating sched_yield's intent to a situation where threads are
contending with other processes instead of just with their
fellows and their fellows can wind up with differing
priorities.

Handled sched_yield wrong could result in a live/deadlock
(i'm fuzzy at the moment on the distinction, sorry) if one
thread is sched_yield/spinning on a resource pending action of a
lower priority thread.  It would seem that sched_yield
should make sure that the calling thread has a priority
lower than the lowest priority thread within the thread
group.

"until it again becomes the head of its thread list"
sounds to me like all other threads in the group should have
an opportunity to run before the calling thread does.

I would suggest that in the case where there are no other
threads in the group that are runnable the process should
sleep(0) so another (lower priority) process can run.



-- 
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		jw@pegasys.ws

		Remember Cernan and Schmitt

      parent reply	other threads:[~2002-06-19  2:11 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-15 22:15 Question about sched_yield() mgix
2002-06-16 14:43 ` [patch] " Ingo Molnar
2002-06-18  0:46 ` David Schwartz
2002-06-18  0:55   ` Robert Love
2002-06-18  1:51     ` mgix
2002-06-18  3:18     ` David Schwartz
2002-06-18  9:36     ` David Schwartz
2002-06-18 16:58       ` Chris Friesen
2002-06-18 17:12         ` Richard B. Johnson
2002-06-18 17:19           ` mgix
2002-06-18 18:01             ` David Schwartz
2002-06-18 18:05               ` mgix
2002-06-18 19:11                 ` David Schwartz
2002-06-18 16:58                   ` Rob Landley
2002-06-18 19:25                   ` Robert Love
2002-06-18 19:53                     ` David Schwartz
2002-06-18 20:12                       ` mgix
2002-06-18 20:42                         ` David Schwartz
2002-06-18 20:47                           ` mgix
2002-06-18 22:00                             ` David Schwartz
2002-06-18 22:28                           ` Ingo Molnar
2002-06-18 20:08                     ` Richard B. Johnson
2002-06-19 11:10                     ` Bill Davidsen
2002-06-19 12:04                       ` Ingo Molnar
2002-06-18 22:43               ` Olivier Galibert
2002-06-18 18:21             ` Richard B. Johnson
2002-06-18 17:13         ` Robert Love
2002-06-18 18:00           ` David Schwartz
2002-06-18 22:45             ` Stevie O
2002-06-19  2:11               ` David Schwartz
2002-06-19  2:52                 ` Stevie O
2002-06-20 20:31               ` David Schwartz
2002-06-18 17:23         ` Rik van Riel
2002-06-18 17:50           ` Chris Friesen
2002-06-18  1:41   ` mgix
2002-06-18  3:21     ` David Schwartz
2002-06-18  3:52       ` mgix
2002-06-18  4:55   ` Ingo Molnar
2002-06-19 11:24     ` Bill Davidsen
2002-06-19 11:47       ` scheduler timeslice distribution, threads, processes. [was: Re: Question about sched_yield()] Ingo Molnar
2002-06-18 18:56   ` Question about sched_yield() Rusty Russell
2002-06-18 19:12     ` David Schwartz
2002-06-18 20:19       ` Rusty Russell
2002-06-18 20:40         ` David Schwartz
2002-06-18 20:42         ` mgix
2002-06-18 22:03           ` David Schwartz
2002-06-18 22:36           ` Ingo Molnar
2002-06-19 11:29     ` Bill Davidsen
2002-06-19 14:03       ` Rusty Russell
2002-06-19 22:25         ` Bill Davidsen
2002-06-19 22:37           ` Ingo Molnar
2002-06-19  2:10   ` jw schultz [this message]

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=20020618191059.C1001@pegasys.ws \
    --to=jw@pegasys.ws \
    --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