mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kirill Tkhai <tkhai@yandex.ru>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>
Subject: [PATCH]sched/rt: Reduce race between inc_rt_group and do_sched_rt_period_timer
Date: Mon, 03 Mar 2014 01:21:29 +0400	[thread overview]
Message-ID: <25081393795289@web10g.yandex.ru> (raw)

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.

Signed-off-by: Kirill Tkhai <tkhai@yandex.ru>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Ingo Molnar <mingo@redhat.com>
---
 kernel/sched/rt.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index facc824..db5303f 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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));
+			}
 		}
 	}
 }

                 reply	other threads:[~2014-03-02 21:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25081393795289@web10g.yandex.ru \
    --to=tkhai@yandex.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®