整体一核专用于单进程 [英] Whole one core dedicated to single process

查看:21
本文介绍了整体一核专用于单进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux 中是否有任何方法可以将一个 CPU 内核分配给特定的给定进程,并且不应在该内核上调度任何其他进程或中断处理程序?

Is there any way in Linux to assign one CPU core to a particular given process and there should not be any other processes or interrupt handlers to be scheduled on this core?

我已经阅读了 Linux 中的进程关联使用任务集实用程序将进程绑定到 CPU 但这并没有解决我的问题,因为 它只是尝试将给定的进程关联到该核心,但它是可能在这个核心上安排了其他进程,这是我想要避免的.

I have read about process affinity in Linux Binding Processes to CPUs using the taskset utility but that's not solving my problem because it just try to affine the given process to that core but it is possible that other processes may be scheduled on this core and this is what I want to avoid.

我们是否应该更改用于调度的内核代码?

Should we change the kernel code for scheduling?

推荐答案

是的.事实上,有两种不同的方法可以做到这一点:-)

Yes there is. In fact, there are two separate ways to do it :-)

现在,实现您想要的最佳方式是执行以下操作:

Right now, the best way to accomplish what you want is to do the following:

  1. 在引导期间从引导加载程序向 Linux 内核命令行添加参数 isolcpus=[cpu_number].这将指示 Linux 调度程序不要在该 CPU 上运行任何常规任务,除非使用 CPU 关联性特别要求.

  1. Add the parameter isolcpus=[cpu_number] to the Linux kernel command line from the boot loader during boot. This will instruct the Linux scheduler not to run any regular tasks on that CPU unless specifically requested using cpu affinity.

使用 IRQ 关联来设置其他 CPU 来处理所有中断,这样您的隔离 CPU 就不会收到任何中断.

Use IRQ affinity to set other CPUs to handle all interrupts so that your isolated CPU will not receive any interrupts.

使用 CPU 亲和性将您的特定任务固定到隔离的 CPU.

Use CPU affinity to fix your specific task to the isolated CPU.

这将为您提供 Linux 在 CPU 隔离方面所能提供的最佳性能,无需外挂和开发中的补丁.

This will give you the best that Linux can provide with regard to CPU isolation without out-of-tree and in-development patches.

您的任务仍然会不时被 Linux 代码中断,包括其他任务 - 例如计时器滴答中断和调度程序代码、来自其他 CPU 的 IPI 以及诸如工作队列内核线程之类的东西,尽管中断应该相当最小.

Your task will still get interrupted from time to time by Linux code, including other tasks - such as the timer tick interrupt and the scheduler code, IPIs from other CPUs and stuff like work queue kernel threads, although the interruption should be quite minimal.

有关(几乎)完整的中断源列表,请查看我在 https://github 上的页面.com/gby/linux/wiki

For an (almost) complete list of interruption sources, check out my page at https://github.com/gby/linux/wiki

另一种方法是使用 cpuset,它更优雅和动态,但在这个时间点存在一些弱点(例如没有定时器迁移),这让我推荐旧的、粗糙但有效的 isolcpus 参数.

The alternative method is to use cpusets which is way more elegant and dynamic but suffers from some weaknesses at this point in time (no migration of timers for example) which makes me recommend the old, crude but effective isolcpus parameter.

请注意,Linux 社区目前正在开展工作以解决所有这些问题,并进一步提供更好的隔离.

Note that work is currently being done by the Linux community to address all these issues and more to give even better isolation.

这篇关于整体一核专用于单进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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