Re: [patch 00/18] CFS Bandwidth Control v7.2

Peter Zijlstra
2011-07-25T14:58:32Z

How about something like the below on top?

---
kernel/sched.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -9228,9 +9228,19 @@ long tg_get_cfs_quota(struct task_group
return quota_us;
}

+int tg_set_cfs_period_down(struct task_group *tg, void *data)
+{
+ u64 period = *(u64 *)data;
+ if (ktime_to_ns(tg->cfs_bandwidth.period) == period)
+ return 0;
+
+ return tg_set_cfs_bandwidth(tg, period, tg->cfs_bandwidth.quota);
+}
+
int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
{
u64 quota, period;
+ int ret;

period = (u64)cfs_period_us * NSEC_PER_USEC;
quota = tg_cfs_bandwidth(tg)->quota;
@@ -9238,7 +9248,28 @@ int tg_set_cfs_period(struct task_group
if (period <= 0)
return -EINVAL;

- return tg_set_cfs_bandwidth(tg, period, quota);
+ /*
+ * If the parent is bandwidth constrained all its children will
+ * have to have the same period.
+ */
+ if (tg->parent && tg->parent->cfs_bandwidth.quota != RUNTIME_INF)
+ return -EINVAL;
+
+ ret = tg_set_cfs_bandwidth(tg, period, quota);
+ if (!ret) {
+ rcu_read_lock();
+ ret = walk_tg_tree_from(tg, tg_set_cfs_period_down, NULL, &period);
+ rcu_read_unlock();
+
+ /*
+ * If we could change the period on the parent we should be
+ * able to change the period on all its children since their
+ * quote is constrained to be equal or less than our.
+ */
+ WARN_ON_ONCE(ret);
+ }
+
+ return ret;
}

long tg_get_cfs_period(struct task_group *tg)