Environment - embedded device with linux kernel 2.6.18 Requirements - 3 threads (created from one process, lets say P1 created T1, T2, T3)
T1 is at linux priority 99 (The highest), T2 is at linux priority 50 (The mid), T3 is at linux priority 2 (the lowest). No nice values is set explicitly for any of the threads.
Both T1, and T3 increments a variable once per second. T1 prints both variables once per 5 seconds. This goes smooth. [Problematic place] When T2 enters into an infinite loop "for(;;);", there after T1's count is increasing properly, but T3's count is not at all increasing. Meaning which T3 has never got time to run in CPU.
All this time I was thinking CFS of linux guarantees all priorities will get its appropriate share (based on weightage). But this proves that any thread which goes to hog CPU without sleeping, stopping all other lower priority threads from running.
Plz answer if anyone knows why CFS scheduler behaves in this way and if there is a way to correct this?
For threads scheduled under one of the normal scheduling policies (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used in scheduling decisions (it must be specified as 0).So you either have CFS, which is replacement for SCHED_OTHER, so doesn't use priorities. Or you have priorities and real time-like policy. In the latter case the behaviour observed by you is fine.SCHED_RRandSCHED_FIFO(real-time) scheduling policies. Highest priority wins. If your priority 99 thread never blocks, the lower priority threads will never run at all, nor will any other process (on this cpu). EvenSCHED_RR(round-robin) is only round-robin among threads at the same priority. This is why @Maquefel asked about your scheduling policy. You don't getSCHED_FIFO/SCHED_RRunless you asked for it, and you have to be super-user to get it at all.