Question on Linux and SCHED_FIFO scheduling for POSIX threads

From: Eirik Nordbrøden
Date: Fri Jul 16 2004 - 04:13:42 EST


Hello

Can anybody clarify how SCHED_FIFO scheduling and thread priorities works on Linux? We are novices in this field in the Linux environment and needs help to understand how it works. To verify the behaviour we made up a small test program consisting of four threads and a mutex. We have run the program on both the 2.6.5 and 2.6.7 kernels with same behaviour.

Program:

T-MAIN: scheduling policy=SCHED_FIFO, priority=1
T-LP: scheduling policy=SCHED_FIFO, priority=10
T-MP: scheduling policy=SCHED_FIFO, priority=20
T-HP: scheduling policy=SCHED_FIFO, priority=30

The program runs like this:

T-MAIN locks mutex => T-MAIN runs.
T-MAIN creates T-LP => T-LP runs.
T-LP waits for mutex => T-MAIN runs.
T-MAIN creates T-MP => T-MP runs.
T-MP waits for mutex => T-MAIN runs.
T-MAIN creates T-HP => T-HP runs.
T-HP waits for mutex => T-MAIN runs.
T-MAIN waits 3 seconds and unlocks mutex => T-LP runs.
T-LP waits 3 seconds and unlocks mutex => T-MP runs.
T-MP waits 3 seconds and unlocks mutex => T-HP runs.
:
:

For us this is unexpected behaviour. We would expect that the thread with the highest priority would be scheduled to run when a number of threads is waiting for a mutex and the mutex is unlocked. Can anyone clarify this? Have we missed something?

PS We have also tested this with POSIX and System V semaphores in stead of the mutex with same behaviour.

Eirik Nordbrøden
moreCom A/S http://www.moreCom.no/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/