Subj : Re: Nice value and thread priority To : comp.programming.threads From : Loic Domaigne Date : Sun Jul 24 2005 10:13 pm Hello Vinay, > I am trying to understand the scheduling in Linux. [snip] > Can anybody please explain me the relationship between the nice value > and the priority needed for thread scheduling in real time. As of Linux v2.6, the kernel uses internally 140 priorities for the scheduling (referred in the sequel as scheduling priority), ranging from 1 to 140. The kernel selects the KSE with the lowest priority to run first. Note that these priorities are only known by the kernel. The relationship with priority / nice value as defined by POSIX is given below. Real-time KSE have a scheduling priority ranging from 1 to 99. The relationship with POSIX priority is 100-p, where p is the priority as defined by POSIX. In other words, a KSE with the lowest POSIX priority (1 on linux) has a scheduling priority of 99 and the KSE with the highest POSIX priority (99 on Linux) has a scheduling priority of 1. Non real-time KSE maps linearly from 100 to 140 depending on the nice value following the formula 120+n, where n is the nice value (the nice value is comprised between -20 and 19 on Linux). In other words, a traditional KSE with a default nice value of 0 has a scheduling priority of 120. Note that the priority of a non-real time KSE is dynamically adjusted using a heuristic that includes, among other, the nice value and the current KSE activity. On the other hand, the priority of a real-time KSE is never adjusted dynamically by the kernel. This assures that a real-time KSE always preempts a non-real time one. More information about scheduling for Linux kernel v2.6 might be found in the excellent book from Robert Love "Linux Kernel Development", §3 pp31-5, ISBN 0-672-32512-8. HTH, Loic. .