有关使用Linux线程优先级和调度策略的指南? [英] Guide for working with Linux thread priorities and scheduling policies?

查看:351
本文介绍了有关使用Linux线程优先级和调度策略的指南?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上无法掌握线程(/进程)优先级的问题,计划策略选择,何时何地选择什么以及实际效果如何.

I'm having trouble getting the hang of thread(/process) prioritization on Linux, scheduling policy selection, what to choose when and how, and what the exact effects are.

在某处是否有任何文档(例如指南),最好是具体的示例和时间表,我可以参考这些文档和时间表?

Is there any documentation (like a guide) somewhere, preferably with concrete examples and timelines, which I could consult?

推荐答案

我无法在Linux上挂起线程(/进程)优先级的问题,无法调度策略选择

I'm having trouble getting the hang of thread(/process) prioritization on Linux, scheduling policy selection

优先级通过利用底层OS的线程和进程优先级来起作用,并且很难从文档的角度概括其具体细节,这也许就是为什么您没有在线找到指南的原因.

The prioritization works by utilizing the underlying OS' thread and process priorities and it is hard to generalize about the specifics of it from the standpoint of documentation which may be why you've not found guides online.

(坦率地说)我的建议是不要打扰线程优先级.我已经做了大量的线程编程,除了默认的优先级排序外,我再也没有发现需要做的其他事情.大约只有一次线程优先级会有所不同,即所有线程都完全受CPU限制,并且您希望一项或多项任务获得更多的周期.

My recommendation is (frankly) to not bother with thread priorities. I've done a large amount of threaded programming and I've never found the need to do anything but the default prioritization. About the only time thread prioritization will make a difference is if all of the threads are completely CPU bound and you want one task or another to get more cycles.

此外,我敢肯定,至少在Linux下,这与抢占无关,而与运行频率有关.许多线程实现使用优先级调度队列,因此较高频率的线程会在其中使用逻辑来获得优先级,从而避免使较低频率的线程饿死.这意味着任何IO或其他阻塞操作都将导致优先级较低的线程运行并获取其时间片.

In addition, I'm pretty sure that under Linux at least, this isn't about preemption but more about run frequency. Many thread implementations use a priority scheduling queue so higher frequency threads get preference with logic in there to avoid starving the lower frequency threads. This means that any IO or other blocking operation is going to cause a lower priority thread to run and get its time slice.

此页面是问题的很好的例子.引用:

This page is a good example of the complexities of the issue. To quote:

可以看出,线程优先级1-8最终在CPU中的份额实际上是相等的,而优先级9和10则获得了更大的份额(尽管9和10之间基本上没有区别).测试的版本是Java 6 Update10.就其价值而言,我在运行Vista的双核计算机上重复了该实验,并且结果图形的形状相同.对于优先级9和10的特殊行为,我的最佳猜测是,前台窗口中的THREAD_PRIORITY_HIGHEST具有足够的优先级,可以由调度程序执行其他某些特殊处理(例如,内部优先级14及更高级别的线程的完整量子被补充)稍等一会,而较低的优先级将它们降低了1).

As can be seen, thread priorities 1-8 end up with a practically equal share of the CPU, whilst priorities 9 and 10 get a vastly greater share (though with essentially no difference between 9 and 10). The version tested was Java 6 Update 10. For what it's worth, I repeated the experiment on a dual core machine running Vista, and the shape of the resulting graph is the same. My best guess for the special behaviour of priorities 9 and 10 is that THREAD_PRIORITY_HIGHEST in a foreground window has just enough priority for certain other special treatment by the scheduler to kick in (for example, threads of internal priority 14 and above have their full quantum replenished after a wait, whereas lower priorities have them reduced by 1).

如果必须使用线程优先级,则可能必须编写一些测试程序以了解您的体系结构如何利用它们.

If you must use thread priorities then to you may have to write some test programs to understand how your architecture utilizes them.

这篇关于有关使用Linux线程优先级和调度策略的指南?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