如何在Linux 2.6.x中计算线程的动态优先级?

时间:2023-02-01 02:14:08

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 )?

线程(或任务)将通过使用大量CPU来丢失动态优先级,并通过使用较少的CPU获得优先级。这些优先级究竟是如何为n个线程计算的(使用正常的调度策略SCHED_OTHER)?

1 个解决方案

#1


1  

Quoting from this

引用此

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 where p 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.

Linux 2.6.8.1调度程序通过添加或减去任务的静态优先级来奖励I / O绑定任务并惩罚CPU绑定任务。调整后的优先级称为任务的动态优先级,可通过任务的prio变量访问(例如p-> prio,其中p是任务)。如果任务是交互式的(调度程序的I / O绑定术语),则优先级提高。如果它是CPU猪,它将受到惩罚。在Linux 2.6.8.1调度程序中,最大优先级奖励为5,最大优先级惩罚为5.由于调度程序使用奖励和惩罚,因此会调整对任务的静态优先级的调整。具有良好值-2的温和CPU占用可能具有0的动态优先级,与既不是CPU也不是I / O占用的任务相同。

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...

我觉得这是一个公平的解释。优先级的计算基于CPU绑定线程还是I / O绑定线程。关于你在问题中提到的内容,通过使用较少的CPU获得优先级是通过交互(I / O绑定)获得优先级。我希望这段摘录能回答你的问题......

#1


1  

Quoting from this

引用此

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 where p 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.

Linux 2.6.8.1调度程序通过添加或减去任务的静态优先级来奖励I / O绑定任务并惩罚CPU绑定任务。调整后的优先级称为任务的动态优先级,可通过任务的prio变量访问(例如p-> prio,其中p是任务)。如果任务是交互式的(调度程序的I / O绑定术语),则优先级提高。如果它是CPU猪,它将受到惩罚。在Linux 2.6.8.1调度程序中,最大优先级奖励为5,最大优先级惩罚为5.由于调度程序使用奖励和惩罚,因此会调整对任务的静态优先级的调整。具有良好值-2的温和CPU占用可能具有0的动态优先级,与既不是CPU也不是I / O占用的任务相同。

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...

我觉得这是一个公平的解释。优先级的计算基于CPU绑定线程还是I / O绑定线程。关于你在问题中提到的内容,通过使用较少的CPU获得优先级是通过交互(I / O绑定)获得优先级。我希望这段摘录能回答你的问题......