SCHED_WEAK vs linux regular threads
Hi,
I'm a bit puzzled about how SCHED_WEAK behaves vs linux regular threads.
Suppose a kernel built without CONFIG_XENO_OPT_SCHED_WEAK (so, only 0 is a valid value for sched_priority, which should be the same as SCHED_OTHER).
Let’s say i have four threads :
* thread 1, RT, with SCHED_FIFO policy and a sched_param value of 90
* thread 2, RT, with SCHED_WEAK policy and a sched_param value of 0
* thread 3, RT, with SCHED_WEAK policy and a sched_param value of 0
* thread 4, non-RT, with SCHED_RR policy and a sched_param value of 30
Now, what happens regarding the scheduling ?
* thread 1 always run first as long as it does not leave the primary domain
* thread 2 and 3 enters the primary domain only during xenomai xthread- only calls ? And leaves it just after.
* if thread 2 and 4 competes for the CPU (while thread 2 is in the secondary domain), who is given CPU ?
* how does thread 2 and 3 competes (while in secondary mode) against linux kernel (while in secondary mode) ? And other programs ? (ie, can a SCHED_WEAK process eating all cpu hang the whole linux system, like with standard RT threads).
* is there a way to prioritize thread 2 and thread 3 (while in the secondary domain) ? (for example by adjusting a posix only priority). Or is it the whole reason behind CONFIG_XENO_OPT_SCHED_WEAK ?
Regards,
Julien
Quoted 5 lines · Julien Blanc via Xenomai
Hi,
I'm a bit puzzled about how
SCHED_WEAKbehaves vs linux regular threads.
Quoted 8 lines
Suppose a kernel built without
CONFIG_XENO_OPT_SCHED_WEAK(so, only 0 is a valid value forsched_priority, which should be the same asSCHED_OTHER).Let’s say i have four threads :
* thread 1, RT, withSCHED_FIFOpolicy and asched_paramvalue of 90
* thread 2, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0
* thread 3, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0
Should 2 and 3 have the same parameters in your scenario?
Quoted 9 lines
* thread 4, non-RT, with
SCHED_RRpolicy and asched_paramvalue of 30Now, what happens regarding the scheduling ?
* thread 1 always run first as long as it does not leave the primary domain
* thread 2 and 3 enters the primary domain only during xenomai xthread- only calls ? And leaves it just after.
* if thread 2 and 4 competes for the CPU (while thread 2 is in the secondary domain), who is given CPU ?
4, due to SCHED_RR vs. SCHED_WEAK with prio 0 -> Linux SCHED_NORMAL.
Quoted 4 lines
* how does thread 2 and 3 competes (while in secondary mode) against linux kernel (while in secondary mode) ? And other programs ? (ie, can a
SCHED_WEAKprocess eating all cpu hang the whole linux system, like with standard RT threads).
SCHED_WEAK maps to SCHED_NORMAL/OTHER with prio = 0. With prio > 0, it is mapped on SCHED_FIFO Linux-wise.
Quoted 3 lines
* is there a way to prioritize thread 2 and thread 3 (while in the secondary domain) ? (for example by adjusting a posix only priority). Or is it the whole reason behind
CONFIG_XENO_OPT_SCHED_WEAK?
You can assign non-zero prios to thread 2 and 3, ordering it this way, but then also while both are in primary mode. For "weak" ordering, you could also leave their prio at 0 and play with their nice level. That would be a Linux-only "prio".
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 7 lines · Julien Blanc via Xenomai
Hi,
Let’s say i have four threads :
* thread 1, RT, withSCHED_FIFOpolicy and asched_paramvalue of 90
* thread 2, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0
* thread 3, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0Should 2 and 3 have the same parameters in your scenario?
That is not necessary. But our kernel currently lacks OPT_SCHED_WEAK, so i need to consider whether we need to rebuild and deploy a new one or not (i’d like to avoid it for now).
Quoted 4 lines
You can assign non-zero prios to thread 2 and 3, ordering it this way, but then also while both are in primary mode. For "weak" ordering, you could also leave their prio at 0 and play with their nice level. That would be a Linux-only "prio".
I’ll give that a try.
Thanks and thanks to Philippe for your detailed answers, this is much clearer now.
Regards,
Julien
Quoted 15 lines · Julien Blanc via Xenomai
Hi,
I'm a bit puzzled about how
SCHED_WEAKbehaves vs linux regular threads.Suppose a kernel built without
CONFIG_XENO_OPT_SCHED_WEAK(so, only 0 is a valid value forsched_priority, which should be the same asSCHED_OTHER).Let’s say i have four threads :
* thread 1, RT, withSCHED_FIFOpolicy and asched_paramvalue of 90
* thread 2, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0
* thread 3, RT, withSCHED_WEAKpolicy and asched_paramvalue of 0
* thread 4, non-RT, withSCHED_RRpolicy and asched_paramvalue of 30
Quoted 3 lines
Now, what happens regarding the scheduling ?
* thread 1 always run first as long as it does not leave the primary domain
Yes.
Quoted 2 lines
* thread 2 and 3 enters the primary domain only during xenomai xthread- only calls ? And leaves it just after.
Correct, unless they hold some Cobalt mutex(es) in which case the switch back to secondary mode is deferred until the (outer) mutex is dropped.
Quoted 2 lines
* if thread 2 and 4 competes for the CPU (while thread 2 is in the secondary domain), who is given CPU ?
thread 4, since in secondary mode this would be SCHED_OTHER(thread2) vs SCHED_RR(thread4).
Quoted 4 lines
* how does thread 2 and 3 competes (while in secondary mode) against linux kernel (while in secondary mode) ? And other programs ? (ie, can a
SCHED_WEAKprocess eating all cpu hang the whole linux system, like with standard RT threads).
Cobalt [SCHED_WEAK,0] translates to Linux [SCHED_OTHER] Cobalt [SCHED_WEAK,1-99] translates to Linux [SCHED_FIFO,1-99]
So you could definitely starve other threads with the latter if running a busy loop in secondary mode.
Quoted 2 lines
* is there a way to prioritize thread 2 and thread 3 (while in the secondary domain) ?
You need to give them non-zero SCHED_WEAK priorities to do that, which would translate as SCHED_FIFO,<prio> on the plain Linux side.
(for example by adjusting a posix only priority).
Quoted 2 lines
Or is it the whole reason behind
CONFIG_XENO_OPT_SCHED_WEAK?
The whole idea behind SCHED_WEAK - which is an extension of the original behavior of SCHED_OTHER,0 threads already available with Xenomai 2.x to the regular SCHED_FIFO class - is about keeping the priority order consistent for threads which need to cross primary/secondary domain boundaries, while ensuring that those threads - when running in primary mode - cannot compete with Cobalt-managed real-time scheduling classes.
IOW, there is a hierarchy in scheduling classes, which Cobalt abides by when looking for the next thread to run (by decreasing priority order):
1. SCHED_FIFO, SCHED_RR (round-robin is in essence FIFO+quantum timer)
2. SCHED_QUOTA
3. SCHED_SPORADIC
4. SCHED_TP
5. SCHED_WEAK (when members run in primary mode)
6. SCHED_IDLE (regular inband/secondary mode context when there is no Cobalt activity basically, including SCHED_WEAK threads running in secondary mode)
Signature · 1 line
Philippe.