哪些任务对应于Linux内核调度程序?

时间:2022-01-04 05:01:42

In Linux at Kernel level we have threads/tasks (belonging to Kernel and user), e.g.,

在Linux内核级别,我们有线程/任务(属于内核和用户),例如,

swapper: is a kernel thread (process 0), the ancestor of all processes, created from scratch during the initialization phase of Linux by the start_kernel() function. Also

swapper:是一个内核线程(进程0),是start_kernel()函数在Linux初始化阶段从头开始创建的所有进程的祖先。也

init: an additional kernel thread, process 1 (init process)

init:一个额外的内核线程,进程1(init进程)

HelloWorld: A thread for user program

HelloWorld:用户程序的一个线程

My question is about the Kernel scheduler, that performs the following jobs:

我的问题是关于内核调度程序,它执行以下作业:

-Schedule tasks within a fixed amount of time (i.e. context-switching)

- 在固定的时间内安排任务(即上下文切换)

-Calculate the timeslices dynamically (short/long vs priority based)

- 动态计算时间片(基于短/长与优先级)

-Assigns process priorities dynamically (when needed)

- 动态分配流程优先级(需要时)

-Monitoring the processes to its jobs (does this include any further?)

- 监视进程到其工作(这包括进一步吗?)

More specifically my questions becomes: Which thread/task(s) at Kernel level correspond to the scheduler? Should it be 'scheduler' etc or Does any other task from kernel do its job?

更具体地说,我的问题变成:内核级别的哪个线程/任务对应于调度程序?应该是'调度程序'等还是来自内核的任何其他任务都能完成它的工作?

P.S.:

"swapper" in kernel is an idle thread/task with lowest priority (halt) [1]. Does this do anything other than "step-down"?

内核中的“swapper”是具有最低优先级(暂停)的空闲线程/任务[1]。除了“降压”之外,这会做什么吗?

Does Linux create a dedicated instance of scheduler for each core in multi-core system? If no, then how it does on multicore?

Linux是否为多核系统中的每个核心创建了一个专用的调度程序实例?如果不是,那么它在多核上的表现如何呢?

[1] Why do we need a swapper task in linux?

[1]为什么我们需要linux中的交换器任务?

2 个解决方案

#1


2  

The Linux scheduler does not have a task or thread corresponding to it. The Linux scheduler code, mainly the schedule() function, is run when the timer used for scheduling issues an interrupt or when it is explicitly called in the kernel code (e.g. as part of a system call).

Linux调度程序没有与之对应的任务或线程。 Linux调度程序代码(主要是schedule()函数)在用于调度的计时器发出中断或在内核代码中显式调用时(例如,作为系统调用的一部分)运行。

On multicore, the scheduler code is run independently on each core. The timer interrupt received on Core 0 is usually broadcast by using IPIs (Inter-Processor Interrupts) to the other cores. If the platform has per CPU timers, then Linux usually uses these to issue the interrupt required for scheduling instead of using IPIs.

在多核上,调度程序代码在每个核心上独立运行。 Core 0上收到的定时器中断通常通过使用IPI(处理器间中断)到其他内核进行广播。如果平台具有每个CPU计时器,则Linux通常使用这些来发出调度所需的中断而不是使用IPI。

#2


-1  

I don't think there is a separate thread that runs the scheduler. schedule() is the function which does the scheduling. Some of the places where schedule() function may be called from:

我不认为有一个单独的线程运行调度程序。 schedule()是执行调度的函数。可以从以下位置调用schedule()函数的某些位置:

  1) A process(A user space or kernel space) which is executing the kernel code wants to wait for some event (calls any of the wait functions)
  2) A process which calls schedule() function to yield the processor for itself for sometime.
  3) Every time when a timer interrupt is generated.

Like this there may be many places where the schedule() function may be invoked.

像这样,可能有许多地方可以调用schedule()函数。

#1


2  

The Linux scheduler does not have a task or thread corresponding to it. The Linux scheduler code, mainly the schedule() function, is run when the timer used for scheduling issues an interrupt or when it is explicitly called in the kernel code (e.g. as part of a system call).

Linux调度程序没有与之对应的任务或线程。 Linux调度程序代码(主要是schedule()函数)在用于调度的计时器发出中断或在内核代码中显式调用时(例如,作为系统调用的一部分)运行。

On multicore, the scheduler code is run independently on each core. The timer interrupt received on Core 0 is usually broadcast by using IPIs (Inter-Processor Interrupts) to the other cores. If the platform has per CPU timers, then Linux usually uses these to issue the interrupt required for scheduling instead of using IPIs.

在多核上,调度程序代码在每个核心上独立运行。 Core 0上收到的定时器中断通常通过使用IPI(处理器间中断)到其他内核进行广播。如果平台具有每个CPU计时器,则Linux通常使用这些来发出调度所需的中断而不是使用IPI。

#2


-1  

I don't think there is a separate thread that runs the scheduler. schedule() is the function which does the scheduling. Some of the places where schedule() function may be called from:

我不认为有一个单独的线程运行调度程序。 schedule()是执行调度的函数。可以从以下位置调用schedule()函数的某些位置:

  1) A process(A user space or kernel space) which is executing the kernel code wants to wait for some event (calls any of the wait functions)
  2) A process which calls schedule() function to yield the processor for itself for sometime.
  3) Every time when a timer interrupt is generated.

Like this there may be many places where the schedule() function may be invoked.

像这样,可能有许多地方可以调用schedule()函数。