[PATCH 2/2] sched: group nice
From: Peter Zijlstra
Date: Wed Dec 10 2008 - 14:45:09 EST
allow to use nice values to set group weights
Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
---
kernel/sched.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -8558,6 +8558,17 @@ static inline void unregister_fair_sched
{
list_del_rcu(&tg->cfs_rq[cpu]->leaf_cfs_rq_list);
}
+
+static int cpu_nice_write(struct cgroup *cgrp, struct cftype *cftype,
+ s64 niceval)
+{
+ return sched_group_set_nice(cgroup_tg(cgrp), niceval);
+}
+
+static s64 cpu_nice_read(struct cgroup *cgrp, struct cftype *cftype)
+{
+ return sched_group_nice(cgroup_tg(cgrp));
+}
#else /* !CONFG_FAIR_GROUP_SCHED */
static inline void free_fair_sched_group(struct task_group *tg)
{
@@ -8867,6 +8878,29 @@ unsigned long sched_group_weight(struct
{
return tg->weight;
}
+
+static int sched_group_set_nice(struct task_group *tg, int nice)
+{
+ unsigned int prio = nice + 20;
+
+ if (prio > ARRAY_SIZE(prio_to_weight))
+ return -EINVAL;
+
+ sched_group_set_weight(tg, prio_to_weight[prio]);
+ return 0;
+}
+
+static int sched_group_nice(struct task_group *tg)
+{
+ unsigned long weight = sched_group_weight(tg);
+ int prio;
+
+ for (prio = 0; prio < ARRAY_SIZE(prio_to_weight); prio++)
+ if (prio_to_weight[prio] <= weight)
+ break;
+
+ return prio - 20;
+}
#endif
#ifdef CONFIG_RT_GROUP_SCHED
@@ -9233,6 +9267,11 @@ static struct cftype cpu_files[] = {
.read_u64 = cpu_weight_read_u64,
.write_u64 = cpu_weight_write_u64,
},
+ {
+ .name = "nice",
+ .read_s64 = cpu_nice_read,
+ .write_s64 = cpu_nice_write,
+ },
#endif
#ifdef CONFIG_RT_GROUP_SCHED
{
--
--
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/