Re: [patch 05/15] sched: unthrottle cfs_rq(s) who ran out of quotaat period refresh

From: Peter Zijlstra
Date: Tue Apr 05 2011 - 09:30:05 EST


On Tue, 2011-03-22 at 20:03 -0700, Paul Turner wrote:
> +static u64 distribute_cfs_bandwidth(struct cfs_bandwidth *cfs_b, u64 runtime)
> +{
> + int i;
> + u64 quota, remaining = runtime;
> + const struct cpumask *span;
> +
> + rcu_read_lock();
> + span = sched_bw_period_mask();
> + for_each_cpu(i, span) {
> + struct rq *rq = cpu_rq(i);
> + struct cfs_rq *cfs_rq = cfs_bandwidth_tg(cfs_b)->cfs_rq[i];
> +
> + raw_spin_lock(&rq->lock);
> + if (within_bandwidth(cfs_rq))
> + goto next;
> +
> + quota = -cfs_rq->quota_remaining;
> + quota += sched_cfs_bandwidth_slice();
> + quota = min(quota, remaining);
> + remaining -= quota;
> +
> + cfs_rq->quota_remaining += quota;
> + if (cfs_rq_throttled(cfs_rq) && cfs_rq->quota_remaining > 0)
> + unthrottle_cfs_rq(cfs_rq);
> +
> +next:
> + raw_spin_unlock(&rq->lock);
> +
> + if (!remaining)
> + break;
> + }
> + rcu_read_unlock();
> +
> + return remaining;
> +}
> +
> static int do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b, int overrun)
> {
> + u64 runtime, runtime_assigned;
> + int idle;
> +
> + raw_spin_lock(&cfs_b->lock);
> + runtime = cfs_b->quota;
> + idle = cfs_b->runtime == cfs_b->runtime_assigned;
> + raw_spin_unlock(&cfs_b->lock);
> +
> + if (runtime == RUNTIME_INF)
> + return 1;
> +
> + runtime *= overrun;
> + runtime_assigned = runtime;
> +
> + runtime = distribute_cfs_bandwidth(cfs_b, runtime);
> +
> + raw_spin_lock(&cfs_b->lock);
> + cfs_b->runtime = runtime;
> + cfs_b->runtime_assigned = runtime_assigned;
> + raw_spin_unlock(&cfs_b->lock);
> +
> + return idle;
> }

There's something fishy there, it looks like ->runtime can end up being
> ->quota in case of overrun > 1, that shouldn't be possible, the
refresh timer should never over-fill the bucket.

The whole ->runtime_assigned stuff had me confused for a while, but I
guess its the easiest way to determine if we indeed had runtime
consumption.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/