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.
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.
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.
sched_setscheduler()
in the parent change the behaviour of the child that was created before?Thanks in advance.
A real-time task scheduler would trade off throughput in favor of correctness, but at the same time, it must ensure minimal task ping-ponging. The standard Linux kernel provides two real-time scheduling policies, SCHED_FIFO and SCHED_RR. The main real-time policy is SCHED_FIFO.
SCHED_FIFO is a simple scheduling algorithm without time slicing. SCHED_RR: Round-robin scheduling. SCHED_RR is a simple enhancement of SCHED_FIFO. Everything described above for SCHED_FIFO also applies to SCHED_RR, except that each thread is allowed to run only for a maximum time quantum.
Linux supports 3 scheduling policies: SCHED_FIFO, SCHED_RR, and SCHED_OTHER.
Change Scheduling Policy “SCHED_FIFO” with Priority To change the scheduling policy of a process and set its priority level, execute the below-mentioned option with the chart command. For example, the current schedule of the program is “Sched_Batch” and we want to change it to “Sched_Fifo”.
sched_setscheduler
sets the scheduler of the process, not the thread. See:
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With