nice(NI), priority(PR), realtime priority(RT)的算术关系( 二 )
随着时间的发展 sched 也会不断的改进。Linux kernel before 2.6.0:Multilevel feedback queueLinux kernel 2.6.0–2.6.23:O(1) schedulerLinux kernel after 2.6.23:Completely Fair SchedulerRefer to: Scheduling (computing)二、新的 Kernel Scheduler最新的 kernel 里面的 scheduler 就比较复杂了。944 /*945 * __normal_prio - return the priority that is based on the static prio946 */947 static inline int __normal_prio(struct task_struct *p)948 {949 return p-\u0026gt;static_prio;950 }951 952 /*953 * Calculate the expected normal priority: i.e. priority954 * without taking RT-inheritance into account. Might be955 * boosted by interactivity modifiers. Changes upon fork,956 * setprio syscalls, and whenever the interactivity957 * estimator recalculates.958 */959 static inline int normal_prio(struct task_struct *p)960 {961 int prio;962 963 if (task_has_dl_policy(p))964 prio = MAX_DL_PRIO-1;965 else if (task_has_rt_policy(p))966 prio = MAX_RT_PRIO-1 - p-\u0026gt;rt_priority;967 else968 prio = __normal_prio(p);969 return prio;970 }971 972 /*973 * Calculate the current priority, i.e. the priority974 * taken into account by the scheduler. This value might975 * be boosted by RT tasks, or might be boosted by976 * interactivity modifiers. Will be RT if the task got977 * RT-boosted. If not then it returns p-\u0026gt;normal_prio.978 */979 static int effective_prio(struct task_struct *p)980 {981 p-\u0026gt;normal_prio = normal_prio(p);982 /*983 * If we are RT tasks or we were boosted to RT priority,984 * keep the priority unchanged. Otherwise, update priority985 * to the normal priority:986 */987 if (!rt_prio(p-\u0026gt;prio))988 return p-\u0026gt;normal_prio;989 return p-\u0026gt;prio;990 }Linux/kernel/sched/core.c1. 如果是 normal process, process priority (PT) 就是 p-\u0026gt;normal_prio(也就是 p-\u0026gt;static_prio)。static_prio 的计算方法是: 4 #define MAX_NICE 19 5 #define MIN_NICE -20 6 #define NICE_WIDTH (MAX_NICE - MIN_NICE + 1) 7 8 /* 9 * Priority of a process goes from 0..MAX_PRIO-1, valid RT 10 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 11 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 12 * values are inverted: lower p-\u0026gt;prio value means higher priority. 13 * 14 * The MAX_USER_RT_PRIO value allows the actual maximum 15 * RT priority to be separate from the value exported to 16 * user-space. This allows kernel threads to set their 17 * priority to a value higher than any user task. Note: 18 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 19 */ 20 21 #define MAX_USER_RT_PRIO 100 22 #define MAX_RT_PRIO MAX_USER_RT_PRIO 23 24 #define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH) 25 #define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2) 26 27 /* 28 * Convert user-nice values 29 * to static priority , 30 * and back. 31 */ 32 #define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO) 33 #define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
推荐阅读
- 欧洲品牌|玛莎拉蒂Ghibli Fenice限量版国交车,陈伟霆都来了,不要太火
- 玛莎拉蒂|玛莎拉蒂新Ghibli Fenice限量版交车仪式,陈伟霆成为中国市场10位车主之一
- 玛莎拉蒂|陈伟霆为首批车主 Ghibli Fenice限量版正式交车
- 宇尘说车|宇尘说车│玛莎拉蒂新Ghibli Fenice限量版驰骋而来
- 界面新闻|玛莎拉蒂新Ghibli Fenice限量版开始交付,陈伟霆成为中国市场10位车主之一
- 环球车讯网|Nice车圈日报 | 大众ID.4推迟美国上市,雷诺工会通过裁员计划
- 以太网中vlan priority优先级是怎样在广域网传输中继承的
- 环球车讯网|Nice车圈日报 | 恒驰汽车正式发布车标,路虎7座版发现改款
- 趣头条|全新一代保时捷911 GT3 RS赛道测试谍照曝光 这大尾翼真Nice!
- 趣头条|高颜值、充足的动力,家用代步瑞虎8很nice
