Linux CFS(完全公平的调度器)延迟

时间:2021-04-27 02:14:42

I am a beginner to the Linux Kernel and I am trying to learn how Linux schedules processes.

我是Linux内核的初学者,我正在尝试学习Linux进程的进程。

I have read some books on the Linux Kernel and gone through the links from IBM http://www.ibm.com/developerworks/linux/library/l-cfs/ and all, but I am still left with some doubts.

我已经阅读了一些关于Linux内核的书籍,并浏览了IBM http://www.ibm.com/developerworks/linux/library/l-cfs/以及所有的链接,但是我仍然有一些疑问。

  1. How does the scheduler schedule all of the tasks within the sysctl_sched_latency time?
  2. 调度程序如何调度sysctl_sched_latency时间内的所有任务?
  3. When a process wakes up what actually is done in the place_entity function?
  4. 当进程醒来时,place_entity函数实际上做了什么?
  5. When a process wakes up why is the vruntime adjusted by subtracting from sched_latency? Can't that lead to processes in the run queue with large differences in the vruntime value?
  6. 当一个进程醒来时,为什么要通过从sched_latency中减去vruntime值来调整vruntime ?难道这不会导致运行队列中的进程在vruntime值上有很大的差异吗?

1 个解决方案

#1


10  

Firstly the virtual runtime of a task

首先是任务的虚拟运行时

  • in theory is the when the task would start its next time slice of execution on a theoretically perfect multiple threaded CPU.
  • 从理论上讲,任务将在理论上完美的多线程CPU上启动下一次执行切片。
  • in practice is its actual runtime normalized to the total number of running tasks
  • 实际上,它的实际运行时被规范化为运行任务的总数

1. How does the scheduler schedule all of the tasks within the sysctl_sched_latency time?

1。调度程序如何调度sysctl_sched_latency时间内的所有任务?

It maintains a time ordered red and black tree, where all the runnable tasks are sorted by their virtual runtime. Nodes on the left have run for the shortest amount of time. CFS picks the left most task and runs it, until the task schedules or the scheduler ticks then the CPU time it spent running is added to its virtual runtime. When it is no longer the left most node, then new task with the shortest virtual is run and the old task prempted.

它维护一个时间有序的红黑树,其中所有可运行的任务都按照它们的虚拟运行时进行排序。左边的节点运行的时间最短。CFS选择最左边的任务并运行它,直到任务调度或调度器计时,然后将它运行的CPU时间添加到它的虚拟运行时中。当它不再是最左的节点时,运行具有最短虚值的新任务,并对旧任务进行预充值。

2. When a process wakes up what actually is done in the place_entity function?

2。当进程醒来时,place_entity函数实际上做了什么?

Short version:

短版:

When a process wakes up the place_entity function either leaves the task's virtual runtime as it was or increases it.

当进程唤醒place_entity函数时,它要么保留任务的虚拟运行时,要么增加它。

Long version:

长版:

When a process wakes up the place_entity function does the following things

当进程醒来时,place_entity函数将执行以下操作

  1. Initialise the temporary virtual runtime to the the CFS run queue's virtual runtime of the smallest task.

    将临时虚拟运行时初始化为CFS运行队列中最小任务的虚拟运行时。

  2. As sleeps less than a single latency don't count, initializses a threshold variable to sysctl_sched_latency. If the GENTLE_FAIR_SLEEPERS feature is enabled, then half the value of the this variable. Decrement the previously initialised temporary virtual runtime by this threshold value.

    由于睡眠时间小于单个延迟,所以初始化一个阈值变量到sysctl_sched_latency。如果启用了GENTLE_FAIR_SLEEPERS特性,则该变量的值为该变量的一半。按此阈值递减先前初始化的临时虚拟运行时。

  3. Ensure that the temporary virtual runtime is at least equal to the task's virtual runtime, by setting the calculated virtual runtime to the maximum of itself and the task's virtual runtime.

    确保临时虚拟运行时至少与任务的虚拟运行时相等,方法是将计算得到的虚拟运行时设置为其自身的最大值,并设置任务的虚拟运行时。

  4. Set the task's virtual runtime to the temporary runtime.

    将任务的虚拟运行时设置为临时运行时。

3. When a process wakes up why is the vruntime adjusted by subtracting from sched_latency?

3所示。当一个进程醒来时,为什么要通过从sched_latency中减去vruntime值来调整vruntime ?

The virtual runtime is decremented because sleeps less than a single latency don't count. E.g the task shouldn't have its position changed in the red black tree changed if it has only slept for a single scheduler latency.

虚拟运行时是递减的,因为睡眠时间少于一个延迟是不计算的。E。任务不应该在红黑树中改变它的位置,如果它只睡一个调度器延迟。

