sched/rt: Document why has_pushable_tasks() isn't called with a runqueue lock
Steven Rostedt
reviewerPATCH 1/1 sched/rt: Document why has_pushable_tasks() isn't called with a runqueue lock
From: Steven Rostedt (VMware) <[email protected]>
While reviewing the RT scheduling IPI logic, I was thinking that it was a bug that has_pushable_tasks(rq) was not called under the runqueue lock. But then I realized that there isn't a case where a race would cause a problem, as to update has_pushable_tasks() would trigger a push_rt_task() call from the CPU doing the update.
This subtle logic deserves a comment.
---
kernel/sched/rt.c +10 -0
@@ -1976,6 +1976,16 @@ static void try_to_push_tasks(void *arg) src_rq =rq_of_rt_rq (rt_rq); again: +/* +* Normally, has_pushable_tasks() would be performed within the +* runqueue lock being held. But if it was not set when entering +* this hard interrupt handler function, then to have it set would +* require a wake up. A wake up of an RT task will either cause a +* schedule if the woken task is higher priority than the running +* task, or it would try to do a push from the CPU doing the wake +* up. Grabbing the runqueue lock in such a case would more likely +* just cause unnecessary contention. +*/ if (has_pushable_tasks (rq)) {raw_spin_lock (&rq->lock);push_rt_task (rq);
Peter Zijlstra
maintainerkernel/sched/rt.c static void try_to_push_tasks(void *arg) · line 1981
Quoted 3 lines · Steven Rostedt
kernel/sched/rt.c +3
-0+/* +* Normally, has_pushable_tasks() would be performed within the +* runqueue lock being held. But if it was not set when entering
"not set" what? I'm having trouble parsing this.
Quoted 10 lines
kernel/sched/rt.c +7
-0+* this hard interrupt handler function, then to have it set would +* require a wake up. A wake up of an RT task will either cause a +* schedule if the woken task is higher priority than the running +* task, or it would try to do a push from the CPU doing the wake +* up. Grabbing the runqueue lock in such a case would more likely +* just cause unnecessary contention. +*/ if (has_pushable_tasks (rq)) {raw_spin_lock (&rq->lock);push_rt_task (rq);
Steven Rostedt
reviewerQuoted 7 lines · On Wed, 1 Mar 2017 09:37:01 +0100 Peter Zijlstra <[email protected]> wrote:
kernel/sched/rt.c static void try_to_push_tasks(void *arg) · line 1981
Quoted 3 lines · Steven Rostedt
kernel/sched/rt.c +3
-0+/* +* Normally, has_pushable_tasks() would be performed within the +* runqueue lock being held. But if it was not set when entering "not set" what? I'm having trouble parsing this.
I always forgot that with documentation, pronouns should be avoided.
"But if has_pushable_tasks is false when entering"
Quoted 2 lines
kernel/sched/rt.c static void try_to_push_tasks(void *arg) · line 1982
Quoted 2 lines
kernel/sched/rt.c +1
-0+* this hard interrupt handler function, then to have it set would
", then to have it set to true would"
Quoted 9 lines
Quoted 9 lines
kernel/sched/rt.c +6
-0+* require a wake up. A wake up of an RT task will either cause a +* schedule if the woken task is higher priority than the running +* task, or it would try to do a push from the CPU doing the wake +* up. Grabbing the runqueue lock in such a case would more likely +* just cause unnecessary contention. +*/ if (has_pushable_tasks (rq)) {raw_spin_lock (&rq->lock);push_rt_task (rq);