sched: task group weight interface
cover sched: task group weight interface
Hi,
Dhaval poked me that he (and others) didn't like the weight interface we currently have for task groups. I concurr and dusted off these old patches.
PATCH 1/2 sched: tg->weight
While going through the whole group thing again, I realized tg->shares ought to be called tg->weight, as its the total group weight, and not a share of the group weight.
--- include/linux/sched.h | 4 ++-- kernel/sched.c | 49 +++++++++++++++++++++++++++---------------------- kernel/sched_fair.c | 2 +- kernel/user.c | 4 ++-- 4 files changed, 32 insertions(+), 27 deletions(-)
kernel/sched.c +27 -22
@@ -275,7 +275,7 @@ struct task_group {struct sched_entity **se;/* runqueue "owned" by this group on each cpu */ struct cfs_rq **cfs_rq; -unsigned long shares; +unsigned long weight;#endif #ifdef CONFIG_RT_GROUP_SCHED
@@ -445,7 +445,7 @@ struct cfs_rq {unsigned long h_load;/* -* this cpu's part of tg->shares +* this cpu's part of tg->weight */ unsigned long shares;
@@ -1465,7 +1465,7 @@ static void __set_se_shares(struct sched* Calculate and set the cpu's group shares. */ static void -update_group_shares_cpu (struct task_group *tg,int cpu, +update_group_weight_cpu (struct task_group *tg,int cpu,unsigned long sd_shares,unsigned long sd_rq_weight) {unsigned long shares;
@@ -1525,14 +1525,14 @@ static int tg_shares_up(struct task_grou shares += tg->cfs_rq[i]->shares; } -if ((!shares && rq_weight) || shares > tg->shares) - shares = tg->shares; +if ((!shares && rq_weight) || shares > tg->weight) + shares = tg->weight;if (!sd->parent || !(sd->parent->flags &SD_LOAD_BALANCE )) - shares = tg->shares; + shares = tg->weight;for_each_cpu (i,sched_domain_span (sd)) -update_group_shares_cpu (tg, i, shares, rq_weight); +update_group_weight_cpu (tg, i, shares, rq_weight);return 0 ; }
@@ -8112,7 +8112,7 @@ static void init_tg_cfs_entry(struct tas se->cfs_rq = parent->my_q; se->my_q = cfs_rq; - se->load.weight = tg->shares; + se->load.weight = tg->weight; se->load.inv_weight =0 ; se->parent = parent; }
@@ -8237,7 +8237,7 @@ void __init sched_init(void)init_cfs_rq (&rq->cfs, rq);init_rt_rq (&rq->rt, rq);#ifdef CONFIG_FAIR_GROUP_SCHED - init_task_group.shares = init_task_group_load; + init_task_group.weight = init_task_group_load;INIT_LIST_HEAD (&rq->leaf_cfs_rq_list);#ifdef CONFIG_CGROUP_SCHED /*
@@ -8261,7 +8261,7 @@ void __init sched_init(void)*/ init_tg_cfs_entry (&init_task_group, &rq->cfs,NULL , i,1 ,NULL );#elif definedCONFIG_USER_SCHED - root_task_group.shares =NICE_0_LOAD ; + root_task_group.weight =NICE_0_LOAD ;init_tg_cfs_entry (&root_task_group, &rq->cfs,NULL , i,0 ,NULL );/* * In case of task-groups formed thr' the user id of tasks,
@@ -8524,7 +8524,7 @@ int alloc_fair_sched_group(struct task_gif (!tg->se) goto err; - tg->shares =NICE_0_LOAD ; + tg->weight =NICE_0_LOAD ;for_each_possible_cpu (i) { rq =cpu_rq (i);
@@ -8807,7 +8807,7 @@ static void set_se_shares(struct sched_estatic DEFINE_MUTEX (shares_mutex); -int sched_group_set_shares (struct task_group *tg,unsigned long shares) +int sched_group_set_weight (struct task_group *tg,unsigned long shares) {int i;unsigned long flags;
@@ -8824,7 +8824,7 @@ int sched_group_set_shares(struct task_g shares =MAX_SHARES ;mutex_lock (&shares_mutex); -if (tg->shares == shares) +if (tg->weight == shares) goto done;spin_lock_irqsave (&task_group_lock, flags);
@@ -8840,7 +8840,7 @@ int sched_group_set_shares(struct task_g* Now we are free to modify the group's share on each cpu * w/o tripping rebalance_share or load_balance_fair. */ - tg->shares = shares; + tg->weight = shares;for_each_possible_cpu (i) {/* * force a rebalance
@@ -8863,9 +8863,9 @@ done: return 0; } -unsigned long sched_group_shares (struct task_group *tg) +unsigned long sched_group_weight (struct task_group *tg) { -return tg->shares; +return tg->weight; }#endif
@@ -9183,17 +9183,17 @@ cpu_cgroup_attach(struct cgroup_subsys * }#ifdef CONFIG_FAIR_GROUP_SCHED -static int cpu_shares_write_u64 (struct cgroup *cgrp,struct cftype *cftype, +static int cpu_weight_write_u64 (struct cgroup *cgrp,struct cftype *cftype,u64 shareval) { -return sched_group_set_shares (cgroup_tg (cgrp), shareval); +return sched_group_set_weight (cgroup_tg (cgrp), shareval); } -static u64 cpu_shares_read_u64 (struct cgroup *cgrp,struct cftype *cft) +static u64 cpu_weight_read_u64 (struct cgroup *cgrp,struct cftype *cft) {struct task_group *tg =cgroup_tg (cgrp); -return (u64 ) tg->shares; +return (u64 ) tg->weight; }#endif /* CONFIG_FAIR_GROUP_SCHED */
@@ -9225,8 +9225,13 @@ static struct cftype cpu_files[] = { #ifdef CONFIG_FAIR_GROUP_SCHED { .name = "shares", - .read_u64 = cpu_shares_read_u64, - .write_u64 = cpu_shares_write_u64, + .read_u64 = cpu_weight_read_u64, + .write_u64 = cpu_weight_write_u64, + }, + { + .name = "weight", + .read_u64 = cpu_weight_read_u64, + .write_u64 = cpu_weight_write_u64, }, #endif #ifdef CONFIG_RT_GROUP_SCHED
kernel/sched_fair.c +1 -1
@@ -1117,7 +1117,7 @@ static long effective_load(struct task_g wl += more_w; wg += more_w; -S = se->my_q->tg->shares; +S = se->my_q->tg->weight; s = se->my_q->shares; rw = se->my_q->rq_weight;
include/linux/sched.h +2 -2
@@ -2282,8 +2282,8 @@ extern struct task_group *sched_create_gextern void sched_destroy_group (struct task_group *tg);extern void sched_move_task (struct task_struct *tsk);#ifdef CONFIG_FAIR_GROUP_SCHED -extern int sched_group_set_shares (struct task_group *tg,unsigned long shares); -extern unsigned long sched_group_shares (struct task_group *tg); +extern int sched_group_set_weight (struct task_group *tg,unsigned long shares); +extern unsigned long sched_group_weight (struct task_group *tg);#endif #ifdef CONFIG_RT_GROUP_SCHED extern int sched_group_set_rt_runtime(struct task_group *tg,
kernel/user.c +2 -2
@@ -142,7 +142,7 @@ static ssize_t cpu_shares_show(struct ko { struct user_struct *up = container_of(kobj, struct user_struct, kobj); -return sprintf (buf,"%lu\n" ,sched_group_shares (up->tg)); +return sprintf (buf,"%lu\n" ,sched_group_weight (up->tg)); } static ssize_t cpu_shares_store(struct kobject *kobj,
@@ -155,7 +155,7 @@ static ssize_t cpu_shares_store(struct ksscanf (buf,"%lu" , &shares); - rc =sched_group_set_shares (up->tg, shares); + rc =sched_group_set_weight (up->tg, shares);return (rc ? rc : size); }
PATCH 2/2 sched: group nice
In reply to Peter Zijlstraallow to use nice values to set group weights
--- kernel/sched.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
kernel/sched.c +39 -0
@@ -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 {
Ingo Molnar
AppliedQuoted 5 lines · Peter Zijlstra
Hi,
Dhaval poked me that he (and others) didn't like the weight interface we currently have for task groups. I concurr and dusted off these old patches.
applied to tip/sched/core, thanks Peter!
Ingo
PATCH RESEND 1/1 : sched: Fix compile errors introduced by new group scheduler interface
Quoted 3 lines
applied to tip/sched/core, thanks Peter!
Also needs this to build,
sched: Fix compile errors introduced by new group scheduler interface
commit e642daa433a5ea1599965576dcea70dcc0a36608 introduces
kernel/sched.c: In function ‘cpu_nice_write’:kernel/sched.c:8505: error: implicit declaration of function ‘sched_group_set_nice’ kernel/sched.c:8505: error: implicit declaration of function ‘cgroup_tg’ kernel/sched.c: In function ‘cpu_nice_read’:kernel/sched.c:8510: error: implicit declaration of function ‘sched_group_nice’ kernel/sched.c: At top level:kernel/sched.c:8822: error: static declaration of ‘sched_group_set_nice’ follows non-static declaration kernel/sched.c:8505: error: previous implicit declaration of ‘sched_group_set_nice’ was here kernel/sched.c:8833: error: static declaration of ‘sched_group_nice’ follows non-static declaration kernel/sched.c:8510: error: previous implicit declaration of ‘sched_group_nice’ was here kernel/sched.c:9103: error: conflicting types for ‘cgroup_tg’kernel/sched.c:8505: error: previous implicit declaration of ‘cgroup_tg’ was here make[1]: *** [kernel/sched.o] Error 1
make: *** [kernel/sched.o] Error 2
Fix those.
--- kernel/sched.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
kernel/sched.c +11 -9
@@ -8499,16 +8499,7 @@ 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) {
@@ -9169,6 +9160,17 @@ static u64 cpu_weight_read_u64(struct cg return (u64) tg->weight; } + +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)); +}#endif /* CONFIG_FAIR_GROUP_SCHED */ #ifdef CONFIG_RT_GROUP_SCHED
Signature · 2 lines
regards, Dhaval
Quoted 5 lines · Peter Zijlstra
Hi,
Dhaval poked me that he (and others) didn't like the weight interface we currently have for task groups. I concurr and dusted off these old patches.
/me wonders what happened to these patches?
Quoted 2 lines
Signature · 1 line
--
Signature · 2 lines
regards, Dhaval