1. 進(jìn)程的nice值與static_prio之間的轉(zhuǎn)換關(guān)系
/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
*/
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
#define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
2.?進(jìn)程的用戶優(yōu)先級值與static_prio之間的轉(zhuǎn)換關(guān)系
/*
* 'User priority' is the nice value converted to something we
* can work with better when scaling various scheduler parameters,
* it's a [ 0 ... 39 ] range.
*/
#define USER_PRIO(p) ((p)-MAX_RT_PRIO)??
#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
說明:MAX_RT_PRIO為100帘营,MAX_PRIO為140票渠,即可計(jì)算出MAX_USER_PRIO=40
3. 時間片與進(jìn)程優(yōu)先級的關(guān)系
#define DEF_TIMESLICE (100 * HZ / 1000)? //默認(rèn)時間片是100ms
/*
* task_timeslice() scales user-nice values [ -20 ... 0 ... 19 ]
* to time slice values: [800ms ... 100ms ... 5ms]
*
* The higher a thread's priority, the bigger timeslices
* it gets during one round of execution. But even the lowest
* priority thread gets MIN_TIMESLICE worth of execution time.
*/
#define SCALE_PRIO(x, prio) \
max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO/2), MIN_TIMESLICE)
static unsigned int task_timeslice(task_t *p)
{
????if (p->static_prio < NICE_TO_PRIO(0))
????????return SCALE_PRIO(DEF_TIMESLICE*4, p->static_prio);
????else
????????return SCALE_PRIO(DEF_TIMESLICE, p->static_prio);
}
說明:
????當(dāng)進(jìn)程的靜態(tài)優(yōu)先級<120時,時間片=400*(140-prio)/20;
? ??當(dāng)進(jìn)程的靜態(tài)優(yōu)先級>=120時芬迄,時間片=100*(140-prio)/20;
結(jié)論:進(jìn)程的時間片與其靜態(tài)優(yōu)先級(static_prio)相關(guān)问顷,在運(yùn)行隊(duì)列中的位置與其實(shí)時優(yōu)先級相關(guān)(prio)。