public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Ben Segall <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, bsegall@google.com, hpa@zytor.com,
	mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de
Subject: [tip:sched/core] sched: Avoid throttle_cfs_rq() racing with period_timer stopping
Date: Tue, 29 Oct 2013 07:07:49 -0700	[thread overview]
Message-ID: <tip-f9f9ffc237dd924f048204e8799da74f9ecf40cf@git.kernel.org> (raw)
In-Reply-To: <20131016181632.22647.84174.stgit@sword-of-the-dawn.mtv.corp.google.com>

Commit-ID:  f9f9ffc237dd924f048204e8799da74f9ecf40cf
Gitweb:     http://git.kernel.org/tip/f9f9ffc237dd924f048204e8799da74f9ecf40cf
Author:     Ben Segall <bsegall@google.com>
AuthorDate: Wed, 16 Oct 2013 11:16:32 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 29 Oct 2013 12:02:32 +0100

sched: Avoid throttle_cfs_rq() racing with period_timer stopping

throttle_cfs_rq() doesn't check to make sure that period_timer is running,
and while update_curr/assign_cfs_runtime does, a concurrently running
period_timer on another cpu could cancel itself between this cpu's
update_curr and throttle_cfs_rq(). If there are no other cfs_rqs running
in the tg to restart the timer, this causes the cfs_rq to be stranded
forever.

Fix this by calling __start_cfs_bandwidth() in throttle if the timer is
inactive.

(Also add some sched_debug lines for cfs_bandwidth.)

Tested: make a run/sleep task in a cgroup, loop switching the cgroup
between 1ms/100ms quota and unlimited, checking for timer_active=0 and
throttled=1 as a failure. With the throttle_cfs_rq() change commented out
this fails, with the full patch it passes.

Signed-off-by: Ben Segall <bsegall@google.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: pjt@google.com
Link: http://lkml.kernel.org/r/20131016181632.22647.84174.stgit@sword-of-the-dawn.mtv.corp.google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/debug.c | 8 ++++++++
 kernel/sched/fair.c  | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index e6ba5e3..5c34d18 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -229,6 +229,14 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
 			atomic_read(&cfs_rq->tg->runnable_avg));
 #endif
 #endif
+#ifdef CONFIG_CFS_BANDWIDTH
+	SEQ_printf(m, "  .%-30s: %d\n", "tg->cfs_bandwidth.timer_active",
+			cfs_rq->tg->cfs_bandwidth.timer_active);
+	SEQ_printf(m, "  .%-30s: %d\n", "throttled",
+			cfs_rq->throttled);
+	SEQ_printf(m, "  .%-30s: %d\n", "throttle_count",
+			cfs_rq->throttle_count);
+#endif
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	print_cfs_group_stats(m, cpu, cfs_rq->tg);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0923ab2..41c02b6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3112,6 +3112,8 @@ static void throttle_cfs_rq(struct cfs_rq *cfs_rq)
 	cfs_rq->throttled_clock = rq_clock(rq);
 	raw_spin_lock(&cfs_b->lock);
 	list_add_tail_rcu(&cfs_rq->throttled_list, &cfs_b->throttled_cfs_rq);
+	if (!cfs_b->timer_active)
+		__start_cfs_bandwidth(cfs_b);
 	raw_spin_unlock(&cfs_b->lock);
 }
 

      parent reply	other threads:[~2013-10-29 14:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16 18:16 [PATCH 0/5] Fix several races in CFS_BANDWIDTH Ben Segall
2013-10-16 18:16 ` [PATCH 1/5] sched: Fix race on toggling cfs_bandwidth_used Ben Segall
2013-10-29 14:07   ` [tip:sched/core] " tip-bot for Ben Segall
2013-10-16 18:16 ` [PATCH 2/5] sched: Fix cfs_bandwidth misuse of hrtimer_expires_remaining Ben Segall
2013-10-16 18:41   ` Peter Zijlstra
2013-10-16 19:12     ` bsegall
2013-10-29 14:07   ` [tip:sched/core] " tip-bot for Ben Segall
2013-10-16 18:16 ` [PATCH 3/5] sched: Fix hrtimer_cancel/rq->lock deadlock Ben Segall
2013-10-29 14:07   ` [tip:sched/core] sched: Fix hrtimer_cancel()/rq->lock deadlock tip-bot for Ben Segall
2013-10-16 18:16 ` [PATCH 4/5] sched: Guarantee new group-entities always have weight Ben Segall
2013-10-16 22:01   ` Peter Zijlstra
2013-10-16 22:16     ` Paul Turner
2013-10-16 22:22       ` Peter Zijlstra
2013-10-16 22:40     ` bsegall
2013-10-29 14:07   ` [tip:sched/core] " tip-bot for Paul Turner
2013-10-16 18:16 ` [PATCH 5/5] sched: Avoid throttle_cfs_rq racing with period_timer stopping Ben Segall
2013-10-16 22:06   ` Peter Zijlstra
2013-10-29 14:07   ` tip-bot for Ben Segall [this message]

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=tip-f9f9ffc237dd924f048204e8799da74f9ecf40cf@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bsegall@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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