Skip to contentSkip to conversation

sched/rt: Reduce race between inc_rt_group and do_sched_rt_period_timer

PATCH New Kirill Tkhai 1 participant 1 message Mar 2, 2014 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/rt: Reduce race between inc_rt_group and do_sched_rt_period_timer

Function do_sched_rt_period_timer() iterates through runqueues sequentially. This makes it racy with inc_rt_group(). Sometimes when timer callback is running we may skip hrtimer restart.

On the one hand it's not good to skip bandwidth timer. On the other hand, there is no simple fix to complitelly get rid of the race.

So, let's use a fix, which is fast and simple and almost complitelly reduces the race. It makes race probability very small.

CC Peter Zijlstra <[email protected]>
CC Ingo Molnar <[email protected]>
---
 kernel/sched/rt.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
kernel/sched/rt.c +14 -2
index facc824..db5303f 100644
@@ -923,11 +923,23 @@ static void update_curr_rt(struct rq *rq)
 		rt_rq = rt_rq_of_se(rt_se);
 
 		if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
+			bool exceed;
 			raw_spin_lock(&rt_rq->rt_runtime_lock);
 			rt_rq->rt_time += delta_exec;
-			if (sched_rt_runtime_exceeded(rt_rq))
-				resched_task(curr);
+			exceed = sched_rt_runtime_exceeded(rt_rq);
 			raw_spin_unlock(&rt_rq->rt_runtime_lock);
+
+			if (exceed) {
+				resched_task(curr);
+				/*
+				 * The pair do_sched_rt_period_timer() and
+				 * inc_rt_group() is racy. Sometimes we may
+				 * have enqueued task and stopped timer
+				 * at this point. We reduce the race and
+				 * make its probability extremely small.
+				 */
+				start_rt_bandwidth(sched_rt_bandwidth(rt_rq));
+			}
 		}
 	}
 }