Linux调度程序如何在多核处理器上调度进程? [英] How Linux scheduler schedules processes on multi-core processors?

查看:562
本文介绍了Linux调度程序如何在多核处理器上调度进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多核处理器利用线程级并行性,这意味着多个线程并行运行.假设一个进程只有一个线程,那么其他内核在执行该进程期间是否保持空闲状态?在linux系统中,调度程序将进程和线程都视为一项任务.在调度进程时,它不会区分进程和线程.那么,这是否意味着不同的内核并行执行不同进程的不同线程?

Multi-core processors exploits thread level parallelism, it means that multiple threads runs in parallel. Suppose, a process has only one thread then, do the other cores remain idle during the execution of this process? In linux system, scheduler consider processes and threads both as a task. It doesn't differentiate between process and thread while scheduling it. So, does this means that different cores executes different threads of different processes in parallel?

发生上下文切换时,这只会发生在一个CPU内核中还是所有cpu内核中吗?

When context-switch happens, does this happen only for one core or for all the cores of the cpu?

推荐答案

您是正确的:从Linux调度程序的角度来看,进程和线程是相同的.这些任务根据调度程序的规则排队,然后等待轮到他们.

You are right: processes and threads are the same from the Linux scheduler's point of view. These tasks are queued according to the scheduler's rules and wait for their turn.

有一些调度规则,例如优先级或CPU关联性(以防止线程迁移到另一个内核并保留高速缓存数据).

There are scheduling rules such as priority or CPU affinity (to prevent a thread to migrate to another core and preserve cache data).

因为CPU会定期定期运行一些内核代码以允许抢占,所以上下文切换可能会在内核上每固定的时间量(一个时间片)发生一次.根据调度程序的规则,任务可以运行许多时间片.当线程调用使其无法运行的函数时(例如,等待IO),也会发生上下文切换.

A context switch may happen on a core every fixed amount of time (a time slice) because the CPU automatically runs some kernel code periodically to permit preemption. Depending on the scheduler's rules, a task can be run for many time slices. A context switch can also occur when a thread calls functions that makes it unrunnable (eg. waiting for IO).

在某些情况下(如果不是全部的话),每个内核只有一个调度过程可以完成所有工作.

In some cases, if not all, there is one scheduling process per core which does all that.

查看全文

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