A thread (or task) will loss dynamic priority by using a lot of cpu and gain priority by using less of CPU. How exactly are these priorities computed for n threads (using normal scheduling policy SCHED_OTHER )?
Threads scheduled with this “real-time” policy can be assigned a priority (under linux) in the range 1..99 with 99 representing the highest priority. Since ordinary, “non-real time” processes execute at priority 0 (nice(1) modifies a “dynamic priority” which only…
How To Use POSIX Thread Priority Scheduling under Linux - EPICS Controls The linux scheduler supports the SCHED_FIFO scheduling policy defined by POSIX.1-2001. Threads scheduled with this “real-time” policy can be assigned a priority (under linux) in the range 1..99 with 99 representing the highest priority.
We know that a thread with high priority will get preference over lower priority threads when it comes to the execution of threads. However, there can be other scenarios where two threads can have the same priority.
In most cases, the thread scheduler schedules the threads according to their priority (known as preemptive scheduling). But it is not guaranteed because it depends on JVM specification that which scheduling it chooses.
Quoting from this document, section 5.4.2:
The Linux 2.6.8.1 scheduler rewards I/O-bound tasks and punishes CPU-bound tasks by adding or subtracting from a task’s static priority. The adjusted priority is called a task’s dynamic priority, and is accessible via the task’s
prio
variable (e.g.p->prio
wherep
is a task). If a task is interactive (the scheduler’s term for I/O bound), its priority is boosted. If it is a CPU hog, it will get a penalty. In the Linux 2.6.8.1 scheduler, the maximum priority bonus is 5 and the maximum priority penalty is 5. Since the scheduler uses bonuses and penalties, adjustments to a task’s static priority are respected. A mild CPU hog with a nice value of -2 might have a dynamic priority of 0, the same as a task that is neither a CPU nor an I/O hog.
I feel this is a fair explanation. The priority is computed based on whether it is a CPU bound thread or an I/O bound one. And regarding what you mentioned in the question, that gain priority by using less of CPU is rather gain priority by being interactive(I/O bound). I hope this excerpt answers your query...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With