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?