From: Robert Hancock <hancockr@shaw.ca>
To: "Jakub W. Jozwicki" <jozwicki@aster.pl>
Cc: linux-kernel@vger.kernel.org
Subject: Re: sched_yield() on 2.6.25
Date: Sun, 08 Jun 2008 16:09:14 -0600 [thread overview]
Message-ID: <484C588A.9090800@shaw.ca> (raw)
In-Reply-To: <fa.5iKTy3xTJkKWZLGio+GIHXi3+0o@ifi.uio.no>
Jakub W. Jozwicki wrote:
> Hello,
> I observe strange behavior of sched_yield() on 2.6.25 (strange comparing to
> 2.6.24). Here is the code (available at
> http://systest.googlecode.com/files/systest20080119.tgz):
>
> ------------------------------------------------------
> timer_t timer;
> sig_atomic_t cnt = 0;
> long long sum = 0;
> long times[21], min, max;
> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
> struct timespec ts = { 0, 0 };
> pthread_t last_th = 0;
>
> void *th_proc(void* p) {
> int n = SIZE(times) -1;
> pthread_t th;
>
> while(1) {
> pthread_mutex_lock(&mutex);
> th = pthread_self();
> if (pthread_equal(th,last_th)) {
> pthread_mutex_unlock(&mutex);
> sched_yield();
> continue;
> }
> rt_timer_stop(&ts);
> last_th = th;
> if (cnt>=1) {
> times[cnt-1] = ts_sum(&ts);
> if (cnt <= n) {
> sum += times[cnt-1];
> box(times[cnt-1],min,max);
> #define uint unsigned int
> printf("[%u] Thread switching time: %ldns\n",(uint)th, times[cnt-1]);
> }
> else {
> printf("[%u] Thread switching time (not counted): %ldns\n",(uint)th,
> times[cnt-1]);
> }
> cnt--;
> }
> ....
> -----------------------------------------------------
> and here are the results:
...
> Is this behavior expected?
The behavior of sched_yield with SCHED_OTHER processes has changed
several times with Linux over the years, since its behavior is not
defined by standards, so it's really "whatever the scheduler feels like
doing". The behavior is only defined with realtime scheduling
(SCHED_FIFO or SCHED_OTHER).
Generally, it's a mistake to assume specific timing behavior from
sched_yied for SCHED_OTHER processes.
next parent reply other threads:[~2008-06-08 22:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fa.5iKTy3xTJkKWZLGio+GIHXi3+0o@ifi.uio.no>
2008-06-08 22:09 ` Robert Hancock [this message]
2008-06-09 6:37 ` sched_yield() on 2.6.25 Jakub Jozwicki
2008-06-09 9:03 ` Helge Hafting
2008-06-09 15:04 ` Peter Zijlstra
[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 ` 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
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=484C588A.9090800@shaw.ca \
--to=hancockr@shaw.ca \
--cc=jozwicki@aster.pl \
--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