如何使用 Linux 调度程序将 CPU 核心限制为仅 2 个应用程序?

How to restrict a CPU core to only 2 applications using Linux scheduler?

我想研究 CPU 内核上两个应用程序之间的交互,一个是持久应用程序(NVM 驻留),另一个是常规应用程序(DRAM 驻留)。为此,我只想将这 2 个应用程序安排在一个核心上,而不是其他任何东西。我正在查看 Linux 调度程序来完成此任务。有人可以帮助我实现这一目标吗?我可以使用 sched 来实现吗?还是我需要修改内核的调度程序代码,以便调度程序不会将应用程序调度到我感兴趣的核心。

可以使用内核的isolcpus命令行参数:

This option can be used to specify one or more CPUs to isolate from the general SMP balancing and scheduling algorithms. You can move a process onto or off an "isolated" CPU via the CPU affinity syscalls or cpuset.

isolcpus 是一个解决方案,但 linux kernel documentation 声明它已弃用:

isolcpus= [KNL,SMP,ISOL] Isolate a given set of CPUs from disturbance.
[Deprecated - use cpusets instead]

cgroups 的cpuset 子系统是首选。像 partrt 这样的工具就是基于这个原则将 CPU 核心分成两个子集: nrt 其中所有进程 运行 和 rt 您可以将应用程序移动到其中。因此,应用程序在某些 CPU 个核心上被隔离。