如何知道linux调度程序时间片? [英] How to know linux scheduler time slice?

查看:40
本文介绍了如何知道linux调度程序时间片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找我的 Linux 内核的时间片(或量子)的值.

I'm looking for the value of the time slice (or quantum) of my Linux kernel.

具体问题:

  • 是否有一个 /proc 文件暴露了这样的信息?
  • (或)它是否在我的发行版的 Linux 标头中有明确定义?
  • (或)Linux API(可能是 sysinfo)的 C 函数是否公开了此值?
  • Is there a /proc file which expose such an information ?
  • (Or) Is it well-defined in the Linux header of my distributions ?
  • (Or) Is there a C function of the Linux API (maybe sysinfo) that expose this value ?

推荐答案

为特定进程分配的量程 可能会有所不同:

The quantum allocated for a particular process may vary:

您可以通过调整 sched_latency_nssched_min_granularity_ns,但请注意切片"不是固定的量子.另请注意,CFS 抢占决定基于瞬时状态.一个任务可能已经收到一个完整的(变量)CPU 时间的切片",但只有在更多时才会触发抢占应得的任务可用,因此切片"不是最大"不间断的 CPU 时间",你可能期望它是......但它是有点相似.

You can tune "slice" by adjusting sched_latency_ns and sched_min_granularity_ns, but note that "slice" is not a fixed quantum. Also note that CFS preemption decisions are based upon instantaneous state. A task may have received a full (variable) "slice" of CPU time, but preemption will be triggered only if a more deserving task is available, so a "slice" is not the "max uninterrupted CPU time" that you may expect it to be.. but it is somewhat similar.

这是因为 Completely Fair Scheduler,默认的 Linux 调度程序,将处理器的一部分分配给进程而不是固定的时间片.这意味着每个进程的时间片是 与当前负载成比例并加权由进程的优先级值.

This is because the Completely Fair Scheduler, the default Linux scheduler, assigns a proportion of the processor to a process rather than a fixed timeslice. That means the timeslice for each process is proportional to the current load and weighted by the process' priority value.

对于使用 SCHED_RR 的特殊目的的实时进程,默认时间片在 Linux 内核中定义为 RR_TIMESLICEinclude/linux/sched/rt.h.

For special-purpose realtime processes which use SCHED_RR, the default timeslice is defined in the Linux kernel as RR_TIMESLICE in include/linux/sched/rt.h.

/*
 * default timeslice is 100 msecs (used only for SCHED_RR tasks).
 * Timeslices get refilled after they expire.
 */
#define RR_TIMESLICE            (100 * HZ / 1000)

您可以使用 sched_rr_get_interval() 来获取特定 SCHED_RR 进程的 SCHED_RR 间隔.

You can use sched_rr_get_interval() to get the SCHED_RR interval for a specific SCHED_RR process.

这篇关于如何知道linux调度程序时间片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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