I am experimenting with SCHED_FIFO
and I am seeing some unexpected behaviour. The server I am using has 12 cores with hyper-threading disabled. All configurable interrupts have been set to run on CPU 0.
我正在尝试SCHED_FIFO,我看到一些意想不到的行为。我使用的服务器有12个内核,禁用超线程。所有可配置中断都设置为在CPU 0上运行。
My program starts creates a thread for lower priority tasks using the pthreads library without changing the scheduling policy with CPU affinity set to core 0. The parent thread then sets its CPU affinity to core 3 and its own scheduling policy to SCHED_FIFO
using sched_setscheduler()
with pid zero and priority 1 and then starts running a non-blocking loop.
我的程序启动使用pthreads库为低优先级任务创建一个线程,而不更改CPU关联设置为核心0的调度策略。然后,父线程使用sched_setscheduler()将其CPU亲和性设置为核心3,并将其自己的调度策略设置为SCHED_FIFO pid为零,优先级为1,然后开始运行非阻塞循环。
The program itself runs well. However, if I attempt to log into the server for a second time while the program is running the terminal is unresponsive until I stop my program. It is like the scheduler is trying to run other processes on the same core as the real time process.
该计划本身运行良好。但是,如果我在程序运行时尝试第二次登录服务器,则终端无响应,直到我停止我的程序。就像调度程序试图在与实时进程相同的核心上运行其他进程一样。
- What am I missing?
- Will the scheduler still attempt to run other processes on a core running a real time process? If so, is there a way to prevent this?
- Will setting the scheduling policy with
sched_setscheduler()
in the parent change the behaviour of the child that was created before?
我错过了什么?
调度程序是否仍会尝试在运行实时进程的核心上运行其他进程?如果是这样,有没有办法防止这种情况?
是否在父级中使用sched_setscheduler()设置调度策略会更改之前创建的子级的行为?
Thanks in advance.
提前致谢。
1 个解决方案
#1
5
sched_setscheduler
sets the scheduler of the process, not the thread. See:
sched_setscheduler设置进程的调度程序,而不是线程。看到:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setscheduler.html
If you want to set the scheduler for a thread, you need to use the pthread_attr_setschedpolicy
and pthread_attr_setschedparam
functions on the attribute object for the new thread before you create it.
如果要为线程设置调度程序,则需要在创建新线程的属性对象上使用pthread_attr_setschedpolicy和pthread_attr_setschedparam函数。
I'm not sure how conformant Linux is on honoring these requirements, but you should at least start out by making sure your code is correct to the specification, then adjust it as needed...
我不确定Linux是否符合这些要求,但至少应该首先确保您的代码符合规范,然后根据需要进行调整......
#1
5
sched_setscheduler
sets the scheduler of the process, not the thread. See:
sched_setscheduler设置进程的调度程序,而不是线程。看到:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setscheduler.html
If you want to set the scheduler for a thread, you need to use the pthread_attr_setschedpolicy
and pthread_attr_setschedparam
functions on the attribute object for the new thread before you create it.
如果要为线程设置调度程序,则需要在创建新线程的属性对象上使用pthread_attr_setschedpolicy和pthread_attr_setschedparam函数。
I'm not sure how conformant Linux is on honoring these requirements, but you should at least start out by making sure your code is correct to the specification, then adjust it as needed...
我不确定Linux是否符合这些要求,但至少应该首先确保您的代码符合规范,然后根据需要进行调整......