Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical use of Linux real time scheduling priorities (SCHED_FIFO and SCHED_RR)?

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.

like image 225
digby280 Avatar asked May 12 '12 10:05

digby280


People also ask

What is real-time scheduling in Linux?

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.

What is SCHED_FIFO in Linux?

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.

Which scheduling policy is used in Linux?

Linux supports 3 scheduling policies: SCHED_FIFO, SCHED_RR, and SCHED_OTHER.

How do I change scheduling policy in Linux?

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


1 Answers

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

like image 123
R.. GitHub STOP HELPING ICE Avatar answered Sep 28 '22 09:09

R.. GitHub STOP HELPING ICE