6
votes

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.

  1. What am I missing?
  2. 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?
  3. Will setting the scheduling policy with sched_setscheduler() in the parent change the behaviour of the child that was created before?

Thanks in advance.

1

1 Answers

6
votes

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...