Skip to contentSkip to conversation

sched/rt: Document why has_pushable_tasks() isn't called with a runqueue lock

PATCH Superseded Steven Rostedt 2 participants 3 messages Feb 28, 2017 – Mar 2, 2017 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Steven Rostedt

author reviewer
#0 lore raw

PATCH 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
index 4101f9d..f39449b 100644
@@ -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);
maintainer
#1 lore raw

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.

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);
author reviewer
#2 lore raw
Quoted 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);