From: "David Schwartz" <davids@webmaster.com>
To: "David@Lang. Hm" <david@lang.hm>
Cc: "linux-kernel" <linux-kernel@vger.kernel.org>
Subject: RE: sched_yield() options
Date: Mon, 20 Oct 2008 18:04:23 -0700 [thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKKEMLAIAD.davids@webmaster.com> (raw)
In-Reply-To: <alpine.DEB.1.10.0810201603510.21749@asgard.lang.hm>
> 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)
Yuck. That forces the worst possible scenario, which is nearly strict
alternation.
There is no reason he should ever be seeing starvation. Each thread should
either:
1) Use out its timeslice. In which case, a thread can at most be starved for
the number of threads multiplied by the size of the timeslice. If this is
too long, then you have too many threads or your timeslice is too big. You
can't fix it with ugly hacks.
2) Get blocked because it needs another thread to help it make forward
progress. In this case, there should be no starvation, since each thread
can't continue until other threads continue.
> what should he be doing instead?
Simply set a limit on the maximum number of messages that can go in the
queue when output threads are CPU limited. Output threads can't starve input
threads because they have to block if the queue is empty (assuming you never
let the queue get too ridiculously full). Input threads can't starve output
threads if there's a reasonable limit on the queue size.
> the link above talks about other cases more, but really doesn't say what
> the right thing to do is for this case.
>
> David Lang
Implement a sensible queue.
DS
next prev parent reply other threads:[~2008-10-21 1:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-20 22:34 david
2008-10-20 22:53 ` Arnaldo Carvalho de Melo
2008-10-20 23:08 ` david
2008-10-20 23:53 ` David M. Lloyd
2008-10-21 0:44 ` david
2008-10-21 0:57 ` David M. Lloyd
2008-10-21 1:04 ` David Schwartz [this message]
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=MDEHLPKNGKAHNMBLJOLKKEMLAIAD.davids@webmaster.com \
--to=davids@webmaster.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®