* Re: sched_yield() on 2.6.25
[not found] <fa.5iKTy3xTJkKWZLGio+GIHXi3+0o@ifi.uio.no>
@ 2008-06-08 22:09 ` Robert Hancock
2008-06-09 6:37 ` Jakub Jozwicki
0 siblings, 1 reply; 11+ messages in thread
From: Robert Hancock @ 2008-06-08 22:09 UTC (permalink / raw)
To: Jakub W. Jozwicki; +Cc: linux-kernel
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.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sched_yield() on 2.6.25
2008-06-08 22:09 ` sched_yield() on 2.6.25 Robert Hancock
@ 2008-06-09 6:37 ` Jakub Jozwicki
2008-06-09 9:03 ` Helge Hafting
2008-06-09 15:04 ` Peter Zijlstra
0 siblings, 2 replies; 11+ messages in thread
From: Jakub Jozwicki @ 2008-06-09 6:37 UTC (permalink / raw)
To: linux-kernel; +Cc: Robert Hancock
> > 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.
>From the man sched_yield:
A process can relinquish the processor voluntarily without blocking by
calling sched_yield(). The process will then be moved to the end of the
queue for its static priority and a new process gets to run.
and also IEEE/Open Group:
http://www.opengroup.org/onlinepubs/000095399/functions/sched_yield.html
>> pthread_mutex_lock(&mutex);
> > th = pthread_self();
> > if (pthread_equal(th,last_th)) {
> > pthread_mutex_unlock(&mutex);
> > sched_yield();
> > continue;
Here with SCHED_OTHER sched_yield for the first 100-200 times does nothing.
Should the man be updated?
Regards,
Jakub
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sched_yield() on 2.6.25
2008-06-09 6:37 ` Jakub Jozwicki
@ 2008-06-09 9:03 ` Helge Hafting
2008-06-09 15:04 ` Peter Zijlstra
1 sibling, 0 replies; 11+ messages in thread
From: Helge Hafting @ 2008-06-09 9:03 UTC (permalink / raw)
To: Jakub Jozwicki; +Cc: linux-kernel, Robert Hancock
Jakub Jozwicki wrote:
> From the man sched_yield:
>
> A process can relinquish the processor voluntarily without blocking by
> calling sched_yield(). The process will then be moved to the end of the
> queue for its static priority and a new process gets to run.
>
> and also IEEE/Open Group:
> http://www.opengroup.org/onlinepubs/000095399/functions/sched_yield.html
>
>
>>> pthread_mutex_lock(&mutex);
>>> th = pthread_self();
>>> if (pthread_equal(th,last_th)) {
>>> pthread_mutex_unlock(&mutex);
>>> sched_yield();
>>> continue;
>>>
>
> Here with SCHED_OTHER sched_yield for the first 100-200 times does nothing.
> Should the man be updated?
>
Having the man page mention the fact that that sched_yield() probably
won't do "what you intend" in the non-realtime cases is probably a
good idea;
that way we get fewer application programmers who mistakenly think
that sched_yield can be used for their purposes. And then we'll have
less broken apps.
A pointer to info about what they might want to use instead is even better.
Helge Hafting
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sched_yield() on 2.6.25
2008-06-09 6:37 ` Jakub Jozwicki
2008-06-09 9:03 ` Helge Hafting
@ 2008-06-09 15:04 ` Peter Zijlstra
1 sibling, 0 replies; 11+ messages in thread
From: Peter Zijlstra @ 2008-06-09 15:04 UTC (permalink / raw)
To: Jakub Jozwicki; +Cc: linux-kernel, Robert Hancock
On Mon, 2008-06-09 at 08:37 +0200, Jakub Jozwicki wrote:
> > > 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.
>
> From the man sched_yield:
>
> A process can relinquish the processor voluntarily without blocking by
> calling sched_yield(). The process will then be moved to the end of the
> queue for its static priority and a new process gets to run.
>
> and also IEEE/Open Group:
> http://www.opengroup.org/onlinepubs/000095399/functions/sched_yield.html
Yeah, except that is for Real-Time scheduling classes, SCHED_OTHER
doesn't have static priority queues.
SCHED_OTHER doesn't have a specified implementation - so relying on it
to do anything specific is well outside the scope of definition.
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <aCBfw-3Cv-23@gated-at.bofh.it>]
* sched_yield() on 2.6.25
@ 2008-06-08 11:34 Jakub W. Jozwicki
2008-06-09 9:35 ` Andrew Morton
0 siblings, 1 reply; 11+ messages in thread
From: Jakub W. Jozwicki @ 2008-06-08 11:34 UTC (permalink / raw)
To: linux-kernel
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:
Setting cpu mask to 1
-- SYSTEM INFO -------------------
localhost: Linux 2.6.24-rt4 #8 SMP PREEMPT RT Mon Jan 21 18:45:00 CET 2008
Setting priority SCHED_OTHER to 0 (normal process) for 20802
[3084102544] Thread switching time (not counted): 10709015ns
[3075709840] Thread switching time: 35468301ns
[3084102544] Thread switching time: 2793ns
[3075709840] Thread switching time 30725ns
[3084102544] Thread switching time: 10405ns
[3075709840] Thread switching time: 2724ns
[3084102544] Thread switching time: 2654ns
[3075709840] Thread switching time: 2653ns
[3084102544] Thread switching time: 3352ns
[3075709840] Thread switching time: 2583ns
[3084102544] Thread switching time: 2514ns
[3075709840] Thread switching time: 2514ns
[3084102544] Thread switching time: 2584ns
[3075709840] Thread switching time: 2584ns
[3084102544] Thread switching time: 2584ns
[3075709840] Thread switching time: 2584ns
[3084102544] Thread switching time: 2584ns
[3075709840] Thread switching time: 2584ns
[3084102544] Thread switching time: 2583ns
[3075709840] Thread switching time: 2584ns
[3084102544] Thread switching time: 2583ns
[3084102544] n=20, min=2514, max=35468301, avg=1777723, stddev=7729151
Setting priority SHED_FIFO to 99 (range is 1-99) for 20802
[3084102544] Thread switching time (not counted): 31004ns
[3075709840] Thread switching time: 2444ns
[3084102544] Thread switching time: 2305ns
[3075709840] Thread switching time: 2305ns
[3084102544] Thread switching time: 2374ns
[3075709840] Thread switching time: 2374ns
[3084102544] Thread switching time: 2374ns
[3075709840] Thread switching time: 2375ns
[3084102544] Thread switching time: 2305ns
[3075709840] Thread switching time: 2374ns
[3084102544] Thread switching time: 2305ns
[3075709840] Thread switching time: 2375ns
[3084102544] Thread switching time: 2305ns
[3075709840] Thread switching time: 2305ns
[3084102544] Thread switching time: 2305ns
[3075709840] Thread switching time: 2305ns
[3084102544] Thread switching time: 2304ns
[3075709840] Thread switching time: 2304ns
[3084102544] Thread switching time: 2374ns
[3075709840] Thread switching time: 2374ns
[3084102544] Thread switching time: 2304ns
[3084102544] n=20, min=2304, max=2444, avg=2339, stddev=41
--------------------------------------------------------------------------
Ustawianie maski procesorow na 1
-- SYSTEM INFO -------------------
hackett: Linux 2.6.25.4-rt6 #5 SMP PREEMPT RT Sun Jun 8 12:40:15 CEST 2008
Ustawianie priorytetu dla SCHED_OTHER na 0 (zwykly proces) dla 20511
[3085323152] Czas przelaczania watku (pomijany): 9286166ns
[3076930448] Czas przelaczania watku: 38678449ns
[3085323152] Czas przelaczania watku: 1181784ns
[3076930448] Czas przelaczania watku: 284114ns
[3085323152] Czas przelaczania watku: 2894642ns
[3076930448] Czas przelaczania watku: 975962ns
[3085323152] Czas przelaczania watku: 2010730ns
[3076930448] Czas przelaczania watku: 980292ns
[3085323152] Czas przelaczania watku: 2004934ns
[3076930448] Czas przelaczania watku: 983994ns
[3085323152] Czas przelaczania watku: 2009682ns
[3076930448] Czas przelaczania watku: 984343ns
[3085323152] Czas przelaczania watku: 2013036ns
[3076930448] Czas przelaczania watku: 979035ns
[3085323152] Czas przelaczania watku: 2013664ns
[3076930448] Czas przelaczania watku: 973727ns
[3085323152] Czas przelaczania watku: 1688204ns
[3076930448] Czas przelaczania watku: 309397ns
[3085323152] Czas przelaczania watku: 985181ns
[3076930448] Czas przelaczania watku: 997822ns
[3085323152] Czas przelaczania watku: 996495ns
[3085323152] n=20, min=284114, max=38678449, avg=3197274, stddev=8164859
Ustawianie priorytetu dla SHED_FIFO na 99 (zakres 1-99) dla 20511
[3085323152] Czas przelaczania watku (pomijany): 39740ns
[3076930448] Czas przelaczania watku: 2723ns
[3085323152] Czas przelaczania watku: 2444ns
[3076930448] Czas przelaczania watku: 2445ns
[3085323152] Czas przelaczania watku: 2444ns
[3076930448] Czas przelaczania watku: 2445ns
[3085323152] Czas przelaczania watku: 2444ns
[3076930448] Czas przelaczania watku: 2445ns
[3085323152] Czas przelaczania watku: 2375ns
[3076930448] Czas przelaczania watku: 2445ns
[3085323152] Czas przelaczania watku: 2375ns
[3076930448] Czas przelaczania watku: 2375ns
[3085323152] Czas przelaczania watku: 2444ns
[3076930448] Czas przelaczania watku: 2374ns
[3085323152] Czas przelaczania watku: 2375ns
[3076930448] Czas przelaczania watku: 2375ns
[3085323152] Czas przelaczania watku: 2445ns
[3076930448] Czas przelaczania watku: 2444ns
[3085323152] Czas przelaczania watku: 2375ns
[3076930448] Czas przelaczania watku: 2374ns
[3085323152] Czas przelaczania watku: 2445ns
[3085323152] n=20, min=2374, max=2723, avg=2430, stddev=75
Is this behavior expected?
Regards,
Jakub
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sched_yield() on 2.6.25
2008-06-08 11:34 Jakub W. Jozwicki
@ 2008-06-09 9:35 ` Andrew Morton
0 siblings, 0 replies; 11+ messages in thread
From: Andrew Morton @ 2008-06-09 9:35 UTC (permalink / raw)
To: Jakub W. Jozwicki; +Cc: linux-kernel
On Sun, 8 Jun 2008 13:34:10 +0200 "Jakub W. Jozwicki" <jozwicki@aster.pl> 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:
>
> Setting cpu mask to 1
>
> -- SYSTEM INFO -------------------
>
> localhost: Linux 2.6.24-rt4 #8 SMP PREEMPT RT Mon Jan 21 18:45:00 CET 2008
>
> Setting priority SCHED_OTHER to 0 (normal process) for 20802
> [3084102544] Thread switching time (not counted): 10709015ns
> [3075709840] Thread switching time: 35468301ns
> [3084102544] Thread switching time: 2793ns
> [3075709840] Thread switching time 30725ns
> [3084102544] Thread switching time: 10405ns
> [3075709840] Thread switching time: 2724ns
> [3084102544] Thread switching time: 2654ns
> [3075709840] Thread switching time: 2653ns
> [3084102544] Thread switching time: 3352ns
> [3075709840] Thread switching time: 2583ns
> [3084102544] Thread switching time: 2514ns
> [3075709840] Thread switching time: 2514ns
It would save us some time if you were to tell us what these results
mean, please.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-06-13 8:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <fa.5iKTy3xTJkKWZLGio+GIHXi3+0o@ifi.uio.no>
2008-06-08 22:09 ` sched_yield() on 2.6.25 Robert Hancock
2008-06-09 6:37 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox