sched/fair: Remove setting task's se->runnable_weight during PELT update
Dietmar Eggemann
reviewerPATCH v2 1/1 sched/fair: Remove setting task's se->runnable_weight during PELT update
A CFS (SCHED_OTHER, SCHED_BATCH or SCHED_IDLE policy) task's se->runnable_weight must always be in sync with its se->load.weight.
se->runnable_weight is set to se->load.weight when the task is forked (init_entity_runnable_average()) or reniced (reweight_entity()).
There are two cases in set_load_weight() which since they currently only set se->load.weight could lead to a situation in which se->load.weight is different to se->runnable_weight for a CFS task:
(1) A task switches to SCHED_IDLE.
(2) A SCHED_FIFO, SCHED_RR or SCHED_DEADLINE task which has been reniced (during which only its static priority gets set) switches to SCHED_OTHER or SCHED_BATCH.
Set se->runnable_weight to se->load.weight in these two cases to prevent this. This eliminates the need to explicitly set it to se->load.weight during PELT updates in the CFS scheduler fastpath.
---
Changes v1->v2:
- Rebased on latest tip/sched/core
This patch has been tested w/ appropriate BUG_ON()'s in __update_load_avg_blocked_se() and __update_load_avg_se() on an Ubuntu 18.04 desktop.
kernel/sched/core.c | 2 ++ kernel/sched/pelt.c | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-)
kernel/sched/core.c +2 -0
@@ -701,6 +701,7 @@ static void set_load_weight(struct task_struct *p, bool update_load)if (idle_policy (p->policy)) { load->weight =scale_load (WEIGHT_IDLEPRIO ); load->inv_weight =WMULT_IDLEPRIO ; + p->se.runnable_weight = load->weight;return ; }
@@ -713,6 +714,7 @@ static void set_load_weight(struct task_struct *p, bool update_load) }else { load->weight =scale_load (sched_prio_to_weight[prio]); load->inv_weight = sched_prio_to_wmult[prio]; + p->se.runnable_weight = load->weight; } }
kernel/sched/pelt.c +0 -6
@@ -269,9 +269,6 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load, unsigned long runnaint __update_load_avg_blocked_se (u64 now,int cpu,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg,0 ,0 ,0 )) {___update_load_avg (&se->avg,se_weight (se),se_runnable (se));return 1 ;
@@ -282,9 +279,6 @@ int __update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se)int __update_load_avg_se (u64 now,int cpu,struct cfs_rq *cfs_rq,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg, !!se->on_rq, !!se->on_rq, cfs_rq->curr == se)) {
Signature · 1 line
2.11.0
Dietmar Eggemann
reviewerHi,
Quoted 70 lines · Dietmar Eggemann
A CFS (
SCHED_OTHER,SCHED_BATCHorSCHED_IDLEpolicy) task'sse->runnable_weightmust always be in sync with itsse->load.weight.
se->runnable_weightis set tose->load.weightwhen the task is forked (init_entity_runnable_average()) or reniced (reweight_entity()).There are two cases in
set_load_weight()which since they currently only setse->load.weightcould lead to a situation in whichse->load.weightis different tose->runnable_weightfor a CFS task:(1) A task switches to
SCHED_IDLE.(2) A
SCHED_FIFO,SCHED_RRorSCHED_DEADLINEtask which has been reniced (during which only its static priority gets set) switches toSCHED_OTHERorSCHED_BATCH.Set
se->runnable_weighttose->load.weightin these two cases to prevent this. This eliminates the need to explicitly set it tose->load.weightduring PELT updates in the CFS scheduler fastpath.Signed-off-by Dietmar Eggemann <[email protected]>---
Changes
v1->v2:
- Rebased on latest tip/sched/coreThis patch has been tested w/ appropriate BUG_ON()'s in
__update_load_avg_blocked_se()and__update_load_avg_se()on an Ubuntu 18.04 desktop.kernel/sched/core.c | 2 ++ kernel/sched/pelt.c | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-)kernel/sched/core.c +2
-0@@ -701,6 +701,7 @@ static void set_load_weight(struct task_struct *p, bool update_load)if (idle_policy (p->policy)) { load->weight =scale_load (WEIGHT_IDLEPRIO ); load->inv_weight =WMULT_IDLEPRIO ; + p->se.runnable_weight = load->weight;return ; }@@ -713,6 +714,7 @@ static void set_load_weight(struct task_struct *p, bool update_load) }else { load->weight =scale_load (sched_prio_to_weight[prio]); load->inv_weight = sched_prio_to_wmult[prio]; + p->se.runnable_weight = load->weight; } }kernel/sched/pelt.c +0
-3@@ -269,9 +269,6 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load, unsigned long runnaint __update_load_avg_blocked_se (u64 now,int cpu,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg,0 ,0 ,0 )) {___update_load_avg (&se->avg,se_weight (se),se_runnable (se));return 1 ;
kernel/sched/pelt.c int __update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se) · line 284
Quoted 9 lines
kernel/sched/pelt.c +0
-3@@ -282,9 +279,6 @@ int __update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se)int __update_load_avg_se (u64 now,int cpu,struct cfs_rq *cfs_rq,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg, !!se->on_rq, !!se->on_rq, cfs_rq->curr == se)) {
Is there anything else I should do for this patch ?
Thanks,
-- Dietmar
Peter Zijlstra
maintainerQuoted 2 lines · Dietmar Eggemann
Is there anything else I should do for this patch ?
This. Got it now, thanks!
tip-bot for Dietmar Eggemann
merge botsched/fair: Remove setting task's se->runnable_weight during PELT update
Commit-ID: 4a465e3ebbc8004ce4f7f08f6022ee8315a94edf Gitweb: https://git.kernel.org/tip/4a465e3ebbc8004ce4f7f08f6022ee8315a94edf Author: Dietmar Eggemann <[email protected]> AuthorDate: Fri, 3 Aug 2018 15:05:38 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 09:45:03 +0200
sched/fair: Remove setting task's se->runnable_weight during PELT update
A CFS (SCHED_OTHER, SCHED_BATCH or SCHED_IDLE policy) task's se->runnable_weight must always be in sync with its se->load.weight.
se->runnable_weight is set to se->load.weight when the task is forked (init_entity_runnable_average()) or reniced (reweight_entity()).
There are two cases in set_load_weight() which since they currently only set se->load.weight could lead to a situation in which se->load.weight is different to se->runnable_weight for a CFS task:
(1) A task switches to SCHED_IDLE.
(2) A SCHED_FIFO, SCHED_RR or SCHED_DEADLINE task which has been reniced (during which only its static priority gets set) switches to SCHED_OTHER or SCHED_BATCH.
Set se->runnable_weight to se->load.weight in these two cases to prevent this. This eliminates the need to explicitly set it to se->load.weight during PELT updates in the CFS scheduler fastpath.
--- kernel/sched/core.c | 2 ++ kernel/sched/pelt.c | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-)
kernel/sched/core.c +2 -0
@@ -700,6 +700,7 @@ static void set_load_weight(struct task_struct *p, bool update_load)if (idle_policy (p->policy)) { load->weight =scale_load (WEIGHT_IDLEPRIO ); load->inv_weight =WMULT_IDLEPRIO ; + p->se.runnable_weight = load->weight;return ; }
@@ -712,6 +713,7 @@ static void set_load_weight(struct task_struct *p, bool update_load) }else { load->weight =scale_load (sched_prio_to_weight[prio]); load->inv_weight = sched_prio_to_wmult[prio]; + p->se.runnable_weight = load->weight; } }
kernel/sched/pelt.c +0 -6
@@ -269,9 +269,6 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load, unsigned long runnaint __update_load_avg_blocked_se (u64 now,int cpu,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg,0 ,0 ,0 )) {___update_load_avg (&se->avg,se_weight (se),se_runnable (se));return 1 ;
@@ -282,9 +279,6 @@ int __update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se)int __update_load_avg_se (u64 now,int cpu,struct cfs_rq *cfs_rq,struct sched_entity *se) { -if (entity_is_task (se)) - se->runnable_weight = se->load.weight; -if (___update_load_sum (now, cpu, &se->avg, !!se->on_rq, !!se->on_rq, cfs_rq->curr == se)) {