本文介绍了线程量子:如何计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读一些有关线程量子的文章和文章(此处,和此处).显然,Windows根据窗口模式"(服务器或其他)为线程数量分配了固定的CPU滴答数.但是,从最后一个链接中,我们可以看到:

I have been reading a few posts and articles regarding thread quanta (here, here and here). Apparently Windows allocate a fix number of CPU ticks for a thread quantum depending on the windows "mode" (server, or something else). However from the last link we can read:

在Linux上有什么方法可以计算量子长度吗?无论如何,对它进行计算有意义吗?(由于我的理解是线程仍然可以被抢占,所以没有什么可以迫使线程在整个量子周期内运行)

Is there any way to compute the quantum length on Linux? Does that make any sense to compute it anyway? (since from my understanding threads can still be pre-empted, nothing forces a thread to run during the full duration of the quantum)

从开发人员的角度来看,我可以看到编写这样的程序的兴趣,该程序可以根据程序的线程数和它们做什么"来预测程序的运行时间(可能删除所有测试以找到最佳的线程数量).线程会很整洁,尽管我不确定这是正确的方法)

From a developer's perspective, I could see the interest in writing a program that could predict the running time of a program given its number of threads, and "what they do" (possibly removing all the testing to find the optimal number of threads would be kind of neat, although I am not sure it is the right approach)

推荐答案

  1. 在Linux上,默认的实时量子长度常数为至少在4.x内核中声明为 RR_TIMESLICE HZ 必须在配置内核时定义.
  2. 间隔之间暂停其量子已过期的线程并恢复该间隔可能取决于许多因素,例如平均负载量.
  3. 为了至少能够一定程度地预测运行时间,请给目标过程实时优先级;按照轮循算法安排实时过程,该算法通常更简单且更可预测比普通的Linux调度算法要好.
  4. 要获取实时量子长度,请调用 sched_rr_get_interval() .
  1. On Linux, the default realtime quantum length constant is declared as RR_TIMESLICE, at least in 4.x kernels; HZ must be defined while configuring the kernel.
  2. The interval between pausing the thread whose quantum has expired and resuming it may depend on a lot of things like, say, load average.
  3. To be able to predict the running time at least with some degree of accuracy, give the target process realtime priority; realtime processes are scheduled following a round-robin algorithm, which is generally simpler and more predictable than the common Linux scheduling algo.
  4. To get the realtime quantum length, call sched_rr_get_interval().

这篇关于线程量子:如何计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:46