psi : calc cfs task memstall time more precisely
Subsystems (3)
PATCH RESEND 1/1 psi : calc cfs task memstall time more precisely
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.
Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15
--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
kernel/sched/psi.c +19 -1
@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;
@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; } +static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;
@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta); groupc->times[PSI_MEM_SOME ] += delta;if (groupc->state_mask & (1 <<PSI_MEM_FULL )) groupc->times[PSI_MEM_FULL ] += delta;
@@ -928,8 +946,8 @@ void psi_memstall_leave(unsigned long *flags)*/ rq =this_rq_lock_irq (&rf); - current->in_memstall =0 ;psi_task_change (current,TSK_MEMSTALL ,0 ); + current->in_memstall =0 ;rq_unlock_irq (rq, &rf); }
Signature · 1 line
1.9.1
Johannes Weiner
maintainerCC peterz as well for rt and timekeeping magic
Quoted 63 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15Signed-off-by Zhaoyang Huang <[email protected]>--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)kernel/sched/psi.c +17
-0@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; } +static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;
kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);
Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
Does util_avg capture that difference? I'm not confident it does - but correct me if I'm wrong. We need length of time during which and IRQ or an RT task preempted the old rq->curr, not absolute irq/rt length.
(Btw, such preemption periods, in addition to being deducted from memory stalls, should probably also be added to CPU contention stalls, to make CPU pressure reporting more accurate as well.)
Quoted 69 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 65 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15Signed-off-by Zhaoyang Huang <[email protected]>--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)kernel/sched/psi.c +17
-0@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; } +static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }
Quoted 3 lines
kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 2 lines
kernel/sched/psi.c +1
-0if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);
add vincent for advise on cpu load mechanism
Quoted 11 lines
Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
Does
util_avgcapture that difference? I'm not confident it does - but correct me if I'm wrong. We need length of time during which and IRQ or an RT task preempted the oldrq->curr, not absolute irq/rt length.
As far as my understanding, core's capacity = IRQ + DEADLINE + RT + CFS. For a certain time period, all cfs tasks preempt each other inside CFS's utilization. So the sleeping on refaults is counted in.
Quoted 4 lines
(Btw, such preemption periods, in addition to being deducted from memory stalls, should probably also be added to CPU contention stalls, to make CPU pressure reporting more accurate as well.)
+Vincent Guittot
Quoted 94 lines · Zhaoyang Huang
Quoted 69 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 65 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15Signed-off-by Zhaoyang Huang <[email protected]>--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)kernel/sched/psi.c +17
-0@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; } +static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }Quoted 3 lines
kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 2 lines
kernel/sched/psi.c +1
-0if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);add vincent for advise on cpu load mechanism
Quoted 11 lines
Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
Does
util_avgcapture that difference? I'm not confident it does - but correct me if I'm wrong. We need length of time during which and IRQ or an RT task preempted the oldrq->curr, not absolute irq/rt length.As far as my understanding, core's capacity = IRQ + DEADLINE + RT + CFS. For a certain time period, all cfs tasks preempt each other inside CFS's utilization. So the sleeping on refaults is counted in.
Quoted 4 lines
(Btw, such preemption periods, in addition to being deducted from memory stalls, should probably also be added to CPU contention stalls, to make CPU pressure reporting more accurate as well.)
Dietmar Eggemann
reviewerQuoted 12 lines · Zhaoyang Huang
+Vincent Guittot
Quoted 9 lines · Zhaoyang Huang
Quoted 7 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 3 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15Signed-off-by Zhaoyang Huang <[email protected]>--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)kernel/sched/psi.c +2
-0@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 503
Quoted 7 lines
kernel/sched/psi.c +7
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed;
This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including SCHED_IDLE) pass?
if (current->sched_class != &fair_sched_class)
return growth_fixed;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 508
Quoted 5 lines
kernel/sched/psi.c +5
-0+ +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); +
We do this slightly different in scale_rt_capacity() [fair.c]:
max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */
used = cpu_util_rt(rq);
used += cpu_util_dl(rq);
used += thermal_load_avg(rq);
free = max - used
irq = cpu_util_irq(rq)
used = scale_irq_capacity(free, irq, max);
scaling then with with: max - used / max
Quoted 32 lines
Quoted 32 lines
Quoted 9 lines
Quoted 9 lines
kernel/sched/psi.c +3
-0+return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }Quoted 3 lines
kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 2 lines
kernel/sched/psi.c +1
-0if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);add vincent for advise on cpu load mechanism
Quoted 11 lines
Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
Does
util_avgcapture that difference? I'm not confident it does - but correct me if I'm wrong. We need length of time during which and IRQ or an RT task preempted the oldrq->curr, not absolute irq/rt length.As far as my understanding, core's capacity = IRQ + DEADLINE + RT + CFS. For a certain time period, all cfs tasks preempt each other inside CFS's utilization. So the sleeping on refaults is counted in.
Quoted 4 lines
(Btw, such preemption periods, in addition to being deducted from memory stalls, should probably also be added to CPU contention stalls, to make CPU pressure reporting more accurate as well.)
Quoted 10 lines · Dietmar Eggemann
Quoted 8 lines · Zhaoyang Huang
+Vincent Guittot
Quoted 5 lines · Zhaoyang Huang
Quoted 3 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Huangzhaoyang
Quoted 3 lines
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time within PSI_MEM_STALL than SMP does.
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15Signed-off-by Zhaoyang Huang <[email protected]>--- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)kernel/sched/psi.c +2
-0@@ -182,6 +182,8 @@ struct psi_group psi_system = {static void psi_avgs_work (struct work_struct *work); +static unsigned long psi_memtime_fixup (u32 growth); +static void group_init (struct psi_group *group) {int cpu;@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; }
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 503
Quoted 7 lines
kernel/sched/psi.c +7
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed;This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?
idle tasks will NOT call psi_memstall_xxx. We just want CFS tasks to scale the STALL time.
Quoted 12 lines
if (
current->sched_class!=&fair_sched_class)return growth_fixed;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 508
Quoted 5 lines
kernel/sched/psi.c +5
-0+ +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); +We do this slightly different in
scale_rt_capacity()[fair.c]:
Quoted 2 lines
max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */
Is it possible that the SUM of rqs' util_avg large than arch_scale_cpu_capacity because of task migration things?
Quoted 11 lines
used =
cpu_util_rt(rq);
used +=cpu_util_dl(rq);
used +=thermal_load_avg(rq);free = max - used
irq =cpu_util_irq(rq)used =
scale_irq_capacity(free, irq, max);scaling then with with: max - used / max
ok. so introduce thermal util.
Quoted 34 lines
Quoted 33 lines
Quoted 33 lines
Quoted 10 lines
Quoted 10 lines
kernel/sched/psi.c +3
-0+return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }Quoted 3 lines
kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 2 lines
kernel/sched/psi.c +1
-0if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);add vincent for advise on cpu load mechanism
Quoted 11 lines
Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
Does
util_avgcapture that difference? I'm not confident it does - but correct me if I'm wrong. We need length of time during which and IRQ or an RT task preempted the oldrq->curr, not absolute irq/rt length.As far as my understanding, core's capacity = IRQ + DEADLINE + RT + CFS. For a certain time period, all cfs tasks preempt each other inside CFS's utilization. So the sleeping on refaults is counted in.
Quoted 4 lines
(Btw, such preemption periods, in addition to being deducted from memory stalls, should probably also be added to CPU contention stalls, to make CPU pressure reporting more accurate as well.)
Dietmar Eggemann
reviewerQuoted 15 lines · Zhaoyang Huang
Quoted 13 lines · Dietmar Eggemann
Quoted 11 lines · Zhaoyang Huang
+Vincent Guittot
Quoted 8 lines · Zhaoyang Huang
Quoted 6 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 2 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
In an EAS enabled system, there are two scenarios discordant to current design,
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time withinPSI_MEM_STALLthan SMP does.
What's your CPU layout? Do you have the little before the big CPUs? Like Hikey 960?
root@linaro-developer:~# cat /sys/devices/system/cpu/cpu*/cpu_capacity 462 462 462 462 1024 1024 1024 1024
And I guess rt class prefers lower CPU numbers hence you see this?
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
eg.
Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS.Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15
[...]
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
kernel/sched/psi.c +0
-0@@ -492,6 +494,21 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)return growth; }Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 503
Quoted 7 lines
kernel/sched/psi.c +7
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed;This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?
Quoted 2 lines
idle tasks will NOT call
psi_memstall_xxx. We just want CFS tasks to scale the STALL time.
Not sure I get this.
__schedule() -> psi_sched_switch() -> psi_task_change() -> psi_group_change() -> record_times() -> psi_memtime_fixup()
is something else than calling psi_memstall_enter() or _leave()?
IMHO, at least record_times() can be called with current equal swapper/X. Or is it that PSI_MEM_SOME is never set for the idle task in this callstack? I don't know the PSI internals.
Quoted 12 lines
Quoted 12 lines
if (
current->sched_class!=&fair_sched_class)return growth_fixed;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
kernel/sched/psi.c static u64 window_update(struct psi_window *win, u64 now, u64 value) · line 508
Quoted 5 lines
kernel/sched/psi.c +5
-0+ +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); +We do this slightly different in
scale_rt_capacity()[fair.c]:
Quoted 4 lines
Quoted 2 lines
max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */Is it possible that the SUM of rqs'
util_avglarge thanarch_scale_cpu_capacitybecause of task migration things?
I assume you meant if the rq (cpu_rq(CPUx)) util_avg sum (CFS, RT, DL, IRQ and thermal part) can be larger than arch_scale_cpu_capacity(CPUx)?
Yes it can.
Have a lock at
effective_cpu_util(..., max, ...) {
if (foo >= max)
return max;
}
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (rq->cpu_capacity_orig).
Have a look at cpu_util(). capacity_orig_of(CPUx) and arch_scale_cpu_capacity(CPUx) both returning rq->cpu_capacity_orig.
[...]
Hi Dietmar
Quoted 22 lines · Dietmar Eggemann
Quoted 6 lines · Zhaoyang Huang
Quoted 3 lines
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time withinPSI_MEM_STALLthan SMP does.What's your CPU layout? Do you have the little before the big CPUs? Like Hikey 960?
root@linaro-developer:~# cat /sys/devices/system/cpu/cpu*/cpu_capacity 462 462 462 462 1024 1024 1024 1024
Quoted 2 lines
And I guess rt class prefers lower CPU numbers hence you see this?
our CPU layout is:
xuewen.yan:/ # cat /sys/devices/system/cpu/cpu*/cpu_capacity 544
544
544
544
544
544
1024
1024
And in our platform, we use the kernel in mobile phones with Android. And we prefer power, so we prefer the RT class to run on little cores.
Quoted 46 lines
Quoted 5 lines
Quoted 3 lines
This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?idle tasks will NOT call
psi_memstall_xxx. We just want CFS tasks to scale the STALL time.Not sure I get this.
__schedule()->psi_sched_switch()->psi_task_change()->psi_group_change()->record_times()->psi_memtime_fixup()is something else than calling
psi_memstall_enter()or_leave()?IMHO, at least
record_times()can be called with current equal swapper/X. Or is it thatPSI_MEM_SOMEis never set for the idle task in this callstack? I don't know the PSI internals.Quoted 12 lines
Quoted 12 lines
if (
current->sched_class!=&fair_sched_class)return growth_fixed;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + if (current->in_memstall) + growth_fixed = div64_ul((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg + 1) * growth, 1024); +We do this slightly different in
scale_rt_capacity()[fair.c]:Quoted 4 lines
Quoted 2 lines
max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */Is it possible that the SUM of rqs'
util_avglarge thanarch_scale_cpu_capacitybecause of task migration things?I assume you meant if the rq (
cpu_rq(CPUx))util_avgsum (CFS, RT, DL, IRQ and thermal part) can be larger thanarch_scale_cpu_capacity(CPUx)?Yes it can.
Have a lock at
effective_cpu_util(..., max, ...){if (foo >= max)
return max;
Quoted 8 lines
}
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (
rq->cpu_capacity_orig).Have a look at
cpu_util().capacity_orig_of(CPUx)andarch_scale_cpu_capacity(CPUx)both returningrq->cpu_capacity_orig.
Well, your means is we should not use the 1024 and should use the original cpu capacity?
And maybe use the "sched_cpu_util()" is a good choice just like this:
+ if (current->in_memstall)
+ growth_fixed = div64_ul(cpu_util_cfs(rq) * growth,sched_cpu_util(rq->cpu, capacity_orig_of(rq->cpu)));
Thanks!
BR
xuewen
Quoted 40 lines · Xuewen Yan
Hi Dietmar
Quoted 22 lines · Dietmar Eggemann
Quoted 6 lines · Zhaoyang Huang
Quoted 3 lines
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time withinPSI_MEM_STALLthan SMP does.What's your CPU layout? Do you have the little before the big CPUs? Like Hikey 960?
root@linaro-developer:~# cat /sys/devices/system/cpu/cpu*/cpu_capacity 462 462 462 462 1024 1024 1024 1024Quoted 2 lines
And I guess rt class prefers lower CPU numbers hence you see this?
our CPU layout is:
xuewen.yan:/ # cat/sys/devices/system/cpu/cpu*/cpu_capacity544
544
544
544
544
544
1024
1024
Quoted 20 lines
And in our platform, we use the kernel in mobile phones with Android. And we prefer power, so we prefer the RT class to run on little cores.
Quoted 16 lines
Quoted 5 lines
Quoted 3 lines
This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?idle tasks will NOT call
psi_memstall_xxx. We just want CFS tasks to scale the STALL time.Not sure I get this.
__schedule()->psi_sched_switch()->psi_task_change()->psi_group_change()->record_times()->psi_memtime_fixup()is something else than calling
psi_memstall_enter()or_leave()?IMHO, at least
record_times()can be called with current equal swapper/X. Or is it thatPSI_MEM_SOMEis never set for the idle task in this callstack? I don't know the PSI internals.
According to my understanding, PSI_MEM_SOME represents the CORE's state within which there is at least one task trapped in memstall path(only counted in by calling PSI_MEMSTALL_ENTER). record_times is responsible for collecting the delta time of the CORE since it start. What we are doing is to make the delta time more precise. So idle task is irrelevant for these.
Quoted 51 lines
Quoted 30 lines
Quoted 13 lines
Quoted 13 lines
if (
current->sched_class!=&fair_sched_class)return growth_fixed;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + if (current->in_memstall) + growth_fixed = div64_ul((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg + 1) * growth, 1024); +We do this slightly different in
scale_rt_capacity()[fair.c]:Quoted 4 lines
Quoted 2 lines
max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */Is it possible that the SUM of rqs'
util_avglarge thanarch_scale_cpu_capacitybecause of task migration things?I assume you meant if the rq (
cpu_rq(CPUx))util_avgsum (CFS, RT, DL, IRQ and thermal part) can be larger thanarch_scale_cpu_capacity(CPUx)?Yes it can.
Have a lock at
effective_cpu_util(..., max, ...){if (foo >= max)
return max;Quoted 8 lines
}
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (
rq->cpu_capacity_orig).Have a look at
cpu_util().capacity_orig_of(CPUx)andarch_scale_cpu_capacity(CPUx)both returningrq->cpu_capacity_orig.Well, your means is we should not use the 1024 and should use the original cpu capacity?
And maybe use the "sched_cpu_util()" is a good choice just like this:(quoted diff) +2
-0+ if (current->in_memstall) + growth_fixed = div64_ul(cpu_util_cfs(rq) * growth,
sched_cpu_util(rq->cpu, capacity_orig_of(rq->cpu)));Thanks!
BR
xuewen
Dietmar Eggemann
reviewerQuoted 8 lines · Zhaoyang Huang
Quoted 7 lines · Xuewen Yan
Hi Dietmar
Quoted 2 lines · Dietmar Eggemann
On 05/11/2021 06:58, Zhaoyang Huang wrote:
[...]
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?idle tasks will NOT call
psi_memstall_xxx. We just want CFS tasks to scale the STALL time.Not sure I get this.
Quoted 8 lines
Quoted 8 lines
__schedule()->psi_sched_switch()->psi_task_change()->psi_group_change()->record_times()->psi_memtime_fixup()is something else than calling
psi_memstall_enter()or_leave()?IMHO, at least
record_times()can be called with current equal swapper/X. Or is it thatPSI_MEM_SOMEis never set for the idle task in this callstack? I don't know the PSI internals.
Quoted 6 lines
According to my understanding,
PSI_MEM_SOMErepresents the CORE's state within which there is at least one task trapped in memstallpath(only counted in by calling PSI_MEMSTALL_ENTER).record_timesis responsible for collecting the delta time of the CORE since it start. What we are doing is to make the delta time more precise. So idle task is irrelevant for these.
Coming back to the original snippet of the patch.
static unsigned long psi_memtime_fixup(u32 growth) {
if (!(current->policy == SCHED_NORMAL ||
current->policy == SCHED_BATCH))
return growth_fixed;With this condition:
(1) you're not bailing when current is the idle task. It has policy equal 0 (SCHED_NORMAL)
(2) But you're bailing for a SCHED_IDLE (CFS) task.
I'm not sure that this is indented here?
Since you want to do the scaling later based on whats left for CFS tasks from the CPU capacity my hunch is that you want to rather do:
if (current->sched_class != &fair_sched_class)
return growth_fixed;What's the possible sched classes of current in psi_memtime_fixup?
Quoted 51 lines · Dietmar Eggemann
Quoted 8 lines · Zhaoyang Huang
Quoted 7 lines · Xuewen Yan
Hi Dietmar
Quoted 2 lines · Dietmar Eggemann
On 05/11/2021 06:58, Zhaoyang Huang wrote:
[...]
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This will let the idle task (swapper) pass. Is this indented? Or do you want to only let CFS tasks (including
SCHED_IDLE) pass?idle tasks will NOT call
psi_memstall_xxx. We just want CFS tasks to scale the STALL time.Not sure I get this.
Quoted 8 lines
Quoted 8 lines
__schedule()->psi_sched_switch()->psi_task_change()->psi_group_change()->record_times()->psi_memtime_fixup()is something else than calling
psi_memstall_enter()or_leave()?IMHO, at least
record_times()can be called with current equal swapper/X. Or is it thatPSI_MEM_SOMEis never set for the idle task in this callstack? I don't know the PSI internals.Quoted 6 lines
According to my understanding,
PSI_MEM_SOMErepresents the CORE's state within which there is at least one task trapped in memstallpath(only counted in by calling PSI_MEMSTALL_ENTER).record_timesis responsible for collecting the delta time of the CORE since it start. What we are doing is to make the delta time more precise. So idle task is irrelevant for these.Coming back to the original snippet of the patch.
static unsigned long
psi_memtime_fixup(u32 growth){if (!(current->policy == SCHED_NORMAL || current->policy == SCHED_BATCH)) return growth_fixed;With this condition:
(1) you're not bailing when current is the idle task. It has policy equal 0 (
SCHED_NORMAL)(2) But you're bailing for a
SCHED_IDLE(CFS) task.
Quoted 7 lines
I'm not sure that this is indented here?
Since you want to do the scaling later based on whats left for CFS tasks from the CPU capacity my hunch is that you want to rather do:
if (current->sched_class != &fair_sched_class) return growth_fixed;
Yes, It is the correct method!
Thanks!
Quoted 2 lines
What's the possible sched classes of current in
psi_memtime_fixup?
Dietmar Eggemann
reviewerQuoted 15 lines · Xuewen Yan
Hi Dietmar
Quoted 11 lines · Dietmar Eggemann
Quoted 6 lines · Zhaoyang Huang
Quoted 3 lines
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time withinPSI_MEM_STALLthan SMP does.What's your CPU layout? Do you have the little before the big CPUs? Like Hikey 960?
[...]
Quoted 13 lines
Quoted 2 lines
And I guess rt class prefers lower CPU numbers hence you see this?
our CPU layout is:
xuewen.yan:/ # cat/sys/devices/system/cpu/cpu*/cpu_capacity544
544
544
544
544
544
1024
1024
Quoted 2 lines
And in our platform, we use the kernel in mobile phones with Android. And we prefer power, so we prefer the RT class to run on little cores.
Ah, OK, out-of-tree extensions.
[...]
Quoted 39 lines
Quoted 24 lines
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (current->in_memstall) + growth_fixed = div64_ul((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg + 1) * growth, 1024); +We do this slightly different in
scale_rt_capacity()[fair.c]:max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */Is it possible that the SUM of rqs'
util_avglarge thanarch_scale_cpu_capacitybecause of task migration things?I assume you meant if the rq (
cpu_rq(CPUx))util_avgsum (CFS, RT, DL, IRQ and thermal part) can be larger thanarch_scale_cpu_capacity(CPUx)?Yes it can.
Have a lock at
effective_cpu_util(..., max, ...){if (foo >= max)
return max;Quoted 8 lines
}
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (
rq->cpu_capacity_orig).Have a look at
cpu_util().capacity_orig_of(CPUx)andarch_scale_cpu_capacity(CPUx)both returningrq->cpu_capacity_orig.Well, your means is we should not use the 1024 and should use the original cpu capacity?
And maybe use the "sched_cpu_util()" is a good choice just like this:(quoted diff) +2
-0+ if (current->in_memstall) + growth_fixed = div64_ul(cpu_util_cfs(rq) * growth,
Quoted 1 line
sched_cpu_util(rq->cpu, capacity_orig_of(rq->cpu)));
Not sure about this. In case util_cfs=0 you would get scale=0.
IMHO, you need
cap = rq->cpu_capacitycap_orig = rq->cpu_capacity_orig
scale = (cap * X) / cap_orig
or if the update of these rq values happens to infrequently for you then you have to calc the pressure evey time. Something like:
pressure = cpu_util_rt(rq) + cpu_util_dl(rq)
irq = cpu_util_irq(rq)
if (irq >= cap_orig)
pressure = cap_orig
else
pressure = scale_irq_capacity(pressure, irq, cap_orig) pressure += irq
scale = ((cap_orig - pressure) * X) / cap_orig
Hi Dietmar
Quoted 77 lines · Dietmar Eggemann
Quoted 15 lines · Xuewen Yan
Hi Dietmar
Quoted 11 lines · Dietmar Eggemann
Quoted 6 lines · Zhaoyang Huang
Quoted 3 lines
I don't understand the EAS (probably asymmetric CPU capacity is meant here) angle of the story. Pressure on CPU capacity which is usable for CFS happens on SMP as well?
Mentioning EAS here mainly about RT tasks preempting small CFS tasks
(big CFS tasks could be scheduled to big core), which would introduce more proportion of preempted time withinPSI_MEM_STALLthan SMP does.What's your CPU layout? Do you have the little before the big CPUs? Like Hikey 960?
[...]
Quoted 13 lines
Quoted 2 lines
And I guess rt class prefers lower CPU numbers hence you see this?
our CPU layout is:
xuewen.yan:/ # cat/sys/devices/system/cpu/cpu*/cpu_capacity544
544
544
544
544
544
1024
1024Quoted 2 lines
And in our platform, we use the kernel in mobile phones with Android. And we prefer power, so we prefer the RT class to run on little cores.
Ah, OK, out-of-tree extensions.
[...]
Quoted 37 lines
Quoted 24 lines
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (current->in_memstall) + growth_fixed = div64_ul((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg + 1) * growth, 1024); +We do this slightly different in
scale_rt_capacity()[fair.c]:max = arch_scale_cpu_capacity(cpu_of(rq) /* instead of 1024 to support
asymmetric CPU capacity */Is it possible that the SUM of rqs'
util_avglarge thanarch_scale_cpu_capacitybecause of task migration things?I assume you meant if the rq (
cpu_rq(CPUx))util_avgsum (CFS, RT, DL, IRQ and thermal part) can be larger thanarch_scale_cpu_capacity(CPUx)?Yes it can.
Have a lock at
effective_cpu_util(..., max, ...){if (foo >= max)
return max;Quoted 8 lines
}
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (
rq->cpu_capacity_orig).Have a look at
cpu_util().capacity_orig_of(CPUx)andarch_scale_cpu_capacity(CPUx)both returningrq->cpu_capacity_orig.Well, your means is we should not use the 1024 and should use the original cpu capacity?
And maybe use the "sched_cpu_util()" is a good choice just like this:
Quoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ if (current->in_memstall) + growth_fixed = div64_ul(cpu_util_cfs(rq) * growth,
sched_cpu_util(rq->cpu, capacity_orig_of(rq->cpu)));Not sure about this. In case util_cfs=0 you would get scale=0.
Yes , we should consider it. In addition, it also should be considered when util_cfs > capacity_orig because of the UTIL_EST......
Quoted 15 lines
IMHO, you need
cap =
rq->cpu_capacitycap_orig=rq->cpu_capacity_origscale = (cap * X) /
cap_origor if the update of these rq values happens to infrequently for you then you have to calc the pressure evey time. Something like:
pressure =
cpu_util_rt(rq)+cpu_util_dl(rq)irq =
cpu_util_irq(rq)
Quoted 7 lines
if (irq >=
cap_orig)
pressure =cap_orig
else
pressure =scale_irq_capacity(pressure, irq, cap_orig)pressure += irqscale = ((
cap_orig- pressure) * X) /cap_orig
Why rescale the util there, the sched_cpu_util() would invoke the effective_cpu_util(), and I don't think it's necessary to rescale it.
Thanks!
Dietmar Eggemann
reviewerQuoted 11 lines · Xuewen Yan
Hi Dietmar
Quoted 8 lines · Dietmar Eggemann
Quoted 6 lines · Xuewen Yan
Hi Dietmar
Quoted 2 lines · Dietmar Eggemann
On 05/11/2021 06:58, Zhaoyang Huang wrote:
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Even the CFS part (cpu_rq(CPUx)->cfs.avg.util_avg) can be larger than the original cpu capacity (
rq->cpu_capacity_orig).Have a look at
cpu_util().capacity_orig_of(CPUx)andarch_scale_cpu_capacity(CPUx)both returningrq->cpu_capacity_orig.Well, your means is we should not use the 1024 and should use the original cpu capacity?
And maybe use the "sched_cpu_util()" is a good choice just like this:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ if (current->in_memstall) + growth_fixed = div64_ul(cpu_util_cfs(rq) * growth,
sched_cpu_util(rq->cpu, capacity_orig_of(rq->cpu)));Not sure about this. In case util_cfs=0 you would get scale=0.
Yes , we should consider it. In addition, it also should be considered when
util_cfs>capacity_origbecause of theUTIL_EST......
We should ]-clamp cpu_util_cfs() with capacity_orig_of(), like we currently do for the CFS internal cpu_util(). In fact, we should only use one function for this. Sent a patch out:
https://lkml.kernel.org/r/[email protected]%3E
[...]
Peter Zijlstra
maintainerQuoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.
It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
Quoted 33 lines
Quoted 24 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 4 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
As Johannes comments, what we are trying to solve is mainly the preempted time of the CFS task by RT/IRQ, NOT the RT/IRQ themselves. Could you please catch up the recent reply of Dietmar, which maybe provide more information.
Quoted 41 lines
Quoted 34 lines
Quoted 25 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
Quoted 7 lines
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
memstall time is counted as exit - enter, which include both blocked and running stat. However, we think the blocked time introduced by preemption of RT/IRQ/DL are memstall irrelevant(should be eliminated), while the ones between CFS tasks could be. Thanks for the mechanism of load tracking, the implementation could be simple by calculating the proportion of CFS_UTIL among the whole core's capacity.
Quoted 3 lines
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
It is NOT randomly scaling, but scales in each record_times for CFS tasks.
Peter Zijlstra
maintainerQuoted 15 lines · Zhaoyang Huang
Quoted 14 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.
Quoted 6 lines
Quoted 2 lines
It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
As Johannes comments, what we are trying to solve is mainly the preempted time of the CFS task by RT/IRQ, NOT the RT/IRQ themselves. Could you please catch up the recent reply of Dietmar, which maybe provide more information.
In that case NAK.
Quoted 17 lines · Peter Zijlstra
Quoted 15 lines · Zhaoyang Huang
Quoted 14 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
As Johannes comments, what we are trying to solve is mainly the preempted time of the CFS task by RT/IRQ, NOT the RT/IRQ themselves. Could you please catch up the recent reply of Dietmar, which maybe provide more information.
In that case NAK.
Would you please explaining if there is any constraint to prevent from doing so? We do think eliminating the preempted time is reasonable and doable as it is memory irrelevant but probably related to lack of CPU etc.
Vincent Guittot
maintainerQuoted 57 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
Quoted 33 lines
Quoted 24 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
Quoted 7 lines
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
I tend to agree with this.
Using rq_clock_task(rq) instead of cpu_clock(cpu) will remove the time spent under interrupt as an example
and AFAICT, rq->clock_task is updated before calling psi function
Quoted 3 lines
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
Quoted 67 lines · Vincent Guittot
Quoted 57 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
Quoted 33 lines
Quoted 24 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
Quoted 7 lines
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
Quoted 4 lines
I tend to agree with this.
Usingrq_clock_task(rq)instead ofcpu_clock(cpu)will remove the time spent under interrupt as an example
and AFAICT,rq->clock_taskis updated before calling psi function
thanks vincent. Could rq_clock_task help on removing the preempted time of CFS task by RT/DL, which is the mainly part we want to solve on memstall time.
Quoted 4 lines
Quoted 4 lines
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
Johannes Weiner
maintainerQuoted 59 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
Quoted 33 lines
Quoted 24 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Quoted 7 lines
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
It *could* be argued that IRQs and RT preemptions are CPU stalls.
I'm less convinced we should subtract preemptions from memory stalls.
Yes, when you're reclaiming and you get preempted for whatever reason, you're technically stalled on CPU in this moment. However, reclaim itself consumes CPU and walltime, and it could be what is causing those preemptions to begin with! For example, reclaim could eat up 90% of your scheduling timeslice and then cause a preemption when the thread is back in userspace and trying to be productive. By consuming time, it also drags out the overall timeline for userspace to finish its work, and a longer timeline will have more disruptions from independent events like IRQs and RT thread wakeups.
So if you *were* to discount CPU contention from memory stalls, it would also mean that you'd have to count *memory stalls* when userspace experiences CPU contention caused by preceding reclaims. I don't think it makes sense to try to go down that road...
They're dependent resources. Just like faster CPUs and faster IO devices mean less memory pressure for the same amount of reclaim and paging activity, it seems logical that contention of those underlying resources will result in longer memory stalls and higher pressure.
Peter Zijlstra
maintainerQuoted 20 lines · Johannes Weiner
Quoted 6 lines · Peter Zijlstra
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Quoted 7 lines
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
It *could* be argued that IRQs and RT preemptions are CPU stalls.
I'm less convinced we should subtract preemptions from memory stalls.
Quoted 9 lines
Yes, when you're reclaiming and you get preempted for whatever reason, you're technically stalled on CPU in this moment. However, reclaim itself consumes CPU and walltime, and it could be what is causing those preemptions to begin with! For example, reclaim could eat up 90% of your scheduling timeslice and then cause a preemption when the thread is back in userspace and trying to be productive. By consuming time, it also drags out the overall timeline for userspace to finish its work, and a longer timeline will have more disruptions from independent events like IRQs and RT thread wakeups.
Reclaim could be running at RT priority. There is fundamentally no distinction between CFS and RT tasks. Consider priority inheritance on kernel mutexes, or an admin thinking it makes sense to chrt kswapd. Or an RT task ends up direct reclaim or...
Either they all count or they don't. There is no sane middle ground here.
Quoted 88 lines · Johannes Weiner
Quoted 59 lines · Peter Zijlstra
Quoted 11 lines · Johannes Weiner
CC peterz as well for rt and timekeeping magic
Quoted 8 lines · Huangzhaoyang
From: Zhaoyang Huang <[email protected]>
In an EAS enabled system, there are two scenarios discordant to current design,
1. workload used to be heavy uneven among cores for sake of scheduler policy. RT task usually preempts CFS task in little core.
2. CFS task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by RT, DL and Irqs.It ignores preemption full-stop. I don't see why RT/IRQ should be special cased here.
Quoted 33 lines
Quoted 24 lines
With these two constraints, the percpu nonidle time would be mainly consumed by none CFS tasks and couldn't be averaged. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq.
kernel/sched/psi.c +15
-0+static unsigned long psi_memtime_fixup (u32 growth) +{ +struct rq *rq =task_rq (current); +unsigned long growth_fixed = (unsigned long )growth; + +if (!(current->policy ==SCHED_NORMAL || current->policy ==SCHED_BATCH )) +return growth_fixed; + +if (current->in_memstall) + growth_fixed =div64_ul ((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg +1 ) * growth,1024 ); + +return growth_fixed; +} +static void init_triggers (struct psi_group *group,u64 now) {struct psi_trigger *t;kernel/sched/psi.c static void record_times(struct psi_group_cpu *groupc, u64 now) · line 678
Quoted 4 lines
kernel/sched/psi.c +1
-0@@ -658,6 +675,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) }if (groupc->state_mask & (1 <<PSI_MEM_SOME )) { + delta =psi_memtime_fixup (delta);Ok, so we want to deduct IRQ and RT preemption time from the memstall period of an active reclaimer, since it's technically not stalled on memory during this time but on CPU.
Quoted 3 lines
However, we do NOT want to deduct IRQ and RT time from memstalls that are sleeping on refaults swapins, since they are not affected by what is going on on the CPU.
I think that focus on RT/IRQ is mis-guided here, and the implementation is horrendous.
So the fundamental question seems to be; and I think Johannes is the one to answer that: What time-base do these metrics want to use?
Quoted 7 lines
Do some of these states want to account in task-time instead of wall-time perhaps? I can't quite remember, but vague memories are telling me most of the PSI accounting was about blocked tasks, not running tasks, which makes all this rather more complicated.
Randomly scaling time as proposed seems almost certainly wrong. What would that make the stats mean?
It *could* be argued that IRQs and RT preemptions are CPU stalls.
I'm less convinced we should subtract preemptions from memory stalls.
Yes, when you're reclaiming and you get preempted for whatever reason, you're technically stalled on CPU in this moment. However, reclaim itself consumes CPU and walltime, and it could be what is causing those preemptions to begin with! For example, reclaim could eat up 90% of your scheduling timeslice and then cause a preemption when the thread is back in userspace and trying to be productive. By consuming time, it also drags out the overall timeline for userspace to finish its work, and a longer timeline will have more disruptions from independent events like IRQs and RT thread wakeups.
So if you *were* to discount CPU contention from memory stalls, it would also mean that you'd have to count *memory stalls* when userspace experiences CPU contention caused by preceding reclaims. I don't think it makes sense to try to go down that road...
Quoted 4 lines
They're dependent resources. Just like faster CPUs and faster IO devices mean less memory pressure for the same amount of reclaim and paging activity, it seems logical that contention of those underlying resources will result in longer memory stalls and higher pressure.
Imagine that two triggers created on CPU and MEMORY with one RT non-memstall process consume 90% of the rq's util while a memstall CFS process get the rest of 10%. The problem is we will be misguided as both of the resources are busy under current mechanisms.