c - 如何知道linux调度器时间片?

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

具体问题:

  • 是否有 /proc 文件可以公开此类信息?
  • (或)它在我的发行版的 Linux header 中是否明确定义?
  • (或者)Linux API 的 C 函数(可能是 sysinfo)是否公开了这个值?

最佳答案

为特定进程分配的量程may vary :

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 调度程序,assigns a proportion of the processor到一个过程而不是一个固定的时间片。这意味着每个进程的时间片是 proportional to the current load and weighted by the process' priority value .

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

/*
 * 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 间隔。

https://stackoverflow.com/questions/16401294/

相关文章:

linux - 通过 linux x86-64 函数调用保留了哪些寄存器

linux - 使用 shell 脚本将行附加到/etc/hosts 文件

linux - 从 FTP 服务器下载所有文件

c - 枚举中这些#define 的目的是什么?

linux - 进程可以拥有的每个不同 UID 的目的是什么?

linux - 解释导出 LANG、LC_CTYPE 和 LC_ALL 的效果

c - Linux 中的 bluetooth/bluetooth.h 位于何处?

linux - 如何在 Linux 上记录内存消耗?

linux - 双斜杠//in `cd//` 在 Linux 中是什么意思?

linux - 我可以阅读 Linux 内核的哪些部分以获得乐趣?