4. Can't that lead to processes in the run queue with large differences in the vruntime value?

4所示。难道这不会导致运行队列中的进程在vruntime值上有很大的差异吗?

I believe that the logic described in Step 3 for Question 2, prevents or at least minimises that.

我相信第3步对问题2所描述的逻辑可以防止或至少将其最小化。

References

参考文献

sched.c Linux Kernel Source

固定播送时间。c Linux内核源代码

sched_fair.c Linux Kernel Source

sched_fair。c Linux内核源代码

Notes on the CFS Scheduler Design

CFS调度器设计说明

#1


10  

Firstly the virtual runtime of a task

首先是任务的虚拟运行时

  • in theory is the when the task would start its next time slice of execution on a theoretically perfect multiple threaded CPU.
  • 从理论上讲,任务将在理论上完美的多线程CPU上启动下一次执行切片。
  • in practice is its actual runtime normalized to the total number of running tasks
  • 实际上,它的实际运行时被规范化为运行任务的总数

1. How does the scheduler schedule all of the tasks within the sysctl_sched_latency time?

1。调度程序如何调度sysctl_sched_latency时间内的所有任务?

It maintains a time ordered red and black tree, where all the runnable tasks are sorted by their virtual runtime. Nodes on the left have run for the shortest amount of time. CFS picks the left most task and runs it, until the task schedules or the scheduler ticks then the CPU time it spent running is added to its virtual runtime. When it is no longer the left most node, then new task with the shortest virtual is run and the old task prempted.

它维护一个时间有序的红黑树,其中所有可运行的任务都按照它们的虚拟运行时进行排序。左边的节点运行的时间最短。CFS选择最左边的任务并运行它,直到任务调度或调度器计时,然后将它运行的CPU时间添加到它的虚拟运行时中。当它不再是最左的节点时,运行具有最短虚值的新任务,并对旧任务进行预充值。

2. When a process wakes up what actually is done in the place_entity function?

2。当进程醒来时,place_entity函数实际上做了什么?

Short version:

短版:

When a process wakes up the place_entity function either leaves the task's virtual runtime as it was or increases it.

当进程唤醒place_entity函数时,它要么保留任务的虚拟运行时,要么增加它。

Long version:

长版:

When a process wakes up the place_entity function does the following things

当进程醒来时,place_entity函数将执行以下操作

  1. Initialise the temporary virtual runtime to the the CFS run queue's virtual runtime of the smallest task.

    将临时虚拟运行时初始化为CFS运行队列中最小任务的虚拟运行时。

  2. As sleeps less than a single latency don't count, initializses a threshold variable to sysctl_sched_latency. If the GENTLE_FAIR_SLEEPERS feature is enabled, then half the value of the this variable. Decrement the previously initialised temporary virtual runtime by this threshold value.

    由于睡眠时间小于单个延迟,所以初始化一个阈值变量到sysctl_sched_latency。如果启用了GENTLE_FAIR_SLEEPERS特性,则该变量的值为该变量的一半。按此阈值递减先前初始化的临时虚拟运行时。

  3. Ensure that the temporary virtual runtime is at least equal to the task's virtual runtime, by setting the calculated virtual runtime to the maximum of itself and the task's virtual runtime.

    确保临时虚拟运行时至少与任务的虚拟运行时相等,方法是将计算得到的虚拟运行时设置为其自身的最大值,并设置任务的虚拟运行时。

  4. Set the task's virtual runtime to the temporary runtime.

    将任务的虚拟运行时设置为临时运行时。

3. When a process wakes up why is the vruntime adjusted by subtracting from sched_latency?

3所示。当一个进程醒来时,为什么要通过从sched_latency中减去vruntime值来调整vruntime ?

The virtual runtime is decremented because sleeps less than a single latency don't count. E.g the task shouldn't have its position changed in the red black tree changed if it has only slept for a single scheduler latency.

虚拟运行时是递减的,因为睡眠时间少于一个延迟是不计算的。E。任务不应该在红黑树中改变它的位置,如果它只睡一个调度器延迟。

4. Can't that lead to processes in the run queue with large differences in the vruntime value?

4所示。难道这不会导致运行队列中的进程在vruntime值上有很大的差异吗?

I believe that the logic described in Step 3 for Question 2, prevents or at least minimises that.

我相信第3步对问题2所描述的逻辑可以防止或至少将其最小化。

References

参考文献

sched.c Linux Kernel Source

固定播送时间。c Linux内核源代码

sched_fair.c Linux Kernel Source

sched_fair。c Linux内核源代码

Notes on the CFS Scheduler Design

CFS调度器设计说明