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

标签 c linux operating-system pthreads scheduled-tasks

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

最佳答案

引自this document , 第 5.4.2 节:

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.

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

关于c - Linux 2.6.x 中线程的动态优先级是如何计算的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577403/

相关文章:

c++ - 循环链表算法

c - 简单的C文本扫描和打印

c++ - 为什么 gdb 不适用于这个简单的 hello world 程序?

unix - Darwin OS已经打折了,但是原来的源代码还能找到吗?

c++ - 如何在 C++ 中读取系统信息?

operating-system - 为什么操作系统软件是从硬盘加载而不是从ROM芯片加载?

c - 使用四舍五入的数据取平均值

为 .txt 文件中的每个条目创建一个新节点

linux - 页缓存与 L1 缓存?

c++ - 如何在Linux上使用Ptrace打印C++其他进程的调用栈