2011-04-24 82 views
3

大家,我發現這裏面static int setscheduler(pid_t pid, int policy, struct sched_param *param)setscheduler()在Linux內核

p->policy = policy; 

if (policy != SCHED_OTHER) p->prio = MAX_USER_RT_PRIO-1 - p->rt_priority; 

p是指向與當前PID(以上參數)的任務描述符 因此,如果它的政策是不SCHED_OHTER(這意味着SCHED_FIFO或SCHED_RR),但爲什麼我們改變p-> prio這種方式呢?究竟是什麼意思rt_priority?在此先感謝

回答

2

簡短的回答rt_priority意味着實時優先級和SCHED_RRSCHED_FIFO它決定過程將需要多少時間獲得。

龍答案

所有Linux首先實現了一種叫Realtime Process SchedulingSCHED_RRSCHED_FIFO)。在這些政策下運營的流程始終優先於其他流程。 Linux提供99個實時優先級,編號爲1(最低)到99(最高)。

在內核中,如果我正確地記得「數字越小意味着更好的偏好」 - 越小p->prio意味着更好的優先級

這裏我們什麼sched_setscheduler樣子:

int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); 

sched_param

struct sched_param { 
    int sched_priority;  /* Scheduling priority */ 
}; 

的整數sched_priority,爲SCHED_RRSCHED_FIFO手段 「實時優先」 的策略,我認爲是rt_priority。所以內核做正確的事

  • 採取優先機器最多
  • 從該值減去實時優先級。調度器的優先級越高(它減去的越多)。