Which real-time priority is the highest priority in Linux

后端 未结 7 1671
长情又很酷
长情又很酷 2020-12-12 12:44

In the Linux real-time process priority range 1 to 99, it\'s unclear to me which is the highest priority, 1 or 99.

Section 7.2.2 of \"Understanding the Linux Kerne

7条回答
  •  忘掉有多难
    2020-12-12 13:26

    Your assumption that normal processes have static priorities from 100 to 139 is volatile at best and invalid at worst. What I mean is that: set_scheduler only allows the sched_priority to be 0 (which indicates dynamic priority scheduler) with SCHED_OTHER / SCHED_BATCH and SCHED_IDLE (true as of 2.6.16).

    Programmatically static priorities are 1-99 only for SCHED_RR and SCHED_FIFO

    Now you may see priorities from 100-139 being used internally by a dynamic scheduler howeve,r what the kernel does internally to manage dynamic priorities (including flipping the meaning of high vs. low priority to make the comparison or sorting easier) should be opaque to the user-space.

    Remember in SCHED_OTHER you are mostly stuffing the processes in the same priority queue.

    The idea is to make kernel easier to debug and avoid goofy out-of-bound mistakes.

    So the rationale in switching the meaning could be that as a kernel developer don't want to use math like 139-idx (just in case idx > 139) ... it is better to do math with idx-100 and reverse the concept of low vs. high because idx < 100 is well understood.

    Also a side effect is that niceness becomes easier to deal with. 100 - 100 <=> nice == 0; 101-100 <=> nice == 1; etc. is easier. It collapses to negative numbers nicely as well (NOTHING to do with static priorities) 99 - 100 <=> nice == -1 ...

提交回复
热议问题