]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
sched: Avoid throttle_cfs_rq() racing with period_timer stopping
authorBen Segall <bsegall@google.com>
Wed, 16 Oct 2013 18:16:32 +0000 (11:16 -0700)
committerIngo Molnar <mingo@kernel.org>
Tue, 29 Oct 2013 11:02:32 +0000 (12:02 +0100)
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
kernel/sched/fair.c

index e6ba5e31c7ca24e67bb3f56fbe8f422371c8fb74..5c34d1817e8f2346e853cc8f273fdabce1d52db1 100644 (file)
@@ -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);
index 0923ab2b7eb9bd7b1fb7456b89b8bbfed53fb377..41c02b6b090e0e376a4242ab05aea099d72354c4 100644 (file)
@@ -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);
 }