是否可以“挂”?带有 SCHED_FIFO 进程的 Linux 机器?

发布于 2024-09-16 11:22:53 字数 460 浏览 4 评论 0原文

我想要一个实时进程接管我的计算机。 :)

我一直在玩这个。我创建了一个本质上是 while (1) 的进程(从不阻塞也不产生处理器),并使用 schedtoolSCHED_FIFO 策略来运行它(也尝试过chrt)。然而,该进程也让其他进程运行。

然后有人告诉我有关 sched_rt_runtime_ussched_rt_period_us 的信息。因此,我将运行时设置为 -1 以使实时进程接管处理器(并尝试使两个值相同),但它也不起作用。

我在 Linux 2.6.27-16-server 上,在一台只有一个 CPU 的虚拟机中。我做错了什么?

谢谢,

编辑:我不需要叉子炸弹。我只想让一个进程永远运行,而不让其他进程运行。

I want to have a real-time process take over my computer. :)

I've been playing a bit with this. I created a process which is essentially a while (1) (never blocks nor yields the processor) and used schedtool to run it with SCHED_FIFO policy (also tried chrt). However, the process was letting other processes run as well.

Then someone told me about sched_rt_runtime_us and sched_rt_period_us. So I set the runtime to -1 in order to make the real-time process take over the processor (and also tried making both values the same), but it didn't work either.

I'm on Linux 2.6.27-16-server, in a virtual machine with just one CPU. What am I doing wrong?

Thanks,

EDIT: I don't want a fork bomb. I just want one process to run forever, without letting other processes run.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

调妓 2024-09-23 11:22:53

还有另一种我不知道的保护措施。

如果您只有一个处理器,并且想要一个像这样的 SCHED_FIFO 进程(一个从不主动阻塞或让出处理器的进程)来独占它,除了给它一个高优先级(在大多数情况下并不是真正必要的,但没有坏处)您必须:

  1. sched_rt_runtime_us 设置为 -1sched_rt_period_us 中的值
  2. 如果您配置了组调度,请设置 < code>/cgroup/cpu.rt_runtime_us 到 -1 (如果
    你将 cgroup 文件系统挂载到 /cgroup 上)

显然,我配置了组调度并且没有绕过最后的保护。

如果您有 N 个处理器,并且希望您的 N 进程独占处理器,您只需执行相同的操作,但从 shell 启动所有这些进程(shell 不应该得到一直卡住,直到启动最后一个,因为它将有处理器运行)。如果您想真正确定每个进程都会转到不同的处理器,请相应地设置其 CPU 关联性。

感谢大家的回复。

There's another protection I didn't know about.

If you have just one processor and want a SCHED_FIFO process like this (one that never blocks nor yields the processor voluntarily) to monopolize it, besides giving it a high priority (not really necessary in most cases, but doesn't hurt) you have to:

  1. Set sched_rt_runtime_us to -1 or to the value in sched_rt_period_us
  2. If you have group scheduling configured, set /cgroup/cpu.rt_runtime_us to -1 (in case
    you mount the cgroup filesystem on /cgroup)

Apparently, I had group scheduling configured and wasn't bypassing that last protection.

If you have N processors, and want your N processes to monopolize the processor, you just do the same but launch all of them from your shell (the shell shouldn't get stuck until you launch the last one, since it will have processors to run on). If you want to be really sure each process will go to a different processor, set its CPU affinity accordingly.

Thanks to everyone for the replies.

缱绻入梦 2024-09-23 11:22:53

我不确定 schedtool,但如果您成功地将调度程序使用 sched_setscheduler 更改为 SCHED_FIFO,然后运行一项不会阻塞的任务,那么一个核心将完全分配给该任务。如果这是唯一的核心,则根本不会运行任何 SCHED_OTHER 任务(即除了少数内核线程之外的任何任务)。

我自己也尝试过。

因此,我推测您的“非阻塞”任务被阻塞,或者您的 schedtool 程序未能更改调度程序(或将其更改为错误的任务)。

I'm not sure about schedtool, but if you successfully change the scheduler using sched_setscheduler to SCHED_FIFO, then run a task which does not block, then one core will be entirely allocated to the task. If this is the only core, no SCHED_OTHER tasks will run at all (i.e. anything except a few kernel threads).

I've tried it myself.

So I speculate that either your "non blocking" task was blocking, or your schedtool program failed to change the scheduler (or changed it for the wrong task).

云裳 2024-09-23 11:22:53

您还可以让您处理最高优先级为 1 的 SCHED_FIFO。这样该进程将永远运行并且不会被抢占。

Also You can make you process a SCHED_FIFO with highest priority of 1. So the process would run forever and it wont be pre-empted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文