remove runnable_load_avg and improve group_classify
Vincent Guittot
maintainerv2 cover remove runnable_load_avg and improve group_classify
This new version stays quite close to the previous one and should replace without problems the previous one that part of Mel's patchset:
https://lkml.org/lkml/2020/2/14/156
NUMA load balancing is the last remaining piece of code that uses the runnable_load_avg of PELT to balance tasks between nodes. The normal load_balance has replaced it by a better description of the current state of the group of cpus. The same policy can be applied to the numa balancing.
Once unused, runnable_load_avg can be replaced by a simpler runnable_avg signal that tracks the waiting time of tasks on rq. Currently, the state of a group of CPUs is defined thanks to the number of running task and the level of utilization of rq. But the utilization can be temporarly low after the migration of a task whereas the rq is still overloaded with tasks. In such case where tasks were competing for the rq, the runnable_avg will stay high after the migration.
Some hackbench results:
- small arm64 dual quad cores system
hackbench -l (2560/#grp) -g #grp
grp tip/sched/core +patchset improvement 1 1,327(+/-10,06 %) 1,247(+/-5,45 %) 5,97 % 4 1,250(+/- 2,55 %) 1,207(+/-2,12 %) 3,42 % 8 1,189(+/- 1,47 %) 1,179(+/-1,93 %) 0,90 % 16 1,221(+/- 3,25 %) 1,219(+/-2,44 %) 0,16 %
- large arm64 2 nodes / 224 cores system
hackbench -l (256000/#grp) -g #grp
grp tip/sched/core +patchset improvement 1 14,197(+/- 2,73 %) 13,917(+/- 2,19 %) 1,98 % 4 6,817(+/- 1,27 %) 6,523(+/-11,96 %) 4,31 % 16 2,930(+/- 1,07 %) 2,911(+/- 1,08 %) 0,66 % 32 2,735(+/- 1,71 %) 2,725(+/- 1,53 %) 0,37 % 64 2,702(+/- 0,32 %) 2,717(+/- 1,07 %) -0,53 % 128 3,533(+/-14,66 %) 3,123(+/-12,47 %) 11,59 % 256 3,918(+/-19,93 %) 3,390(+/- 5,93 %) 13,47 %
The significant improvement for 128 and 256 should be taken with care because of some instabilities over iterations without the patchset.
The table below shows figures of the classification of sched group during load balance (idle, newly or busy lb) with the disribution according to the number of running tasks for:
hackbench -l 640 -g 4 on octo cores
tip/sched/core +patchset
state
has spare 3973 1934
nr_running
0 1965 1858
1 518 56
2 369 18
3 270 2
4+ 851 0
fully busy 546 1018
nr_running
0 0 0
1 546 1018
2 0 0
3 0 0
4+ 0 0
overloaded 2109 3056
nr_running
0 0 0
1 0 0
2 241 483
3 170 348
4+ 1698 2225total 6628 6008
Without the patchset, there is a significant number of time that a CPU has spare capacity with more than 1 running task. Although this is a valid case, this is not a state that should often happen when 160 tasks are competing on 8 cores like for this test. The patchset fixes the situation by taking into account the runnable_avg, which stays high after the migration of a task on another CPU.
Changes since RFC:
- fix come comment and typo
- split in 2 patches the removale of runnable_load_avg and the addition of runnbale_avg
Vincent Guittot (5):
sched/fair: Reorder enqueue/dequeue_task_fair path sched/numa: Replace runnable_load_avg by load_avg sched/pelt: Remove unused runnable load average sched/pelt: Add a new runnable average signal sched/fair: Take into account runnable_avg to classify group
include/linux/sched.h | 33 +++-- kernel/sched/core.c | 2 - kernel/sched/debug.c | 17 +-- kernel/sched/fair.c | 337 ++++++++++++++++++++++-------------------- kernel/sched/pelt.c | 45 +++--- kernel/sched/sched.h | 29 +++- 6 files changed, 247 insertions(+), 216 deletions(-)
Signature · 1 line
2.17.1
Vincent Guittot
maintainerPATCH v2 1/5 sched/fair: Reorder enqueue/dequeue_task_fair path
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled cfs_rq without any added value but making code less readable.
Change the code ordering such that everything related to a cfs_rq (throttled or not) will be done in the same loop.
In addition, the same steps ordering is used when updating a cfs_rq:
- update_load_avg
- update_cfs_group
- update *h_nr_running
No functional and performance changes are expected and have been noticed during tests.
--- kernel/sched/fair.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
kernel/sched/fair.c +20 -22
@@ -5259,32 +5259,31 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) cfs_rq =cfs_rq_of (se);enqueue_entity (cfs_rq, se, flags); -/* -* end evaluation on encountering a throttled cfs_rq -* -* note: in the case of encountering a throttled cfs_rq we will -* post the final h_nr_running increment below. -*/ -if (cfs_rq_throttled (cfs_rq)) -break ; cfs_rq->h_nr_running++; cfs_rq->idle_h_nr_running += idle_h_nr_running; +/* end evaluation on encountering a throttled cfs_rq */ +if (cfs_rq_throttled (cfs_rq)) + goto enqueue_throttle; + flags =ENQUEUE_WAKEUP ; }for_each_sched_entity (se) { cfs_rq =cfs_rq_of (se); - cfs_rq->h_nr_running++; - cfs_rq->idle_h_nr_running += idle_h_nr_running; +/* end evaluation on encountering a throttled cfs_rq */ if (cfs_rq_throttled (cfs_rq)) -break ; + goto enqueue_throttle;update_load_avg (cfs_rq, se,UPDATE_TG );update_cfs_group (se); + + cfs_rq->h_nr_running++; + cfs_rq->idle_h_nr_running += idle_h_nr_running; } +enqueue_throttle:if (!se) {add_nr_running (rq,1 );/*
@@ -5345,17 +5344,13 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) cfs_rq =cfs_rq_of (se);dequeue_entity (cfs_rq, se, flags); -/* -* end evaluation on encountering a throttled cfs_rq -* -* note: in the case of encountering a throttled cfs_rq we will -* post the final h_nr_running decrement below. -*/ -if (cfs_rq_throttled (cfs_rq)) -break ; cfs_rq->h_nr_running--; cfs_rq->idle_h_nr_running -= idle_h_nr_running; +/* end evaluation on encountering a throttled cfs_rq */ +if (cfs_rq_throttled (cfs_rq)) + goto dequeue_throttle; +/* Don't dequeue parent if it has other entities besides us */ if (cfs_rq->load.weight) {/* Avoid re-evaluating load for this entity: */
@@ -5373,16 +5368,19 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)for_each_sched_entity (se) { cfs_rq =cfs_rq_of (se); - cfs_rq->h_nr_running--; - cfs_rq->idle_h_nr_running -= idle_h_nr_running; +/* end evaluation on encountering a throttled cfs_rq */ if (cfs_rq_throttled (cfs_rq)) -break ; + goto dequeue_throttle;update_load_avg (cfs_rq, se,UPDATE_TG );update_cfs_group (se); + + cfs_rq->h_nr_running--; + cfs_rq->idle_h_nr_running -= idle_h_nr_running; } +dequeue_throttle:if (!se)sub_nr_running (rq,1 );
Signature · 1 line
2.17.1
Dietmar Eggemann
reviewerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_running
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (se->on_rq); break;'.
[...]
Peter Zijlstra
maintainerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 8 lines · Dietmar Eggemann
Quoted 7 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.
Quoted 8 lines
Quoted 4 lines
In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_runningIs this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.
IIRC he relies on the presented ordering in patch #5 -- adding the running_avg metric.
Vincent Guittot
maintainerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 15 lines · Peter Zijlstra
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_running
Quoted 6 lines
Quoted 3 lines
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.IIRC he relies on the presented ordering in patch #5 -- adding the
running_avgmetric.
Yes, that's the main reason, updating load_avg before h_nr_running
Dietmar Eggemann
reviewerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Peter Zijlstra
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_running
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.IIRC he relies on the presented ordering in patch #5 -- adding the
running_avgmetric.Yes, that's the main reason, updating
load_avgbeforeh_nr_running
My hunch is you refer to the new function:
static inline void se_update_runnable(struct sched_entity *se)
{
if (!entity_is_task(se))
se->runnable_weight = se->my_q->h_nr_running;
}I don't see the dependency to the 'update_load_avg -> h_nr_running' order since it operates on se->my_q, not cfs_rq = cfs_rq_of(se), i.e. se->cfs_rq.
What do I miss here?
Vincent Guittot
maintainerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 35 lines · Dietmar Eggemann
Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Peter Zijlstra
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_runningQuoted 8 lines
Quoted 6 lines
Quoted 3 lines
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.IIRC he relies on the presented ordering in patch #5 -- adding the
running_avgmetric.Yes, that's the main reason, updating
load_avgbeforeh_nr_runningMy hunch is you refer to the new function:
static inline void
se_update_runnable(struct sched_entity *se){ if (!entity_is_task(se)) se->runnable_weight = se->my_q->h_nr_running; }
Quoted 5 lines
I don't see the dependency to the '
update_load_avg->h_nr_running' order since it operates onse->my_q, notcfs_rq=cfs_rq_of(se), i.e.se->cfs_rq.What do I miss here?
update_load_avg() updates both se and cfs_rq so if you update cfs_rq->h_nr_running before calling update_load_avg() like in the 2nd for_each_sched_entity, you will update cfs_rq runnable_avg for the past time slot with the new h_nr_running value instead of the previous value.
Dietmar Eggemann
reviewerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Quoted 40 lines · Vincent Guittot
Quoted 39 lines · Dietmar Eggemann
Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Peter Zijlstra
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_runningQuoted 8 lines
Quoted 6 lines
Quoted 3 lines
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.IIRC he relies on the presented ordering in patch #5 -- adding the
running_avgmetric.Yes, that's the main reason, updating
load_avgbeforeh_nr_runningMy hunch is you refer to the new function:
static inline void
se_update_runnable(struct sched_entity *se){ if (!entity_is_task(se)) se->runnable_weight = se->my_q->h_nr_running; }I don't see the dependency to the '
update_load_avg->h_nr_running' order since it operates onse->my_q, notcfs_rq=cfs_rq_of(se), i.e.se->cfs_rq.
Quoted 7 lines
Quoted 1 line
What do I miss here?
update_load_avg()updates both se andcfs_rqso if you updatecfs_rq->h_nr_runningbefore callingupdate_load_avg()like in the 2ndfor_each_sched_entity, you will updatecfs_rqrunnable_avgfor the past time slot with the newh_nr_runningvalue instead of the previous value.
Ah, now I see:
update_load_avg()
update_cfs_rq_load_avg()
__update_load_avg_cfs_rq()
___update_load_sum(..., cfs_rq->h_nr_running, ...)
^^^^^^^^^^^^^^^^^^^^Not really obvious IMHO, since the code is introduced only in 4/5.
Could you add a comment to this patch header?
I see you mentioned this dependency already in v1 discussion
https://lore.kernel.org/r/CAKfTPtAM=kgF7Fz-JKFY+s_k5KFirs-8Bub3s1Eqtq7P0NMa0w@mail.gmail.com
"... But the following patches make PELT using h_nr_running ...".
IMHO it would be helpful to have this explanation in the 1/5 patch header so people stop wondering why this is necessary.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Vincent Guittot
maintainerRe: [PATCH v2 1/5] sched/fair: Reorder enqueue/dequeue_task_fair path
Hi Tao,
Quoted 60 lines · Tao Zhou
Hi,
Quoted 56 lines · Dietmar Eggemann
Quoted 40 lines · Vincent Guittot
Quoted 39 lines · Dietmar Eggemann
Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Peter Zijlstra
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Vincent Guittot
The walk through the cgroup hierarchy during the enqueue/dequeue of a task is split in 2 distinct parts for throttled
cfs_rqwithout any added value but making code less readable.Change the code ordering such that everything related to a
cfs_rq(throttled or not) will be done in the same loop.In addition, the same steps ordering is used when updating a
cfs_rq:
-update_load_avg
-update_cfs_group
- update*h_nr_runningQuoted 8 lines
Quoted 6 lines
Quoted 3 lines
Is this code change really necessary? You pay with two extra goto's. We still have the two for_each_sched_entity(se)'s because of 'if (
se->on_rq); break;'.IIRC he relies on the presented ordering in patch #5 -- adding the
running_avgmetric.Yes, that's the main reason, updating
load_avgbeforeh_nr_runningMy hunch is you refer to the new function:
static inline void
se_update_runnable(struct sched_entity *se){ if (!entity_is_task(se)) se->runnable_weight = se->my_q->h_nr_running; }I don't see the dependency to the '
update_load_avg->h_nr_running' order since it operates onse->my_q, notcfs_rq=cfs_rq_of(se), i.e.se->cfs_rq.Quoted 7 lines
Quoted 1 line
What do I miss here?
update_load_avg()updates both se andcfs_rqso if you updatecfs_rq->h_nr_runningbefore callingupdate_load_avg()like in the 2ndfor_each_sched_entity, you will updatecfs_rqrunnable_avgfor the past time slot with the newh_nr_runningvalue instead of the previous value.Ah, now I see:
update_load_avg()
update_cfs_rq_load_avg()__update_load_avg_cfs_rq() ___update_load_sum(..., cfs_rq->h_nr_running, ...)
Quoted 4 lines
Quoted 1 line
^^^^^^^^^^^^^^^^^^^^throttle/unthrottle_cfs_rq() update
h_nr_runningalso. Maybe need to consider callse_update_runnablethere.
yes you're right, group entity which are not enqueued/dequeued, which updates runnable_avg and se->runnable_weight, during the throttling/unthrottling are not updated. I'm going to send a fix on top of sched/core
Quoted 1 line
And the name
update_se_runnableseems to be consistent with others.
In fact, I have reused the same name as with runnable_load_avg
Thanks and sorry for the late reply
Quoted 16 lines
Thanks,
TaoQuoted 12 lines
Not really obvious IMHO, since the code is introduced only in 4/5.
Could you add a comment to this patch header?
I see you mentioned this dependency already in v1 discussion
https://lore.kernel.org/r/CAKfTPtAM=kgF7Fz-JKFY+s_k5KFirs-8Bub3s1Eqtq7P0NMa0w@mail.gmail.com
"... But the following patches make PELT using
h_nr_running...".IMHO it would be helpful to have this explanation in the 1/5 patch header so people stop wondering why this is necessary.
Vincent Guittot
maintainerPATCH v2 2/5 sched/numa: Replace runnable_load_avg by load_avg
In reply to Vincent GuittotSimilarly to what has been done for the normal load balancer, we can replace runnable_load_avg by load_avg in numa load balancing and track the other statistics like the utilization and the number of running tasks to get to better view of the current state of a node.
--- kernel/sched/fair.c | 102 ++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 27 deletions(-)
kernel/sched/fair.c +75 -27
@@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page,group_faults_cpu (ng, src_nid) *group_faults (p, dst_nid) *4 ; } -static inline unsigned long cfs_rq_runnable_load_avg (struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load (struct rq *rq) -{ -return cfs_rq_runnable_load_avg (&rq->cfs); -} +/* +* 'numa_type' describes the node at the moment of load balancing. +*/ +enum numa_type { +/* The node has spare capacity that can be used to run more tasks. */ + node_has_spare =0 , +/* +* The node is fully used and the tasks don't compete for more CPU +* cycles. Nevertheless, some tasks might wait before running. +*/ + node_fully_busy, +/* +* The node is overloaded and can't provide expected CPU cycles to all +* tasks. +*/ + node_overloaded +};/* Cached statistics for all CPUs within a node */ struct numa_stats {unsigned long load; - +unsigned long util;/* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; +unsigned int nr_running; +unsigned int weight; +enum numa_type node_type; }; -/* -* XXX borrowed from update_sg_lb_stats -*/ -static void update_numa_stats (struct numa_stats *ns,int nid) -{ -int cpu; - -memset (ns,0 ,sizeof (*ns)); -for_each_cpu (cpu,cpumask_of_node (nid)) { -struct rq *rq =cpu_rq (cpu); - - ns->load +=cpu_runnable_load (rq); - ns->compute_capacity +=capacity_of (cpu); - } - -} -struct task_numa_env {struct task_struct *p;
@@ -1521,6 +1518,47 @@ struct task_numa_env {int best_cpu; }; +static unsigned long cpu_load (struct rq *rq); +static unsigned long cpu_util (int cpu); + +static inline enum +numa_type numa_classify (unsigned int imbalance_pct, +struct numa_stats *ns) +{ +if ((ns->nr_running > ns->weight) && + ((ns->compute_capacity *100 ) < (ns->util * imbalance_pct))) +return node_overloaded; + +if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity *100 ) > (ns->util * imbalance_pct))) +return node_has_spare; + +return node_fully_busy; +} + +/* +* XXX borrowed from update_sg_lb_stats +*/ +static void update_numa_stats (struct task_numa_env *env, +struct numa_stats *ns,int nid) +{ +int cpu; + +memset (ns,0 ,sizeof (*ns)); +for_each_cpu (cpu,cpumask_of_node (nid)) { +struct rq *rq =cpu_rq (cpu); + + ns->load +=cpu_load (rq); + ns->util +=cpu_util (cpu); + ns->nr_running += rq->cfs.h_nr_running; + ns->compute_capacity +=capacity_of (cpu); + } + + ns->weight =cpumask_weight (cpumask_of_node (nid)); + + ns->node_type =numa_classify (env->imbalance_pct, ns); +} +static void task_numa_assign (struct task_numa_env *env,struct task_struct *p,long imp) {
@@ -1556,6 +1594,11 @@ static bool load_too_imbalanced(long src_load, long dst_load,long orig_src_load, orig_dst_load;long src_capacity, dst_capacity; + +/* If dst node has spare capacity, there is no real load imbalance */ +if (env->dst_stats.node_type == node_has_spare) +return false; +/* * The load is corrected for the CPU capacity available on each node. *
@@ -1788,10 +1831,10 @@ static int task_numa_migrate(struct task_struct *p) dist = env.dist =node_distance (env.src_nid, env.dst_nid); taskweight =task_weight (p, env.src_nid, dist); groupweight =group_weight (p, env.src_nid, dist); -update_numa_stats (&env.src_stats, env.src_nid); +update_numa_stats (&env, &env.src_stats, env.src_nid); taskimp =task_weight (p, env.dst_nid, dist) - taskweight; groupimp =group_weight (p, env.dst_nid, dist) - groupweight; -update_numa_stats (&env.dst_stats, env.dst_nid); +update_numa_stats (&env, &env.dst_stats, env.dst_nid);/* Try to find a spot on the preferred nid. */ task_numa_find_cpu (&env, taskimp, groupimp);
@@ -1824,7 +1867,7 @@ static int task_numa_migrate(struct task_struct *p) env.dist = dist; env.dst_nid = nid; -update_numa_stats (&env.dst_stats, env.dst_nid); +update_numa_stats (&env, &env.dst_stats, env.dst_nid);task_numa_find_cpu (&env, taskimp, groupimp); } }
@@ -5446,6 +5489,11 @@ static unsigned long cpu_load_without(struct rq *rq, struct task_struct *p)return load; } +static unsigned long cpu_runnable_load (struct rq *rq) +{ +return cfs_rq_runnable_load_avg (&rq->cfs); +} +static unsigned long capacity_of (int cpu) {return cpu_rq (cpu)->cpu_capacity;
Signature · 1 line
2.17.1
Dietmar Eggemann
reviewerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
kernel/sched/fair.c static int task_numa_migrate(struct task_struct *p) · line 1834
Quoted 9 lines
kernel/sched/fair.c +1
-1/* * The load is corrected for the CPU capacity available on each node. * @@ -1788,10 +1831,10 @@ static int task_numa_migrate(struct task_struct *p) dist = env.dist =node_distance (env.src_nid, env.dst_nid); taskweight =task_weight (p, env.src_nid, dist); groupweight =group_weight (p, env.src_nid, dist); -update_numa_stats (&env.src_stats, env.src_nid); +update_numa_stats (&env, &env.src_stats, env.src_nid);
This looks strange. Can you do:
-static void update_numa_stats(struct task_numa_env *env, +static void update_numa_stats(unsigned int imbalance_pct,
struct numa_stats *ns, int nid)
- update_numa_stats(&env, &env.src_stats, env.src_nid);
+ update_numa_stats(env.imbalance_pct, &env.src_stats, env.src_nid);
[...]
kernel/sched/fair.c static unsigned long cpu_load_without(struct rq *rq, struct task_struct *p) · line 5496
Quoted 5 lines
kernel/sched/fair.c +5
-0+static unsigned long cpu_runnable_load (struct rq *rq) +{ +return cfs_rq_runnable_load_avg (&rq->cfs); +} +
Why not remove cpu_runnable_load() in this patch rather moving it?
kernel/sched/fair.c:5492:22: warning: ‘cpu_runnable_load’ defined but not used [-Wunused-function]
static unsigned long cpu_runnable_load(struct rq *rq)
Mel Gorman
reviewerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 17 lines · Dietmar Eggemann
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
kernel/sched/fair.c static int task_numa_migrate(struct task_struct *p) · line 1834
Quoted 9 lines
kernel/sched/fair.c +1
-1/* * The load is corrected for the CPU capacity available on each node. * @@ -1788,10 +1831,10 @@ static int task_numa_migrate(struct task_struct *p) dist = env.dist =node_distance (env.src_nid, env.dst_nid); taskweight =task_weight (p, env.src_nid, dist); groupweight =group_weight (p, env.src_nid, dist); -update_numa_stats (&env.src_stats, env.src_nid); +update_numa_stats (&env, &env.src_stats, env.src_nid);This looks strange. Can you do:
Review
Quoted 6 lines
(quoted diff) +2
-2-static void update_numa_stats(struct task_numa_env *env, +static void update_numa_stats(unsigned int imbalance_pct, struct numa_stats *ns, int nid) - update_numa_stats(&env, &env.src_stats, env.src_nid); + update_numa_stats(env.imbalance_pct, &env.src_stats, env.src_nid);
You'd also have to pass in env->p and while it could be done, I do not think its worthwhile.
Quoted 10 lines
[...]
kernel/sched/fair.c static unsigned long cpu_load_without(struct rq *rq, struct task_struct *p) · line 5496
Quoted 5 lines
kernel/sched/fair.c +5
-0+static unsigned long cpu_runnable_load (struct rq *rq) +{ +return cfs_rq_runnable_load_avg (&rq->cfs); +} +Why not remove
cpu_runnable_load()in this patch rather moving it?
Quoted 4 lines
kernel/sched/fair.c:5492:22: warning: ???cpu_runnable_load??? defined but not used [-Wunused-function]
static unsigned longcpu_runnable_load(struct rq *rq)
I took the liberty of addressing that when I picked up Vincent's patches for "Reconcile NUMA balancing decisions with the load balancer v3" to fix a build warning. I did not highlight it when I posted because it was such a trivial change.
Signature · 2 lines
Mel Gorman SUSE Labs
Vincent Guittot
maintainerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 22 lines · Mel Gorman
Quoted 20 lines · Dietmar Eggemann
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
kernel/sched/fair.c static int task_numa_migrate(struct task_struct *p) · line 1834
Quoted 9 lines
/* * The load is corrected for the CPU capacity available on each node. *kernel/sched/fair.c +1
-1@@ -1788,10 +1831,10 @@ static int task_numa_migrate(struct task_struct *p) dist = env.dist =node_distance (env.src_nid, env.dst_nid); taskweight =task_weight (p, env.src_nid, dist); groupweight =group_weight (p, env.src_nid, dist); -update_numa_stats (&env.src_stats, env.src_nid); +update_numa_stats (&env, &env.src_stats, env.src_nid);This looks strange. Can you do:
(quoted diff) +1
-1-static void update_numa_stats(struct task_numa_env *env, +static void update_numa_stats(unsigned int imbalance_pct, struct numa_stats *ns, int nid)
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +1
-1- update_numa_stats(&env, &env.src_stats, env.src_nid); + update_numa_stats(env.imbalance_pct, &env.src_stats, env.src_nid);You'd also have to pass in
env->pand while it could be done, I do not think its worthwhile.
I agree
Quoted 16 lines
Quoted 11 lines
[...]
kernel/sched/fair.c static unsigned long cpu_load_without(struct rq *rq, struct task_struct *p) · line 5496
Quoted 5 lines
kernel/sched/fair.c +5
-0+static unsigned long cpu_runnable_load (struct rq *rq) +{ +return cfs_rq_runnable_load_avg (&rq->cfs); +} +Why not remove
cpu_runnable_load()in this patch rather moving it?Quoted 4 lines
kernel/sched/fair.c:5492:22: warning: ???cpu_runnable_load??? defined but not used [-Wunused-function]
static unsigned longcpu_runnable_load(struct rq *rq)
Quoted 4 lines
I took the liberty of addressing that when I picked up Vincent's patches for "Reconcile NUMA balancing decisions with the load balancer v3" to fix a build warning. I did not highlight it when I posted because it was such a trivial change.
yes I have noticed that.
Thanks
Quoted 4 lines
--
Mel Gorman
SUSE Labs
Dietmar Eggemann
reviewerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 4 lines · Vincent Guittot
Quoted 3 lines · Mel Gorman
Quoted 1 line · Dietmar Eggemann
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +1
-1-static void update_numa_stats(struct task_numa_env *env, +static void update_numa_stats(unsigned int imbalance_pct, struct numa_stats *ns, int nid)
Quoted 8 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +1
-1- update_numa_stats(&env, &env.src_stats, env.src_nid); + update_numa_stats(env.imbalance_pct, &env.src_stats, env.src_nid);You'd also have to pass in
env->pand while it could be done, I do not think its worthwhile.I agree
Ah, another patch in Mel's patch-set:
https://lore.kernel.org/r/[email protected]
I see.
[...]
Re: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
In reply to Vincent GuittotQuoted 17 lines · Vincent Guittot
kernel/sched/fair.c +7
-6@@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page,group_faults_cpu (ng, src_nid) *group_faults (p, dst_nid) *4 ; } -static inline unsigned long cfs_rq_runnable_load_avg (struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load (struct rq *rq) -{ -return cfs_rq_runnable_load_avg (&rq->cfs); -} +/* +* 'numa_type' describes the node at the moment of load balancing. +*/ +enum numa_type { +/* The node has spare capacity that can be used to run more tasks. */ + node_has_spare =0 , +/*
kernel/sched/fair.c bool should_numa_migrate_memory(struct task_struct *p, struct page * page, · line 1492
Quoted 10 lines
kernel/sched/fair.c +10
-0+* The node is fully used and the tasks don't compete for more CPU +* cycles. Nevertheless, some tasks might wait before running. +*/ + node_fully_busy, +/* +* The node is overloaded and can't provide expected CPU cycles to all +* tasks. +*/ + node_overloaded +};
Could we reuse group_type instead? The definitions are the same modulo s/group/node/.
Quoted 45 lines
kernel/sched/fair.c +12
-18/* Cached statistics for all CPUs within a node */ struct numa_stats {unsigned long load; - +unsigned long util;/* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; +unsigned int nr_running; +unsigned int weight; +enum numa_type node_type; }; -/* -* XXX borrowed from update_sg_lb_stats -*/ -static void update_numa_stats (struct numa_stats *ns,int nid) -{ -int cpu; - -memset (ns,0 ,sizeof (*ns)); -for_each_cpu (cpu,cpumask_of_node (nid)) { -struct rq *rq =cpu_rq (cpu); - - ns->load +=cpu_runnable_load (rq); - ns->compute_capacity +=capacity_of (cpu); - } - -} -struct task_numa_env {struct task_struct *p;@@ -1521,6 +1518,47 @@ struct task_numa_env {int best_cpu; }; +static unsigned long cpu_load (struct rq *rq); +static unsigned long cpu_util (int cpu); + +static inline enum +numa_type numa_classify (unsigned int imbalance_pct, +struct numa_stats *ns) +{ + if ((ns->nr_running > ns->weight) &&
kernel/sched/fair.c struct task_numa_env { · line 1538
Quoted 10 lines
kernel/sched/fair.c +10
-0+ ((ns->compute_capacity * 100) < (ns->util * imbalance_pct))) +return node_overloaded; + +if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity *100 ) > (ns->util * imbalance_pct))) +return node_has_spare; + +return node_fully_busy; +} +
As Mel pointed out, this is group_is_overloaded() and group_has_capacity(). @Mel, you mentioned having a common helper, do you have that laying around? I haven't seen it in your reconciliation series.
What I'm naively thinking here is that we could have either move the whole thing to just sg_lb_stats (AFAICT the fields of numa_stats are a subset of it), or if we really care about the stack we could tweak the ordering to ensure we can cast one into the other (not too enticed by that one though).
Quoted 26 lines
kernel/sched/fair.c +23
-0+/* +* XXX borrowed from update_sg_lb_stats +*/ +static void update_numa_stats (struct task_numa_env *env, +struct numa_stats *ns,int nid) +{ +int cpu; + +memset (ns,0 ,sizeof (*ns)); +for_each_cpu (cpu,cpumask_of_node (nid)) { +struct rq *rq =cpu_rq (cpu); + + ns->load +=cpu_load (rq); + ns->util +=cpu_util (cpu); + ns->nr_running += rq->cfs.h_nr_running; + ns->compute_capacity +=capacity_of (cpu); + } + + ns->weight =cpumask_weight (cpumask_of_node (nid)); + + ns->node_type =numa_classify (env->imbalance_pct, ns); +} +static void task_numa_assign (struct task_numa_env *env,struct task_struct *p,long imp) {
Vincent Guittot
maintainerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 24 lines · Valentin Schneider
Quoted 22 lines · Vincent Guittot
kernel/sched/fair.c +12
-6@@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page,group_faults_cpu (ng, src_nid) *group_faults (p, dst_nid) *4 ; } -static inline unsigned long cfs_rq_runnable_load_avg (struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load (struct rq *rq) -{ -return cfs_rq_runnable_load_avg (&rq->cfs); -} +/* +* 'numa_type' describes the node at the moment of load balancing. +*/ +enum numa_type { +/* The node has spare capacity that can be used to run more tasks. */ + node_has_spare =0 , +/* +* The node is fully used and the tasks don't compete for more CPU +* cycles. Nevertheless, some tasks might wait before running. +*/ + node_fully_busy, +/*
Quoted 8 lines
kernel/sched/fair.c bool should_numa_migrate_memory(struct task_struct *p, struct page * page, · line 1492
Quoted 5 lines
kernel/sched/fair.c +5
-0+* The node is overloaded and can't provide expected CPU cycles to all +* tasks. +*/ + node_overloaded +};Could we reuse
group_typeinstead? The definitions are the same modulo s/group/node/.
Also, imbalance might have but misfit and asym have no meaning at NUMA level
For now I prefer to keep them separate to ease code readability. Also more changes will come on top of this for NUMA balancing which could also ends up with numa dedicated states
Quoted 92 lines
Quoted 46 lines
kernel/sched/fair.c +12
-18/* Cached statistics for all CPUs within a node */ struct numa_stats {unsigned long load; - +unsigned long util;/* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; +unsigned int nr_running; +unsigned int weight; +enum numa_type node_type; }; -/* -* XXX borrowed from update_sg_lb_stats -*/ -static void update_numa_stats (struct numa_stats *ns,int nid) -{ -int cpu; - -memset (ns,0 ,sizeof (*ns)); -for_each_cpu (cpu,cpumask_of_node (nid)) { -struct rq *rq =cpu_rq (cpu); - - ns->load +=cpu_runnable_load (rq); - ns->compute_capacity +=capacity_of (cpu); - } - -} -struct task_numa_env {struct task_struct *p;@@ -1521,6 +1518,47 @@ struct task_numa_env {int best_cpu; }; +static unsigned long cpu_load (struct rq *rq); +static unsigned long cpu_util (int cpu); + +static inline enum +numa_type numa_classify (unsigned int imbalance_pct, +struct numa_stats *ns) +{ + if ((ns->nr_running > ns->weight) &&kernel/sched/fair.c struct task_numa_env { · line 1538
Quoted 10 lines
kernel/sched/fair.c +10
-0+ ((ns->compute_capacity * 100) < (ns->util * imbalance_pct))) +return node_overloaded; + +if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity *100 ) > (ns->util * imbalance_pct))) +return node_has_spare; + +return node_fully_busy; +} +As Mel pointed out, this is
group_is_overloaded()andgroup_has_capacity(). @Mel, you mentioned having a common helper, do you have that laying around? I haven't seen it in your reconciliation series.What I'm naively thinking here is that we could have either move the whole thing to just
sg_lb_stats(AFAICT the fields ofnuma_statsare a subset of it), or if we really care about the stack we could tweak the ordering to ensure we can cast one into the other (not too enticed by that one though).Quoted 26 lines
kernel/sched/fair.c +23
-0+/* +* XXX borrowed from update_sg_lb_stats +*/ +static void update_numa_stats (struct task_numa_env *env, +struct numa_stats *ns,int nid) +{ +int cpu; + +memset (ns,0 ,sizeof (*ns)); +for_each_cpu (cpu,cpumask_of_node (nid)) { +struct rq *rq =cpu_rq (cpu); + + ns->load +=cpu_load (rq); + ns->util +=cpu_util (cpu); + ns->nr_running += rq->cfs.h_nr_running; + ns->compute_capacity +=capacity_of (cpu); + } + + ns->weight =cpumask_weight (cpumask_of_node (nid)); + + ns->node_type =numa_classify (env->imbalance_pct, ns); +} +static void task_numa_assign (struct task_numa_env *env,struct task_struct *p,long imp) {
Mel Gorman
reviewerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
In reply to Valentin SchneiderQuoted 23 lines · Valentin Schneider
Quoted 22 lines · Vincent Guittot
kernel/sched/fair.c +12
-6@@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page,group_faults_cpu (ng, src_nid) *group_faults (p, dst_nid) *4 ; } -static inline unsigned long cfs_rq_runnable_load_avg (struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load (struct rq *rq) -{ -return cfs_rq_runnable_load_avg (&rq->cfs); -} +/* +* 'numa_type' describes the node at the moment of load balancing. +*/ +enum numa_type { +/* The node has spare capacity that can be used to run more tasks. */ + node_has_spare =0 , +/* +* The node is fully used and the tasks don't compete for more CPU +* cycles. Nevertheless, some tasks might wait before running. +*/ + node_fully_busy, +/*
Quoted 9 lines
kernel/sched/fair.c bool should_numa_migrate_memory(struct task_struct *p, struct page * page, · line 1492
Quoted 5 lines
kernel/sched/fair.c +5
-0+* The node is overloaded and can't provide expected CPU cycles to all +* tasks. +*/ + node_overloaded +};Could we reuse
group_typeinstead? The definitions are the same modulo s/group/node/.
I kept the naming because there is the remote possibility that NUMA balancing will deviate in some fashion. Right now, it's harmless.
Quoted 51 lines
Quoted 51 lines
kernel/sched/fair.c +18
-18/* Cached statistics for all CPUs within a node */ struct numa_stats {unsigned long load; - +unsigned long util;/* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; +unsigned int nr_running; +unsigned int weight; +enum numa_type node_type; }; -/* -* XXX borrowed from update_sg_lb_stats -*/ -static void update_numa_stats (struct numa_stats *ns,int nid) -{ -int cpu; - -memset (ns,0 ,sizeof (*ns)); -for_each_cpu (cpu,cpumask_of_node (nid)) { -struct rq *rq =cpu_rq (cpu); - - ns->load +=cpu_runnable_load (rq); - ns->compute_capacity +=capacity_of (cpu); - } - -} -struct task_numa_env {struct task_struct *p;@@ -1521,6 +1518,47 @@ struct task_numa_env {int best_cpu; }; +static unsigned long cpu_load (struct rq *rq); +static unsigned long cpu_util (int cpu); + +static inline enum +numa_type numa_classify (unsigned int imbalance_pct, +struct numa_stats *ns) +{ +if ((ns->nr_running > ns->weight) && + ((ns->compute_capacity *100 ) < (ns->util * imbalance_pct))) +return node_overloaded; + +if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity *100 ) > (ns->util * imbalance_pct))) +return node_has_spare;
Quoted 9 lines
kernel/sched/fair.c struct task_numa_env { · line 1538
Quoted 4 lines
kernel/sched/fair.c +4
-0+ +return node_fully_busy; +} +As Mel pointed out, this is
group_is_overloaded()andgroup_has_capacity(). @Mel, you mentioned having a common helper, do you have that laying around? I haven't seen it in your reconciliation series.
I didn't merge that part of the first version of my series. I was waiting to see how the implementation for allowing a small degree of imbalance looks like. If it's entirely confined in adjust_numa_balance then I'll create the common helper at the same time. For now, I left the possibility open that numa_classify would use something different than group_is_overloaded or group_has_capacity even if I find that hard to imagine at the moment.
Quoted 5 lines
What I'm naively thinking here is that we could have either move the whole thing to just
sg_lb_stats(AFAICT the fields ofnuma_statsare a subset of it), or if we really care about the stack we could tweak the ordering to ensure we can cast one into the other (not too enticed by that one though).
Yikes, no I'd rather not do that. Basically all I did before was create a common helper like __lb_has_capacity that only took basic types as parameters. group_has_capacity and numa_has_capacity were simple wrappers that read the correct fields from their respective stats structures.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 8 lines · Mel Gorman
Quoted 4 lines
Could we reuse
group_typeinstead? The definitions are the same modulo s/group/node/.I kept the naming because there is the remote possibility that NUMA balancing will deviate in some fashion. Right now, it's harmless.
Since it's just a subset ATM I'd go for the reuse and change that later if shown a split is required, but fair enough.
Quoted 3 lines
I didn't merge that part of the first version of my series. I was waiting to see how the implementation for allowing a small degree of imbalance looks like. If it's entirely confined in
adjust_numa_balance
^^^^^^^^^^^^^^^^^^^
Apologies if that's a newbie question, but I'm not familiar with that one. Would that be added in your reconciliation series? I've only had a brief look at it yet (it's next on the chopping block).
Quoted 11 lines
then I'll create the common helper at the same time. For now, I left the possibility open that
numa_classifywould use something different thangroup_is_overloadedorgroup_has_capacityeven if I find that hard to imagine at the moment.Quoted 5 lines
What I'm naively thinking here is that we could have either move the whole thing to just
sg_lb_stats(AFAICT the fields ofnuma_statsare a subset of it), or if we really care about the stack we could tweak the ordering to ensure we can cast one into the other (not too enticed by that one though).
Quoted 5 lines
Yikes, no I'd rather not do that. Basically all I did before was create a common helper like
__lb_has_capacitythat only took basic types as parameters.group_has_capacityandnuma_has_capacitywere simple wrappers that read the correct fields from their respective stats structures.
That's more sensible indeed. It'd definitely be nice to actually reconcile the two balancers with these common helpers, though I guess it doesn't *have* to happen with this very patch.
Mel Gorman
reviewerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 6 lines · Valentin Schneider
Quoted 5 lines · Mel Gorman
Quoted 4 lines
Could we reuse
group_typeinstead? The definitions are the same modulo s/group/node/.
Quoted 7 lines
Quoted 3 lines
I kept the naming because there is the remote possibility that NUMA balancing will deviate in some fashion. Right now, it's harmless.
Since it's just a subset ATM I'd go for the reuse and change that later if shown a split is required, but fair enough.
I would feel that I was churning code for the sake of it.
Quoted 8 lines
Quoted 3 lines
I didn't merge that part of the first version of my series. I was waiting to see how the implementation for allowing a small degree of imbalance looks like. If it's entirely confined in
adjust_numa_balance^^^^^^^^^^^^^^^^^^^Apologies if that's a newbie question, but I'm not familiar with that one. Would that be added in your reconciliation series? I've only had a brief look at it yet (it's next on the chopping block).
I should have wrote adjust_numa_imbalance but yes, it's part of the reconciled series so that NUMA balancing and the load balancer use the same helper.
Quoted 9 lines
Quoted 5 lines
Yikes, no I'd rather not do that. Basically all I did before was create a common helper like
__lb_has_capacitythat only took basic types as parameters.group_has_capacityandnuma_has_capacitywere simple wrappers that read the correct fields from their respective stats structures.That's more sensible indeed. It'd definitely be nice to actually reconcile the two balancers with these common helpers, though I guess it doesn't *have* to happen with this very patch.
Yep, it can happen at a later time.
As it stands, I think the reconciled series stands on its own even though there are further improvements that could be built on top.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
Quoted 9 lines · Mel Gorman
Quoted 8 lines
Quoted 3 lines
I didn't merge that part of the first version of my series. I was waiting to see how the implementation for allowing a small degree of imbalance looks like. If it's entirely confined in
adjust_numa_balance^^^^^^^^^^^^^^^^^^^Apologies if that's a newbie question, but I'm not familiar with that one. Would that be added in your reconciliation series? I've only had a brief look at it yet (it's next on the chopping block).
Quoted 4 lines
I should have wrote
adjust_numa_imbalancebut yes, it's part of the reconciled series so that NUMA balancing and the load balancer use the same helper.
Okay, thanks, then I guess I'll forget about any reconciliation for now and whinge about it when I'll get to your series ;)
Vincent Guittot
maintainerRe: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg
In reply to Mel GormanQuoted 35 lines · Mel Gorman
Quoted 23 lines · Valentin Schneider
Quoted 22 lines · Vincent Guittot
kernel/sched/fair.c +12
-6@@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page,group_faults_cpu (ng, src_nid) *group_faults (p, dst_nid) *4 ; } -static inline unsigned long cfs_rq_runnable_load_avg (struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load (struct rq *rq) -{ -return cfs_rq_runnable_load_avg (&rq->cfs); -} +/* +* 'numa_type' describes the node at the moment of load balancing. +*/ +enum numa_type { +/* The node has spare capacity that can be used to run more tasks. */ + node_has_spare =0 , +/* +* The node is fully used and the tasks don't compete for more CPU +* cycles. Nevertheless, some tasks might wait before running. +*/ + node_fully_busy, +/* Quoted 9 lines
kernel/sched/fair.c bool should_numa_migrate_memory(struct task_struct *p, struct page * page, · line 1492
Quoted 5 lines
kernel/sched/fair.c +5
-0+* The node is overloaded and can't provide expected CPU cycles to all +* tasks. +*/ + node_overloaded +};Could we reuse
group_typeinstead? The definitions are the same modulo s/group/node/.
Quoted 2 lines
I kept the naming because there is the remote possibility that NUMA balancing will deviate in some fashion. Right now, it's harmless.
+1
This 1st round mainly aims to align NUMA way of working with load balance but we can imagine using some NUMA or memory specific information to create new state
Quoted 84 lines
Quoted 52 lines
Quoted 52 lines
kernel/sched/fair.c +18
-18/* Cached statistics for all CPUs within a node */ struct numa_stats {unsigned long load; - +unsigned long util;/* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; +unsigned int nr_running; +unsigned int weight; +enum numa_type node_type; }; -/* -* XXX borrowed from update_sg_lb_stats -*/ -static void update_numa_stats (struct numa_stats *ns,int nid) -{ -int cpu; - -memset (ns,0 ,sizeof (*ns)); -for_each_cpu (cpu,cpumask_of_node (nid)) { -struct rq *rq =cpu_rq (cpu); - - ns->load +=cpu_runnable_load (rq); - ns->compute_capacity +=capacity_of (cpu); - } - -} -struct task_numa_env {struct task_struct *p;@@ -1521,6 +1518,47 @@ struct task_numa_env {int best_cpu; }; +static unsigned long cpu_load (struct rq *rq); +static unsigned long cpu_util (int cpu); + +static inline enum +numa_type numa_classify (unsigned int imbalance_pct, +struct numa_stats *ns) +{ +if ((ns->nr_running > ns->weight) && + ((ns->compute_capacity *100 ) < (ns->util * imbalance_pct))) +return node_overloaded; + +if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity *100 ) > (ns->util * imbalance_pct))) +return node_has_spare;Quoted 9 lines
kernel/sched/fair.c struct task_numa_env { · line 1538
Quoted 4 lines
kernel/sched/fair.c +4
-0+ +return node_fully_busy; +} +As Mel pointed out, this is
group_is_overloaded()andgroup_has_capacity(). @Mel, you mentioned having a common helper, do you have that laying around? I haven't seen it in your reconciliation series.I didn't merge that part of the first version of my series. I was waiting to see how the implementation for allowing a small degree of imbalance looks like. If it's entirely confined in
adjust_numa_balancethen I'll create the common helper at the same time. For now, I left the possibility open thatnuma_classifywould use something different thangroup_is_overloadedorgroup_has_capacityeven if I find that hard to imagine at the moment.Quoted 5 lines
What I'm naively thinking here is that we could have either move the whole thing to just
sg_lb_stats(AFAICT the fields ofnuma_statsare a subset of it), or if we really care about the stack we could tweak the ordering to ensure we can cast one into the other (not too enticed by that one though).Yikes, no I'd rather not do that. Basically all I did before was create a common helper like
__lb_has_capacitythat only took basic types as parameters.group_has_capacityandnuma_has_capacitywere simple wrappers that read the correct fields from their respective stats structures.--
Mel Gorman
SUSE Labs
Vincent Guittot
maintainerPATCH v2 3/5 sched/pelt: Remove unused runnable load average
In reply to Vincent GuittotNow that runnable_load_avg is no more used, we can remove it to make space for a new signal.
--- include/linux/sched.h | 5 +- kernel/sched/core.c | 2 - kernel/sched/debug.c | 8 --- kernel/sched/fair.c | 136 +++++------------------------------------- kernel/sched/pelt.c | 62 ++++++++----------- kernel/sched/sched.h | 7 +-- 6 files changed, 41 insertions(+), 179 deletions(-)
include/linux/sched.h +1 -4
@@ -357,7 +357,7 @@ struct util_est {/* * The load_avg/util_avg accumulates an infinite geometric series -* (see __update_load_avg() in kernel/sched/fair.c). +* (see __update_load_avg_cfs_rq() in kernel/sched/pelt.c). * * [load_avg definition] *
@@ -401,11 +401,9 @@ struct util_est {struct sched_avg {u64 last_update_time;u64 load_sum; -u64 runnable_load_sum;u32 util_sum;u32 period_contrib;unsigned long load_avg; -unsigned long runnable_load_avg;unsigned long util_avg;struct util_est util_est; }____cacheline_aligned ;
@@ -449,7 +447,6 @@ struct sched_statistics {struct sched_entity {/* For load-balancing: */ struct load_weight load; -unsigned long runnable_weight;struct rb_node run_node;struct list_head group_node;unsigned int on_rq;
kernel/sched/core.c +0 -2
@@ -761,7 +761,6 @@ static void set_load_weight(struct task_struct *p, bool update_load)if (task_has_idle_policy (p)) { load->weight =scale_load (WEIGHT_IDLEPRIO ); load->inv_weight =WMULT_IDLEPRIO ; - p->se.runnable_weight = load->weight;return ; }
@@ -774,7 +773,6 @@ 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/debug.c +0 -8
@@ -402,11 +402,9 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group }P (se->load.weight); -P (se->runnable_weight);#ifdef CONFIG_SMP P (se->avg.load_avg);P (se->avg.util_avg); -P (se->avg.runnable_load_avg);#endif #undef PN_SCHEDSTAT
@@ -524,11 +522,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)SEQ_printf (m," .%-30s: %d\n" ,"nr_running" , cfs_rq->nr_running);SEQ_printf (m," .%-30s: %ld\n" ,"load" , cfs_rq->load.weight);#ifdef CONFIG_SMP -SEQ_printf (m," .%-30s: %ld\n" ,"runnable_weight" , cfs_rq->runnable_weight);SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg); -SEQ_printf (m," .%-30s: %lu\n" ,"runnable_load_avg" , - cfs_rq->avg.runnable_load_avg);SEQ_printf (m," .%-30s: %lu\n" ,"util_avg" , cfs_rq->avg.util_avg); SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued",
@@ -947,13 +942,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns, "nr_involuntary_switches", (long long)p->nivcsw);P (se.load.weight); -P (se.runnable_weight);#ifdef CONFIG_SMP P (se.avg.load_sum); -P (se.avg.runnable_load_sum);P (se.avg.util_sum);P (se.avg.load_avg); -P (se.avg.runnable_load_avg);P (se.avg.util_avg);P (se.avg.last_update_time);P (se.avg.util_est.ewma);
kernel/sched/fair.c +14 -122
286 lines not on this page · raw message
kernel/sched/pelt.c +24 -38
195 lines not on this page · raw message
kernel/sched/sched.h +2 -5
@@ -489,7 +489,6 @@ struct cfs_bandwidth { };/* CFS-related fields in a runqueue */ struct cfs_rq {struct load_weight load; -unsigned long runnable_weight;unsigned int nr_running;unsigned int h_nr_running;/* SCHED_{NORMAL,BATCH,IDLE} */ unsigned int idle_h_nr_running;/* SCHED_IDLE */
@@ -688,8 +687,10 @@ struct dl_rq {#ifdef CONFIG_FAIR_GROUP_SCHED /* An entity is a task if it doesn't "own" a runqueue */ #define entity_is_task (se) (!se->my_q) +#else #define entity_is_task (se) 1 +#endif #ifdef CONFIG_SMP
@@ -701,10 +702,6 @@ static inline long se_weight(struct sched_entity *se)return scale_load_down (se->load.weight); } -static inline long se_runnable (struct sched_entity *se) -{ -return scale_load_down (se->runnable_weight); -}static inline bool sched_asym_prefer (int a,int b) {
Signature · 1 line
2.17.1
Dietmar Eggemann
reviewerRe: [PATCH v2 3/5] sched/pelt: Remove unused runnable load average
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
fdef CONFIG_SMP
Quoted 4 lines
kernel/sched/fair.c +0
-0@@ -2940,15 +2913,12 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,u32 divider =LOAD_AVG_MAX -1024 + se->avg.period_contrib; se->avg.load_avg =div_u64 (se_weight (se) * se->avg.load_sum, divider);
kernel/sched/fair.c static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, · line 2922
Quoted 10 lines
kernel/sched/fair.c +0
-3- se->avg.runnable_load_avg = - div_u64(se_runnable(se) * se->avg.runnable_load_sum, divider); } while (0);#endif enqueue_load_avg (cfs_rq, se);if (se->on_rq) {account_entity_enqueue (cfs_rq, se); -enqueue_runnable_load_avg (cfs_rq, se); }
Nit pick: No curly brackets needed anymore.
[...]
Vincent Guittot
maintainerRe: [PATCH v2 3/5] sched/pelt: Remove unused runnable load average
Quoted 15 lines · Dietmar Eggemann
On 14/02/2020 16:27, Vincent Guittot wrote:
[...]
fdef
CONFIG_SMPQuoted 9 lines
kernel/sched/fair.c +0
-2@@ -2940,15 +2913,12 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,u32 divider =LOAD_AVG_MAX -1024 + se->avg.period_contrib; se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider); - se->avg.runnable_load_avg = - div_u64(se_runnable(se) * se->avg.runnable_load_sum, divider); }while (0 );#endif
Quoted 8 lines
kernel/sched/fair.c static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, · line 2922
Quoted 5 lines
kernel/sched/fair.c +0
-1enqueue_load_avg (cfs_rq, se);if (se->on_rq) {account_entity_enqueue (cfs_rq, se); -enqueue_runnable_load_avg (cfs_rq, se); }Nit pick: No curly brackets needed anymore.
good catch
Quoted 1 line
[...]
Vincent Guittot
maintainerPATCH v2 4/5 sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotNow that runnable_load_avg has been removed, we can replace it by a new signal that will highlight the runnable pressure on a cfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.
At now, only util_avg is used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.
But the util_avg signal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.
When tasks compete for the same rq, their runnable average signal will be higher than util_avg as it will include the waiting time and we can use this signal to better classify cfs_rqs.
The new runnable_avg will track the runnable time of a task which simply adds the waiting time to the running time. The runnable _avg of cfs_rq will be the /Sum of se's runnable_avg and the runnable_avg of group entity will follow the one of the rq similarly to util_avg.
--- include/linux/sched.h | 28 +++++++++------ kernel/sched/debug.c | 9 +++-- kernel/sched/fair.c | 79 ++++++++++++++++++++++++++++++++++++++----- kernel/sched/pelt.c | 51 +++++++++++++++++++--------- kernel/sched/sched.h | 22 +++++++++++- 5 files changed, 151 insertions(+), 38 deletions(-)
include/linux/sched.h +17 -11
@@ -356,28 +356,30 @@ struct util_est { } __attribute__((__aligned__(sizeof(u64))));/* -* The load_avg/util_avg accumulates an infinite geometric series +* The load/runnable/util_avg accumulates an infinite geometric series * (see __update_load_avg_cfs_rq() in kernel/sched/pelt.c). * * [load_avg definition] * * load_avg = runnable% * scale_load_down(load) * -* where runnable% is the time ratio that a sched_entity is runnable. -* For cfs_rq, it is the aggregated load_avg of all runnable and -* blocked sched_entities. +* [runnable_avg definition] * -* [util_avg definition] +* runnable_avg = runnable% * SCHED_CAPACITY_SCALE +* +* [util_avg definition] * * util_avg = running% * SCHED_CAPACITY_SCALE * -* where running% is the time ratio that a sched_entity is running on -* a CPU. For cfs_rq, it is the aggregated util_avg of all runnable -* and blocked sched_entities. +* where runnable% is the time ratio that a sched_entity is runnable and +* running% the time ratio that a sched_entity is running. +* +* For cfs_rq, they are the aggregated values of all runnable and blocked +* sched_entities. * -* load_avg and util_avg don't direcly factor frequency scaling and CPU -* capacity scaling. The scaling is done through the rq_clock_pelt that -* is used for computing those signals (see update_rq_clock_pelt()) +* The load/runnable/util_avg doesn't direcly factor frequency scaling and CPU +* capacity scaling. The scaling is done through the rq_clock_pelt that is used +* for computing those signals (see update_rq_clock_pelt()) * * N.B., the above ratios (runnable% and running%) themselves are in the * range of [0, 1]. To do fixed point arithmetics, we therefore scale them
@@ -401,9 +403,11 @@ struct util_est {struct sched_avg {u64 last_update_time;u64 load_sum; +u64 runnable_sum;u32 util_sum;u32 period_contrib;unsigned long load_avg; +unsigned long runnable_avg;unsigned long util_avg;struct util_est util_est; }____cacheline_aligned ;
@@ -467,6 +471,8 @@ struct sched_entity {struct cfs_rq *cfs_rq;/* rq "owned" by this entity/group: */ struct cfs_rq *my_q; +/* cached value of my_q->h_nr_running */ +unsigned long runnable_weight;#endif #ifdef CONFIG_SMP
kernel/sched/debug.c +7 -2
@@ -405,6 +405,7 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group#ifdef CONFIG_SMP P (se->avg.load_avg);P (se->avg.util_avg); +P (se->avg.runnable_avg);#endif #undef PN_SCHEDSTAT
@@ -524,6 +525,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)#ifdef CONFIG_SMP SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg); +SEQ_printf (m," .%-30s: %lu\n" ,"runnable_avg" , + cfs_rq->avg.runnable_avg);SEQ_printf (m," .%-30s: %lu\n" ,"util_avg" , cfs_rq->avg.util_avg); SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued",
@@ -532,8 +535,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->removed.load_avg);SEQ_printf (m," .%-30s: %ld\n" ,"removed.util_avg" , cfs_rq->removed.util_avg); -SEQ_printf (m," .%-30s: %ld\n" ,"removed.runnable_sum" , - cfs_rq->removed.runnable_sum); +SEQ_printf (m," .%-30s: %ld\n" ,"removed.runnable_avg" , + cfs_rq->removed.runnable_avg);#ifdef CONFIG_FAIR_GROUP_SCHED SEQ_printf (m," .%-30s: %lu\n" ,"tg_load_avg_contrib" , cfs_rq->tg_load_avg_contrib);
@@ -944,8 +947,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,P (se.load.weight);#ifdef CONFIG_SMP P (se.avg.load_sum); +P (se.avg.runnable_sum);P (se.avg.util_sum);P (se.avg.load_avg); +P (se.avg.runnable_avg);P (se.avg.util_avg);P (se.avg.last_update_time);P (se.avg.util_est.ewma);
kernel/sched/fair.c +71 -8
195 lines not on this page · raw message
kernel/sched/pelt.c +35 -16
184 lines not on this page · raw message
kernel/sched/sched.h +21 -1
@@ -527,7 +527,7 @@ struct cfs_rq {int nr;unsigned long load_avg;unsigned long util_avg; -unsigned long runnable_sum; +unsigned long runnable_avg; } removed;#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -688,9 +688,29 @@ struct dl_rq {/* An entity is a task if it doesn't "own" a runqueue */ #define entity_is_task (se) (!se->my_q) +static inline void se_update_runnable (struct sched_entity *se) +{ +if (!entity_is_task (se)) + se->runnable_weight = se->my_q->h_nr_running; +} + +static inline long se_runnable (struct sched_entity *se) +{ +if (entity_is_task (se)) +return !!se->on_rq; +else +return se->runnable_weight; +} +#else #define entity_is_task (se) 1 +static inline void se_update_runnable (struct sched_entity *se) {} + +static inline long se_runnable (struct sched_entity *se) +{ +return !!se->on_rq; +}#endif #ifdef CONFIG_SMP
Signature · 1 line
2.17.1
Re: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
Review void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) · line 536
Quoted 6 lines · Vincent Guittot
(quoted diff) +0
-2@@ -532,8 +535,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->removed.load_avg); SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg", cfs_rq->removed.util_avg); - SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_sum", - cfs_rq->removed.runnable_sum);
Shouldn't that have been part of patch 3?
Quoted 25 lines
(quoted diff) +18
-0+ SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_avg", + cfs_rq->removed.runnable_avg); #ifdef CONFIG_FAIR_GROUP_SCHED SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib", cfs_rq->tg_load_avg_contrib);@@ -3278,6 +3280,32 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq cfs_rq->avg.util_sum = cfs_rq->avg.util_avg * LOAD_AVG_MAX; } +static inline void +update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) +{ + long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; + + /* Nothing to update */ + if (!delta) + return; + + /* + * The relation between sum and avg is: + * + * LOAD_AVG_MAX - 1024 + sa->period_contrib + * + * however, the PELT windows are not aligned between grq and gse. + */
Review update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq · line 3308
Quoted 10 lines
(quoted diff) +10
-0+ + /* Set new sched_entity's runnable */ + se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; + se->avg.runnable_sum = se->avg.runnable_avg * LOAD_AVG_MAX; + + /* Update parent cfs_rq runnable */ + add_positive(&cfs_rq->avg.runnable_avg, delta); + cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg * LOAD_AVG_MAX; +} +
Humph, that's an exact copy of update_tg_cfs_util(). FWIW the following eldritch horror compiles...
---
kernel/sched/fair.c +27 -50
@@ -3254,57 +3254,34 @@ void set_task_rq_fair(struct sched_entity *se,* */ -static inline void -update_tg_cfs_util (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) -{ -long delta = gcfs_rq->avg.util_avg - se->avg.util_avg; - -/* Nothing to update */ -if (!delta) -return ; - -/* -* The relation between sum and avg is: -* -* LOAD_AVG_MAX - 1024 + sa->period_contrib -* -* however, the PELT windows are not aligned between grq and gse. -*/ - -/* Set new sched_entity's utilization */ - se->avg.util_avg = gcfs_rq->avg.util_avg; - se->avg.util_sum = se->avg.util_avg *LOAD_AVG_MAX ; - -/* Update parent cfs_rq utilization */ -add_positive (&cfs_rq->avg.util_avg, delta); - cfs_rq->avg.util_sum = cfs_rq->avg.util_avg *LOAD_AVG_MAX ; -} - -static inline void -update_tg_cfs_runnable (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) -{ -long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; - -/* Nothing to update */ -if (!delta) -return ; - -/* -* The relation between sum and avg is: -* -* LOAD_AVG_MAX - 1024 + sa->period_contrib -* -* however, the PELT windows are not aligned between grq and gse. -*/ - -/* Set new sched_entity's runnable */ - se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; - se->avg.runnable_sum = se->avg.runnable_avg *LOAD_AVG_MAX ; +#define DECLARE_UPDATE_TG_CFS_SIGNAL (signal) \ +static inline void \ +update_tg_cfs_##signal(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) \ +{ \ + long delta = gcfs_rq->avg.signal##_avg - se->avg.signal##_avg; \ + \ +/* Nothing to update */ \ +if (!delta) \ +return ; \ + \ +/* \ +* The relation between sum and avg is: \ +* \ +* LOAD_AVG_MAX - 1024 + sa->period_contrib \ +* \ +* however, the PELT windows are not aligned between grq and gse. \ +*/ \ +/* Set new sched_entity's runnable */ \ + se->avg.signal##_avg = gcfs_rq->avg.signal##_avg; \ + se->avg.signal##_sum = se->avg.signal##_avg * LOAD_AVG_MAX; \ + \ +/* Update parent cfs_rq signal## */ \ + add_positive(&cfs_rq->avg.signal##_avg, delta); \ + cfs_rq->avg.signal##_sum = cfs_rq->avg.signal##_avg * LOAD_AVG_MAX; \ +} \ -/* Update parent cfs_rq runnable */ -add_positive (&cfs_rq->avg.runnable_avg, delta); - cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg *LOAD_AVG_MAX ; -} +DECLARE_UPDATE_TG_CFS_SIGNAL (util); +DECLARE_UPDATE_TG_CFS_SIGNAL (runnable);static inline void update_tg_cfs_load (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq)
---
Quoted 12 lines
(quoted diff) +1
-0static inline void update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) {@@ -3358,6 +3386,7 @@ static inline int propagate_entity_load_avg(struct sched_entity *se) add_tg_cfs_propagate(cfs_rq, gcfs_rq->prop_runnable_sum); update_tg_cfs_util(cfs_rq, se, gcfs_rq); + update_tg_cfs_runnable(cfs_rq, se, gcfs_rq); update_tg_cfs_load(cfs_rq, se, gcfs_rq); trace_pelt_cfs_tp(cfs_rq);
Review update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) · line 3442
Quoted 4 lines
(quoted diff) +0
-1@@ -3439,7 +3468,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) raw_spin_lock(&cfs_rq->removed.lock); swap(cfs_rq->removed.util_avg, removed_util); swap(cfs_rq->removed.load_avg, removed_load); - swap(cfs_rq->removed.runnable_sum, removed_runnable_sum);
Ditto on the stray from patch 3?
Quoted 5 lines
(quoted diff) +1
-0+ swap(cfs_rq->removed.runnable_avg, removed_runnable); cfs_rq->removed.nr = 0; raw_spin_unlock(&cfs_rq->removed.lock);@@ -3451,7 +3480,16 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
Peter Zijlstra
maintainerRe: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
Quoted 26 lines · Valentin Schneider
Humph, that's an exact copy of
update_tg_cfs_util(). FWIW the following eldritch horror compiles...kernel/sched/fair.c +22
-0+#define DECLARE_UPDATE_TG_CFS_SIGNAL (signal) \ +static inline void \ +update_tg_cfs_##signal(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) \ +{ \ + long delta = gcfs_rq->avg.signal##_avg - se->avg.signal##_avg; \ + \ +/* Nothing to update */ \ +if (!delta) \ +return ; \ + \ +/* \ +* The relation between sum and avg is: \ +* \ +* LOAD_AVG_MAX - 1024 + sa->period_contrib \ +* \ +* however, the PELT windows are not aligned between grq and gse. \ +*/ \ +/* Set new sched_entity's runnable */ \ + se->avg.signal##_avg = gcfs_rq->avg.signal##_avg; \ + se->avg.signal##_sum = se->avg.signal##_avg * LOAD_AVG_MAX; \ + \ +/* Update parent cfs_rq signal## */ \
kernel/sched/fair.c void set_task_rq_fair(struct sched_entity *se, · line 3284
Quoted 10 lines
kernel/sched/fair.c +5
-4+ add_positive(&cfs_rq->avg.signal##_avg, delta); \ + cfs_rq->avg.signal##_sum = cfs_rq->avg.signal##_avg * LOAD_AVG_MAX; \ +} \ -/* Update parent cfs_rq runnable */ -add_positive (&cfs_rq->avg.runnable_avg, delta); - cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg *LOAD_AVG_MAX ; -} +DECLARE_UPDATE_TG_CFS_SIGNAL (util); +DECLARE_UPDATE_TG_CFS_SIGNAL (runnable);
I'm not sure that's actually better though... :-)
Vincent Guittot
maintainerRe: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
In reply to Valentin SchneiderQuoted 10 lines · Valentin Schneider
Review void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) · line 536
Quoted 6 lines · Vincent Guittot
(quoted diff) +0
-2@@ -532,8 +535,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->removed.load_avg); SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg", cfs_rq->removed.util_avg); - SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_sum", - cfs_rq->removed.runnable_sum);Shouldn't that have been part of patch 3?
No this was used to propagate load_avg
Quoted 117 lines
Quoted 26 lines
(quoted diff) +18
-0+ SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_avg", + cfs_rq->removed.runnable_avg); #ifdef CONFIG_FAIR_GROUP_SCHED SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib", cfs_rq->tg_load_avg_contrib);@@ -3278,6 +3280,32 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq cfs_rq->avg.util_sum = cfs_rq->avg.util_avg * LOAD_AVG_MAX; } +static inline void +update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) +{ + long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; + + /* Nothing to update */ + if (!delta) + return; + + /* + * The relation between sum and avg is: + * + * LOAD_AVG_MAX - 1024 + sa->period_contrib + * + * however, the PELT windows are not aligned between grq and gse. + */Review update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq · line 3308
Quoted 10 lines
(quoted diff) +10
-0+ + /* Set new sched_entity's runnable */ + se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; + se->avg.runnable_sum = se->avg.runnable_avg * LOAD_AVG_MAX; + + /* Update parent cfs_rq runnable */ + add_positive(&cfs_rq->avg.runnable_avg, delta); + cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg * LOAD_AVG_MAX; +} +Humph, that's an exact copy of
update_tg_cfs_util(). FWIW the following eldritch horror compiles...---
kernel/sched/fair.c +22
-46@@ -3254,57 +3254,34 @@ void set_task_rq_fair(struct sched_entity *se,* */ -static inline void -update_tg_cfs_util (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) -{ -long delta = gcfs_rq->avg.util_avg - se->avg.util_avg; - -/* Nothing to update */ -if (!delta) -return ; - -/* -* The relation between sum and avg is: -* -* LOAD_AVG_MAX - 1024 + sa->period_contrib -* -* however, the PELT windows are not aligned between grq and gse. -*/ - -/* Set new sched_entity's utilization */ - se->avg.util_avg = gcfs_rq->avg.util_avg; - se->avg.util_sum = se->avg.util_avg *LOAD_AVG_MAX ; - -/* Update parent cfs_rq utilization */ -add_positive (&cfs_rq->avg.util_avg, delta); - cfs_rq->avg.util_sum = cfs_rq->avg.util_avg *LOAD_AVG_MAX ; -} - -static inline void -update_tg_cfs_runnable (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) -{ -long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; - -/* Nothing to update */ -if (!delta) -return ; - -/* -* The relation between sum and avg is: -* -* LOAD_AVG_MAX - 1024 + sa->period_contrib -* -* however, the PELT windows are not aligned between grq and gse. -*/ - -/* Set new sched_entity's runnable */ - se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; - se->avg.runnable_sum = se->avg.runnable_avg *LOAD_AVG_MAX ; +#define DECLARE_UPDATE_TG_CFS_SIGNAL (signal) \ +static inline void \ +update_tg_cfs_##signal(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) \ +{ \ + long delta = gcfs_rq->avg.signal##_avg - se->avg.signal##_avg; \ + \ +/* Nothing to update */ \ +if (!delta) \ +return ; \ + \ +/* \ +* The relation between sum and avg is: \ +* \ +* LOAD_AVG_MAX - 1024 + sa->period_contrib \ +* \ +* however, the PELT windows are not aligned between grq and gse. \ +*/ \ +/* Set new sched_entity's runnable */ \ + se->avg.signal##_avg = gcfs_rq->avg.signal##_avg; \ + se->avg.signal##_sum = se->avg.signal##_avg * LOAD_AVG_MAX; \ + \ +/* Update parent cfs_rq signal## */ \
kernel/sched/fair.c void set_task_rq_fair(struct sched_entity *se, · line 3284
Quoted 10 lines
kernel/sched/fair.c +5
-4+ add_positive(&cfs_rq->avg.signal##_avg, delta); \ + cfs_rq->avg.signal##_sum = cfs_rq->avg.signal##_avg * LOAD_AVG_MAX; \ +} \ -/* Update parent cfs_rq runnable */ -add_positive (&cfs_rq->avg.runnable_avg, delta); - cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg *LOAD_AVG_MAX ; -} +DECLARE_UPDATE_TG_CFS_SIGNAL (util); +DECLARE_UPDATE_TG_CFS_SIGNAL (runnable);
TBH, I prefer keeping the current version which is easier to read IMO
Quoted 15 lines
kernel/sched/fair.c +0
-1static inline void update_tg_cfs_load (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) ---Quoted 11 lines
kernel/sched/fair.c +1
-0static inline void update_tg_cfs_load (struct cfs_rq *cfs_rq,struct sched_entity *se,struct cfs_rq *gcfs_rq) {@@ -3358,6 +3386,7 @@ static inline int propagate_entity_load_avg(struct sched_entity *se)add_tg_cfs_propagate (cfs_rq, gcfs_rq->prop_runnable_sum);update_tg_cfs_util (cfs_rq, se, gcfs_rq); +update_tg_cfs_runnable (cfs_rq, se, gcfs_rq);update_tg_cfs_load (cfs_rq, se, gcfs_rq);
Quoted 8 lines
Review update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) · line 3442
Quoted 6 lines
(quoted diff) +0
-1trace_pelt_cfs_tp(cfs_rq);@@ -3439,7 +3468,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) raw_spin_lock(&cfs_rq->removed.lock); swap(cfs_rq->removed.util_avg, removed_util); swap(cfs_rq->removed.load_avg, removed_load); - swap(cfs_rq->removed.runnable_sum, removed_runnable_sum);Ditto on the stray from patch 3?
same as 1st point above
Quoted 7 lines
Quoted 6 lines
(quoted diff) +1
-0+ swap(cfs_rq->removed.runnable_avg, removed_runnable); cfs_rq->removed.nr = 0; raw_spin_unlock(&cfs_rq->removed.lock);@@ -3451,7 +3480,16 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
Re: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
Quoted 11 lines · Vincent Guittot
Quoted 8 lines
Review void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) · line 536
Quoted 6 lines
(quoted diff) +0
-2@@ -532,8 +535,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->removed.load_avg); SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg", cfs_rq->removed.util_avg); - SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_sum", - cfs_rq->removed.runnable_sum);Shouldn't that have been part of patch 3?
No this was used to propagate
load_avg
Right, sorry about that.
Quoted 6 lines
kernel/sched/fair.c void set_task_rq_fair(struct sched_entity *se, · line 3284
Quoted 3 lines
<fugly here>
kernel/sched/fair.c +2
-0+DECLARE_UPDATE_TG_CFS_SIGNAL (util); +DECLARE_UPDATE_TG_CFS_SIGNAL (runnable);TBH, I prefer keeping the current version which is easier to read IMO
I did call it an eldritch horror :-) I agree with you here, it's a shame we don't really have better ways to factorize this (I don't think splitting the inputs is really an alternative).
Re: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotQuoted 12 lines · Vincent Guittot
Now that
runnable_load_avghas been removed, we can replace it by a new signal that will highlight the runnable pressure on acfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.At now, only
util_avgis used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.But the
util_avgsignal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.
Quoted 9 lines
When tasks compete for the same rq, their runnable average signal will be higher than
util_avgas it will include the waiting time and we can use this signal to better classifycfs_rqs.The new
runnable_avgwill track the runnable time of a task which simply adds the waiting time to the running time. The runnable_avgofcfs_rqwill be the /Sum of se'srunnable_avgand therunnable_avgof group entity will follow the one of the rq similarly toutil_avg.
I did a bit of playing around with tracepoints and it seems to be behaving fine. For instance, if I spawn 12 always runnable tasks (sysbench --test=cpu) on my Juno (6 CPUs), I get to a system-wide runnable value (\Sum cpu_runnable()) of about 12K. I've only eyeballed them, but migration of the signal values seem fine too.
I have a slight worry that the rq-wide runnable signal might be too easy to inflate, since we aggregate for *all* runnable tasks, and that may not play well with your group_is_overloaded() change (despite having the imbalance_pct on the "right" side).
In any case I'll need to convince myself of it with some messing around, and this concerns patch 5 more than patch 4. So FWIW for this one:
I also have one (two) more nit(s) below.
Quoted 21 lines
Signed-off-by Vincent Guittot <[email protected]>---
kernel/sched/pelt.c +2
-2@@ -227,14 +231,14 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Step 1: accumulate *_sum since last_update_time. If we haven't * crossed period boundaries, finish. */ -if (!accumulate_sum (delta, sa, load, running)) +if (!accumulate_sum (delta, sa, load, runnable, running))return 0 ;return 1 ; } static __always_inline void -___update_load_avg (struct sched_avg *sa,unsigned long load) +___update_load_avg (struct sched_avg *sa,unsigned long load,unsigned long runnable) {u32 divider =LOAD_AVG_MAX -1024 + sa->period_contrib;
kernel/sched/pelt.c ___update_load_avg(struct sched_avg *sa, unsigned long load) · line 249
Quoted 4 lines
kernel/sched/pelt.c +1
-0@@ -242,6 +246,7 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* Step 2: update *_avg. */ sa->load_avg =div_u64 (load * sa->load_sum, divider); + sa->runnable_avg = div _u64(runnable * sa->runnable_sum, divider);
^^^^^^ ^^^^^^^^
a) b)a) That's a tab
b) The value being passed is always 1, do we really need it to expose it as a parameter?
Vincent Guittot
maintainerRe: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
Quoted 69 lines · Valentin Schneider
Quoted 12 lines · Vincent Guittot
Now that
runnable_load_avghas been removed, we can replace it by a new signal that will highlight the runnable pressure on acfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.At now, only
util_avgis used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.But the
util_avgsignal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.Quoted 9 lines
When tasks compete for the same rq, their runnable average signal will be higher than
util_avgas it will include the waiting time and we can use this signal to better classifycfs_rqs.The new
runnable_avgwill track the runnable time of a task which simply adds the waiting time to the running time. The runnable_avgofcfs_rqwill be the /Sum of se'srunnable_avgand therunnable_avgof group entity will follow the one of the rq similarly toutil_avg.I did a bit of playing around with tracepoints and it seems to be behaving fine. For instance, if I spawn 12 always runnable tasks (sysbench --test=cpu) on my Juno (6 CPUs), I get to a system-wide runnable value (\Sum
cpu_runnable()) of about 12K. I've only eyeballed them, but migration of the signal values seem fine too.I have a slight worry that the rq-wide runnable signal might be too easy to inflate, since we aggregate for *all* runnable tasks, and that may not play well with your
group_is_overloaded()change (despite having theimbalance_pcton the "right" side).In any case I'll need to convince myself of it with some messing around, and this concerns patch 5 more than patch 4. So FWIW for this one:
Tested-by Valentin Schneider <[email protected]>I also have one (two) more nit(s) below.
Quoted 21 lines
Signed-off-by Vincent Guittot <[email protected]>---
kernel/sched/pelt.c +2
-2@@ -227,14 +231,14 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Step 1: accumulate *_sum since last_update_time. If we haven't * crossed period boundaries, finish. */ -if (!accumulate_sum (delta, sa, load, running)) +if (!accumulate_sum (delta, sa, load, runnable, running))return 0 ;return 1 ; } static __always_inline void -___update_load_avg (struct sched_avg *sa,unsigned long load) +___update_load_avg (struct sched_avg *sa,unsigned long load,unsigned long runnable) {u32 divider =LOAD_AVG_MAX -1024 + sa->period_contrib;kernel/sched/pelt.c ___update_load_avg(struct sched_avg *sa, unsigned long load) · line 249
Quoted 4 lines
kernel/sched/pelt.c +1
-0@@ -242,6 +246,7 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* Step 2: update *_avg. */ sa->load_avg =div_u64 (load * sa->load_sum, divider); + sa->runnable_avg = div _u64(runnable * sa->runnable_sum, divider);^^^^^^ ^^^^^^^^ a) b)
Quoted 4 lines
a) That's a tab
b) The value being passed is always 1, do we really need it to expose it as a parameter?
In fact, I haven't been able to convince myself if it was better to add the SCHED_CAPACITY_SCALE range in the _sum or only in the _avg. That's the reason for this parameter to still being there. On one side we do a shift at every PELT update and the attach/detach/propagate are quite straight forward. On the other side it is done only during attach/detach/propagate but it complexify the thing. Having it in _sum doesn't seem to be a concern so I will keep it there and remove the parameter
Mel Gorman
reviewerRe: [PATCH v2 4/5] sched/pelt: Add a new runnable average signal
In reply to Valentin SchneiderQuoted 34 lines · Valentin Schneider
Quoted 12 lines · Vincent Guittot
Now that
runnable_load_avghas been removed, we can replace it by a new signal that will highlight the runnable pressure on acfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.At now, only
util_avgis used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.But the
util_avgsignal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.Quoted 9 lines
When tasks compete for the same rq, their runnable average signal will be higher than
util_avgas it will include the waiting time and we can use this signal to better classifycfs_rqs.The new
runnable_avgwill track the runnable time of a task which simply adds the waiting time to the running time. The runnable_avgofcfs_rqwill be the /Sum of se'srunnable_avgand therunnable_avgof group entity will follow the one of the rq similarly toutil_avg.I did a bit of playing around with tracepoints and it seems to be behaving fine. For instance, if I spawn 12 always runnable tasks (sysbench --test=cpu) on my Juno (6 CPUs), I get to a system-wide runnable value (\Sum
cpu_runnable()) of about 12K. I've only eyeballed them, but migration of the signal values seem fine too.I have a slight worry that the rq-wide runnable signal might be too easy to inflate, since we aggregate for *all* runnable tasks, and that may not play well with your
group_is_overloaded()change (despite having theimbalance_pcton the "right" side).
Quoted 7 lines
In any case I'll need to convince myself of it with some messing around, and this concerns patch 5 more than patch 4. So FWIW for this one:
Tested-by Valentin Schneider <[email protected]>I also have one (two) more nit(s) below.
Thanks.
Quoted 20 lines
Quoted 20 lines
Signed-off-by Vincent Guittot <[email protected]>---
kernel/sched/pelt.c +2
-2@@ -227,14 +231,14 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Step 1: accumulate *_sum since last_update_time. If we haven't * crossed period boundaries, finish. */ -if (!accumulate_sum (delta, sa, load, running)) +if (!accumulate_sum (delta, sa, load, runnable, running))return 0 ;return 1 ; } static __always_inline void -___update_load_avg (struct sched_avg *sa,unsigned long load) +___update_load_avg (struct sched_avg *sa,unsigned long load,unsigned long runnable) {u32 divider =LOAD_AVG_MAX -1024 + sa->period_contrib;
Quoted 9 lines
kernel/sched/pelt.c ___update_load_avg(struct sched_avg *sa, unsigned long load) · line 249
Quoted 5 lines
kernel/sched/pelt.c +1
-0@@ -242,6 +246,7 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* Step 2: update *_avg. */ sa->load_avg =div_u64 (load * sa->load_sum, divider); + sa->runnable_avg = div _u64(runnable * sa->runnable_sum, divider);^^^^^^ ^^^^^^^^ a) b)a) That's a tab
Fixed and I'll post a v4 of my own series with Vincent's included.
Quoted 2 lines
b) The value being passed is always 1, do we really need it to expose it as a parameter?
This does appear to be an oversight but I'm not familiar enough with pelt to be sure.
___update_load_avg() is called when sum of the load has changed because a pelt period has passed and it has lost sight and does not care if an individual sched entity is runnable or not. The parameter was added by this patch but I cannot find any useful meaning for it.
Vincent, what was your thinking here? Should the parameter be removed?
Signature · 2 lines
Mel Gorman SUSE Labs
Vincent Guittot
maintainerPATCH v3 4/5 sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotNow that runnable_load_avg has been removed, we can replace it by a new signal that will highlight the runnable pressure on a cfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.
At now, only util_avg is used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.
But the util_avg signal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.
When tasks compete for the same rq, their runnable average signal will be higher than util_avg as it will include the waiting time and we can use this signal to better classify cfs_rqs.
The new runnable_avg will track the runnable time of a task which simply adds the waiting time to the running time. The runnable _avg of cfs_rq will be the /Sum of se's runnable_avg and the runnable_avg of group entity will follow the one of the rq similarly to util_avg.
---
Changes for v3:
- Fixed tab typo
- Removed runnable parameter of ___update_load_avg()
include/linux/sched.h | 26 ++++++++------ kernel/sched/debug.c | 9 +++-- kernel/sched/fair.c | 79 ++++++++++++++++++++++++++++++++++++++----- kernel/sched/pelt.c | 37 +++++++++++++++----- kernel/sched/sched.h | 22 +++++++++++- 5 files changed, 143 insertions(+), 30 deletions(-)
include/linux/sched.h +16 -10
@@ -356,28 +356,30 @@ struct util_est { } __attribute__((__aligned__(sizeof(u64))));/* -* The load_avg/util_avg accumulates an infinite geometric series +* The load/runnable/util_avg accumulates an infinite geometric series * (see __update_load_avg_cfs_rq() in kernel/sched/pelt.c). * * [load_avg definition] * * load_avg = runnable% * scale_load_down(load) * -* where runnable% is the time ratio that a sched_entity is runnable. -* For cfs_rq, it is the aggregated load_avg of all runnable and -* blocked sched_entities. +* [runnable_avg definition] +* +* runnable_avg = runnable% * SCHED_CAPACITY_SCALE * * [util_avg definition] * * util_avg = running% * SCHED_CAPACITY_SCALE * -* where running% is the time ratio that a sched_entity is running on -* a CPU. For cfs_rq, it is the aggregated util_avg of all runnable -* and blocked sched_entities. +* where runnable% is the time ratio that a sched_entity is runnable and +* running% the time ratio that a sched_entity is running. +* +* For cfs_rq, they are the aggregated values of all runnable and blocked +* sched_entities. * -* load_avg and util_avg don't direcly factor frequency scaling and CPU -* capacity scaling. The scaling is done through the rq_clock_pelt that -* is used for computing those signals (see update_rq_clock_pelt()) +* The load/runnable/util_avg doesn't direcly factor frequency scaling and CPU +* capacity scaling. The scaling is done through the rq_clock_pelt that is used +* for computing those signals (see update_rq_clock_pelt()) * * N.B., the above ratios (runnable% and running%) themselves are in the * range of [0, 1]. To do fixed point arithmetics, we therefore scale them
@@ -401,9 +403,11 @@ struct util_est {struct sched_avg {u64 last_update_time;u64 load_sum; +u64 runnable_sum;u32 util_sum;u32 period_contrib;unsigned long load_avg; +unsigned long runnable_avg;unsigned long util_avg;struct util_est util_est; }____cacheline_aligned ;
@@ -467,6 +471,8 @@ struct sched_entity {struct cfs_rq *cfs_rq;/* rq "owned" by this entity/group: */ struct cfs_rq *my_q; +/* cached value of my_q->h_nr_running */ +unsigned long runnable_weight;#endif #ifdef CONFIG_SMP
kernel/sched/debug.c +7 -2
@@ -405,6 +405,7 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group#ifdef CONFIG_SMP P (se->avg.load_avg);P (se->avg.util_avg); +P (se->avg.runnable_avg);#endif #undef PN_SCHEDSTAT
@@ -524,6 +525,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)#ifdef CONFIG_SMP SEQ_printf (m," .%-30s: %lu\n" ,"load_avg" , cfs_rq->avg.load_avg); +SEQ_printf (m," .%-30s: %lu\n" ,"runnable_avg" , + cfs_rq->avg.runnable_avg);SEQ_printf (m," .%-30s: %lu\n" ,"util_avg" , cfs_rq->avg.util_avg); SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued",
@@ -532,8 +535,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->removed.load_avg);SEQ_printf (m," .%-30s: %ld\n" ,"removed.util_avg" , cfs_rq->removed.util_avg); -SEQ_printf (m," .%-30s: %ld\n" ,"removed.runnable_sum" , - cfs_rq->removed.runnable_sum); +SEQ_printf (m," .%-30s: %ld\n" ,"removed.runnable_avg" , + cfs_rq->removed.runnable_avg);#ifdef CONFIG_FAIR_GROUP_SCHED SEQ_printf (m," .%-30s: %lu\n" ,"tg_load_avg_contrib" , cfs_rq->tg_load_avg_contrib);
@@ -944,8 +947,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,P (se.load.weight);#ifdef CONFIG_SMP P (se.avg.load_sum); +P (se.avg.runnable_sum);P (se.avg.util_sum);P (se.avg.load_avg); +P (se.avg.runnable_avg);P (se.avg.util_avg);P (se.avg.last_update_time);P (se.avg.util_est.ewma);
kernel/sched/fair.c +71 -8
195 lines not on this page · raw message
kernel/sched/pelt.c +28 -9
@@ -108,7 +108,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)*/ static __always_inline u32accumulate_sum (u64 delta,struct sched_avg *sa, -unsigned long load,int running) +unsigned long load,unsigned long runnable,int running) {u32 contrib = (u32 )delta;/* p == 0 -> delta < 1024 */ u64 periods;
@@ -121,6 +121,8 @@ accumulate_sum(u64 delta, struct sched_avg *sa,*/ if (periods) { sa->load_sum =decay_load (sa->load_sum, periods); + sa->runnable_sum = +decay_load (sa->runnable_sum, periods); sa->util_sum =decay_load ((u64)(sa->util_sum), periods);/*
@@ -146,6 +148,8 @@ accumulate_sum(u64 delta, struct sched_avg *sa,if (load) sa->load_sum += load * contrib; +if (runnable) + sa->runnable_sum += runnable * contrib <<SCHED_CAPACITY_SHIFT ;if (running) sa->util_sum += contrib <<SCHED_CAPACITY_SHIFT ;
@@ -182,7 +186,7 @@ accumulate_sum(u64 delta, struct sched_avg *sa,*/ static __always_inline int___update_load_sum (u64 now,struct sched_avg *sa, -unsigned long load,int running) +unsigned long load,unsigned long runnable,int running) {u64 delta;
@@ -218,7 +222,7 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Also see the comment in accumulate_sum(). */ if (!load) - running =0 ; + runnable = running =0 ;/* * Now we know we crossed measurement unit boundaries. The *_avg
@@ -227,7 +231,7 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Step 1: accumulate *_sum since last_update_time. If we haven't * crossed period boundaries, finish. */ -if (!accumulate_sum (delta, sa, load, running)) +if (!accumulate_sum (delta, sa, load, runnable, running))return 0 ;return 1 ;
@@ -242,6 +246,7 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* Step 2: update *_avg. */ sa->load_avg =div_u64 (load * sa->load_sum, divider); + sa->runnable_avg =div_u64 (sa->runnable_sum, divider);WRITE_ONCE (sa->util_avg, sa->util_sum / divider); }
@@ -250,9 +255,14 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* * task: * se_weight() = se->load.weight +* se_runnable() = !!on_rq * * group: [ see update_cfs_group() ] * se_weight() = tg->weight * grq->load_avg / tg->load_avg +* se_runnable() = grq->h_nr_running +* +* runnable_sum = se_runnable() * runnable = grq->runnable_sum +* runnable_avg = runnable_sum * * load_sum := runnable * load_avg = se_weight(se) * load_sum
@@ -261,13 +271,16 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load)* * cfq_rq: * +* runnable_sum = \Sum se->avg.runnable_sum +* runnable_avg = \Sum se->avg.runnable_avg +* * load_sum = \Sum se_weight(se) * se->avg.load_sum * load_avg = \Sum se->avg.load_avg */ int __update_load_avg_blocked_se (u64 now,struct sched_entity *se) { -if (___update_load_sum (now, &se->avg,0 ,0 )) { +if (___update_load_sum (now, &se->avg,0 ,0 ,0 )) {___update_load_avg (&se->avg,se_weight (se));trace_pelt_se_tp (se);return 1 ;
@@ -278,7 +291,8 @@ int __update_load_avg_blocked_se(u64 now, struct sched_entity *se)int __update_load_avg_se (u64 now,struct cfs_rq *cfs_rq,struct sched_entity *se) { -if (___update_load_sum (now, &se->avg, !!se->on_rq, cfs_rq->curr == se)) { +if (___update_load_sum (now, &se->avg, !!se->on_rq,se_runnable (se), + cfs_rq->curr == se)) {___update_load_avg (&se->avg,se_weight (se));cfs_se_util_change (&se->avg);
@@ -293,6 +307,7 @@ int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq) {if (___update_load_sum (now, &cfs_rq->avg,scale_load_down (cfs_rq->load.weight), + cfs_rq->h_nr_running, cfs_rq->curr !=NULL )) {___update_load_avg (&cfs_rq->avg,1 );
@@ -310,13 +325,14 @@ int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq)* util_sum = cpu_scale * load_sum * runnable_sum = util_sum * -* load_avg is not supported and meaningless. +* load_avg and runnable_load_avg are not supported and meaningless. * */ int update_rt_rq_load_avg (u64 now,struct rq *rq,int running) {if (___update_load_sum (now, &rq->avg_rt, + running, running, running)) {
@@ -335,13 +351,14 @@ int update_rt_rq_load_avg(u64 now, struct rq *rq, int running)* util_sum = cpu_scale * load_sum * runnable_sum = util_sum * -* load_avg is not supported and meaningless. +* load_avg and runnable_load_avg are not supported and meaningless. * */ int update_dl_rq_load_avg (u64 now,struct rq *rq,int running) {if (___update_load_sum (now, &rq->avg_dl, + running, running, running)) {
@@ -361,7 +378,7 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running)* util_sum = cpu_scale * load_sum * runnable_sum = util_sum * -* load_avg is not supported and meaningless. +* load_avg and runnable_load_avg are not supported and meaningless. * */
@@ -389,9 +406,11 @@ int update_irq_load_avg(struct rq *rq, u64 running)* rq->clock += delta with delta >= running */ ret =___update_load_sum (rq->clock - running, &rq->avg_irq, +0 ,0 ,0 ); ret +=___update_load_sum (rq->clock, &rq->avg_irq, +1 ,1 ,1 );
kernel/sched/sched.h +21 -1
@@ -527,7 +527,7 @@ struct cfs_rq {int nr;unsigned long load_avg;unsigned long util_avg; -unsigned long runnable_sum; +unsigned long runnable_avg; } removed;#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -688,9 +688,29 @@ struct dl_rq {/* An entity is a task if it doesn't "own" a runqueue */ #define entity_is_task (se) (!se->my_q) +static inline void se_update_runnable (struct sched_entity *se) +{ +if (!entity_is_task (se)) + se->runnable_weight = se->my_q->h_nr_running; +} + +static inline long se_runnable (struct sched_entity *se) +{ +if (entity_is_task (se)) +return !!se->on_rq; +else +return se->runnable_weight; +} +#else #define entity_is_task (se) 1 +static inline void se_update_runnable (struct sched_entity *se) {} + +static inline long se_runnable (struct sched_entity *se) +{ +return !!se->on_rq; +}#endif #ifdef CONFIG_SMP
Signature · 1 line
2.17.1
Re: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 16 lines · Vincent Guittot
Now that
runnable_load_avghas been removed, we can replace it by a new signal that will highlight the runnable pressure on acfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.At now, only
util_avgis used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.But the
util_avgsignal of a rq can become temporaly low after that a task migrated onto another rq which can bias the classification of the rq.When tasks compete for the same rq, their runnable average signal will be higher than
util_avgas it will include the waiting time and we can use this signal to better classifycfs_rqs.
Quoted 7 lines
The new
runnable_avgwill track the runnable time of a task which simply adds the waiting time to the running time. The runnable_avgofcfs_rqwill be the /Sum of se'srunnable_avgand therunnable_avgof group entity will follow the one of the rq similarly toutil_avg.Tested-by Valentin Schneider <[email protected]>Signed-off-by Vincent Guittot <[email protected]>
Thanks.
Picked up and included in "Reconcile NUMA balancing decisions with the load balancer v4". The only change I made to your patches was move the reintroduction of cpu_runnable to the patch that requires it to avoid a build warning.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotReview void init_entity_runnable_average(struct sched_entity *se) · line 744
Quoted 7 lines · Vincent Guittot
(quoted diff) +2
-1@@ -740,8 +740,10 @@ void init_entity_runnable_average(struct sched_entity *se) * Group entities are initialized with zero load to reflect the fact that * nothing has been attached to the task group yet. */ - if (entity_is_task(se)) + if (entity_is_task(se)) { + sa->runnable_avg = SCHED_CAPACITY_SCALE;
So this is a comment that's more related to patch 5, but the relevant bit is here. I'm thinking this initialization might be too aggressive wrt load balance. This will also give different results between symmetric vs asymmetric topologies - a single fork() will make a LITTLE CPU group (at the base domain level) overloaded straight away. That won't happen for bigs or on symmetric topologies because
// group_is_overloaded()
sgs->group_capacity * imbalance_pct) < (sgs->group_runnable * 100)
will be false - it would take more than one task for that to happen (due to the imbalance_pct).
So maybe what we want here instead is to mimic what he have for utilization, i.e. initialize to half the spare capacity of the local CPU. IOW, conceptually something like this:
---
kernel/sched/fair.c +3 -3
@@ -740,10 +740,8 @@ void init_entity_runnable_average(struct sched_entity *se)* Group entities are initialized with zero load to reflect the fact that * nothing has been attached to the task group yet. */ -if (entity_is_task (se)) { - sa->runnable_avg =SCHED_CAPACITY_SCALE ; +if (entity_is_task (se)) sa->load_avg =scale_load_down (se->load.weight); - }/* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */ }
@@ -796,6 +794,8 @@ void post_init_entity_util_avg(struct task_struct *p) } } + sa->runnable_avg = sa->util_avg; +if (p->sched_class != &fair_sched_class) {/* * For !fair tasks do:
---
The current approach has the merit of giving some sort of hint to the LB that there is a bunch of new tasks that it could spread out, but I fear it is too aggressive.
Quoted 5 lines
(quoted diff) +1
-0sa->load_avg = scale_load_down(se->load.weight); + } /* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */ }
Vincent Guittot
maintainerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 55 lines · Valentin Schneider
kernel/sched/fair.c void init_entity_runnable_average(struct sched_entity *se) · line 744
Quoted 7 lines · Vincent Guittot
kernel/sched/fair.c +2
-1@@ -740,8 +740,10 @@ void init_entity_runnable_average(struct sched_entity *se)* Group entities are initialized with zero load to reflect the fact that * nothing has been attached to the task group yet. */ -if (entity_is_task (se)) +if (entity_is_task (se)) { + sa->runnable_avg =SCHED_CAPACITY_SCALE ;So this is a comment that's more related to patch 5, but the relevant bit is here. I'm thinking this initialization might be too aggressive wrt load balance. This will also give different results between symmetric vs asymmetric topologies - a single
fork()will make a LITTLE CPU group (at the base domain level) overloaded straight away. That won't happen for bigs or on symmetric topologies because//
group_is_overloaded()
sgs->group_capacity*imbalance_pct) < (sgs->group_runnable* 100)will be false - it would take more than one task for that to happen (due to the
imbalance_pct).So maybe what we want here instead is to mimic what he have for utilization, i.e. initialize to half the spare capacity of the local CPU. IOW, conceptually something like this:
---
kernel/sched/fair.c +3
-4@@ -740,10 +740,8 @@ void init_entity_runnable_average(struct sched_entity *se)* Group entities are initialized with zero load to reflect the fact that * nothing has been attached to the task group yet. */ -if (entity_is_task (se)) { - sa->runnable_avg =SCHED_CAPACITY_SCALE ; +if (entity_is_task (se)) sa->load_avg =scale_load_down (se->load.weight); - }/* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */ }@@ -796,6 +794,8 @@ void post_init_entity_util_avg(struct task_struct *p) } } + sa->runnable_avg = sa->util_avg; +if (p->sched_class != &fair_sched_class) {/* * For !fair tasks do: ---
Quoted 3 lines
The current approach has the merit of giving some sort of hint to the LB that there is a bunch of new tasks that it could spread out, but I fear it is too aggressive.
I agree that setting by default to SCHED_CAPACITY_SCALE is too much for little core.
The problem for little core can be fixed by using the cpu capacity instead
@@ -796,6 +794,8 @@ void post_init_entity_util_avg(struct task_struct *p)
}
}+ sa->runnable_avg = cpu_scale;
+
if (p->sched_class != &fair_sched_class) {
/*
* For !fair tasks do:Quoted 6 lines
Quoted 6 lines
kernel/sched/fair.c +1
-0sa->load_avg =scale_load_down (se->load.weight); + }/* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */ }
Re: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity instead
So that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of util_avg ?
With the default MC imbalance_pct (117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128 util_avg)
With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against it - in which case this should also appear in the changelog with so far only mentions issues with util_avg migration, not the fork time initialization.
Quoted 15 lines
kernel/sched/fair.c +2
-0@@ -796,6 +794,8 @@ void post_init_entity_util_avg(struct task_struct *p) } } + sa->runnable_avg = cpu_scale; +if (p->sched_class != &fair_sched_class) {/* * For !fair tasks do: Quoted 6 lines
Quoted 6 lines
sa->load_avg = scale_load_down(se->load.weight);+ }
/* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */}
Vincent Guittot
maintainerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 9 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?
The runnable_avg is the unweighted version of the load_avg so they should both be sync at init and SCHED_CAPACITY_SCALE is in fact the right value. Using cpu_scale is the same for smp and big core so we can use it instead.
Then, the initial value of util_avg has never reflected some kind of realistic value for the utilization of a new task, especially if those tasks will become big ones. Runnable_avg now balances this effect to say that we don't know what will be the behavior of the new task, which might end up using all spare capacity although current utilization is low and CPU is not "fully used". In fact, this is exactly the purpose of runnable: highlight that there is maybe no spare capacity even if CPU's utilization is low because of external event like task migration or having new tasks with most probably wrong utilization.
That being said, there is a bigger problem with the current version of this patch, which is that I forgot to use runnable in update_sg_wakeup_stats(). I have a patch that fixes this problem.
Also, I have tested both proposals with hackbench on my octo cores and using cpu_scale gives slightly better results than util_avg, which probably reflects the case I mentioned above.
grp cpu_scale util_avg improvement 1 1,191(+/-0.77 %) 1,204(+/-1.16 %) -1.07 % 4 1,147(+/-1.14 %) 1,195(+/-0.52 %) -4.21 % 8 1,112(+/-1,52 %) 1,124(+/-1,45 %) -1.12 % 16 1,163(+/-1.72 %) 1,169(+/-1.58 %) -0,45 %
Quoted 8 lines
With the default MC
imbalance_pct(117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128util_avg)With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against
I don't see any reason for keeping them aligned
Quoted 18 lines
it - in which case this should also appear in the changelog with so far only mentions issues with
util_avgmigration, not the fork time initialization.Quoted 15 lines
kernel/sched/fair.c +2
-0@@ -796,6 +794,8 @@ void post_init_entity_util_avg(struct task_struct *p) } } + sa->runnable_avg = cpu_scale; +if (p->sched_class != &fair_sched_class) {/* * For !fair tasks do: Quoted 6 lines
Quoted 6 lines
sa->load_avg = scale_load_down(se->load.weight);+ }
/* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */}
Re: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
I somehow lost track of that email, sorry for the delayed response.
Quoted 17 lines · Vincent Guittot
Quoted 9 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?The
runnable_avgis the unweighted version of theload_avgso they should both be sync at init andSCHED_CAPACITY_SCALEis in fact the right value. Usingcpu_scaleis the same for smp and big core so we can use it instead.
Quoted 6 lines
Then, the initial value of
util_avghas never reflected some kind of realistic value for the utilization of a new task, especially if those tasks will become big ones.Runnable_avgnow balances this effect to say that we don't know what will be the behavior of the new task, which might end up using all spare capacity although current utilization is low and CPU is not "fully used".
I'd argue that the init values we pick for either runnable_avg or util_avg are both equally bogus.
Quoted 14 lines
In fact, this is
exactly the purpose of runnable: highlight that there is maybe no spare capacity even if CPU's utilization is low because of external event like task migration or having new tasks with most probably wrong utilization.That being said, there is a bigger problem with the current version of this patch, which is that I forgot to use runnable in
update_sg_wakeup_stats(). I have a patch that fixes this problem.Also, I have tested both proposals with hackbench on my octo cores and using
cpu_scalegives slightly better results thanutil_avg, which probably reflects the case I mentioned above.
Quoted 6 lines
grp cpu_scale util_avg improvement 1 1,191(+/-0.77 %) 1,204(+/-1.16 %) -1.07 % 4 1,147(+/-1.14 %) 1,195(+/-0.52 %) -4.21 % 8 1,112(+/-1,52 %) 1,124(+/-1,45 %) -1.12 % 16 1,163(+/-1.72 %) 1,169(+/-1.58 %) -0,45 %
Interesting, thanks for providing the numbers. I'd be curious to figure out where the difference really stems from, but in the meantime consider me convinced ;)
Mel Gorman
reviewerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
In reply to Valentin SchneiderQuoted 14 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?With the default MC
imbalance_pct(117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128util_avg)
Quoted 5 lines
With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against it - in which case this should also appear in the changelog with so far only mentions issues with
util_avgmigration, not the fork time initialization.
So, what is the way forward here? Should this patch be modified now, a patch be placed on top or go with what we have for the moment that works for symmetric CPUs and deal with the asym case later?
I do not have any asym systems at all so I've no means of checking whether there is a problem or not.
Signature · 2 lines
Mel Gorman SUSE Labs
Vincent Guittot
maintainerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 22 lines · Mel Gorman
Quoted 14 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?With the default MC
imbalance_pct(117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128util_avg)Quoted 5 lines
With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against it - in which case this should also appear in the changelog with so far only mentions issues with
util_avgmigration, not the fork time initialization.
Quoted 6 lines
So, what is the way forward here? Should this patch be modified now, a patch be placed on top or go with what we have for the moment that works for symmetric CPUs and deal with the asym case later?
I do not have any asym systems at all so I've no means of checking whether there is a problem or not.
I'm going to send a new version at least for patch 4 and 5 using cpu_scale as initial value and fixing update_sg_wakeup_stats()
Quoted 4 lines
--
Mel Gorman
SUSE Labs
Mel Gorman
reviewerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 27 lines · Vincent Guittot
Quoted 26 lines · Mel Gorman
Quoted 14 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?With the default MC
imbalance_pct(117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128util_avg)Quoted 5 lines
With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against it - in which case this should also appear in the changelog with so far only mentions issues with
util_avgmigration, not the fork time initialization.So, what is the way forward here? Should this patch be modified now, a patch be placed on top or go with what we have for the moment that works for symmetric CPUs and deal with the asym case later?
Quoted 6 lines
Quoted 2 lines
I do not have any asym systems at all so I've no means of checking whether there is a problem or not.
I'm going to send a new version at least for patch 4 and 5 using
cpu_scaleas initial value and fixingupdate_sg_wakeup_stats()
No problem. FWIW, when I see them, I'll slot them in and rerun the tests as the previous results will be invalidated. Obviously the asym case will not be tested by me but I imagine you or Valentin have that covered.
Thanks.
Signature · 2 lines
Mel Gorman SUSE Labs
Vincent Guittot
maintainerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 32 lines · Mel Gorman
Quoted 30 lines · Vincent Guittot
Quoted 28 lines · Mel Gorman
Quoted 14 lines · Valentin Schneider
Quoted 4 lines · Vincent Guittot
I agree that setting by default to
SCHED_CAPACITY_SCALEis too much for little core.
The problem for little core can be fixed by using the cpu capacity insteadSo that's indeed better for big.LITTLE & co. Any reason however for not aligning with the initialization of
util_avg?With the default MC
imbalance_pct(117), it takes 875 utilization to make a single CPU group (with 1024 capacity) overloaded (group_is_overloaded()). For a completely idle CPU, that means forking at least 3 tasks (512 + 256 + 128util_avg)Quoted 5 lines
With your change, it only takes 2 tasks. I know I'm being nitpicky here, but I feel like those should be aligned, unless we have a proper argument against it - in which case this should also appear in the changelog with so far only mentions issues with
util_avgmigration, not the fork time initialization.So, what is the way forward here? Should this patch be modified now, a patch be placed on top or go with what we have for the moment that works for symmetric CPUs and deal with the asym case later?
I do not have any asym systems at all so I've no means of checking whether there is a problem or not.
Quoted 6 lines
Quoted 3 lines
I'm going to send a new version at least for patch 4 and 5 using
cpu_scaleas initial value and fixingupdate_sg_wakeup_stats()No problem. FWIW, when I see them, I'll slot them in and rerun the tests as the previous results will be invalidated. Obviously the asym case will
I have just sent the new version.
Thanks for testing
Quoted 7 lines
not be tested by me but I imagine you or Valentin have that covered.
Thanks.
--
Mel Gorman
SUSE Labs
Dietmar Eggemann
reviewerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotQuoted 8 lines · Vincent Guittot
Now that
runnable_load_avghas been removed, we can replace it by a new signal that will highlight the runnable pressure on acfs_rq. This signal track the waiting time of tasks on rq and can help to better define the state of rqs.At now, only
util_avgis used to define the state of a rq:
A rq with more that around 80% of utilization and more than 1 tasks is considered as overloaded.
Don't we make the distinction of overutilized and overloaded?
update_sg_lb_stats(), SG_OVERUTILIZED and SG_OVERLOAD
[...]
kernel/sched/pelt.c int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq) · line 328
Quoted 6 lines
kernel/sched/pelt.c +1
-1@@ -310,13 +325,14 @@ int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq)* util_sum = cpu_scale * load_sum * runnable_sum = util_sum * -* load_avg is not supported and meaningless. +* load_avg and runnable_load_avg are not supported and meaningless.
Nit pick:
s/runnable_load_avg/runnable_avg
[...]
Quoted 5 lines
kernel/sched/pelt.c +1
-0+* load_avg and runnable_load_avg are not supported and meaningless. * */ int update_dl_rq_load_avg (u64 now,struct rq *rq,int running)
[...]
Quoted 6 lines
- *
load_avgis not supported and meaningless.
+ *load_avgandrunnable_load_avgare not supported and meaningless.
*
*/(quoted diff) +0
-0@@ -389,9 +406,11 @@ int update_irq_load_avg(struct rq *rq, u64 running)
[...]
Dietmar Eggemann
reviewerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
In reply to Vincent GuittotOn 19/02/2020 13:55, Vincent Guittot wrote:
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+static inline long se_runnable(struct sched_entity *se) +{
Why returning long here? sched_entity::runnable_weight is unsigned long but could be unsigned int (cfs_rq::h_nr_running is unsigned int).
___update_load_sum() has 'unsigned long runnable' as parameter.
Vincent Guittot
maintainerRe: [PATCH v3 4/5] sched/pelt: Add a new runnable average signal
Quoted 10 lines · Dietmar Eggemann
On 19/02/2020 13:55, Vincent Guittot wrote:
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+static inline long se_runnable(struct sched_entity *se) +{Why returning long here?
sched_entity::runnable_weightis unsigned long but could be unsigned int (cfs_rq::h_nr_runningis unsigned int).
I have reused the same prototype as for runnable_laod_avg
Quoted 2 lines
___update_load_sum()has 'unsigned long runnable' as parameter.
Vincent Guittot
maintainerPATCH v2 5/5 sched/fair: Take into account runnable_avg to classify group
In reply to Vincent GuittotTake into account the new runnable_avg signal to classify a group and to mitigate the volatility of util_avg in face of intensive migration.
--- kernel/sched/fair.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
kernel/sched/fair.c +11 -1
@@ -7718,7 +7718,8 @@ struct sg_lb_stats {unsigned long avg_load;/*Avg load across the CPUs of the group */ unsigned long group_load;/* Total load over the CPUs of the group */ unsigned long group_capacity; -unsigned long group_util;/* Total utilization of the group */ +unsigned long group_util;/* Total utilization over the CPUs of the group */ +unsigned long group_runnable;/* Total runnable time over the CPUs of the group */ unsigned int sum_nr_running;/* Nr of tasks running in the group */ unsigned int sum_h_nr_running;/* Nr of CFS tasks running in the group */ unsigned int idle_cpus;
@@ -7939,6 +7940,10 @@ group_has_capacity(unsigned int imbalance_pct, struct sg_lb_stats *sgs)if (sgs->sum_nr_running < sgs->group_weight)return true; +if ((sgs->group_capacity * imbalance_pct) < + (sgs->group_runnable *100 )) +return false; +if ((sgs->group_capacity *100 ) > (sgs->group_util * imbalance_pct))return true;
@@ -7964,6 +7969,10 @@ group_is_overloaded(unsigned int imbalance_pct, struct sg_lb_stats *sgs) (sgs->group_util * imbalance_pct))return true; +if ((sgs->group_capacity * imbalance_pct) < + (sgs->group_runnable *100 )) +return true; +return false; }
@@ -8058,6 +8067,7 @@ static inline void update_sg_lb_stats(struct lb_env *env, sgs->group_load +=cpu_load (rq); sgs->group_util +=cpu_util (i); + sgs->group_runnable +=cpu_runnable (rq); sgs->sum_h_nr_running += rq->cfs.h_nr_running; nr_running = rq->nr_running;
Signature · 1 line
2.17.1
Mel Gorman
reviewerQuoted 4 lines · Vincent Guittot
This new version stays quite close to the previous one and should replace without problems the previous one that part of Mel's patchset:
https://lkml.org/lkml/2020/2/14/156
As far as I can see, the differences are harmless and look sane. I do think that an additional fix is mandatory as I see no reason why the regression was fixed. As such, I'll release a v3 of the series that includes your new patches with the minimal fix inserted where appropriate. I'll have tests running over the rest of the weekend.
Quoted 23 lines
Some hackbench results:
- small arm64 dual quad cores system
hackbench -l (2560/#grp) -g #grpgrp tip/sched/core +patchset improvement 1 1,327(+/-10,06 %) 1,247(+/-5,45 %) 5,97 % 4 1,250(+/- 2,55 %) 1,207(+/-2,12 %) 3,42 % 8 1,189(+/- 1,47 %) 1,179(+/-1,93 %) 0,90 % 16 1,221(+/- 3,25 %) 1,219(+/-2,44 %) 0,16 %- large arm64 2 nodes / 224 cores system
hackbench -l (256000/#grp) -g #grpgrp tip/sched/core +patchset improvement 1 14,197(+/- 2,73 %) 13,917(+/- 2,19 %) 1,98 % 4 6,817(+/- 1,27 %) 6,523(+/-11,96 %) 4,31 % 16 2,930(+/- 1,07 %) 2,911(+/- 1,08 %) 0,66 % 32 2,735(+/- 1,71 %) 2,725(+/- 1,53 %) 0,37 % 64 2,702(+/- 0,32 %) 2,717(+/- 1,07 %) -0,53 % 128 3,533(+/-14,66 %) 3,123(+/-12,47 %) 11,59 % 256 3,918(+/-19,93 %) 3,390(+/- 5,93 %) 13,47 %
Quoted 3 lines
The significant improvement for 128 and 256 should be taken with care because of some instabilities over iterations without the patchset.
For the most part I do not see similar results to this with hackbench with one exception -- EPYC first generation. I don't have results for EPYC 2 yet but I'm curious if the machine you have has multiple L3 caches per NUMA domain? Various Intel CPU generations show improvements but they're not as dramatic. Tests will tell me for sure but I have some confidence that it'll look like
Small tracing patches -- no difference
Vincent Patches 1-2 -- regressions Fix from Mel -- small overall improvement on baseline Vincent patches 3-5 -- small improvements mostly, sometimes big ones
on hackbench depending on the machine
Rest of Mel series -- generally ok across machines and CPU generations
Even if the improvements are not dramatic, I think it'll be worth it to have NUMA and CPU balancer using similarly sane logic and overall I find the load balancer easier to understand with the new logic so yey!
Signature · 2 lines
Mel Gorman SUSE Labs
Quoted 10 lines · Vincent Guittot
This new version stays quite close to the previous one and should replace without problems the previous one that part of Mel's patchset:
https://lkml.org/lkml/2020/2/14/156NUMA load balancing is the last remaining piece of code that uses the
runnable_load_avgof PELT to balance tasks between nodes. The normalload_balancehas replaced it by a better description of the current state of the group of cpus. The same policy can be applied to the numa balancing.
Quoted 7 lines
Once unused,
runnable_load_avgcan be replaced by a simplerrunnable_avgsignal that tracks the waiting time of tasks on rq. Currently, the state of a group of CPUs is defined thanks to the number of running task and the level of utilization of rq. But the utilization can be temporarly low after the migration of a task whereas the rq is still overloaded with tasks. In such case where tasks were competing for the rq, therunnable_avgwill stay high after the migration.
With those small things I commented on: