All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David M. Lloyd" <dmlloyd@flurg.com>
To: david@lang.hm
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: sched_yield() options
Date: Mon, 20 Oct 2008 18:53:13 -0500	[thread overview]
Message-ID: <48FD19E9.8010807@flurg.com> (raw)
In-Reply-To: <alpine.DEB.1.10.0810201603510.21749@asgard.lang.hm>

On 10/20/2008 06:08 PM, david@lang.hm wrote:
> in the case I'm looking at there are two (or more) threads running with 
> one message queue in the center.
> 
> 'input threads' are grabbing the lock to add messages to the queue
> 
> 'output threads' are grabbing the lock to remove messages from the queue
> 
> the programmer is doing a pthread_yield() after each message is 
> processed in an attempt to help fairness (he initially added it in when 
> he started seeing starvation on single-core systems)
> 
> what should he be doing instead?

If you're seeing starvation, to me that's a good indicator that the 
granularity of queue items are too small... probably there'd be an overall 
benefit of grabbing more things at once from the queue.

To make a silly metaphor out of it - imagine you've got a bunch of office 
interns (threads) whose jobs are to fill out PQ9-12b forms.  An intern has 
to wait in line before they can get to the desk where the secretary is 
handing out the forms to be filled out, one by one.  An intern can fill out 
the form just as fast as the secretary hands it to them; if they do so, 
then one intern ends up doing all the work while the others just wait in line.

But in order to make everyone equally busy (by injecting sched_yield()) 
you're making the interns take the paper, walk back to their desk, fill it 
out, and then get back in line, which takes somewhat more time overall, 
despite making the interns look much busier.  A better solution would be to 
give each intern a big stack of forms so that they spend a greater 
proportion of time filling them out rather than waiting in line; perhaps if 
each intern is kept busy enough, the line will always be empty, which would 
be the best situation of all.

- DML

  reply	other threads:[~2008-10-21  0:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20 22:34 sched_yield() options david
2008-10-20 22:53 ` Arnaldo Carvalho de Melo
2008-10-20 23:08   ` david
2008-10-20 23:53     ` David M. Lloyd [this message]
2008-10-21  0:44       ` david
2008-10-21  0:57         ` David M. Lloyd
2008-10-21  1:04     ` David Schwartz
2008-10-21 13:42     ` Michal Hocko
2008-10-20 23:02 ` Chris Friesen

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=48FD19E9.8010807@flurg.com \
    --to=dmlloyd@flurg.com \
    --cc=acme@redhat.com \
    --cc=david@lang.hm \
    --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.