sched: Remove update_rq_runnable_avg
PATCH 1/2 sched: Remove update_rq_runnable_avg
The current rq->avg is not made use of anywhere, and the code is in fair scheduler's critical path, so remove it.
--- kernel/sched/debug.c | 8 -------- kernel/sched/fair.c | 24 ++++-------------------- kernel/sched/sched.h | 2 -- 3 files changed, 4 insertions(+), 30 deletions(-)
kernel/sched/debug.c +0 -8
@@ -68,14 +68,6 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group#define PN (F ) \ SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F)) -if (!se) { -struct sched_avg *avg = &cpu_rq (cpu)->avg; -P (avg->runnable_avg_sum); -P (avg->runnable_avg_period); -return ; - } - -PN (se->exec_start);PN (se->vruntime);PN (se->sum_exec_runtime);
kernel/sched/fair.c +4 -20
@@ -2430,18 +2430,12 @@ static inline void __update_group_entity_contrib(struct sched_entity *se) } } -static inline void update_rq_runnable_avg (struct rq *rq,int runnable) -{ -__update_entity_runnable_avg (rq_clock_task (rq), &rq->avg, runnable); -__update_tg_runnable_avg (&rq->avg, &rq->cfs); -}#else /* CONFIG_FAIR_GROUP_SCHED */ static inline void __update_cfs_rq_tg_load_contrib (struct cfs_rq *cfs_rq,int force_update) {}static inline void __update_tg_runnable_avg (struct sched_avg *sa,struct cfs_rq *cfs_rq) {}static inline void __update_group_entity_contrib (struct sched_entity *se) {} -static inline void update_rq_runnable_avg (struct rq *rq,int runnable) {}#endif /* CONFIG_FAIR_GROUP_SCHED */ static inline void __update_task_entity_contrib (struct sched_entity *se)
@@ -2614,7 +2608,6 @@ static inline void dequeue_entity_load_avg(struct cfs_rq *cfs_rq,*/ void idle_enter_fair (struct rq *this_rq) { -update_rq_runnable_avg (this_rq,1 ); }/*
@@ -2624,7 +2617,6 @@ void idle_enter_fair(struct rq *this_rq)*/ void idle_exit_fair (struct rq *this_rq) { -update_rq_runnable_avg (this_rq,0 ); }static int idle_balance (struct rq *this_rq);
@@ -2633,7 +2625,6 @@ static int idle_balance(struct rq *this_rq);static inline void update_entity_load_avg (struct sched_entity *se,int update_cfs_rq) {} -static inline void update_rq_runnable_avg (struct rq *rq,int runnable) {}static inline void enqueue_entity_load_avg (struct cfs_rq *cfs_rq,struct sched_entity *se,int wakeup) {}
@@ -3936,10 +3927,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)update_entity_load_avg (se,1 ); } -if (!se) { -update_rq_runnable_avg (rq, rq->nr_running); +if (!se)add_nr_running (rq,1 ); - } +hrtick_update (rq); }
@@ -3997,10 +3987,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)update_entity_load_avg (se,1 ); } -if (!se) { +if (!se)sub_nr_running (rq,1 ); -update_rq_runnable_avg (rq,1 ); - } +hrtick_update (rq); }
@@ -5437,9 +5426,6 @@ static void __update_blocked_averages_cpu(struct task_group *tg, int cpu)*/ if (!se->avg.runnable_avg_sum && !cfs_rq->nr_running)list_del_leaf_cfs_rq (cfs_rq); - }else { -struct rq *rq =rq_of (cfs_rq); -update_rq_runnable_avg (rq, rq->nr_running); } }
@@ -7352,8 +7338,6 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)if (numabalancing_enabled)task_tick_numa (rq, curr); - -update_rq_runnable_avg (rq,1 ); }/*
kernel/sched/sched.h +0 -2
@@ -542,8 +542,6 @@ struct rq {#ifdef CONFIG_FAIR_GROUP_SCHED /* list of leaf cfs_rq on this cpu: */ struct list_head leaf_cfs_rq_list; - -struct sched_avg avg;#endif /* CONFIG_FAIR_GROUP_SCHED */ /*
Signature · 1 line
1.7.9.5
PATCH 2/2 sched: Rewrite per entity runnable load average tracking
The idea of per entity runnable load average (aggregated to cfs_rq and task_group load) was proposed by Paul Turner, and it is still followed by this rewrite. But this rewrite is made due to the following ends:
(1). cfs_rq's load average (namely runnable_load_avg and blocked_load_avg) is updated incrementally by one entity at one time, which means the cfs_rq load average is only partially updated or asynchronous accross its entities (the entity in question is up to date and contributes to the cfs_rq, but all other entities are effectively lagging behind).
(2). cfs_rq load average is different between top rq->cfs_rq and task_group's per CPU cfs_rqs in whether or not blocked_load_average contributes to the load.
(3). How task_group's load is tracked is very confusing and complex.
Therefore, this rewrite tackles these by:
(1). Combine runnable and blocked load averages for cfs_rq. And track cfs_rq's load average as a whole (contributed by all runnabled and blocked entities on this cfs_rq).
(2). Only track task load average. Do not track task_group's per CPU entity average, but track that entity's own cfs_rq's aggregated average.
This rewrite resutls in significantly reduced codes and expected consistency and clarity. Also, if draw the lines of previous cfs_rq runnable_load_avg and blocked_load_avg and the new rewritten load_avg, then compare those lines, you can see the new load_avg is much more continuous (no abrupt jumping ups and downs) and decayed/updated more quickly and synchronously.
--- include/linux/sched.h | 13 +- kernel/sched/debug.c | 22 +-- kernel/sched/fair.c | 475 +++++++++++-------------------------------------- kernel/sched/proc.c | 2 +- kernel/sched/sched.h | 17 +- 5 files changed, 115 insertions(+), 414 deletions(-)
include/linux/sched.h +5 -8
@@ -1069,14 +1069,11 @@ struct load_weight {struct sched_avg {/* -* These sums represent an infinite geometric series and so are bound -* above by 1024/(1-y). Thus we only need a u32 to store them for all -* choices of y < 1-2^(-32)*1024. +* The load_avg represents an infinite geometric series. */ -u32 runnable_avg_sum, runnable_avg_period; -u64 last_runnable_update; -s64 decay_count; -unsigned long load_avg_contrib; +u32 load_avg; +u32 period_contrib; +u64 last_update_time; };#ifdef CONFIG_SCHEDSTATS
@@ -1142,7 +1139,7 @@ struct sched_entity {#endif #ifdef CONFIG_SMP -/* Per-entity load-tracking */ +/* Per task load tracking */ struct sched_avg avg;#endif };
kernel/sched/debug.c +4 -18
@@ -85,10 +85,7 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group#endif P (se->load.weight);#ifdef CONFIG_SMP -P (se->avg.runnable_avg_sum); -P (se->avg.runnable_avg_period); -P (se->avg.load_avg_contrib); -P (se->avg.decay_count); +P (se->my_q->avg.load_avg);#endif #undef PN#undef P
@@ -205,19 +202,11 @@ 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_load_avg" , - cfs_rq->runnable_load_avg); -SEQ_printf (m," .%-30s: %ld\n" ,"blocked_load_avg" , - cfs_rq->blocked_load_avg); +SEQ_printf (m," .%-30s: %u\n" ,"load_avg" , + cfs_rq->avg.load_avg);#ifdef CONFIG_FAIR_GROUP_SCHED -SEQ_printf (m," .%-30s: %ld\n" ,"tg_load_contrib" , - cfs_rq->tg_load_contrib); -SEQ_printf (m," .%-30s: %d\n" ,"tg_runnable_contrib" , - cfs_rq->tg_runnable_contrib);SEQ_printf (m," .%-30s: %ld\n" ,"tg_load_avg" ,atomic_long_read (&cfs_rq->tg->load_avg)); -SEQ_printf (m," .%-30s: %d\n" ,"tg->runnable_avg" , -atomic_read (&cfs_rq->tg->runnable_avg));#endif #endif #ifdef CONFIG_CFS_BANDWIDTH
@@ -624,10 +613,7 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)P (se.load.weight);#ifdef CONFIG_SMP -P (se.avg.runnable_avg_sum); -P (se.avg.runnable_avg_period); -P (se.avg.load_avg_contrib); -P (se.avg.decay_count); +P (se.avg.load_avg);#endif P (policy);P (prio);
kernel/sched/fair.c +101 -374
703 lines not on this page · raw message
kernel/sched/proc.c +1 -1
@@ -504,7 +504,7 @@ static void __update_cpu_load(struct rq *this_rq, unsigned long this_load,#ifdef CONFIG_SMP static inline unsigned long get_rq_runnable_load (struct rq *rq) { -return rq->cfs.runnable_load_avg; +return rq->cfs.avg.load_avg; }#else static inline unsigned long get_rq_runnable_load (struct rq *rq)
kernel/sched/sched.h +4 -13
@@ -210,7 +210,6 @@ struct task_group {#ifdef CONFIG_SMP atomic_long_t load_avg; -atomic_t runnable_avg;#endif #endif
@@ -331,21 +330,13 @@ struct cfs_rq {#ifdef CONFIG_SMP /* -* CFS Load tracking -* Under CFS, load is tracked on a per-entity basis and aggregated up. -* This allows for the description of both thread and group usage (in -* the FAIR_GROUP_SCHED case). +* CFS load tracking +* XXX as load.weight could be large, the avg.load_avg may overflow +* its u32 */ -unsigned long runnable_load_avg, blocked_load_avg; -atomic64_t decay_counter; -u64 last_decay; -atomic_long_t removed_load; +struct sched_avg avg;#ifdef CONFIG_FAIR_GROUP_SCHED -/* Required to track per-cpu representation of a task_group */ -u32 tg_runnable_contrib; -unsigned long tg_load_contrib; -/* * h_load = weight * f(tg) *
Signature · 1 line
1.7.9.5
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 20 lines · Yuyang Du
The idea of per entity runnable load average (aggregated to
cfs_rqandtask_groupload) was proposed by Paul Turner, and it is still followed by this rewrite. But this rewrite is made due to the following ends:(1). cfs_rq's load average (namely
runnable_load_avgandblocked_load_avg) is updated incrementally by one entity at one time, which means thecfs_rqload average is only partially updated or asynchronous accross its entities (the entity in question is up to date and contributes to thecfs_rq, but all other entities are effectively lagging behind).(2).
cfs_rqload average is different between toprq->cfs_rqand task_group's per CPUcfs_rqsin whether or notblocked_load_averagecontributes to the load.(3). How task_group's load is tracked is very confusing and complex.
Therefore, this rewrite tackles these by:
(1). Combine runnable and blocked load averages for
cfs_rq. And track cfs_rq's load average as a whole (contributed by all runnabled and blocked entities on thiscfs_rq).
Quoted 8 lines
(2). Only track task load average. Do not track task_group's per CPU entity average, but track that entity's own cfs_rq's aggregated average.
This rewrite resutls in significantly reduced codes and expected consistency and clarity. Also, if draw the lines of previous
cfs_rqrunnable_load_avgandblocked_load_avgand the new rewrittenload_avg, then compare those lines, you can see the newload_avgis much more continuous (no abrupt jumping ups and downs) and decayed/updated more quickly and synchronously.
This patch is too big.. and I can't figure out wth you've done. The Changelog also doesn't seem to help much.
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to Yuyang DuQuoted 4 lines · Yuyang Du
The idea of per entity runnable load average (aggregated to
cfs_rqandtask_groupload) was proposed by Paul Turner, and it is still followed by this rewrite. But this rewrite is made due to the following ends:
Quoted 8 lines
(1). cfs_rq's load average (namely
runnable_load_avgandblocked_load_avg) is updated incrementally by one entity at one time, which means thecfs_rqload average is only partially updated or asynchronous accross its entities (the entity in question is up to date and contributes to thecfs_rq, but all other entities are effectively lagging behind).(2).
cfs_rqload average is different between toprq->cfs_rqand task_group's per CPUcfs_rqsin whether or notblocked_load_averagecontributes to the load.
ISTR there was a reason for it; can't remember though, maybe pjt/ben can remember.
Quoted 7 lines
(3). How task_group's load is tracked is very confusing and complex.
Therefore, this rewrite tackles these by:
(1). Combine runnable and blocked load averages for
cfs_rq. And track cfs_rq's load average as a whole (contributed by all runnabled and blocked entities on thiscfs_rq).
Quoted 8 lines
(2). Only track task load average. Do not track task_group's per CPU entity average, but track that entity's own cfs_rq's aggregated average.
This rewrite resutls in significantly reduced codes and expected consistency and clarity. Also, if draw the lines of previous
cfs_rqrunnable_load_avgandblocked_load_avgand the new rewrittenload_avg, then compare those lines, you can see the newload_avgis much more continuous (no abrupt jumping ups and downs) and decayed/updated more quickly and synchronously.
OK, maybe seeing what you're doing. I worry about a fwe things though:
kernel/sched/fair.c static __always_inline int __update_entity_runnable_avg(u64 now, · line 2337
Quoted 7 lines
kernel/sched/fair.c +4
-0+static inline void synchronize_tg_load_avg (struct cfs_rq *cfs_rq,u32 old) { +s32 delta = cfs_rq->avg.load_avg - old; +if (delta) +atomic_long_add (delta, &cfs_rq->tg->load_avg); }
That tg->load_avg cacheline is already red hot glowing, and you've just increased the amount of updates to it.. That's not going to be pleasant.
Quoted 14 lines
kernel/sched/fair.c +11
-0+static inline void enqueue_entity_load_avg (struct sched_entity *se) { +struct sched_avg *sa = &se->avg; +struct cfs_rq *cfs_rq =cfs_rq_of (se); +u64 now =cfs_rq_clock_task (cfs_rq); +u32 old_load_avg = cfs_rq->avg.load_avg; +int migrated =0 ; +if (entity_is_task (se)) { +if (sa->last_update_time ==0 ) { + sa->last_update_time = now; + migrated =1 ; } +else
kernel/sched/fair.c static __always_inline int __update_entity_runnable_avg(u64 now, · line 2384
Quoted 10 lines
kernel/sched/fair.c +5
-0+__update_load_avg (now, sa, se->on_rq * se->load.weight); } +__update_load_avg (now, &cfs_rq->avg, cfs_rq->load.weight); +if (migrated) + cfs_rq->avg.load_avg += sa->load_avg; +synchronize_tg_load_avg (cfs_rq, old_load_avg); }
So here you add the task to the cfs_rq avg when its got migrate in, however:
kernel/sched/fair.c migrate_task_rq_fair(struct task_struct *p, int next_cpu) · line 4334
Quoted 10 lines
kernel/sched/fair.c +3
-0@@ -4552,17 +4326,9 @@ migrate_task_rq_fair(struct task_struct *p, int next_cpu)struct sched_entity *se = &p->se;struct cfs_rq *cfs_rq =cfs_rq_of (se); +/* Update task on old CPU, then ready to go (entity must be off the queue) */ +__update_load_avg (cfs_rq_clock_task (cfs_rq), &se->avg,0 ); + se->avg.last_update_time =0 ;/* We have migrated, no longer consider this task hot */ se->exec_start =0 ;
there you don't remove it first..
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Yuyang Du
The idea of per entity runnable load average (aggregated to
cfs_rqandtask_groupload) was proposed by Paul Turner, and it is still followed by this rewrite. But this rewrite is made due to the following ends:(1). cfs_rq's load average (namely
runnable_load_avgandblocked_load_avg) is updated incrementally by one entity at one time, which means thecfs_rqload average is only partially updated or asynchronous accross its entities (the entity in question is up to date and contributes to thecfs_rq, but all other entities are effectively lagging behind).
Quoted 5 lines
Quoted 2 lines
(2).
cfs_rqload average is different between toprq->cfs_rqand task_group's per CPUcfs_rqsin whether or notblocked_load_averagecontributes to the load.ISTR there was a reason for it; can't remember though, maybe pjt/ben can remember.
I'm not sure exactly which usages are being talked about here, but we used runnanble+blocked for tg_load_contrib because that's the number which has any actual meaning. The stuff (h_load, weighted_cpuload, etc) that uses runnable_load_avg by itself is all morally wrong, but iirc when the patches came up making them use runnable+blocked always was worse on the quoted benchmarks.
Quoted 23 lines
Quoted 8 lines
(3). How task_group's load is tracked is very confusing and complex.
Therefore, this rewrite tackles these by:
(1). Combine runnable and blocked load averages for
cfs_rq. And track cfs_rq's load average as a whole (contributed by all runnabled and blocked entities on thiscfs_rq).Quoted 8 lines
(2). Only track task load average. Do not track task_group's per CPU entity average, but track that entity's own cfs_rq's aggregated average.
This rewrite resutls in significantly reduced codes and expected consistency and clarity. Also, if draw the lines of previous
cfs_rqrunnable_load_avgandblocked_load_avgand the new rewrittenload_avg, then compare those lines, you can see the newload_avgis much more continuous (no abrupt jumping ups and downs) and decayed/updated more quickly and synchronously.OK, maybe seeing what you're doing. I worry about a fwe things though:
Quoted 4 lines
kernel/sched/fair.c +2
-0+static inline void synchronize_tg_load_avg (struct cfs_rq *cfs_rq,u32 old) { +s32 delta = cfs_rq->avg.load_avg - old;
Quoted 7 lines
kernel/sched/fair.c static __always_inline int __update_entity_runnable_avg(u64 now, · line 2337
Quoted 3 lines
kernel/sched/fair.c +2
-0+if (delta) +atomic_long_add (delta, &cfs_rq->tg->load_avg); }That
tg->load_avgcacheline is already red hot glowing, and you've just increased the amount of updates to it.. That's not going to be pleasant.
Yeah, while this is technically limited to 1/us (per cpu), it is still much higher - the replaced code would do updates generally only on period overflow (1ms) and even then only with nontrivial delta.
Also something to note is that cfs_rq->load_avg just takes samples of load.weight every 1us, which seems unfortunate. We thought this was ok for p->se.load.weight, because it isn't really likely for userspace to be calling nice(2) all the time, but wake/sleeps are more frequent, particularly on newer cpus. Still, it might not be /that/ bad.
Quoted 34 lines
Quoted 16 lines
kernel/sched/fair.c +11
-0+static inline void enqueue_entity_load_avg (struct sched_entity *se) { +struct sched_avg *sa = &se->avg; +struct cfs_rq *cfs_rq =cfs_rq_of (se); +u64 now =cfs_rq_clock_task (cfs_rq); +u32 old_load_avg = cfs_rq->avg.load_avg; +int migrated =0 ; +if (entity_is_task (se)) { +if (sa->last_update_time ==0 ) { + sa->last_update_time = now; + migrated =1 ; } +else kernel/sched/fair.c static __always_inline int __update_entity_runnable_avg(u64 now, · line 2384
Quoted 10 lines
kernel/sched/fair.c +5
-0+__update_load_avg (now, sa, se->on_rq * se->load.weight); } +__update_load_avg (now, &cfs_rq->avg, cfs_rq->load.weight); +if (migrated) + cfs_rq->avg.load_avg += sa->load_avg; +synchronize_tg_load_avg (cfs_rq, old_load_avg); }So here you add the task to the
cfs_rqavg when its got migrate in, however:Quoted 4 lines
kernel/sched/fair.c +0
-0@@ -4552,17 +4326,9 @@ migrate_task_rq_fair(struct task_struct *p, int next_cpu)struct sched_entity *se = &p->se;struct cfs_rq *cfs_rq =cfs_rq_of (se);
Quoted 8 lines
kernel/sched/fair.c migrate_task_rq_fair(struct task_struct *p, int next_cpu) · line 4334
Quoted 6 lines
kernel/sched/fair.c +3
-0+/* Update task on old CPU, then ready to go (entity must be off the queue) */ +__update_load_avg (cfs_rq_clock_task (cfs_rq), &se->avg,0 ); + se->avg.last_update_time =0 ;/* We have migrated, no longer consider this task hot */ se->exec_start =0 ;there you don't remove it first..
Yeah, the issue is that you can't remove it, because you don't hold the lock. Thus the whole runnable/blocked split iirc. Also the cfs_rq_clock_task read is incorrect for the same reason (and while rq_clock_task could certainly be fixed min_vruntime-style, cfs_rq_clock_task would be harder).
The problem with just working around the clock issue somehow and then using an atomic to do this subtraction is that you have no idea when the /cfs_rq/ last updated - there's no guarantee it is up to date, and if it's not then the subtraction is wrong. You can't update it to make it up to date like the se->avg, becasue you don't hold any locks. You would need decay_counter stuff like the current code, and I'm not certain how well that would work out without the runnable/blocked split.
Other issues:
Quoted 9 lines
include/linux/sched.h +0
-0@@ -1069,14 +1069,11 @@ struct load_weight {struct sched_avg {/*
include/linux/sched.h struct load_weight { · line 1074
Quoted 10 lines
include/linux/sched.h +2
-7-* These sums represent an infinite geometric series and so are bound -* above by 1024/(1-y). Thus we only need a u32 to store them for all -* choices of y < 1-2^(-32)*1024. +* The load_avg represents an infinite geometric series. */ -u32 runnable_avg_sum, runnable_avg_period; -u64 last_runnable_update; -s64 decay_count; -unsigned long load_avg_contrib; +u32 load_avg;
As the patch notes later, this absolutely cannot be u32, this needs to be unsigned long, as with any weight variable. Actually, it's worse, I think this is up to LOAD_AVG_MAX * weight, and thus probably needs to just be u64 even on 32 bit, since having only 16 bits of cfs_rq->load.weight is not a great plan. While this is mostly u32*u32=>u64 multiplies, calc_cfs_shares would be a u64/u64 per cfs_rq on every enqueue/dequeue.
Also, as a nitpick/annoyance this does a lot of
if (entity_is_task(se)) __update_load_avg(... se ...) __update_load_avg(... cfs_rq_of(se) ...)
which is just a waste of the avg struct on every group se, and all it buys you is the ability to not have a separate rq->avg struct (removed by patch 1) instead of rq->cfs.avg.
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Thanks, Ben,
Quoted 5 lines · On Mon, Jul 07, 2014 at 03:25:07PM -0700, [email protected] wrote:
Yeah, while this is technically limited to 1/us (per cpu), it is still much higher - the replaced code would do updates generally only on period overflow (1ms) and even then only with nontrivial delta.
Will update it in "batch" mode as I replied to Peter. Whether or not set up a threshold to not update trivial delta, will see.
Quoted 5 lines
Also something to note is that
cfs_rq->load_avgjust takes samples of load.weight every 1us, which seems unfortunate. We thought this was ok forp->se.load.weight, because it isn't really likely for userspace to be calling nice(2) all the time, but wake/sleeps are more frequent, particularly on newer cpus. Still, it might not be /that/ bad.
The sampling of cfs_rq->load.weight should be equivalent to the current code in that at the end of day cfs_rq->load.weight worth of runnable would contribute to runnable_load_avg/blocked_load_avg for both the current and the rewrite.
Quoted 6 lines
Also, as a nitpick/annoyance this does a lot of
if (entity_is_task(se)) __update_load_avg(... se ...) __update_load_avg(...cfs_rq_of(se)...)
which is just a waste of the avg struct on every group se, and all it buys you is the ability to not have a separaterq->avgstruct (removed by patch 1) instead ofrq->cfs.avg.
I actually struggled on this issue. As we only need a sched_avg for task (not entity), and a sched_avg for cfs_rq, I planned to move entity avg to task. Good?
So left are the migrate_task_rq_fair() not holding lock issue and cfs_rq->avg.load_avg overflow issue. I need some time to study them.
Overall, I think none of these issues are originally caused by combination/split of runnable and blocked. It is just a matter of how synchronized we want to be (this rewrite is the most synchronized), and the workaround I need to borrow from the current codes.
Yuyang
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 9 lines · Yuyang Du
Thanks, Ben,
Quoted 5 lines · On Mon, Jul 07, 2014 at 03:25:07PM -0700, [email protected] wrote:
Also something to note is that
cfs_rq->load_avgjust takes samples of load.weight every 1us, which seems unfortunate. We thought this was ok forp->se.load.weight, because it isn't really likely for userspace to be calling nice(2) all the time, but wake/sleeps are more frequent, particularly on newer cpus. Still, it might not be /that/ bad.
Quoted 4 lines
The sampling of
cfs_rq->load.weightshould be equivalent to the current code in that at the end of daycfs_rq->load.weightworth of runnable would contribute to runnable_load_avg/blocked_load_avg for both the current and the rewrite.
Yes, but the point is that it looks at load.weight when delta/1024 > 0 and assumes that it has had that load.weight the entire time, when this might not actually be true. The largest error I can think of is if you have a very high weight task that tends to run for very short periods of time, you could end up losing their entire contribution to load. This may be acceptable, I'm not certain.
Quoted 11 lines
Quoted 7 lines
Also, as a nitpick/annoyance this does a lot of
if (entity_is_task(se)) __update_load_avg(... se ...) __update_load_avg(...cfs_rq_of(se)...)
which is just a waste of the avg struct on every group se, and all it buys you is the ability to not have a separaterq->avgstruct (removed by patch 1) instead ofrq->cfs.avg.I actually struggled on this issue. As we only need a
sched_avgfor task (not entity), and asched_avgforcfs_rq, I planned to move entity avg to task. Good?
Yeah, that can probably be done perfectly fine.
Quoted 8 lines
So left are the
migrate_task_rq_fair()not holding lock issue andcfs_rq->avg.load_avgoverflow issue. I need some time to study them.Overall, I think none of these issues are originally caused by combination/split of runnable and blocked. It is just a matter of how synchronized we want to be (this rewrite is the most synchronized), and the workaround I need to borrow from the current codes.
If you can manage to find a to deal with the migration issue without it, that would be great, I'm just pretty sure that's why we did the split.
Quoted 2 lines
Yuyang
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Thanks, Ben.
Quoted 11 lines · On Tue, Jul 08, 2014 at 10:04:22AM -0700, [email protected] wrote:
Quoted 4 lines
The sampling of
cfs_rq->load.weightshould be equivalent to the current code in that at the end of daycfs_rq->load.weightworth of runnable would contribute to runnable_load_avg/blocked_load_avg for both the current and the rewrite.Yes, but the point is that it looks at load.weight when delta/1024 > 0 and assumes that it has had that load.weight the entire time, when this might not actually be true. The largest error I can think of is if you have a very high weight task that tends to run for very short periods of time, you could end up losing their entire contribution to load. This may be acceptable, I'm not certain.
That I believe is not a problem. It is a matter of when cfs_rq->load.weight changes and when we look at it to contribute to the cfs_rq's load_avg. Fortunately, we will not miss any change of cfs_rq->load.weight, always contributing to the load_avg the right amount. Put another way, we always use the right cfs_rq->load.weight.
Quoted 10 lines
Quoted 7 lines
So left are the
migrate_task_rq_fair()not holding lock issue andcfs_rq->avg.load_avgoverflow issue. I need some time to study them.Overall, I think none of these issues are originally caused by combination/split of runnable and blocked. It is just a matter of how synchronized we want to be (this rewrite is the most synchronized), and the workaround I need to borrow from the current codes.
If you can manage to find a to deal with the migration issue without it, that would be great, I'm just pretty sure that's why we did the split.
After thinking about it the whole morning, this issue is a killer... :)
But I think, even by spliting and by using atomic operations, the current code does not substract the migrating task's load absolutely synchronized:
When se migrating, you atomic_read cfs_rq->decay_counter (say t1), and then atomic_add the se's load_avg_contrib to removed_load. However, when updating the cfs_rq->blocked_load_avg it is not guranteed when substracting the removed_load from the blocked_load_avg, the actual decay_counter (say t2) is the same as t1. Because at t1 time (when you atomic_read it), the decay_counter can be being updated (before you atomic_add to removed_load). Atomic operation does not help synchronize them. Right?
So essentially, to perfectly substract the right amount, we must first synchronize the migrating task with its cfs_rq (catch up), and then substract it right away. Those two steps must be synchronized (with lock) or atomically done at once. Considering migrating and load averaging are not sequential (strict interleaving). Separating the two steps but synchronizing them is not enough, they must be done atomically.
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Thanks,
Yuyang
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 16 lines · Yuyang Du
Thanks, Ben.
Quoted 11 lines · On Tue, Jul 08, 2014 at 10:04:22AM -0700, [email protected] wrote:
Quoted 4 lines
The sampling of
cfs_rq->load.weightshould be equivalent to the current code in that at the end of daycfs_rq->load.weightworth of runnable would contribute to runnable_load_avg/blocked_load_avg for both the current and the rewrite.Yes, but the point is that it looks at load.weight when delta/1024 > 0 and assumes that it has had that load.weight the entire time, when this might not actually be true. The largest error I can think of is if you have a very high weight task that tends to run for very short periods of time, you could end up losing their entire contribution to load. This may be acceptable, I'm not certain.
Quoted 5 lines
That I believe is not a problem. It is a matter of when
cfs_rq->load.weightchanges and when we look at it to contribute to the cfs_rq'sload_avg. Fortunately, we will not miss any change ofcfs_rq->load.weight, always contributing to theload_avgthe right amount. Put another way, we always use the rightcfs_rq->load.weight.
You always call __update_load_avg with every needed load.weight, but if now - sa->last_update_time < 1024, then it will not do anything with that weight, and the next actual update may be with a different weight.
Quoted 24 lines
Quoted 11 lines
Quoted 8 lines
So left are the
migrate_task_rq_fair()not holding lock issue andcfs_rq->avg.load_avgoverflow issue. I need some time to study them.Overall, I think none of these issues are originally caused by combination/split of runnable and blocked. It is just a matter of how synchronized we want to be (this rewrite is the most synchronized), and the workaround I need to borrow from the current codes.
If you can manage to find a to deal with the migration issue without it, that would be great, I'm just pretty sure that's why we did the split.
After thinking about it the whole morning, this issue is a killer... :)
But I think, even by spliting and by using atomic operations, the current code does not substract the migrating task's load absolutely synchronized:
When se migrating, you
atomic_readcfs_rq->decay_counter(say t1), and thenatomic_addthe se'sload_avg_contribtoremoved_load. However, when updating thecfs_rq->blocked_load_avgit is not guranteed when substracting theremoved_loadfrom theblocked_load_avg, the actualdecay_counter(say t2) is the same as t1. Because at t1 time (when youatomic_readit), thedecay_countercan be being updated (before youatomic_addtoremoved_load). Atomic operation does not help synchronize them. Right?
Quoted 6 lines
So essentially, to perfectly substract the right amount, we must first synchronize the migrating task with its
cfs_rq(catch up), and then substract it right away. Those two steps must be synchronized (with lock) or atomically done at once. Considering migrating and load averaging are not sequential (strict interleaving). Separating the two steps but synchronizing them is not enough, they must be done atomically.
Yeah, I don't think it is actually entirely safe, and looking at it again, there's not even any guarantee that the decay_counter read is anything close to current, even on something like x86, which is... bad. I know this is why subtract_blocked_load_contrib makes sure to clamp at zero.
To do this actually correctly, you'd need cmpxchg16b or locking. Given that we end up pulling a cacheline to do the removed_load add RMW anyway, it might be reasonable to do something like that, I don't know.
Quoted 5 lines
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Thanks,
Yuyang
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 9 lines · On Wed, Jul 09, 2014 at 10:08:42AM -0700, [email protected] wrote:
Quoted 5 lines
That I believe is not a problem. It is a matter of when
cfs_rq->load.weightchanges and when we look at it to contribute to the cfs_rq'sload_avg. Fortunately, we will not miss any change ofcfs_rq->load.weight, always contributing to theload_avgthe right amount. Put another way, we always use the rightcfs_rq->load.weight.You always call
__update_load_avgwith every needed load.weight, but if now -sa->last_update_time< 1024, then it will not do anything with that weight, and the next actual update may be with a different weight.
Oh, yes, I finally understand, :) You are right. That is the matter of 1ms period. Within period boundary, everything will be lost.
Thanks,
Yuyang
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to Yuyang DuQuoted 1 line · Yuyang Du
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Nope :-).. we got rid of that lock for a good reason.
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the sched_clock_cpu() difference is a strict upper bound on the rq_clock_task() difference (and under 'normal' circumstances shouldn't be much off).
So we could simply use a timestamps from dequeue and one from enqueue, and use that.
As to the remote subtraction, a RMW on another cacheline than the rq->lock one should be good; esp since we don't actually observe the per-rq total often (once per tick or so) I think, no?
The thing is, we do not want to disturb scheduling on whatever cpu the task last ran on if we wake it to another cpu. Taking rq->lock wrecks that for sure.
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 10 lines · Peter Zijlstra
Quoted 1 line · Yuyang Du
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Nope :-).. we got rid of that lock for a good reason.
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the
sched_clock_cpu()difference is a strict upper bound on therq_clock_task()difference (and under 'normal' circumstances shouldn't be much off).
Well, unless IRQ_TIME_ACCOUNTING or such is on, in which case you lose. Or am I misunderstanding the suggestion? Actually the simplest thing would probably be to grab last_update_time (which on 32-bit could be done with the _copy hack) and use that. Then I think the accuracy is only worse than current in that you can lose runnable load as well as blocked load, and that it isn't as easily corrected - currently if the blocked tasks wake up they'll add the correct numbers to runnable_load_avg, even if blocked_load_avg is screwed up and hit zero. This code would have to wait until it stabilized again.
Quoted 7 lines
So we could simply use a timestamps from dequeue and one from enqueue, and use that.
As to the remote subtraction, a RMW on another cacheline than the
rq->lockone should be good; esp since we don't actually observe the per-rq total often (once per tick or so) I think, no?
Yeah, it's definitely a different cacheline, and the current code only reads per-ms or on loadbalance migration.
Quoted 4 lines
The thing is, we do not want to disturb scheduling on whatever cpu the task last ran on if we wake it to another cpu. Taking
rq->lockwrecks that for sure.
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 7 lines · On Wed, Jul 09, 2014 at 12:07:08PM -0700, [email protected] wrote:
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Yuyang Du
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Nope :-).. we got rid of that lock for a good reason.
Quoted 8 lines
Quoted 5 lines
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the
sched_clock_cpu()difference is a strict upper bound on therq_clock_task()difference (and under 'normal' circumstances shouldn't be much off).Well, unless
IRQ_TIME_ACCOUNTINGor such is on, in which case you lose. Or am I misunderstanding the suggestion?
If its on its still an upper bound, and typically the difference is not too large I think.
Since clock_task is the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound on clock_task differences.
Quoted 8 lines
Actually the simplest thing
would probably be to grablast_update_time(which on 32-bit could be done with the_copyhack) and use that. Then I think the accuracy is only worse than current in that you can lose runnable load as well as blocked load, and that it isn't as easily corrected - currently if the blocked tasks wake up they'll add the correct numbers torunnable_load_avg, even ifblocked_load_avgis screwed up and hit zero. This code would have to wait until it stabilized again.
The problem with that is that last_update_time is measured in clock_task, and you cannot transfer these values between CPUs. clock_task can drift unbounded between CPUs.
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 33 lines · Peter Zijlstra
Quoted 7 lines · On Wed, Jul 09, 2014 at 12:07:08PM -0700, [email protected] wrote:
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Yuyang Du
That is chalenging... Can someone (Peter) grant us a lock of the remote rq? :)
Nope :-).. we got rid of that lock for a good reason.
Quoted 8 lines
Quoted 5 lines
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the
sched_clock_cpu()difference is a strict upper bound on therq_clock_task()difference (and under 'normal' circumstances shouldn't be much off).Well, unless
IRQ_TIME_ACCOUNTINGor such is on, in which case you lose. Or am I misunderstanding the suggestion?If its on its still an upper bound, and typically the difference is not too large I think.
Since
clock_taskis the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound onclock_taskdifferences.Quoted 8 lines
Actually the simplest thing
would probably be to grablast_update_time(which on 32-bit could be done with the_copyhack) and use that. Then I think the accuracy is only worse than current in that you can lose runnable load as well as blocked load, and that it isn't as easily corrected - currently if the blocked tasks wake up they'll add the correct numbers torunnable_load_avg, even ifblocked_load_avgis screwed up and hit zero. This code would have to wait until it stabilized again.
Quoted 3 lines
The problem with that is that
last_update_timeis measured inclock_task, and you cannot transfer these values between CPUs.clock_taskcan drift unbounded between CPUs.
Yes, but we don't need to - we just use the remote last_update_time to do a final update on p->se.avg, and then subtract that from cfs_rq->avg with atomics (and then set p->se.avg.last_update_time to 0 as now). This throws away any time since last_update_time, but that's no worse than current, which throws away any time since decay_counter, and they're both called from enqueue/dequeue/tick/update_blocked_averages.
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 10 lines · On Thu, Jul 10, 2014 at 10:01:42AM -0700, [email protected] wrote:
Quoted 3 lines
The problem with that is that
last_update_timeis measured inclock_task, and you cannot transfer these values between CPUs.clock_taskcan drift unbounded between CPUs.Yes, but we don't need to - we just use the remote
last_update_timeto do a final update onp->se.avg, and then subtract that fromcfs_rq->avgwith atomics (and then setp->se.avg.last_update_timeto 0 as now). This throws away any time sincelast_update_time, but that's no worse than current, which throws away any time sincedecay_counter, and they're both called from enqueue/dequeue/tick/update_blocked_averages.
Yes, old CPU clock_task will not go to new CPU, we set last_update_time to 0, and on new CPU, when enqueued, it will start with new clock. Just throw some time way as Ben said.
Actually, this throwing away is not bad after a second thought, because it results in less decaying the wakee load, which effectively add some load/weight to the wakee, sounds good.
Thanks,
Yuyang
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to Peter ZijlstraQuoted 5 lines · Peter Zijlstra
Since
clock_taskis the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound onclock_taskdifferences.
This is inspiring. Regarding the clock source in load avg tracking, should we simply use rq_clock_task instead of cfs_rq_clock_task.
For the bandwidth control case, just update/increase the last_update_time when unthrottled by this throttled time, so the time would look like freezed. Am I understanding right?
Not sure how much bandwidth control is used, but even not used, every time we read cfs_rq_clock_task, will burn useless cycles here.
Thanks,
Yuyang
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 8 lines · Yuyang Du
Quoted 5 lines · Peter Zijlstra
Since
clock_taskis the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound onclock_taskdifferences.This is inspiring. Regarding the clock source in load avg tracking, should we simply use
rq_clock_taskinstead ofcfs_rq_clock_task.
Oh *groan* I forgot about that thing. But no, it obviously doesn't matter for running time, because if you're throttled you're nor running and therefore it all doesn't matter, but it can make a huge difference for blocked time accounting I suppose.
Quoted 3 lines
For the bandwidth control case, just update/increase the
last_update_timewhen unthrottled by this throttled time, so the time would look like freezed. Am I understanding right?
Yes, it stops the clock when throttled.
Quoted 2 lines
Not sure how much bandwidth control is used, but even not used, every time we read
cfs_rq_clock_task, will burn useless cycles here.
Yep, nothing much you can do about that.
In any case, it is still the case that a normal clock difference is an upper bound.
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 21 lines · Peter Zijlstra
Quoted 8 lines · Yuyang Du
Quoted 5 lines · Peter Zijlstra
Since
clock_taskis the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound onclock_taskdifferences.This is inspiring. Regarding the clock source in load avg tracking, should we simply use
rq_clock_taskinstead ofcfs_rq_clock_task.Oh *groan* I forgot about that thing. But no, it obviously doesn't matter for running time, because if you're throttled you're nor running and therefore it all doesn't matter, but it can make a huge difference for blocked time accounting I suppose.
Quoted 3 lines
For the bandwidth control case, just update/increase the
last_update_timewhen unthrottled by this throttled time, so the time would look like freezed. Am I understanding right?Yes, it stops the clock when throttled.
Quoted 7 lines
Quoted 2 lines
Not sure how much bandwidth control is used, but even not used, every time we read
cfs_rq_clock_task, will burn useless cycles here.Yep, nothing much you can do about that.
In any case, it is still the case that a normal clock difference is an upper bound.
I meant, not for this migrating case. But completely don't use cfs_rq_clock_task in the entire load avg tracking (and specially compensate the throttle case). No?
Thanks,
Yuyang
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 25 lines · Yuyang Du
Quoted 24 lines · Peter Zijlstra
Quoted 8 lines · Yuyang Du
Quoted 5 lines · Peter Zijlstra
Since
clock_taskis the regular clock minus some local amount, the difference between two regular clock reads is always a strict upper bound onclock_taskdifferences.This is inspiring. Regarding the clock source in load avg tracking, should we simply use
rq_clock_taskinstead ofcfs_rq_clock_task.Oh *groan* I forgot about that thing. But no, it obviously doesn't matter for running time, because if you're throttled you're nor running and therefore it all doesn't matter, but it can make a huge difference for blocked time accounting I suppose.
Quoted 3 lines
For the bandwidth control case, just update/increase the
last_update_timewhen unthrottled by this throttled time, so the time would look like freezed. Am I understanding right?Yes, it stops the clock when throttled.
Quoted 2 lines
Not sure how much bandwidth control is used, but even not used, every time we read
cfs_rq_clock_task, will burn useless cycles here.
Quoted 8 lines
Quoted 4 lines
Yep, nothing much you can do about that.
In any case, it is still the case that a normal clock difference is an upper bound.
I meant, not for this migrating case. But completely don't use
cfs_rq_clock_taskin the entire load avg tracking (and specially compensate the throttle case). No?
Oh, there seems no way to change every task's last_update_time when unthrottled.
Still, need cfs_rq_clock_task.
Thanks,
Yuyang
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to Peter ZijlstraThanks, Peter.
Quoted 7 lines · Peter Zijlstra
Nope :-).. we got rid of that lock for a good reason.
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the
sched_clock_cpu()difference is a strict upper bound on therq_clock_task()difference (and under 'normal' circumstances shouldn't be much off).
Strictly, migrating wakee task on remote CPU entails two steps:
(1) Catch up with task's queue's last_update_time, and then substract
(2) Cache up with "current" time of remote CPU (for comparable matter), and then on new CPU, change to the new timing source (when enqueue)
So I will try sched_clock_cpu(remote_cpu) for step (2). For step (2), maybe we should not use cfs_rq_clock_task anyway, since the task is about to going to another CPU/queue. Is this right?
I made another mistake. Should not only track task entity load, group entity (as an entity) is also needed. Otherwise, task_h_load can't be done correctly... Sorry for the messup. But this won't make much change in the codes.
Thanks,
Yuyang
Quoted 10 lines
So we could simply use a timestamps from dequeue and one from enqueue, and use that.
As to the remote subtraction, a RMW on another cacheline than the
rq->lockone should be good; esp since we don't actually observe the per-rq total often (once per tick or so) I think, no?The thing is, we do not want to disturb scheduling on whatever cpu the task last ran on if we wake it to another cpu. Taking
rq->lockwrecks that for sure.
[email protected]
reviewerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 14 lines · Yuyang Du
Thanks, Peter.
Quoted 7 lines · Peter Zijlstra
Nope :-).. we got rid of that lock for a good reason.
Also, this is one area where I feel performance really trumps correctness, we can fudge the blocked load a little. So the
sched_clock_cpu()difference is a strict upper bound on therq_clock_task()difference (and under 'normal' circumstances shouldn't be much off).Strictly, migrating wakee task on remote CPU entails two steps:
Quoted 8 lines
(1) Catch up with task's queue's
last_update_time, and then substract(2) Cache up with "current" time of remote CPU (for comparable matter), and then on new CPU, change to the new timing source (when enqueue)
So I will try
sched_clock_cpu(remote_cpu)for step (2). For step (2), maybe we should not usecfs_rq_clock_taskanyway, since the task is about to going to another CPU/queue. Is this right?
So, sched_clock(_cpu) can be arbitrarily far off of cfs_rq_clock_task, so you can't really do that. Ideally, yes, you would account for any time since the last update and account that time as !runnable. However, I don't think there is any good way to do that, and the current code doesn't.
Quoted 4 lines
I made another mistake. Should not only track task entity load, group entity (as an entity) is also needed. Otherwise,
task_h_loadcan't be done correctly... Sorry for the messup. But this won't make much change in the codes.
This will increase it to 2x __update_load_avg per cgroup per enqueue/dequeue. What does this (and this patch in general) do to context switch cost at cgroup depth 1/2/3?
Quoted 14 lines
Thanks,
YuyangQuoted 10 lines
So we could simply use a timestamps from dequeue and one from enqueue, and use that.
As to the remote subtraction, a RMW on another cacheline than the
rq->lockone should be good; esp since we don't actually observe the per-rq total often (once per tick or so) I think, no?The thing is, we do not want to disturb scheduling on whatever cpu the task last ran on if we wake it to another cpu. Taking
rq->lockwrecks that for sure.
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
Quoted 4 lines · On Thu, Jul 10, 2014 at 10:06:27AM -0700, [email protected] wrote:
So,
sched_clock(_cpu)can be arbitrarily far off ofcfs_rq_clock_task, so you can't really do that. Ideally, yes, you would account for any time since the last update and account that time as !runnable. However, I don't think there is any good way to do that, and the current code doesn't.
Yeah. We only catch up the migrating task to its cfs_rq and substract. No catching up to "current" time.
Quoted 8 lines
Quoted 4 lines
I made another mistake. Should not only track task entity load, group entity (as an entity) is also needed. Otherwise,
task_h_loadcan't be done correctly... Sorry for the messup. But this won't make much change in the codes.This will increase it to 2x
__update_load_avgper cgroup per enqueue/dequeue. What does this (and this patch in general) do to context switch cost at cgroup depth 1/2/3?
We can update cfs_rq load_avg, and let the cfs_rq's own se take a ride in that update. These two should get exactly synchronized anyway (group se's load is only usefull for task_h_load calc, and group cfs_rq's load is useful for task_h_load and update_cfs_share calc). And technically, it looks easy:
To update cfs_rq, the update weight is cfs_rq->load.weight
To update its se, the update weight is cfs_rq->tg->se[cpu]->load.weight * on_rq
So the it will not increase to 2x, but 1.05x, maybe, :)
Thanks,
Yuyang
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to [email protected]Quoted 47 lines · On Mon, Jul 07, 2014 at 03:25:07PM -0700, [email protected] wrote:
Quoted 32 lines
Quoted 14 lines
kernel/sched/fair.c +11
-0+static inline void enqueue_entity_load_avg (struct sched_entity *se) { +struct sched_avg *sa = &se->avg; +struct cfs_rq *cfs_rq =cfs_rq_of (se); +u64 now =cfs_rq_clock_task (cfs_rq); +u32 old_load_avg = cfs_rq->avg.load_avg; +int migrated =0 ; +if (entity_is_task (se)) { +if (sa->last_update_time ==0 ) { + sa->last_update_time = now; + migrated =1 ; } +else kernel/sched/fair.c static __always_inline int __update_entity_runnable_avg(u64 now, · line 2384
Quoted 10 lines
kernel/sched/fair.c +5
-0+__update_load_avg (now, sa, se->on_rq * se->load.weight); } +__update_load_avg (now, &cfs_rq->avg, cfs_rq->load.weight); +if (migrated) + cfs_rq->avg.load_avg += sa->load_avg; +synchronize_tg_load_avg (cfs_rq, old_load_avg); }So here you add the task to the
cfs_rqavg when its got migrate in, however:Quoted 4 lines
kernel/sched/fair.c +0
-0@@ -4552,17 +4326,9 @@ migrate_task_rq_fair(struct task_struct *p, int next_cpu)struct sched_entity *se = &p->se;struct cfs_rq *cfs_rq =cfs_rq_of (se);Quoted 8 lines
kernel/sched/fair.c migrate_task_rq_fair(struct task_struct *p, int next_cpu) · line 4334
Quoted 6 lines
kernel/sched/fair.c +3
-0+/* Update task on old CPU, then ready to go (entity must be off the queue) */ +__update_load_avg (cfs_rq_clock_task (cfs_rq), &se->avg,0 ); + se->avg.last_update_time =0 ;/* We have migrated, no longer consider this task hot */ se->exec_start =0 ;there you don't remove it first..
Yeah, the issue is that you can't remove it, because you don't hold the lock. Thus the whole runnable/blocked split iirc. Also the
cfs_rq_clock_taskread is incorrect for the same reason (and whilerq_clock_taskcould certainly be fixed min_vruntime-style,cfs_rq_clock_taskwould be harder).
Quoted 7 lines
The problem with just working around the clock issue somehow and then using an atomic to do this subtraction is that you have no idea when the /cfs_rq/ last updated - there's no guarantee it is up to date, and if it's not then the subtraction is wrong. You can't update it to make it up to date like the
se->avg, becasue you don't hold any locks. You would needdecay_counterstuff like the current code, and I'm not certain how well that would work out without the runnable/blocked split.
Right; so the current code jumps through a few nasty hoops because of this. But I think the proposed code got this wrong (understandably).
But yes, we spend a lot of time and effort to remove the rq->lock from the remote wakeup path, which makes all this very tedious indeed.
Like you said, we can indeed make the time thing work, but the remote subtraction is going to be messy. Can't seem to come up with anything sane there either.
Re: [PATCH 2/2] sched: Rewrite per entity runnable load average tracking
In reply to Peter ZijlstraThanks, Peter.
Quoted 4 lines · Peter Zijlstra
That
tg->load_avgcacheline is already red hot glowing, and you've just increased the amount of updates to it.. That's not going to be pleasant.
Logically, this rewrite updates tg->load_avg as soon as it is changed. But technically, this is not necessary, as it is only needed to be updated when it is used before update_cfs_shares() and update_cfs_rq_h_load().
Yes, I can optimize it.
Quoted 7 lines
So here you add the task to the
cfs_rqavg when its got migrate in, however:Quoted 4 lines
kernel/sched/fair.c +0
-0@@ -4552,17 +4326,9 @@ migrate_task_rq_fair(struct task_struct *p, int next_cpu)struct sched_entity *se = &p->se;struct cfs_rq *cfs_rq =cfs_rq_of (se);
Quoted 9 lines
kernel/sched/fair.c migrate_task_rq_fair(struct task_struct *p, int next_cpu) · line 4334
Quoted 6 lines
kernel/sched/fair.c +3
-0+/* Update task on old CPU, then ready to go (entity must be off the queue) */ +__update_load_avg (cfs_rq_clock_task (cfs_rq), &se->avg,0 ); + se->avg.last_update_time =0 ;/* We have migrated, no longer consider this task hot */ se->exec_start =0 ;there you don't remove it first..
Yes, I missed it. I wonder what I was thinking. Migration is the only reason to track task load average...
Yuyang