I am currently playing around with the POSIX Realtime Extensions API implementation in Linux. It offers the function sched_rr_get_interval(), which allows to get the quantum for a process in the SCHED_RR (real-time round robin) scheduling class. I asked myself why one need to provide a PID to this function – it could be expected that for the SCHED_RR scheduling class the quantum value is system-wide.
After searching the web, Martin pointed me to something very cool – the XRAT page. Citation:
“The rationale used to justify the simple time-quantum scheduler is that it is common practice to depend upon this type of scheduling to ensure ‘fair’ distribution of processor resources among portions of the application that must interoperate in a serial fashion. Note that IEEE Std 1003.1-2001 is silent with respect to the setting of this time quantum, or whether it is a system-wide value or a per-process value, although it appears that the prevailing realtime practice is for it to be a system-wide value.”
In Linux kernel 2.4.27, the function reads the quantum value from the nice (!) member in the task_struct for the given PID. Since sys_nice() does not check for the scheduling class, you can set the quantum of a SCHED_RR RT process in Linux with a simple nice() call (POSIX does not support the setting of the quantum). If you now want to achieve a specific quantum length, this becomes tricky. The nice value is another representation of a ticks, which is scaled in accordance to the system speed (more speed, less ticks for the same nice value). The resulting value is called jiffies in the scheduling case. The duration of one jiffie (or one tick) again depends on the clock frequency of the particular system. The method therefore returns different time specs for systems of different speed.