sched/fair/schedutil: Better manage system response time
Subsystems (4)
v2 cover sched/fair/schedutil: Better manage system response time
This is the long delayed follow up to the series sent back in August 2024 [1]. Life got in the way to some extent (I had a baby, and now my time that I used to do upstream work late at night was stolen :). Apologies for those who replied and I didn't get a chance to respond back.
The series is now rebased on top of tip/sched/core 78cde54ea5f0. I removed a number of optimization patches that are not necessary for this initial merge and can be treated as their own separate topics once this is hopefully accepted.
I discussed the problem in LPC in 2024 [2] and the initial cover letter contains all the details. I hope all the key parties are up-to-date on the problem details by now.
As a brief recap, there are some hardcoded constants in the kernel that introduce a bias that frequently fails to deliver the best outcome on various systems. It turns out these constant seem to help somewhat against a bigger problem in utilization signal distortion due to utilization invariance causing what I call black hole effect. The lower the capacity, the harder it is to accumulate runtime to cause the signal to rise acting like a gravitational pull causing time dilation.
One of the major difficulties we will face is that this distortion turns up bad for performance but good for power. The fix will inevitably rebalance the system, while in the right way, but also in a surprising way to potentially cause some to be unhappy. sched_features were added to ensure those unhappy folks can revert the system to the old behavior while still allow us to make the right progress.
That is to retain the older behavior one must:
echo 0 | sudo tee /proc/sys/kernel/sched_qos_default_rampup_multiplier
echo CONST_DVFS_HEADROOM NO_UTIL_EST_RAMPUP_ZERO UTIL_EST_FORCE_POST_INIT > /sys/kernel/debug/sched/features
Note for migration margin there's no sched features since I think the old behavior was worse for perf and power and doesn't require reverting back to.
The system is going to be a lot faster now by default with sched_qos_default_rampup_multiplier=1 since it fixes the distortion issue and provides a constant rise time regardless of DVFS latencies.
The desired behavior is for default rampup_multiplier to be 0 and only those interactive tasks to request a higher rampup multiplier. Preliminary integration with schedqos is available [3] for those who want to see the full benefit of fine grained control to mange perf and power.
Open questions:
* The details of the QoS interface is the biggest one.
* Would debugfs be better for setting the default rampup multiplier instead of sysctl?
* Patch 13 makes updating load_avg unconditional not on period boundaries.
Patches 1-3 are prepatory patches renaming a function and introducing new ones.
Patches 4-5 handle the magic margin problem but making them dynamic based on actual hardware limitations.
Patches 6-7 fix the black hole problem and teaches the scheduler how to handle bursty and periodic tasks via extending util_est.
Patches 8-9 is where I expect most of the discussion on as I introduce a new sched_qos interface to support the new rampup_multiplier to help manage DVFS.
Patches 10-11 introduces a couple of necessary optimizations to counter the power impact of increased responsiveness by disabling some features that we now know how to handle better.
Patches 12-13 fix a couple of issues causing util_est and util_avg value to swing for a periodic task. Patch 12 must go via stable.
My mac mini M1 system where I did the testing on before is down and it has been proven difficult to revive it before sending this series. I will revive and repeat the testing to ensure all is okay after the rebase.
I did test it on AMD system, but it has only 3 freqs so no real perf numbers to report since it just whizzes by these 3 freqs anyway. But I did spend enough time to verify the util_est behaves as expected under different scenarios. More testing would still be appreciated :)
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lpc.events/event/18/contributions/1880/
[3] https://github.com/qais-yousef/schedqos/compare/main...schedqos
Qais Yousef (13):
sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom sched/pelt: Add a new function to approximate the future util_avg
value
sched/pelt: Add a new function to approximate runtime to reach given
util
sched/fair: Remove magic hardcoded margin in fits_capacity()
sched: cpufreq: Remove magic 1.25 headroom from
sugov_apply_dvfs_headroom()
sched/fair: Extend util_est to improve rampup time sched/fair: util_est: Take into account periodic tasks sched/qos: Add a new sched-qos interface
sched/qos: Add rampup multiplier QoS
sched/fair: Disable util_est when rampup_multiplier is 0 sched/fair: Don't mess with util_avg post init sched/fair: Call update_util_est() after dequeue_entities() sched/pelt: Always allow load updates
Documentation/scheduler/index.rst | 1 + Documentation/scheduler/sched-qos.rst | 66 ++++++++++ include/linux/sched.h | 10 ++ include/linux/sched/cpufreq.h | 5 - include/uapi/linux/sched.h | 10 +- include/uapi/linux/sched/types.h | 46 +++++++ kernel/sched/core.c | 71 ++++++++++ kernel/sched/cpufreq_schedutil.c | 49 ++++++- kernel/sched/debug.c | 1 + kernel/sched/fair.c | 124 ++++++++++++++++-- kernel/sched/features.h | 21 +++ kernel/sched/pelt.c | 44 ++++++- kernel/sched/sched.h | 12 ++ kernel/sched/syscalls.c | 61 +++++++++ .../trace/beauty/include/uapi/linux/sched.h | 4 + 15 files changed, 501 insertions(+), 24 deletions(-) create mode 100644 Documentation/scheduler/sched-qos.rst
Signature · 1 line
2.34.1
PATCH v2 1/13 sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom
We are providing headroom for the utilization to grow until the next decision point to pick the next frequency. Give the function a better name and give it some documentation. It is not really mapping anything.
Also move it to cpufreq_schedutil.c. This function relies on updating util signal appropriately to give a headroom to grow. This is tied to schedutil and scheduler and not something that can be shared with other governors.
--- include/linux/sched/cpufreq.h | 5 ----- kernel/sched/cpufreq_schedutil.c | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-)
include/linux/sched/cpufreq.h +0 -5
@@ -28,11 +28,6 @@ static inline unsigned long map_util_freq(unsigned long util, {return freq * util / cap; } - -static inline unsigned long map_util_perf (unsigned long util) -{ -return util + (util >>2 ); -}#endif /* CONFIG_CPU_FREQ */ #endif /* _LINUX_SCHED_CPUFREQ_H */
kernel/sched/cpufreq_schedutil.c +19 -1
@@ -206,12 +206,30 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,return cpufreq_driver_resolve_freq (policy, freq); } +/* +* DVFS decision are made at discrete points. If CPU stays busy, the util will +* continue to grow, which means it could need to run at a higher frequency +* before the next decision point was reached. IOW, we can't follow the util as +* it grows immediately, but there's a delay before we issue a request to go to +* higher frequency. The headroom caters for this delay so the system continues +* to run at adequate performance point. +* +* This function provides enough headroom to provide adequate performance +* assuming the CPU continues to be busy. +* +* At the moment it is a constant multiplication with 1.25. +*/ +static inline unsigned long sugov_apply_dvfs_headroom (unsigned long util) +{ +return util + (util >>2 ); +} +unsigned long sugov_effective_cpu_perf (int cpu,unsigned long actual,unsigned long min,unsigned long max) {/* Add dvfs headroom to actual utilization */ - actual =map_util_perf (actual); + actual =sugov_apply_dvfs_headroom (actual);/* Actually we don't need to target the max performance */ if (actual < max) max = actual;
Signature · 1 line
2.34.1
PATCH v2 2/13 sched/pelt: Add a new function to approximate the future util_avg value
In reply to Qais YousefGiven a util_avg value, the new function will return the future one given a runtime delta.
This will be useful in later patches to help replace some magic margins with more deterministic behavior.
--- kernel/sched/pelt.c | 20 ++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 21 insertions(+)
kernel/sched/pelt.c +20 -0
@@ -488,3 +488,23 @@ bool update_other_load_avgs(struct rq *rq)update_hw_load_avg (rq_clock_task (rq), rq, hw_pressure) |update_irq_load_avg (rq,0 ); } + +/* +* Approximate the new util_avg value assuming an entity has continued to run +* for @delta us. +*/ +unsigned long approximate_util_avg (unsigned long util,u64 delta) +{ +struct sched_avg sa = { + .util_sum = util *PELT_MIN_DIVIDER , + .util_avg = util, + }; + +if (unlikely (!delta)) +return util; + +accumulate_sum (delta, &sa,1 ,0 ,1 ); +___update_load_avg (&sa,0 ); + +return sa.util_avg; +}
kernel/sched/sched.h +1 -0
@@ -3527,6 +3527,7 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual,unsigned long min, unsigned long max); +unsigned long approximate_util_avg (unsigned long util,u64 delta);/* * Verify the fitness of task @p to run on @cpu taking into account the
Signature · 1 line
2.34.1
PATCH v2 3/13 sched/pelt: Add a new function to approximate runtime to reach given util
In reply to Qais YousefIt is basically the ramp-up time from 0 to a given value. Will be used later to implement new tunable to control response time for schedutil.
--- kernel/sched/pelt.c | 21 +++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 22 insertions(+)
kernel/sched/pelt.c +21 -0
@@ -508,3 +508,24 @@ unsigned long approximate_util_avg(unsigned long util, u64 delta)return sa.util_avg; } + +/* +* Approximate the required amount of runtime in ms required to reach @util. +*/ +u64 approximate_runtime (unsigned long util) +{ +struct sched_avg sa = {}; +u64 delta =1024 ;// period = 1024 = ~1ms +u64 runtime =0 ; + +if (unlikely (!util)) +return runtime; + +while (sa.util_avg < util) { +accumulate_sum (delta, &sa,1 ,0 ,1 ); +___update_load_avg (&sa,0 ); + runtime++; + } + +return runtime; +}
kernel/sched/sched.h +1 -0
@@ -3528,6 +3528,7 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual, unsigned long max);unsigned long approximate_util_avg (unsigned long util,u64 delta); +u64 approximate_runtime (unsigned long util);/* * Verify the fitness of task @p to run on @cpu taking into account the
Signature · 1 line
2.34.1
Vincent Guittot
maintainerRe: [PATCH v2 03/13] sched/pelt: Add a new function to approximate runtime to reach given util
Quoted 15 lines · Qais Yousef
It is basically the ramp-up time from 0 to a given value. Will be used later to implement new tunable to control response time for schedutil.
Signed-off-by Qais Yousef <[email protected]>--- kernel/sched/pelt.c | 21 +++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 22 insertions(+)kernel/sched/pelt.c +0
-0
kernel/sched/pelt.c unsigned long approximate_util_avg(unsigned long util, u64 delta) · line 513
Quoted 6 lines
kernel/sched/pelt.c +3
-0@@ -508,3 +508,24 @@ unsigned long approximate_util_avg(unsigned long util, u64 delta)return sa.util_avg; } + +/* +* Approximate the required amount of runtime in ms required to reach @util.
Why ms when we use us or ns everywhere else
Quoted 33 lines
kernel/sched/pelt.c +18
-0+*/ +u64 approximate_runtime (unsigned long util) +{ +struct sched_avg sa = {}; +u64 delta =1024 ;// period = 1024 = ~1ms +u64 runtime =0 ; + +if (unlikely (!util)) +return runtime; + +while (sa.util_avg < util) { +accumulate_sum (delta, &sa,1 ,0 ,1 ); +___update_load_avg (&sa,0 ); + runtime++; + } + +return runtime; +}kernel/sched/sched.h +1
-1@@ -3528,6 +3528,7 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual, unsigned long max);unsigned long approximate_util_avg (unsigned long util,u64 delta); +u64 approximate_runtime (unsigned long util);/* * Verify the fitness of task @p to run on @cpu taking into account the -- 2.34.1
Re: [PATCH v2 03/13] sched/pelt: Add a new function to approximate runtime to reach given util
Quoted 17 lines · Vincent Guittot
Quoted 16 lines · Qais Yousef
It is basically the ramp-up time from 0 to a given value. Will be used later to implement new tunable to control response time for schedutil.
Signed-off-by Qais Yousef <[email protected]>--- kernel/sched/pelt.c | 21 +++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 22 insertions(+)kernel/sched/pelt.c +0
-0@@ -508,3 +508,24 @@ unsigned long approximate_util_avg(unsigned long util, u64 delta)
Quoted 7 lines
kernel/sched/pelt.c unsigned long approximate_util_avg(unsigned long util, u64 delta) · line 513
Quoted 5 lines
kernel/sched/pelt.c +3
-0return sa.util_avg; } + +/* +* Approximate the required amount of runtime in ms required to reach @util. Why ms when we use us or ns everywhere else
Yeah us makes sense. I think it started initially for an older user to introduce response_time_ms knob to schedutil. I'll update it in next version.
PATCH v2 4/13 sched/fair: Remove magic hardcoded margin in fits_capacity()
In reply to Qais YousefReplace hardcoded margin value in fits_capacity() with better dynamic logic.
80% margin is a magic value that has served its purpose for now, but it no longer fits the variety of systems that exist today. If a system is over powered specifically, this 80% will mean we leave a lot of capacity unused before we decide to upmigrate on HMP system.
On many systems the little cores are under powered and ability to migrate faster away from them is desired.
Redefine misfit migration to mean the utilization threshold at which the task would become misfit at the next load balance event assuming it becomes an always running task.
To calculate this threshold, we use the new approximate_util_avg() function to find out the threshold, based on arch_scale_cpu_capacity() the task will be misfit if it continues to run for a TICK_USEC which is our worst case scenario for when misfit migration will kick in.
--- kernel/sched/core.c | 1 + kernel/sched/fair.c | 40 ++++++++++++++++++++++++++++++++-------- kernel/sched/sched.h | 1 + 3 files changed, 34 insertions(+), 8 deletions(-)
kernel/sched/core.c +1 -0
@@ -8921,6 +8921,7 @@ void __init sched_init(void) rq->sd =NULL ; rq->rd =NULL ; rq->cpu_capacity =SCHED_CAPACITY_SCALE ; + rq->fits_capacity_threshold =SCHED_CAPACITY_SCALE ; rq->balance_callback = &balance_push_callback; rq->active_balance =0 ; rq->next_balance = jiffies;
kernel/sched/fair.c +32 -8
@@ -97,11 +97,15 @@ int __weak arch_asym_cpu_priority(int cpu) }/* -* The margin used when comparing utilization with CPU capacity. -* -* (default: ~20%) +* fits_capacity() must ensure that a task will not be 'stuck' on a CPU with +* lower capacity for too long. This the threshold is the util value at which +* if a task becomes always busy it could miss misfit migration load balance +* event. So we consider a task is misfit before it reaches this point. */ -#define fits_capacity (cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity (unsigned long util,int cpu) +{ +return util <cpu_rq (cpu)->fits_capacity_threshold; +}/* * The margin used when comparing CPU capacities.
@@ -5180,14 +5184,13 @@ static inline int util_fits_cpu(unsigned long util, unsigned long uclamp_max, int cpu) { -unsigned long capacity =capacity_of (cpu);unsigned long capacity_orig;bool fits, uclamp_max_fits;/* * Check if the real util fits without any uclamp boost/cap applied. */ - fits =fits_capacity (util, capacity); + fits =fits_capacity (util, cpu);if (!uclamp_is_used ())return fits;
@@ -10299,12 +10302,33 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu) {unsigned long capacity =scale_rt_capacity (cpu);struct sched_group *sdg = sd->groups; +struct rq *rq =cpu_rq (cpu); +u64 limit;if (!capacity) capacity =1 ; -cpu_rq (cpu)->cpu_capacity = capacity; -trace_sched_cpu_capacity_tp (cpu_rq (cpu)); + rq->cpu_capacity = capacity; +trace_sched_cpu_capacity_tp (rq); + +/* +* Calculate the util at which the task must be considered a misfit. +* +* We must ensure that a task experiences the same ramp-up time to +* reach max performance point of the system regardless of the CPU it +* is running on (due to invariance, time will stretch and task will +* take longer to achieve the same util value compared to a task +* running on a big CPU) and a delay in misfit migration which depends +* on TICK doesn't end up hurting it as it can happen after we would +* have crossed this threshold. +* +* To ensure that invaraince is taken into account, we don't scale time +* and use it as-is, approximate_util_avg() will then let us know the +* our threshold. +*/ + limit =approximate_runtime (arch_scale_cpu_capacity (cpu)) *USEC_PER_MSEC ; + limit -=TICK_USEC ;/* sd->balance_interval is more accurate */ + rq->fits_capacity_threshold =approximate_util_avg (0 , limit); sdg->sgc->capacity = capacity; sdg->sgc->min_capacity = capacity;
kernel/sched/sched.h +1 -0
@@ -1236,6 +1236,7 @@ struct rq {unsigned char nohz_idle_balance;unsigned char idle_balance; +unsigned long fits_capacity_threshold;unsigned long misfit_task_load;/* For active balancing */
Signature · 1 line
2.34.1
Vincent Guittot
maintainerRe: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
Quoted 9 lines · Qais Yousef
Replace hardcoded margin value in
fits_capacity()with better dynamic logic.80% margin is a magic value that has served its purpose for now, but it no longer fits the variety of systems that exist today. If a system is over powered specifically, this 80% will mean we leave a lot of capacity unused before we decide to upmigrate on HMP system.
Quoted 5 lines
On many systems the little cores are under powered and ability to migrate faster away from them is desired.
Redefine misfit migration to mean the utilization threshold at which the task would become misfit at the next load balance event assuming it
Do you mean at the next tick?
Quoted 89 lines
becomes an always running task.
To calculate this threshold, we use the new
approximate_util_avg()function to find out the threshold, based onarch_scale_cpu_capacity()the task will be misfit if it continues to run for aTICK_USECwhich is our worst case scenario for when misfit migration will kick in.Signed-off-by Qais Yousef <[email protected]>--- kernel/sched/core.c | 1 + kernel/sched/fair.c | 40 ++++++++++++++++++++++++++++++++-------- kernel/sched/sched.h | 1 + 3 files changed, 34 insertions(+), 8 deletions(-)kernel/sched/core.c +1
-0@@ -8921,6 +8921,7 @@ void __init sched_init(void) rq->sd =NULL ; rq->rd =NULL ; rq->cpu_capacity =SCHED_CAPACITY_SCALE ; + rq->fits_capacity_threshold =SCHED_CAPACITY_SCALE ; rq->balance_callback = &balance_push_callback; rq->active_balance =0 ; rq->next_balance = jiffies;kernel/sched/fair.c +22
-8@@ -97,11 +97,15 @@ int __weak arch_asym_cpu_priority(int cpu) }/* -* The margin used when comparing utilization with CPU capacity. -* -* (default: ~20%) +* fits_capacity() must ensure that a task will not be 'stuck' on a CPU with +* lower capacity for too long. This the threshold is the util value at which +* if a task becomes always busy it could miss misfit migration load balance +* event. So we consider a task is misfit before it reaches this point. */ -#define fits_capacity (cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity (unsigned long util,int cpu) +{ +return util <cpu_rq (cpu)->fits_capacity_threshold; +}/* * The margin used when comparing CPU capacities. @@ -5180,14 +5184,13 @@ static inline int util_fits_cpu(unsigned long util, unsigned long uclamp_max, int cpu) { -unsigned long capacity =capacity_of (cpu);unsigned long capacity_orig;bool fits, uclamp_max_fits;/* * Check if the real util fits without any uclamp boost/cap applied. */ - fits =fits_capacity (util, capacity); + fits =fits_capacity (util, cpu);if (!uclamp_is_used ())return fits;@@ -10299,12 +10302,33 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu) {unsigned long capacity =scale_rt_capacity (cpu);struct sched_group *sdg = sd->groups; +struct rq *rq =cpu_rq (cpu); +u64 limit;if (!capacity) capacity =1 ; -cpu_rq (cpu)->cpu_capacity = capacity; -trace_sched_cpu_capacity_tp (cpu_rq (cpu)); + rq->cpu_capacity = capacity; +trace_sched_cpu_capacity_tp (rq); + +/* +* Calculate the util at which the task must be considered a misfit. +* +* We must ensure that a task experiences the same ramp-up time to +* reach max performance point of the system regardless of the CPU it +* is running on (due to invariance, time will stretch and task will +* take longer to achieve the same util value compared to a task +* running on a big CPU) and a delay in misfit migration which depends
kernel/sched/fair.c static void update_cpu_capacity(struct sched_domain *sd, int cpu) · line 10331
Quoted 10 lines
kernel/sched/fair.c +10
-0+* on TICK doesn't end up hurting it as it can happen after we would +* have crossed this threshold. +* +* To ensure that invaraince is taken into account, we don't scale time +* and use it as-is, approximate_util_avg() will then let us know the +* our threshold. +*/ + limit =approximate_runtime (arch_scale_cpu_capacity (cpu)) *USEC_PER_MSEC ; + limit -=TICK_USEC ;/* sd->balance_interval is more accurate */ + rq->fits_capacity_threshold =approximate_util_avg (0 , limit);
update_cpu_capacity() is called in build_sched_domain() and also during periodic load balancing, but fits_capacity_threshold is fixed and should be set once
I'm not sure to get what you want to do here. Do you want to get a tick margin at max compute capacity compared to arch_scale_cpu_capacity() ?
On the big core (1024), this means a threshold of 1023 which sounds reasonable. On the little core (280), this means a threshold of 268 (1ms tick). However, reaching 268 at max freq on the little core requires 41ms, whereas the task will be at 602 after 41ms running on the big core
Quoted 18 lines
kernel/sched/fair.c +0
-0sdg->sgc->capacity = capacity; sdg->sgc->min_capacity = capacity;kernel/sched/sched.h +1
-1@@ -1236,6 +1236,7 @@ struct rq {unsigned char nohz_idle_balance;unsigned char idle_balance; +unsigned long fits_capacity_threshold;unsigned long misfit_task_load;/* For active balancing */ --2.34.1
Re: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
Quoted 10 lines · Vincent Guittot
Quoted 9 lines · Qais Yousef
Replace hardcoded margin value in
fits_capacity()with better dynamic logic.80% margin is a magic value that has served its purpose for now, but it no longer fits the variety of systems that exist today. If a system is over powered specifically, this 80% will mean we leave a lot of capacity unused before we decide to upmigrate on HMP system.
Quoted 7 lines
Quoted 5 lines
On many systems the little cores are under powered and ability to migrate faster away from them is desired.
Redefine misfit migration to mean the utilization threshold at which the task would become misfit at the next load balance event assuming it
Do you mean at the next tick?
Yes. But the way currently load balancer works it could take several ticks to trigger, but implementation wise we assume next tick. I'll update the wording. Hopefully with your push lb it will always trigger on next tick worst case scenario.
Quoted 105 lines
Quoted 90 lines
becomes an always running task.
To calculate this threshold, we use the new
approximate_util_avg()function to find out the threshold, based onarch_scale_cpu_capacity()the task will be misfit if it continues to run for aTICK_USECwhich is our worst case scenario for when misfit migration will kick in.Signed-off-by Qais Yousef <[email protected]>--- kernel/sched/core.c | 1 + kernel/sched/fair.c | 40 ++++++++++++++++++++++++++++++++-------- kernel/sched/sched.h | 1 + 3 files changed, 34 insertions(+), 8 deletions(-)kernel/sched/core.c +1
-0@@ -8921,6 +8921,7 @@ void __init sched_init(void) rq->sd =NULL ; rq->rd =NULL ; rq->cpu_capacity =SCHED_CAPACITY_SCALE ; + rq->fits_capacity_threshold =SCHED_CAPACITY_SCALE ; rq->balance_callback = &balance_push_callback; rq->active_balance =0 ; rq->next_balance = jiffies;kernel/sched/fair.c +22
-8@@ -97,11 +97,15 @@ int __weak arch_asym_cpu_priority(int cpu) }/* -* The margin used when comparing utilization with CPU capacity. -* -* (default: ~20%) +* fits_capacity() must ensure that a task will not be 'stuck' on a CPU with +* lower capacity for too long. This the threshold is the util value at which +* if a task becomes always busy it could miss misfit migration load balance +* event. So we consider a task is misfit before it reaches this point. */ -#define fits_capacity (cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity (unsigned long util,int cpu) +{ +return util <cpu_rq (cpu)->fits_capacity_threshold; +}/* * The margin used when comparing CPU capacities. @@ -5180,14 +5184,13 @@ static inline int util_fits_cpu(unsigned long util, unsigned long uclamp_max, int cpu) { -unsigned long capacity =capacity_of (cpu);unsigned long capacity_orig;bool fits, uclamp_max_fits;/* * Check if the real util fits without any uclamp boost/cap applied. */ - fits =fits_capacity (util, capacity); + fits =fits_capacity (util, cpu);if (!uclamp_is_used ())return fits;@@ -10299,12 +10302,33 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu) {unsigned long capacity =scale_rt_capacity (cpu);struct sched_group *sdg = sd->groups; +struct rq *rq =cpu_rq (cpu); +u64 limit;if (!capacity) capacity =1 ; -cpu_rq (cpu)->cpu_capacity = capacity; -trace_sched_cpu_capacity_tp (cpu_rq (cpu)); + rq->cpu_capacity = capacity; +trace_sched_cpu_capacity_tp (rq); + +/* +* Calculate the util at which the task must be considered a misfit. +* +* We must ensure that a task experiences the same ramp-up time to +* reach max performance point of the system regardless of the CPU it +* is running on (due to invariance, time will stretch and task will +* take longer to achieve the same util value compared to a task +* running on a big CPU) and a delay in misfit migration which depends kernel/sched/fair.c static void update_cpu_capacity(struct sched_domain *sd, int cpu) · line 10331
Quoted 10 lines
kernel/sched/fair.c +10
-0+* on TICK doesn't end up hurting it as it can happen after we would +* have crossed this threshold. +* +* To ensure that invaraince is taken into account, we don't scale time +* and use it as-is, approximate_util_avg() will then let us know the +* our threshold. +*/ + limit =approximate_runtime (arch_scale_cpu_capacity (cpu)) *USEC_PER_MSEC ; + limit -=TICK_USEC ;/* sd->balance_interval is more accurate */ + rq->fits_capacity_threshold =approximate_util_avg (0 , limit);
update_cpu_capacity()is called inbuild_sched_domain()and also during periodic load balancing, butfits_capacity_thresholdis fixed and should be set once
Quoted 3 lines
I'm not sure to get what you want to do here. Do you want to get a tick margin at max compute capacity compared to
arch_scale_cpu_capacity()?
Yes. If a task continues to run how will the util signal grow by the time the next tick arrives, if we are going to cross the capacity, then it is misfit now. This will automatically adjust the value to be low for little cores and high for bigger cores. IOW smaller cores need higher margin and bigger cores need smaller margin.
Quoted 5 lines
On the big core (1024), this means a threshold of 1023 which sounds reasonable. On the little core (280), this means a threshold of 268 (1ms tick). However, reaching 268 at max freq on the little core requires 41ms, whereas the task will be at 602 after 41ms running on the big core
I think you're talking about the invariance problem (black hole effect that distorts util at lower capacities/freqs). Yes this is a problem, but the new approximate function don't take invariance into account. And with util_est fixes using rampup multiplier of 1 we will always rise at a constant rate as if we are running at biggest core/max freq. So I'd expect util_est to rise to 602 after 41ms regardless if we are on little or big core - which is the major problem the rest of the series fix. From what I've seen the little cores capacity can be hit within ~13ms if util rises normally. Which is a true reflection of how slow they are. And the major problem folks encounter of tasks stuck on little core for many 10s of ms.
Even when the rampup multiplier is 0, the values are still correct. It is true they will take longer to reach this threshold, and arguably will need more than 1 tick to hit the capacity once reached it, but two things to keep in mind:
1. This current slow rise behavior is good for power, and we want to retain this behavior for them.
2. If we more accurately represent the threshold to counter for distortion, the tasks will get double hit, the slow rise time AND the higher threshold, which is genuinely a problem today with the 80% threshold for example. So while it is not accurate when rampup multiplier is 0, but I do believe it is correct as tasks are already getting a perf hit to rise to this value slower than they should (due to invariance impact), and from experience this is a high enough of a penalty already even for those tasks that are not important. We don't want to grind them to a halt. That said we can work in the future to create two thresholds, but I don't see the point at this stage and not keen on the additional complexity in general.
Quoted 22 lines
Quoted 22 lines
kernel/sched/fair.c +0
-0sdg->sgc->capacity = capacity; sdg->sgc->min_capacity = capacity;kernel/sched/sched.h +1
-1@@ -1236,6 +1236,7 @@ struct rq {unsigned char nohz_idle_balance;unsigned char idle_balance; +unsigned long fits_capacity_threshold;unsigned long misfit_task_load;/* For active balancing */ --2.34.1
Re: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
In reply to Qais YousefReview
Quoted 5 lines · Qais Yousef
(quoted diff) +4
-1-#define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity(unsigned long util, int cpu) +{ + return util < cpu_rq(cpu)->fits_capacity_threshold; +}
This does not hold on current tip anymore: fits_capacity() has picked up a second caller that does not pass a capacity, and the new signature accepts it silently.
kernel/sched/fair.c, invalid_llc_nr():
return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads), (scale * per_cpu(sd_llc_size, cpu)));
The second argument is a scaled count of the CPUs in an LLC. sd_llc_size is a per-CPU int and scale is an int, so the product binds to the new @cpu parameter with no conversion and no warning, and the test becomes
cpu_rq(scale * per_cpu(sd_llc_size, cpu))->fits_capacity_threshold
With the defaults (CONFIG_SCHED_CACHE=y, sysctl_sched_cache_user=1, llc_aggr_tolerance=1) scale is 1, so this is cpu_rq(sd_llc_size), which is not a valid CPU id on a machine with a single LLC. invalid_llc_nr() is called from account_mm_sched(), task_cache_work() and can_migrate_llc_task().
Separating the two uses first makes 04/13 safe to apply. Something like the below, against tip/sched/urgent (3cb0243767fd, where the cache-aware fixes have just landed; sched/core still has the older mm->sc_stat form). It is a no functional change, since x * 1280 < y * 1024 is equivalent to x * 100 < y * 80. Built with CONFIG_SCHED_CACHE=y and =n, no new warnings.
I can post it as a standalone patch if you would rather not carry it in the series.
--- kernel/sched/fair.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
kernel/sched/fair.c +17 -2
@@ -1526,6 +1526,21 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)return false; } +/* +* The margin used when comparing the number of a process' active threads +* with the number of CPUs in an LLC. +* +* Mirrors the ~20% margin of fits_capacity(), but is kept separate because +* fits_capacity() describes a utilization versus CPU capacity relation, +* which this is not. +* +* (default: ~80% of the LLC's CPUs) +*/ +static inline bool fits_llc_nr (u64 nr_threads,unsigned int nr_cpus) +{ +return nr_threads *100 < (u64 )nr_cpus *80 ; +} +static bool invalid_llc_nr (struct sched_cache_group *grp,struct task_struct *p,int cpu) {
@@ -1542,8 +1557,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,if (scale ==INT_MAX )return false; -return !fits_capacity ((READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads), - (scale *per_cpu (sd_llc_size, cpu))); +return !fits_llc_nr (READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads, + scale *per_cpu (sd_llc_size, cpu)); }/*
Re: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
Quoted 28 lines · Zhan Xusheng
Review
Quoted 5 lines · Qais Yousef
(quoted diff) +4
-1-#define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity(unsigned long util, int cpu) +{ + return util < cpu_rq(cpu)->fits_capacity_threshold; +}This does not hold on current tip anymore:
fits_capacity()has picked up a second caller that does not pass a capacity, and the new signature accepts it silently.
kernel/sched/fair.c,invalid_llc_nr():return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads), (scale * per_cpu(sd_llc_size, cpu)));The second argument is a scaled count of the CPUs in an LLC.
sd_llc_sizeis a per-CPU int and scale is an int, so the product binds to the new @cpu parameter with no conversion and no warning, and the test becomescpu_rq(scale * per_cpu(sd_llc_size, cpu))->fits_capacity_thresholdWith the defaults (
CONFIG_SCHED_CACHE=y, sysctl_sched_cache_user=1, llc_aggr_tolerance=1) scale is 1, so this iscpu_rq(sd_llc_size), which is not a valid CPU id on a machine with a single LLC.invalid_llc_nr()is called fromaccount_mm_sched(),task_cache_work()andcan_migrate_llc_task().
Quoted 6 lines
Separating the two uses first makes 04/13 safe to apply. Something like the below, against tip/sched/urgent (
3cb0243767fd, where the cache-aware fixes have just landed; sched/core still has the oldermm->sc_statform). It is a no functional change, since x * 1280 < y * 1024 is equivalent to x * 100 < y * 80. Built withCONFIG_SCHED_CACHE=yand =n, no new warnings.
How about x * 5 < y * 4 ? The y * 4 is a left-shift which could be faster.
Thanks,
Chenyu
Quoted 44 lines
I can post it as a standalone patch if you would rather not carry it in the series.
--- kernel/sched/fair.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)kernel/sched/fair.c +17
-2@@ -1526,6 +1526,21 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)return false; } +/* +* The margin used when comparing the number of a process' active threads +* with the number of CPUs in an LLC. +* +* Mirrors the ~20% margin of fits_capacity(), but is kept separate because +* fits_capacity() describes a utilization versus CPU capacity relation, +* which this is not. +* +* (default: ~80% of the LLC's CPUs) +*/ +static inline bool fits_llc_nr (u64 nr_threads,unsigned int nr_cpus) +{ +return nr_threads *100 < (u64 )nr_cpus *80 ; +} +static bool invalid_llc_nr (struct sched_cache_group *grp,struct task_struct *p,int cpu) {@@ -1542,8 +1557,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,if (scale ==INT_MAX )return false; -return !fits_capacity ((READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads), - (scale *per_cpu (sd_llc_size, cpu))); +return !fits_llc_nr (READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads, + scale *per_cpu (sd_llc_size, cpu)); }/*
Re: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
Quoted 1 line · Yu C
How about x * 5 < y * 4 ? The y * 4 is a left-shift which could be faster.
Works for me, and it is the smallest pair: 1280/256 = 5 and 1024/256 = 4, so x * 5 < y * 4 is exactly the old comparison, same as x * 100 < y * 80.
Overflow is not a reason to pick either. nr_running_avg is u64, so the left side is evaluated in 64 bits whichever multiplier is used. On the right, get_sched_cache_scale() returns INT_MAX for llc_aggr_tolerance >= 100 and invalid_llc_nr() bails out on that, so scale is at most 99 and scale * sd_llc_size * 1024 stays far below INT_MAX either way.
I will use your form when I post this, which I am holding until 04/13 is queued -- before that the helper only moves an integer comparison out of the fits_capacity() macro and fixes nothing.
Thanks,
Zhan Xusheng
Re: [PATCH v2 04/13] sched/fair: Remove magic hardcoded margin in fits_capacity()
In reply to Zhan XushengQuoted 28 lines · Zhan Xusheng
Review
Quoted 5 lines · Qais Yousef
(quoted diff) +4
-1-#define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) +static inline bool fits_capacity(unsigned long util, int cpu) +{ + return util < cpu_rq(cpu)->fits_capacity_threshold; +}This does not hold on current tip anymore:
fits_capacity()has picked up a second caller that does not pass a capacity, and the new signature accepts it silently.
kernel/sched/fair.c,invalid_llc_nr():return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads), (scale * per_cpu(sd_llc_size, cpu)));The second argument is a scaled count of the CPUs in an LLC.
sd_llc_sizeis a per-CPU int and scale is an int, so the product binds to the new @cpu parameter with no conversion and no warning, and the test becomescpu_rq(scale * per_cpu(sd_llc_size, cpu))->fits_capacity_thresholdWith the defaults (
CONFIG_SCHED_CACHE=y, sysctl_sched_cache_user=1, llc_aggr_tolerance=1) scale is 1, so this iscpu_rq(sd_llc_size), which is not a valid CPU id on a machine with a single LLC.invalid_llc_nr()is called fromaccount_mm_sched(),task_cache_work()andcan_migrate_llc_task().
Quoted 8 lines
Separating the two uses first makes 04/13 safe to apply. Something like the below, against tip/sched/urgent (
3cb0243767fd, where the cache-aware fixes have just landed; sched/core still has the oldermm->sc_statform). It is a no functional change, since x * 1280 < y * 1024 is equivalent to x * 100 < y * 80. Built withCONFIG_SCHED_CACHE=yand =n, no new warnings.I can post it as a standalone patch if you would rather not carry it in the series.
Thanks for catching this and reporting it. I am preparing an updated version and would have missed this tbh.
I'm happy for them to be split; but not happy we have a new user with magic numbers :( I am trying to remove these numbers, so seeing more added is unfortunate.
If you don't mind posting a patch to split and discuss the details that'd be great.
Thanks!
--
Qais Yousef
Quoted 42 lines
--- kernel/sched/fair.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)kernel/sched/fair.c +17
-2@@ -1526,6 +1526,21 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)return false; } +/* +* The margin used when comparing the number of a process' active threads +* with the number of CPUs in an LLC. +* +* Mirrors the ~20% margin of fits_capacity(), but is kept separate because +* fits_capacity() describes a utilization versus CPU capacity relation, +* which this is not. +* +* (default: ~80% of the LLC's CPUs) +*/ +static inline bool fits_llc_nr (u64 nr_threads,unsigned int nr_cpus) +{ +return nr_threads *100 < (u64 )nr_cpus *80 ; +} +static bool invalid_llc_nr (struct sched_cache_group *grp,struct task_struct *p,int cpu) {@@ -1542,8 +1557,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,if (scale ==INT_MAX )return false; -return !fits_capacity ((READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads), - (scale *per_cpu (sd_llc_size, cpu))); +return !fits_llc_nr (READ_ONCE (grp->nr_running_avg) * cpu_smt_num_threads, + scale *per_cpu (sd_llc_size, cpu)); }/*
PATCH v2 5/13 sched: cpufreq: Remove magic 1.25 headroom from sugov_apply_dvfs_headroom()
In reply to Qais YousefReplace 1.25 headroom in sugov_apply_dvfs_headroom() with better dynamic logic.
Instead of the magical 1.25 headroom, use the new approximate_util_avg() to provide headroom based on the dvfs_update_delay, which is the period at which the cpufreq governor will send DVFS updates to the hardware, or min(curr.se.slice, TICK_USEC) which is the max delay for util signal to change and promote a cpufreq update; whichever is higher.
Add a new percpu dvfs_update_delay that can be cheaply accessed whenever sugov_apply_dvfs_headroom() is called. We expect cpufreq governors that rely on util to drive its DVFS logic/algorithm to populate these percpu variables. schedutil is the only such governor at the moment.
The behavior of schedutil will change. Some systems will experience faster dvfs rampup (because of higher TICK or rate_limit_us), others will experience slower rampup.
The impact on performance should not be visible if not for the black hole effect of utilization invariance. A problem that will be addressed in later patches.
CONST_DVFS_HEADROOM sched_feat allows reverting back to the old behavior for easy backward compatibility.
--- kernel/sched/core.c | 1 + kernel/sched/cpufreq_schedutil.c | 39 +++++++++++++++++++++++++++----- kernel/sched/features.h | 6 +++++ kernel/sched/sched.h | 9 ++++++++ 4 files changed, 49 insertions(+), 6 deletions(-)
kernel/sched/core.c +1 -0
@@ -124,6 +124,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_exit_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_set_need_resched_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); +DEFINE_PER_CPU_READ_MOSTLY (u64, dvfs_update_delay); DEFINE_PER_CPU(struct rnd_state, sched_rnd_state);#ifdef CONFIG_SCHED_PROXY_EXEC
kernel/sched/cpufreq_schedutil.c +33 -6
@@ -215,13 +215,31 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,* to run at adequate performance point. * * This function provides enough headroom to provide adequate performance -* assuming the CPU continues to be busy. +* assuming the CPU continues to be busy. This headroom is based on the +* dvfs_update_delay of the cpufreq governor or min(curr.se.slice, TICK_US), +* whichever is higher. * -* At the moment it is a constant multiplication with 1.25. +* XXX: Should we provide headroom when the util is decaying? */ -static inline unsigned long sugov_apply_dvfs_headroom (unsigned long util) +static inline unsigned long sugov_apply_dvfs_headroom (unsigned long util,int cpu) { -return util + (util >>2 ); +struct rq *rq =cpu_rq (cpu); +u64 delay; + +if (sched_feat (CONST_DVFS_HEADROOM )) +return util + (util >>2 ); + +/* +* What is the possible worst case scenario for updating util_avg, ctx +* switch or TICK? +*/ +if (rq->cfs.h_nr_queued >1 ) + delay =min (rq->curr->se.slice/1000 ,TICK_USEC ); +else + delay =TICK_USEC ; + delay =max (delay,per_cpu (dvfs_update_delay, cpu)); + +return approximate_util_avg (util, delay); } unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual,
@@ -229,7 +247,7 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual, unsigned long max) {/* Add dvfs headroom to actual utilization */ - actual =sugov_apply_dvfs_headroom (actual); + actual =sugov_apply_dvfs_headroom (actual, cpu);/* Actually we don't need to target the max performance */ if (actual < max) max = actual;
@@ -615,15 +633,21 @@ rate_limit_us_store(struct gov_attr_set *attr_set, const char *buf, size_t countstruct sugov_tunables *tunables =to_sugov_tunables (attr_set);struct sugov_policy *sg_policy;unsigned int rate_limit_us; +int cpu;if (kstrtouint (buf,10 , &rate_limit_us))return -EINVAL ; tunables->rate_limit_us = rate_limit_us; -list_for_each_entry (sg_policy, &attr_set->policy_list, tunables_hook) +list_for_each_entry (sg_policy, &attr_set->policy_list, tunables_hook) { + sg_policy->freq_update_delay_ns = rate_limit_us *NSEC_PER_USEC ; +for_each_cpu (cpu, sg_policy->policy->cpus) +per_cpu (dvfs_update_delay, cpu) = rate_limit_us; + } +return count; }
@@ -886,6 +910,9 @@ static int sugov_start(struct cpufreq_policy *policy)memset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; + +per_cpu (dvfs_update_delay, cpu) = sg_policy->tunables->rate_limit_us; +cpufreq_add_update_util_hook (cpu, &sg_cpu->update_util, uu); }return 0 ;
kernel/sched/features.h +6 -0
@@ -129,3 +129,9 @@ SCHED_FEAT(LATENCY_WARN, false)*/ SCHED_FEAT(NI_RANDOM, true)SCHED_FEAT (NI_RATE , true) + +/* +* For backward compatibility. Use the constant 1.25 dvfs headroom in +* schedutil instead of the dynamic one. + */ +SCHED_FEAT (CONST_DVFS_HEADROOM , false)
kernel/sched/sched.h +9 -0
@@ -3531,6 +3531,15 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual,unsigned long approximate_util_avg (unsigned long util,u64 delta);u64 approximate_runtime (unsigned long util); +/* +* Any governor that relies on util signal to drive DVFS, must populate these +* percpu dvfs_update_delay variables. +* +* It should describe the rate/delay at which the governor sends DVFS freq +* update to the hardware in us. +*/ +DECLARE_PER_CPU_READ_MOSTLY (u64, dvfs_update_delay); +/* * Verify the fitness of task @p to run on @cpu taking into account the * CPU original capacity and the runtime/deadline ratio of the task.
Signature · 1 line
2.34.1
PATCH v2 6/13 sched/fair: Extend util_est to improve rampup time
In reply to Qais YousefUtilization invariance can cause big delays. When tasks are running, accumulate non-invairiant version of utilization to help tasks to settle down to their new util_avg values faster.
Keep track of delta_exec during runnable across activations to help update util_est for a long running task accurately. util_est shoudl still behave the same at enqueue/dequeue.
Before this patch the a busy task tamping up would experience the following transitions, running on M1 Mac Mini
rampup-6338 util_avg running
┌─────────────────────────────────────────────────────────────────────────┐
986.0┤ ▄▄▄▄▄▟▀▀▀▀│
│ ▗▄▄▟▀▀▀▘ │
│ ▗▄▟▀▀ │
│ ▄▟▀▀ │
739.5┤ ▄▟▀▘ │
│ ▗▄▛▘ │
│ ▗▟▀ │
493.0┤ ▗▛▀ │
│ ▗▄▛▀ │
│ ▄▟▀ │
│ ▄▛▘ │
246.5┤ ▗▟▀▘ │
│ ▄▟▀▀ │
│ ▗▄▄▛▘ │
│ ▗▄▄▄▟▀ │
0.0┤ ▗ ▗▄▄▟▀▀ │
└┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬┘
1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000───────────────── rampup-6338 util_avg running residency (ms) ────────────────── 0.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.5 15.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7.9 36.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 8.0 57.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 8.0 78.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7.9 98.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.0
117.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.0 137.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.0 156.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4.0 176.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
191.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4.0 211.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4.0 230.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
248.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
266.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
277.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
294.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.6
311.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.4
327.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
340.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
358.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
371.0 ▇▇▇▇▇▇▇▇▇ 1.0
377.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
389.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
401.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
413.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
431.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
442.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
456.0 ▇▇▇▇▇▇▇▇▇ 1.0
───────────────────────── Sum Time Running on CPU (ms) ───────────────────────── CPU0.0 ▇▇▇▇▇ 90.39
CPU4.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1156.93
6338 rampup CPU0.0 Frequency
┌──────────────────────────────────────────────────────────────────────────┐
2.06┤ ▛▀▀ │
│ ▌ │
│ ▌ │
│ ▌ │
1.70┤ ▛▀▀▘ │
│ ▌ │
│ ▌ │
1.33┤ ▗▄▄▄▌ │
│ ▐ │
│ ▐ │
│ ▐ │
0.97┤ ▗▄▄▄▟ │
│ ▐ │
│ ▐ │
│ ▐ │
0.60┤ ▗ ▗▄▄▄▄▄▄▄▄▟ │
└┬───────┬───────┬───────┬───────┬────────┬───────┬───────┬───────┬───────┬┘
1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000 6338 rampup CPU4.0 Frequency
┌──────────────────────────────────────────────────────────────────────────┐
3.20┤ ▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│
│ ▐ │
│ ▛▀▀ │
│ ▌ │
2.78┤ ▐▀▀▘ │
│ ▗▄▟ │
│ ▌ │
2.35┤ ▗▄▄▌ │
│ ▐ │
│ ▄▄▟ │
│ ▌ │
1.93┤ ▗▄▄▌ │
│ ▐ │
│ ▐ │
│ ▐ │
1.50┤ ▗▄▄▟ │
└┬───────┬───────┬───────┬───────┬────────┬───────┬───────┬───────┬───────┬┘
1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000───────────────── 6338 rampup CPU0.0 Frequency residency (ms) ────────────────── 0.6 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 37.300000000000004
0.972 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 15.0
1.332 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 15.0
1.704 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 11.0
2.064 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 12.1
───────────────── 6338 rampup CPU4.0 Frequency residency (ms) ────────────────── 1.5 ▇▇▇▇▇▇▇▇▇▇ 11.9
1.956 ▇▇▇▇▇▇▇▇ 10.0
2.184 ▇▇▇▇▇▇▇▇ 10.0
2.388 ▇▇▇▇▇▇▇▇▇ 11.0
2.592 ▇▇▇▇▇▇▇▇ 10.0
2.772 ▇▇▇▇▇▇▇▇ 10.0
2.988 ▇▇▇▇▇▇▇▇ 10.0
3.204 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 85.3
After the patch the response is improved to rampup frequencies faster and migrate from little quicker
rampup-2234 util_avg running
┌───────────────────────────────────────────────────────────────────────────┐ 984┤ ▗▄▄▄▄▄▛▀▀▀▀│ │ ▄▄▟▀▀▀▀ │ │ ▄▄▟▀▀ │ │ ▄▟▀▘ │ 738┤ ▄▟▀▘ │ │ ▗▟▀▘ │ │ ▗▟▀ │ 492┤ ▗▟▀ │ │ ▗▟▀ │ │ ▟▀ │ │ ▄▛▘ │ 246┤ ▗▟▘ │ │ ▗▟▀ │ │ ▗▟▀ │ │ ▗▟▀ │ 0┤ ▄▄▄▛▀ │ └┬───────┬───────┬────────┬───────┬───────┬───────┬────────┬───────┬───────┬┘ 1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000
───────────────── rampup-2234 util_avg running residency (ms) ────────────────── 0.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.6000000000000005 15.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 8.0 39.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.0 61.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4.0 85.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0 99.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
120.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.0
144.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
160.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
176.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
192.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
210.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
228.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
246.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
263.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
282.0 ▇▇▇▇▇▇▇ 1.0
291.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
309.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
327.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
344.0 ▇▇▇▇▇▇▇ 1.0
354.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
373.0 ▇▇▇▇▇▇▇ 1.0
382.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
400.0 ▇▇▇▇▇▇▇ 1.0
408.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
425.0 ▇▇▇▇▇▇▇ 1.0
434.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2.0
452.0 ▇▇▇▇▇▇▇ 1.0
2234 rampup CPU1.0 Frequency
┌──────────────────────────────────────────────────────────────────────────┐
2.06┤ ▐▀ │
│ ▐ │
│ ▐ │
│ ▐ │
1.70┤ ▛▀ │
│ ▌ │
│ ▌ │
1.33┤ ▄▌ │
│ ▌ │
│ ▌ │
│ ▌ │
0.97┤ ▗▄▌ │
│ ▐ │
│ ▐ │
│ ▐ │
0.60┤ ▗▄▄▟ │
└┬───────┬───────┬───────┬───────┬────────┬───────┬───────┬───────┬───────┬┘
1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000 2234 rampup CPU4.0 Frequency
┌──────────────────────────────────────────────────────────────────────────┐
3.10┤ ▐▀▀▀▀▀▀▀▀▀▀▀▀▀│
│ ▛▀▀▀▀▀▀▀▀▀▀▀ │
│ ▌ │
│ ▐▀▀▀▀▘ │
2.70┤ ▐ │
│ ▐▀▀▀▀ │
│ ▐ │
2.30┤ ▛▀▀ │
│ ▌ │
│ ▐▀▀▘ │
│ ▐ │
1.90┤ ▐▀▀ │
│ ▐ │
│ ▗▄▟ │
│ ▐ │
1.50┤ ▗▟ │
└┬───────┬───────┬───────┬───────┬────────┬───────┬───────┬───────┬───────┬┘
1.700 1.733 1.767 1.800 1.833 1.867 1.900 1.933 1.967 2.000───────────────────────── Sum Time Running on CPU (ms) ───────────────────────── CPU1.0 ▇▇▇▇ 32.53
CPU4.0 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 540.3
───────────────── 2234 rampup CPU1.0 Frequency residency (ms) ────────────────── 0.6 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 12.1
0.972 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 6.5
1.332 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3.7
1.704 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5.5
2.064 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4.8
───────────────── 2234 rampup CPU4.0 Frequency residency (ms) ────────────────── 1.5 ▇▇▇▇▇ 4.0
1.728 ▇▇▇▇▇▇▇▇▇▇ 8.0
1.956 ▇▇▇▇▇▇▇▇▇▇▇▇ 9.0
2.184 ▇▇▇▇▇▇▇▇▇▇▇▇ 9.0
2.388 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 11.0
2.592 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 16.0
2.772 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 18.0
2.988 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 47.0 3.096 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 53.4
--- include/linux/sched.h | 1 + kernel/sched/core.c | 1 + kernel/sched/fair.c | 41 ++++++++++++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 7 deletions(-)
include/linux/sched.h +1 -0
@@ -589,6 +589,7 @@ struct sched_entity {/* hole */ u64 exec_start; +u64 delta_exec;u64 sum_exec_runtime;u64 prev_sum_exec_runtime;u64 vruntime;
kernel/sched/core.c +1 -0
@@ -4391,6 +4391,7 @@ static void __sched_fork(u64 clone_flags, struct task_struct *p) p->se.on_rq =0 ; p->se.exec_start =0 ; + p->se.delta_exec =0 ; p->se.sum_exec_runtime =0 ; p->se.prev_sum_exec_runtime =0 ; p->se.nr_migrations =0 ;
kernel/sched/fair.c +34 -7
80 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 7/13 sched/fair: util_est: Take into account periodic tasks
In reply to Qais YousefThe new faster rampup is great for performance. But terrible for power. We want the faster rampup to be only applied for tasks that are transitioning from one periodic/steady state to another periodic/steady state. But if they are stably periodic, then the faster rampup doesn't make sense as util_avg describes their computational demand accurately and we can rely on that to make accurate decision. And preserve the power savings from being exact with the resources we give to this task (ie: smaller DVFS headroom).
We detect periodic tasks based on util_avg across util_est_update() calls. If it is rising, then the task is going through a transition.
We rely on util_avg being stable for periodic tasks with very little variations around one stable point.
--- include/linux/sched.h | 2 ++ kernel/sched/core.c | 2 ++ kernel/sched/fair.c | 35 ++++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 11 deletions(-)
include/linux/sched.h +2 -0
@@ -907,6 +907,8 @@ struct task_struct {struct uclamp_se uclamp[UCLAMP_CNT ];#endif +unsigned long util_avg_dequeued; +struct sched_statistics stats;#ifdef CONFIG_PREEMPT_NOTIFIERS
kernel/sched/core.c +2 -0
@@ -4409,6 +4409,8 @@ static void __sched_fork(u64 clone_flags, struct task_struct *p)#endif #endif + p->util_avg_dequeued =0 ; +#ifdef CONFIG_SCHEDSTATS /* Even if schedstat is disabled, there should not be garbage */ memset (&p->stats,0 ,sizeof (p->stats));
kernel/sched/fair.c +24 -11
@@ -5041,6 +5041,11 @@ static inline unsigned long task_util(struct task_struct *p)return READ_ONCE (p->se.avg.util_avg); } +static inline unsigned long task_util_dequeued (struct task_struct *p) +{ +return READ_ONCE (p->util_avg_dequeued); +} +static inline unsigned long task_runnable (struct task_struct *p) {return READ_ONCE (p->se.avg.runnable_avg);
@@ -5108,18 +5113,22 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,* quickly to settle down to our new util_avg. */ if (!task_sleep) { -u64 delta = p->se.delta_exec; -unsigned int prev_ewma = ewma & ~UTIL_AVG_UNCHANGED ; +if (task_util (p) >task_util_dequeued (p) && +task_util (p) -task_util_dequeued (p) >UTIL_EST_MARGIN ) { +u64 delta = p->se.delta_exec; +unsigned int prev_ewma = ewma & ~UTIL_AVG_UNCHANGED ; -do_div (delta,1000 ); - ewma =approximate_util_avg (prev_ewma, delta); -/* -* Keep accumulating delta_exec if it is too small to cause -* a change. -*/ -if (ewma != prev_ewma) - p->se.delta_exec =0 ; - goto done; +do_div (delta,1000 ); + ewma =approximate_util_avg (prev_ewma, delta); +/* +* Keep accumulating delta_exec if it is too small to cause +* a change. +*/ +if (ewma != prev_ewma) + p->se.delta_exec =0 ; + goto done_running; + } +return ; }else { p->se.delta_exec =0 ; }
@@ -5134,6 +5143,9 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,/* Get utilization at dequeue */ dequeued =task_util (p); +if (!task_on_rq_migrating (p)) + p->util_avg_dequeued = dequeued; +/* * Reset EWMA on utilization increases, the moving average is used only * to smooth utilization decreases.
@@ -5180,6 +5192,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq, ewma >>=UTIL_EST_WEIGHT_SHIFT ; done: ewma |=UTIL_AVG_UNCHANGED ; +done_running:WRITE_ONCE (p->se.avg.util_est, ewma);trace_sched_util_est_se_tp (&p->se);
Signature · 1 line
2.34.1
RFC PATCH v2 8/13 sched/qos: Add a new sched-qos interface
In reply to Qais YousefProvide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing sched_attr.
The interface is broken into three parts:
* Type
* Value
* Cookie
Type is an enum that should be give us enough space to extend (and deprecate) comfortably.
Value is a signed 64bit number to allow for arbitrary high values.
Cookie is to help group tasks selectively so that some QoS might want to operate on tasks per groups. A value of 0 indicates system wide.
There are two anticipated users being discussed on the list.
1. Per task rampup multiplier to allow controlling how fast util rises, and by implication it can migrate between cores on HMP systems and cause freqs to rise with schedutil.
2. Tag a group of task that are memory dependent for Cache Aware Scheduling.
The interface is anticipated to be provisioned to apps via utilities and libraries. schedqos [1] is an example how such interface can be used to provide higher level QoS abstraction to describe workloads without baking it into the binaries, and by implication without worrying about potential abuse. The interface requires privileged access since QoS is considered scarce resource and requires admin control to ensure it is set properly. Again that admin control is anticipated to be the schedqos utility service.
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
A reasonable point of debate is whether to make the sched_qos an array of 3 or 5 value to avoid potential bottleneck if this grows large and users do end up hitting a bottleneck of having to issue too many syscalls to set all QoS. Being limited as it is now helps enforce intentionality and scarcity of tagging.
[1] https://github.com/qais-yousef/schedqos
--- Documentation/scheduler/index.rst | 1 + Documentation/scheduler/sched-qos.rst | 44 ++++++++++++++++++ include/uapi/linux/sched.h | 4 ++ include/uapi/linux/sched/types.h | 46 +++++++++++++++++++ kernel/sched/syscalls.c | 10 ++++ .../trace/beauty/include/uapi/linux/sched.h | 4 ++ 6 files changed, 109 insertions(+) create mode 100644 Documentation/scheduler/sched-qos.rst
Documentation/scheduler/index.rst +1 -0
@@ -23,5 +23,6 @@ Scheduler sched-stats sched-ext sched-debug + sched-qos text_files
Documentation/scheduler/sched-qos.rst new file +44 -0
44 lines not on this page · raw message
include/uapi/linux/sched.h +4 -0
@@ -102,6 +102,9 @@ struct clone_args {__aligned_u64 set_tid_size; __aligned_u64 cgroup; }; + +enum sched_qos_type { +};#endif #define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */
@@ -133,6 +136,7 @@ struct clone_args {#define SCHED_FLAG_KEEP_PARAMS 0x10#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_QOS 0x80#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS)
include/uapi/linux/sched/types.h +46 -0
58 lines not on this page · raw message
kernel/sched/syscalls.c +10 -0
@@ -481,6 +481,13 @@ static int user_check_sched_setscheduler(struct task_struct *p,if (p->sched_reset_on_fork && !reset_on_fork) goto req_priv; +/* +* Normal users can't set QoS on their own, must go via admin +* controlled service +*/ +if (attr->sched_flags &SCHED_FLAG_QOS ) + goto req_priv; +return 0 ; req_priv:
@@ -552,6 +559,9 @@ int __sched_setscheduler(struct task_struct *p,return retval; } +if (attr->sched_flags &SCHED_FLAG_QOS ) +return -EOPNOTSUPP ; +/* * SCHED_DEADLINE bandwidth accounting relies on stable cpusets * information.
tools/perf/trace/beauty/include/uapi/linux/sched.h +4 -0
@@ -102,6 +102,9 @@ struct clone_args {__aligned_u64 set_tid_size; __aligned_u64 cgroup; }; + +enum sched_qos_type { +};#endif #define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */
@@ -133,6 +136,7 @@ struct clone_args {#define SCHED_FLAG_KEEP_PARAMS 0x10#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_QOS 0x80#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS)
Signature · 1 line
2.34.1
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 89 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* CookieType is an enum that should be give us enough space to extend (and deprecate) comfortably.
Value is a signed 64bit number to allow for arbitrary high values.
Cookie is to help group tasks selectively so that some QoS might want to operate on tasks per groups. A value of 0 indicates system wide.
There are two anticipated users being discussed on the list.
1. Per task rampup multiplier to allow controlling how fast util rises, and by implication it can migrate between cores on HMP systems and cause freqs to rise with schedutil.
2. Tag a group of task that are memory dependent for Cache Aware Scheduling.
The interface is anticipated to be provisioned to apps via utilities and libraries. schedqos [1] is an example how such interface can be used to provide higher level QoS abstraction to describe workloads without baking it into the binaries, and by implication without worrying about potential abuse. The interface requires privileged access since QoS is considered scarce resource and requires admin control to ensure it is set properly. Again that admin control is anticipated to be the schedqos utility service.
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
A reasonable point of debate is whether to make the
sched_qosan array of 3 or 5 value to avoid potential bottleneck if this grows large and users do end up hitting a bottleneck of having to issue too many syscalls to set all QoS. Being limited as it is now helps enforce intentionality and scarcity of tagging.[1] https://github.com/qais-yousef/schedqos
Signed-off-by Qais Yousef <[email protected]>--- Documentation/scheduler/index.rst | 1 + Documentation/scheduler/sched-qos.rst | 44 ++++++++++++++++++ include/uapi/linux/sched.h | 4 ++ include/uapi/linux/sched/types.h | 46 +++++++++++++++++++ kernel/sched/syscalls.c | 10 ++++ .../trace/beauty/include/uapi/linux/sched.h | 4 ++ 6 files changed, 109 insertions(+) create mode 100644 Documentation/scheduler/sched-qos.rstDocumentation/scheduler/index.rst +1
-0@@ -23,5 +23,6 @@ Scheduler sched-stats sched-ext sched-debug + sched-qos text_filesDocumentation/scheduler/sched-qos.rst new file +13
-0@@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +Scheduler QoS +============= + +1. Introduction +=============== + +Different workloads have different scheduling requirements to operate +optimally. The same applies to tasks within the same workload. + +To enable smarter usage of system resources and to cater for the conflicting
Documentation/scheduler/sched-qos.rst line 23
Quoted 10 lines
Documentation/scheduler/sched-qos.rst new file +10
-0+demands of various tasks, Scheduler QoS provides a mechanism to provide more +information about those demands so that scheduler can do best-effort to +honour them. + + @sched_qos_type what QoS hint to apply + @sched_qos_value value of the QoS hint + @sched_qos_cookie magic cookie to tag a group of tasks for which the QoS + applies. If 0, the hint will apply globally system + wide. If not 0, the hint will be relative to tasks that + has the same cookie value only.
Qais,
Thanks for your proposal. I have some follow up thoughts.
How can we query all the tasks that use a cookie?
A scenario I can think of is there may be two group of tasks, and we may want to merge the two group of tasks into one when they start sharing data in the context of cache aware scheduling. In that case, we need to get all the tasks under the second cookie and change them to that of the first. We may need to link together tasks sharing a cookie.
We probably need a sched_qos_cookie structure defined analogous to
the sched_core_cookie to anchor the tasks. And sched_qos_cookie could be a ptr value to sched_qos_cookie, as in sched_core_cookie instead of it being a __u32 as in the patch below.
Tim
Quoted 157 lines
Documentation/scheduler/sched-qos.rst new file +21
-0+ +QoS hints are set once and not inherited by children by design. The +rationale is that each task has its individual characteristics and it is +encouraged to describe each of these separately. Also since system resources +are finite, there's a limit to what can be done to honour these requests +before reaching a tipping point where there are too many requests for +a particular QoS that is impossible to service for all of them at once and +some will start to lose out. For example if 10 tasks require better wake +up latencies on a 4 CPUs SMP system, then if they all wake up at once, only +4 can perceive the hint honoured and the rest will have to wait. Inheritance +can lead these 10 to become a 100 or a 1000 more easily, and then the QoS +hint will lose its meaning and effectiveness rapidly. The chances of 10 +tasks waking up at the same time is lower than a 100 and lower than a 1000. + +To set multiple QoS hints, a syscall is required for each. This is a +trade-off to reduce the churn on extending the interface as the hope for +this to evolve as workloads and hardware get more sophisticated and the +need for extension will arise; and when this happen the task should be +simpler to add the kernel extension and allow userspace to use readily by +setting the newly added flag without having to update the whole of +sched_attr.include/uapi/linux/sched.h +4
-0@@ -102,6 +102,9 @@ struct clone_args {__aligned_u64 set_tid_size; __aligned_u64 cgroup; }; + +enum sched_qos_type { +};#endif #define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */ @@ -133,6 +136,7 @@ struct clone_args {#define SCHED_FLAG_KEEP_PARAMS 0x10#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_QOS 0x80#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS)include/uapi/linux/sched/types.h +46
-0@@ -94,6 +94,48 @@* scheduled on a CPU with no more capacity than the specified value. * * A task utilization boundary can be reset by setting the attribute to -1. +* +* Scheduler QoS +* ============= +* +* Different workloads have different scheduling requirements to operate +* optimally. The same applies to tasks within the same workload. +* +* To enable smarter usage of system resources and to cater for the conflicting +* demands of various tasks, Scheduler QoS provides a mechanism to provide more +* information about those demands so that scheduler can do best-effort to +* honour them. +* +* @sched_qos_type what QoS hint to apply +* @sched_qos_value value of the QoS hint +* @sched_qos_cookie magic cookie to tag a group of tasks for which the QoS +* applies. If 0, the hint will apply globally system +* wide. If not 0, the hint will be relative to tasks that +* has the same cookie value only. +* +* QoS hints are set once and not inherited by children by design. The +* rationale is that each task has its individual characteristics and it is +* encouraged to describe each of these separately. Also since system resources +* are finite, there's a limit to what can be done to honour these requests +* before reaching a tipping point where there are too many requests for +* a particular QoS that is impossible to service for all of them at once and +* some will start to lose out. For example if 10 tasks require better wake +* up latencies on a 4 CPUs SMP system, then if they all wake up at once, only +* 4 can perceive the hint honoured and the rest will have to wait. Inheritance +* can lead these 10 to become a 100 or a 1000 more easily, and then the QoS +* hint will lose its meaning and effectiveness rapidly. The chances of 10 +* tasks waking up at the same time is lower than a 100 and lower than a 1000. +* +* To set multiple QoS hints, a syscall is required for each. This is a +* trade-off to reduce the churn on extending the interface as the hope for +* this to evolve as workloads and hardware get more sophisticated and the +* need for extension will arise; and when this happen the task should be +* simpler to add the kernel extension and allow userspace to use readily by +* setting the newly added flag without having to update the whole of +* sched_attr. +* +* Details about the available QoS hints can be found in: +* Documentation/scheduler/sched-qos.rst */ struct sched_attr {__u32 size;@@ -116,6 +158,10 @@ struct sched_attr {__u32 sched_util_min;__u32 sched_util_max; +__u32 sched_qos_type; +__s64 sched_qos_value; + __u32 sched_qos_cookie; + };#endif /* _UAPI_LINUX_SCHED_TYPES_H */ kernel/sched/syscalls.c +10
-0@@ -481,6 +481,13 @@ static int user_check_sched_setscheduler(struct task_struct *p,if (p->sched_reset_on_fork && !reset_on_fork) goto req_priv; +/* +* Normal users can't set QoS on their own, must go via admin +* controlled service +*/ +if (attr->sched_flags &SCHED_FLAG_QOS ) + goto req_priv; +return 0 ; req_priv:@@ -552,6 +559,9 @@ int __sched_setscheduler(struct task_struct *p,return retval; } +if (attr->sched_flags &SCHED_FLAG_QOS ) +return -EOPNOTSUPP ; +/* * SCHED_DEADLINE bandwidth accounting relies on stable cpusets * information. tools/perf/trace/beauty/include/uapi/linux/sched.h +4
-0@@ -102,6 +102,9 @@ struct clone_args {__aligned_u64 set_tid_size; __aligned_u64 cgroup; }; + +enum sched_qos_type { +};#endif #define CLONE_ARGS_SIZE_VER0 64/* sizeof first published struct */ @@ -133,6 +136,7 @@ struct clone_args {#define SCHED_FLAG_KEEP_PARAMS 0x10#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_QOS 0x80#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS)
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 103 lines · Tim Chen
Quoted 89 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* CookieType is an enum that should be give us enough space to extend (and deprecate) comfortably.
Value is a signed 64bit number to allow for arbitrary high values.
Cookie is to help group tasks selectively so that some QoS might want to operate on tasks per groups. A value of 0 indicates system wide.
There are two anticipated users being discussed on the list.
1. Per task rampup multiplier to allow controlling how fast util rises, and by implication it can migrate between cores on HMP systems and cause freqs to rise with schedutil.
2. Tag a group of task that are memory dependent for Cache Aware Scheduling.
The interface is anticipated to be provisioned to apps via utilities and libraries. schedqos [1] is an example how such interface can be used to provide higher level QoS abstraction to describe workloads without baking it into the binaries, and by implication without worrying about potential abuse. The interface requires privileged access since QoS is considered scarce resource and requires admin control to ensure it is set properly. Again that admin control is anticipated to be the schedqos utility service.
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
A reasonable point of debate is whether to make the
sched_qosan array of 3 or 5 value to avoid potential bottleneck if this grows large and users do end up hitting a bottleneck of having to issue too many syscalls to set all QoS. Being limited as it is now helps enforce intentionality and scarcity of tagging.[1] https://github.com/qais-yousef/schedqos
Signed-off-by Qais Yousef <[email protected]>--- Documentation/scheduler/index.rst | 1 + Documentation/scheduler/sched-qos.rst | 44 ++++++++++++++++++ include/uapi/linux/sched.h | 4 ++ include/uapi/linux/sched/types.h | 46 +++++++++++++++++++ kernel/sched/syscalls.c | 10 ++++ .../trace/beauty/include/uapi/linux/sched.h | 4 ++ 6 files changed, 109 insertions(+) create mode 100644 Documentation/scheduler/sched-qos.rstDocumentation/scheduler/index.rst +1
-0@@ -23,5 +23,6 @@ Scheduler sched-stats sched-ext sched-debug + sched-qos text_filesDocumentation/scheduler/sched-qos.rst new file +13
-0@@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +Scheduler QoS +============= + +1. Introduction +=============== + +Different workloads have different scheduling requirements to operate +optimally. The same applies to tasks within the same workload. + +To enable smarter usage of system resources and to cater for the conflictingDocumentation/scheduler/sched-qos.rst line 23
Quoted 10 lines
Documentation/scheduler/sched-qos.rst new file +10
-0+demands of various tasks, Scheduler QoS provides a mechanism to provide more +information about those demands so that scheduler can do best-effort to +honour them. + + @sched_qos_type what QoS hint to apply + @sched_qos_value value of the QoS hint + @sched_qos_cookie magic cookie to tag a group of tasks for which the QoS + applies. If 0, the hint will apply globally system + wide. If not 0, the hint will be relative to tasks that + has the same cookie value only.Qais,
Quoted 3 lines
Thanks for your proposal. I have some follow up thoughts.
How can we query all the tasks that use a cookie?
At the moment you can use sched_getattr() to query the cookie set for a specific QOS.
We'll probably have to expose something in procfs to allow parsing all tasks that share a cookie.
Generally the idea is that this is managed by userspace and I'd expect schedqos service to already know this info as it has to set it.
Quoted 1 line
A scenario I can think of is there may be two group of tasks, and we may
To be clear, two group of tasks belonging to the same process, right?
I am still not clear on grouping tasks to different processes. Nothing in the API prevents it, but I am wary of inter-process task grouping as same application can have several instances running in the system and this is a layer of complexity that I am not sure warranted. That said, nothing in the proposal prevents us from handling this if it ends up really making sense. It'd be a matter of saying QOS_TYPE_XYZ cookie has to be system wide unique and can be used to tag tasks to different processes, unlike the default behavior which is unique per process. It's still have to be unique per sched_qos_type.
Quoted 4 lines
want to merge the two group of tasks into one when they start sharing data in the context of cache aware scheduling. In that case, we need to get all the tasks under the second cookie and change them to that of the first. We may need to link together tasks sharing a cookie.
My implementation for cookie should have been explicit to return EOPNOTSUP if spescified. And the doc text could have been clearer.
The idea is that the cookie is per QOS per process. So QOS_TYPE_A would have its unique cookie range, and QOS_TYPE_B would have its independent unique cookie range. To allow flexibility and extensibilty to describe independent behavior that requires independent grouping.
So in your example assuming the grouping is done for a single process, group_a would have QOS_DATA_DEP with cookie value of 1, and group_b would have QOS_DATA_DEP with cookie value of 2. To merge them, you'd change group_a or group_b cookie to match the other group's value.
I still haven't thought fully through how to do this with schedqos configs, but one idea
{
"process_a" {
"thread_qos" {
"task_1": [ ... ],
"task_2": [ ... ],
"task_3": [ ... ],
"task_4": [ ... ]
},
"qos_groups" {
"group_a" {
"QOS_DATA_DEP": ["task_1", "task_2"],
},
"group_b" {
"QOS_DATA_DEP": ["task_3", "task_4"],
}
}
}
}It implies of course to merge you'd have to change the description and restart the service..
If you want to merge and unmerge at runtime, then I'd have big question marks on the fact they belong to a group. From experience for this to be really beneficial you need to describe the dominant behavior even if sometimes it is untrue. Trying to be exact tends to backfire.
If we really want to do something at runtime, then group control (the planned userspace extension to exercise QOS control based on cgroup grouping) would be the way to go IMO.
Quoted 5 lines
We probably need a
sched_qos_cookiestructure defined analogous to
thesched_core_cookieto anchor the tasks. Andsched_qos_cookiecould be a ptr value tosched_qos_cookie, as insched_core_cookieinstead of it being a__u32as in the patch below.
As part of the API or internal implementation detail? I think we do need a cookie structure that stores the sched_qos_type and sched_qos_cookie tuple internally as implementation detail. But not expose it as an interface.
I think the cookie values should be userspace managed. From experience, this has to be done in a centralized way via a service otherwise you'd end up with a mess. There has to be an all knowledgeable entity managing things, which is what I am proposing in schedqos service. That's why the whole QOS now is protected with CAP_NICE capability - which I forgot to mention this change from v1.
We want the interface to be flexible and survive the test of time. I don't just want to support extensibility, but for us to be able to say we know better now and we must deprecate something in favour of a new thing that does it better. It means schedqos has to deal with some complexity to manage deprecation, but kernel side hopefully we can just delete code with ease. Hopefully there will be one or few centralized entities around.
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 2 lines · Qais Yousef
Quoted 1 line · Tim Chen
On Mon, 2026-05-04 at 02:59 +0100, Qais Yousef wrote:
[ ... ]
Quoted 5 lines
The idea is that the cookie is per QOS per process. So
QOS_TYPE_Awould have its unique cookie range, andQOS_TYPE_Bwould have its independent unique cookie range. To allow flexibility and extensibilty to describe independent behavior that requires independent grouping.
From a user point of view, I can think of the following use cases for fine-grained cache-aware scheduling:
u1. A user wants to enable or disable cache-aware scheduling for all
threads of a process. (No extra tagging is needed.)
u2. A user wants to enable or disable cache-aware scheduling for all
tasks within a cgroup. (No extra tagging is needed.) Vern from Tencent was advocating for this model.
u3. A user wants to enable or disable cache-aware scheduling for an
arbitrary set of tasks. (Userspace tagging is required.)
If I understand correctly, u3 is exactly the use case where schedqos cookie can help. Under your design, we cannot tag an arbitrary set of tasks with the same cookie; we are only allowed to assign the same cookie to threads within the same process and under the same QoS type. So this might eliminate the case where different processes share data with each other that we want to aggregate(NUMA balancing's numa_group is an indicator of tasks sharing data)
Quoted 10 lines
Quoted 5 lines
We probably need a
sched_qos_cookiestructure defined analogous to
thesched_core_cookieto anchor the tasks. Andsched_qos_cookiecould be a ptr value tosched_qos_cookie, as insched_core_cookieinstead of it being a__u32as in the patch below.As part of the API or internal implementation detail? I think we do need a cookie structure that stores the
sched_qos_typeandsched_qos_cookietuple internally as implementation detail. But not expose it as an interface.
Yes, I think Tim was referring to the internal implementation. We need a pointer to link tasks to their shared sched_qos_cookie.
Quoted 7 lines
I think the cookie values should be userspace managed. From experience, this has to be done in a centralized way via a service otherwise you'd end up with a mess. There has to be an all knowledgeable entity managing things, which is what I am proposing in schedqos service. That's why the whole QOS now is protected with
CAP_NICEcapability - which I forgot to mention this change from v1.
Not sure why we do not leverage the OS to allocate and manage cookies. The OS has full visibility of system-wide information and can maintain globally unique cookies. Users only need to request the OS to allocate, attach, or detach tasks to an existing group without supplying an explicit cookie value. One possible reason I can think of: since the schedqos cookie is defined per QoS type and per process,it may be more convenient to manage it entirely within the schedqos service?
thanks,
Chenyu
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 12 lines · Yu C
Quoted 2 lines · Qais Yousef
Quoted 1 line · Tim Chen
On Mon, 2026-05-04 at 02:59 +0100, Qais Yousef wrote:
[ ... ]
Quoted 5 lines
The idea is that the cookie is per QOS per process. So
QOS_TYPE_Awould have its unique cookie range, andQOS_TYPE_Bwould have its independent unique cookie range. To allow flexibility and extensibilty to describe independent behavior that requires independent grouping.
Quoted 6 lines
From a user point of view, I can think of the following use cases for fine-grained
cache-aware scheduling:u1. A user wants to enable or disable cache-aware scheduling for all
threads of a process. (No extra tagging is needed.)
This is a special case of u3 where you say all threads are part of one group. So tagging is required; to enable/disable you'll have to have a knob to switch that behavior but you're deferring to the kernel to group, which IMO is a problem to delegate to the kernel. More on this below.
Quoted 3 lines
u2. A user wants to enable or disable cache-aware scheduling for all
tasks within a cgroup. (No extra tagging is needed.) Vern from Tencent was advocating for this model.
Same as above. We can have a NETLINK to tell us when tasks switch group and auto tag based on that. Although I am still worried that this is not a great way to tag and should be based on process and task. But I guess we can try things out and see what works best. According to the plan this becomes a userspace (schedqos service) description problem rather than kernel implementation detail.
Quoted 8 lines
u3. A user wants to enable or disable cache-aware scheduling for an
arbitrary set of tasks. (Userspace tagging is required.)If I understand correctly, u3 is exactly the use case where schedqos cookie can help. Under your design, we cannot tag an arbitrary set of tasks with the same cookie; we are only allowed to assign the same cookie to threads within the same process and under the same QoS type. So this might eliminate the case where different processes share data
Is this a real case? I'd really love to know more details on why. I still think inter-process grouping is better done via cpuset as this tends more towards a partitioning problem.
That said nothing in the API actually prevent us from adding QOS_INTER_PROCESS_MEM_DEP tag and make the cookie global and unique. But this will come with implementation challenges and complexity. As a starter I'll make sure to catch and error on this case to not repeat latest tcmalloc mistake. If it makes sense at anytime, it'd be a matter of adding new qos for inter process support.
Quoted 25 lines
with each other that we want to
aggregate(NUMA balancing's numa_group is an indicator of tasks sharing data)Quoted 10 lines
Quoted 5 lines
We probably need a
sched_qos_cookiestructure defined analogous to
thesched_core_cookieto anchor the tasks. Andsched_qos_cookiecould be a ptr value tosched_qos_cookie, as insched_core_cookieinstead of it being a__u32as in the patch below.As part of the API or internal implementation detail? I think we do need a cookie structure that stores the
sched_qos_typeandsched_qos_cookietuple internally as implementation detail. But not expose it as an interface.Yes, I think Tim was referring to the internal implementation. We need a pointer to link tasks to their shared
sched_qos_cookie.Quoted 7 lines
I think the cookie values should be userspace managed. From experience, this has to be done in a centralized way via a service otherwise you'd end up with a mess. There has to be an all knowledgeable entity managing things, which is what I am proposing in schedqos service. That's why the whole QOS now is protected with
CAP_NICEcapability - which I forgot to mention this change from v1.
Quoted 11 lines
Not sure why we do not leverage the OS to allocate and manage cookies. The OS has full visibility of system-wide information and can maintain globally
unique cookies. Users only need to request the OS to allocate, attach, or detach
tasks to an existing group without supplying an explicit cookie value. One possible reason I can think of: since the schedqos cookie is defined per QoS
type and per process,it may be more convenient to manage it entirely within the
schedqos service?
Because for kernel to manage the cookies it means it needs to understand all the rules for grouping, corner cases and trade-offs. We lose flexibility of adding new QoS easily since for each new QoS we need to nail down all these rules and progress will never happen - or very slowly at best. AND the scheduler will have more policy embedded in it that will make it trickier to change and evolve code without breaking user space behavior since the behavior is purely embedded in kernel space.
By delegating to userspace we remove all of this. We provide the mechanisms and the trade-offs, grouping rules etc are all managed by an all knowing entity. If grouping rule A is better than grouping rule B, we don't care. Even schedqos service hopefully wouldn't care. It'd be a matter for each admin to specify the grouping that makes sense to them in a config file and restart the service and hopefully everyone will stroll away happy. That's the dream at least :)
Note users will still get an abstraction via schedqos, but this abstraction is in userspace rather than in the kernel. I anticipate users will just interact with config files to describe their cases.
And as I mentioned in LPC, we can easily add a new service to schedqos to help admins find out which tasks are memory dependent and help them fine tune their configs. Perf can do that, and writing a simple daemon that can help admins monitor/profile a live workload and spit out that grouping these tasks based on cache would be beneficial shouldn't be too hard. The process can be fully automated too to change things on the fly if folks really want to.
Peter Zijlstra
maintainerRe: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
In reply to Qais YousefQuoted 80 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* CookieType is an enum that should be give us enough space to extend (and deprecate) comfortably.
Value is a signed 64bit number to allow for arbitrary high values.
Cookie is to help group tasks selectively so that some QoS might want to operate on tasks per groups. A value of 0 indicates system wide.
There are two anticipated users being discussed on the list.
1. Per task rampup multiplier to allow controlling how fast util rises, and by implication it can migrate between cores on HMP systems and cause freqs to rise with schedutil.
2. Tag a group of task that are memory dependent for Cache Aware Scheduling.
The interface is anticipated to be provisioned to apps via utilities and libraries. schedqos [1] is an example how such interface can be used to provide higher level QoS abstraction to describe workloads without baking it into the binaries, and by implication without worrying about potential abuse. The interface requires privileged access since QoS is considered scarce resource and requires admin control to ensure it is set properly. Again that admin control is anticipated to be the schedqos utility service.
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
A reasonable point of debate is whether to make the
sched_qosan array of 3 or 5 value to avoid potential bottleneck if this grows large and users do end up hitting a bottleneck of having to issue too many syscalls to set all QoS. Being limited as it is now helps enforce intentionality and scarcity of tagging.+.. SPDX-License-Identifier: GPL-2.0
Documentation/scheduler/sched-qos.rst new file +33
-0+ +============= +Scheduler QoS +============= + +1. Introduction +=============== + +Different workloads have different scheduling requirements to operate +optimally. The same applies to tasks within the same workload. + +To enable smarter usage of system resources and to cater for the conflicting +demands of various tasks, Scheduler QoS provides a mechanism to provide more +information about those demands so that scheduler can do best-effort to +honour them. + + @sched_qos_type what QoS hint to apply + @sched_qos_value value of the QoS hint + @sched_qos_cookie magic cookie to tag a group of tasks for which the QoS + applies. If 0, the hint will apply globally system + wide. If not 0, the hint will be relative to tasks that + has the same cookie value only. + +QoS hints are set once and not inherited by children by design. The +rationale is that each task has its individual characteristics and it is +encouraged to describe each of these separately. Also since system resources +are finite, there's a limit to what can be done to honour these requests +before reaching a tipping point where there are too many requests for +a particular QoS that is impossible to service for all of them at once and +some will start to lose out. For example if 10 tasks require better wake +up latencies on a 4 CPUs SMP system, then if they all wake up at once, only +4 can perceive the hint honoured and the rest will have to wait. Inheritance +can lead these 10 to become a 100 or a 1000 more easily, and then the QoS
Documentation/scheduler/sched-qos.rst line 44
Quoted 10 lines
Documentation/scheduler/sched-qos.rst new file +10
-0+hint will lose its meaning and effectiveness rapidly. The chances of 10 +tasks waking up at the same time is lower than a 100 and lower than a 1000. + +To set multiple QoS hints, a syscall is required for each. This is a +trade-off to reduce the churn on extending the interface as the hope for +this to evolve as workloads and hardware get more sophisticated and the +need for extension will arise; and when this happen the task should be +simpler to add the kernel extension and allow userspace to use readily by +setting the newly added flag without having to update the whole of +sched_attr.
So 'type' is effectively meant to be an ephemeral space of hints. A kernel can, or can not, support this arbitrary set of hints.
If a particular type is supported across two kernels, it is assumed to be the same -- although its implementation might be different.
Your next patch implements type-0 to be this pelt multiplier thing.
I wonder about discoverability, suppose we create and discard a fair number of these types, just because. Then how is someone (this muddle-ware component for example) to discover which set of hints is supported by the kernel of the day?
I suppose it can go and scan the space, by trying to set hints on itself or something, but that seems sub-optimal.
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 86 lines · Peter Zijlstra
Quoted 85 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* CookieType is an enum that should be give us enough space to extend (and deprecate) comfortably.
Value is a signed 64bit number to allow for arbitrary high values.
Cookie is to help group tasks selectively so that some QoS might want to operate on tasks per groups. A value of 0 indicates system wide.
There are two anticipated users being discussed on the list.
1. Per task rampup multiplier to allow controlling how fast util rises, and by implication it can migrate between cores on HMP systems and cause freqs to rise with schedutil.
2. Tag a group of task that are memory dependent for Cache Aware Scheduling.
The interface is anticipated to be provisioned to apps via utilities and libraries. schedqos [1] is an example how such interface can be used to provide higher level QoS abstraction to describe workloads without baking it into the binaries, and by implication without worrying about potential abuse. The interface requires privileged access since QoS is considered scarce resource and requires admin control to ensure it is set properly. Again that admin control is anticipated to be the schedqos utility service.
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
A reasonable point of debate is whether to make the
sched_qosan array of 3 or 5 value to avoid potential bottleneck if this grows large and users do end up hitting a bottleneck of having to issue too many syscalls to set all QoS. Being limited as it is now helps enforce intentionality and scarcity of tagging.+.. SPDX-License-Identifier: GPL-2.0
Documentation/scheduler/sched-qos.rst new file +38
-0+ +============= +Scheduler QoS +============= + +1. Introduction +=============== + +Different workloads have different scheduling requirements to operate +optimally. The same applies to tasks within the same workload. + +To enable smarter usage of system resources and to cater for the conflicting +demands of various tasks, Scheduler QoS provides a mechanism to provide more +information about those demands so that scheduler can do best-effort to +honour them. + + @sched_qos_type what QoS hint to apply + @sched_qos_value value of the QoS hint + @sched_qos_cookie magic cookie to tag a group of tasks for which the QoS + applies. If 0, the hint will apply globally system + wide. If not 0, the hint will be relative to tasks that + has the same cookie value only. + +QoS hints are set once and not inherited by children by design. The +rationale is that each task has its individual characteristics and it is +encouraged to describe each of these separately. Also since system resources +are finite, there's a limit to what can be done to honour these requests +before reaching a tipping point where there are too many requests for +a particular QoS that is impossible to service for all of them at once and +some will start to lose out. For example if 10 tasks require better wake +up latencies on a 4 CPUs SMP system, then if they all wake up at once, only +4 can perceive the hint honoured and the rest will have to wait. Inheritance +can lead these 10 to become a 100 or a 1000 more easily, and then the QoS +hint will lose its meaning and effectiveness rapidly. The chances of 10 +tasks waking up at the same time is lower than a 100 and lower than a 1000. + +To set multiple QoS hints, a syscall is required for each. This is a +trade-off to reduce the churn on extending the interface as the hope for
Quoted 8 lines
Documentation/scheduler/sched-qos.rst line 44
Quoted 5 lines
Documentation/scheduler/sched-qos.rst new file +5
-0+this to evolve as workloads and hardware get more sophisticated and the +need for extension will arise; and when this happen the task should be +simpler to add the kernel extension and allow userspace to use readily by +setting the newly added flag without having to update the whole of +sched_attr.So 'type' is effectively meant to be an ephemeral space of hints. A kernel can, or can not, support this arbitrary set of hints.
Yes. A 'type' is not expected to be recycled if deprecated. It'll just return an error if no longer supported.
Quoted 3 lines
If a particular type is supported across two kernels, it is assumed to be the same -- although its implementation might be different.
Yes. If implementation details were too different that a 'type' no longer makes sense, it'd be just deprecated (return EOPNOTSUP) in favour of whatever makes sense then, if still necessary.
Will document this more explicitly.
Quoted 10 lines
Your next patch implements type-0 to be this pelt multiplier thing.
I wonder about discoverability, suppose we create and discard a fair number of these types, just because. Then how is someone (this muddle-ware component for example) to discover which set of hints is supported by the kernel of the day?
I suppose it can go and scan the space, by trying to set hints on itself or something, but that seems sub-optimal.
Yes, I think that would be best starting point. If you saw schedqos code I already have to parse procfs to discover all existing running processes/tasks after connecting to netlink socket to listen to new forks/execs (and plug the race). Inefficient, but done once at service start is simple enough and unlikely to be a real bottleneck or pain point.
Current line of thought is to keep as much in userspace until we have enough data on usage and bottlenecks to drive any kernel changes. userspace here means schedqos service.
One thing to note also, with the schedqos integration when folks need to add a new hint they can actually deploy at scale more easily. I am hoping the development process would be:
* Add new hint to address particular problem
* Integrate with schedqos to auto tag applications that can benefit from this hint
* Deploy on production or production like system to prove the benefit, trade-offs
* Discuss inclusion with upstream
IOW, I am hoping we can get more real life data on benefit for real workloads and systems outside of usual synthetic cases. I am expecting any (well, most at least) kernel hint is connected somehow to higher level of abstraction in schedqos service - expectation so far is that kernel level hint are hard for apps to use directly. More on this in reply to your next email.
Peter Zijlstra
maintainerRe: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 1 line · Qais Yousef
If you saw schedqos code
I was in fact looking for that, but found this series did not include it. Didn't get around to looking harder yet..
Quoted 3 lines
I already have to parse procfs to discover all existing running processes/tasks after connecting to netlink socket to listen to new forks/execs (and plug the race).
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 6 lines · Peter Zijlstra
Quoted 1 line · Qais Yousef
If you saw schedqos code
I was in fact looking for that, but found this series did not include it. Didn't get around to looking harder yet..
I had a link to the commit that integrates rampup multiplier [1]. The utility is in my github [2] at the moment. I am hoping, if we all agree it is the right thing to do, to move it to kernel.org and get the development on the list.
I yet to introduce how to manage cookies there FWIW. I still need to spend more time to bring it to full shape.. I plan to add support to help Tim and Chen to easily tag QOS_MEM_DEP (or whatever name we choose) tasks/processes so that can help with driving how cache aware support can be added and managed by this service. And give us more confidence in the interface and overall concept.
It'd be reassuring to know if it's moving in the right direction or not before I sink more time on it :)
[1] https://github.com/qais-yousef/schedqos/compare/main...schedqos
[2] https://github.com/qais-yousef/schedqos
Quoted 5 lines
Quoted 4 lines
I already have to parse procfs to discover all existing running processes/tasks after connecting to netlink socket to listen to new forks/execs (and plug the race).
Peter Zijlstra
maintainerRe: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
In reply to Qais YousefQuoted 3 lines · Qais Yousef
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
This is somewhat awkward. Most all state is inherited on fork. And all our tools are built around that. This is for example how I set a shorter slice on proton when launching a game (chrt -o --sched-runtime 280000 0). Tagging each individual thread that comes out of wine / random .exe is going to be painful.
Can't we have both by using something like SCHED_FLAG_RESET_ON_FORK combined with setting a hint?
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 11 lines · Peter Zijlstra
Quoted 3 lines · Qais Yousef
QoS is treated as a scarce resource and the intention is for the a syscall to be done for each individual QoS tag. QoS tags are not inherited on fork by default too for the same reason.
This is somewhat awkward. Most all state is inherited on fork. And all our tools are built around that. This is for example how I set a shorter slice on proton when launching a game (chrt -o --sched-runtime 280000 0). Tagging each individual thread that comes out of wine / random .exe is going to be painful.
Hmm. The problem is that with the benefit of a hindsight and after running different experiments, you really don't want to inherit these properties by default. I think if this tagging is not all designed, you end up with randoms.
With schedqos it is easy to tag all tasks by the way.
For example
{
"chrome": {
"qos": "QOS_INTERACTIVE"
}
}will cause all chrome tasks to be interactive by default, from /var/log/schedqos.log
[2026-05-19 11:24:36] [INFO] [qos_manager.c:262] New app instance of 505409 /snap/chromium/3258/usr/lib/chromium-browser/chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505409:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505409 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505410:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505410 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505411:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505411 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505412:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505412 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505413:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505413 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505410:505409 PerfettoTrace [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505410 PerfettoTrace [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505412:505409 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505412 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505414:505409 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505414 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505413:505409 Chrome_ChildIOT [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505413 Chrome_ChildIOT [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505411:505409 ThreadPoolServi [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505411 ThreadPoolServi [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505414:505409 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505414 ThreadPoolForeg [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505415:505409 Compositor [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505415 Compositor [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505415:505409 Compositor [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505415 Compositor [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505416:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505416 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505416:505409 ThreadPoolSingl [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505416 ThreadPoolSingl [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505417:505409 chrome [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505417 chrome [2026-05-19 11:24:36] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505417:505409 HangWatcher [2026-05-19 11:24:36] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505417 HangWatcher
This is what I call the poor/easy way to tag; but the log gives you all created tasks so you can try to use that to create smarter tagging, I found by experiment for instance that the main chrome thread is the main interactive task and while speedometer still drops a little bit, but I get really close with this simple intentional tagging
{
"chrome": {
"thread_qos": {
"chrome": "QOS_INTERACTIVE"
}
}
}
sudo schedqos restart --daemon
(no need to reboot or even restart chrome)
[2026-05-19 11:28:38] [INFO] [qos_manager.c:262] New app instance of 505345 /snap/chromium/3258/usr/lib/chromium-browser/chrome
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505345:505345 chrome
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505345 chrome
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505346:505345 PerfettoTrace
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505346 PerfettoTrace
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505348:505345 ThreadPoolServi
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505348 ThreadPoolServi
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505349:505345 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505349 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505350:505345 Chrome_ChildIOT
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505350 Chrome_ChildIOT
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505351:505345 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505351 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505363:505345 Compositor
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505363 Compositor
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505367:505345 ThreadPoolSingl
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505367 ThreadPoolSingl
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505368:505345 HangWatcher
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505368 HangWatcher
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505407:505345 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505407 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505766:505345 MemoryInfra
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505766 MemoryInfra
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505405:505405 kworker/u4:4-ev
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505405 kworker/u4:4-ev
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505406:505406 kworker/u4:5
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505406 kworker/u4:5
[2026-05-19 11:28:38] [INFO] [qos_manager.c:262] New app instance of 505409 /snap/chromium/3258/usr/lib/chromium-browser/chrome
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_USER_INTERACTIVE for 505409:505409 chrome
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_USER_INTERACTIVE for 505409 chrome
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505410:505409 PerfettoTrace
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505410 PerfettoTrace
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505411:505409 ThreadPoolServi
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505411 ThreadPoolServi
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505412:505409 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505412 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505413:505409 Chrome_ChildIOT
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505413 Chrome_ChildIOT
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505414:505409 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505414 ThreadPoolForeg
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505415:505409 Compositor
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505415 Compositor
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505416:505409 ThreadPoolSingl
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505416 ThreadPoolSingl
[2026-05-19 11:28:38] [INFO] [qos_manager.c:309] Applying QoS Tag QOS_DEFAULT for 505417:505409 HangWatcher
[2026-05-19 11:28:38] [INFO] [qos_tagging.c:271] Applying QoS Tag QOS_DEFAULT for 505417 HangWatcherYou should be able to use that for testing by the way already instead of chrt :-)
Actually on my laptop since I am very power sensitive and I use chrome a lot I have this config to force all chrome tasks to be background except for one (uclamp_max should help prevent using the top freqs often when not needed to deliver meaningful perf)
{
"chrome": {
"qos": "QOS_BACKGROUND",
"thread_qos": {
"chrome": "QOS_INTERACTIVE"
}
}
}I did create a config for steam to test gaming, but I still can't get a booting kernel on ToT for my M1 system to run tests and collect more data.. The other machine I have is poor for gaming workloads.
You can control the slice values for each QoS levels from qos_mappings.json. Restarting the daemon is enough for it to take effect globally. So you can change configs, restart and collect data for different experiments on the fly.
Only caveat: you have to reboot to undo schedqos fiddling with all tasks. I don't have a good way to restore system state yet and I am not sure it can be reversible..
Quoted 3 lines
Can't we have both by using something like
SCHED_FLAG_RESET_ON_FORKcombined with setting a hint?
We had similar discussion in the past in [1]. And I think we'll end up getting more of such proposals to selectively reset specific tags.
I do set this flag anyway in schedqos so that we can introduce the option to introduce new high level QoS to take advantage of RT, DL etc. Not that users can escape schedqos listening to all forks and execs anyway :p
Anyway, my point is that I hopefully fixed the problem how folks can be intentional very easily, and while I won't spend a lot of time arguing for it, but my strong recommendation being reserved and not inherit is the easier problem to deal with. A big part of the problem space is noise management, not just functional development of new QoS.
We still have the question whether we must enforce a single CAP_PERF_MANAGER user of this interface. Maybe at LPC we can discuss these details better.
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
In reply to Qais YousefQuoted 9 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* Cookie
Hi Qais,
I tested the proposed ABI on an Android device running 6.18.20-android17-3-maybe-dirty-4k with this sched_qos series carried locally. This was a direct syscall preflight rather than an app-level benchmark:
- set SCHED_FLAG_QOS / SCHED_QOS_RAMPUP_MULTIPLIER=4 on an existing
task with sched_setattr();
- read it back with sched_getattr() and check type/value;
- repeat with value 0;
- fail the test if sched_setattr() returns 0 but readback does not match.
This exposed two ABI semantics that I think need to be nailed down.
First, a QoS-only sched_setattr() can return success without applying the QoS state.
In __sched_setscheduler(), the policy-unchanged fast path checks whether nice, RT priority, DL params, or util-clamp changed before deciding there is nothing to do. It does not treat SCHED_FLAG_QOS as a change there, so a call that only changes sched_qos_type/value can return 0 before reaching __setscheduler_sched_qos().
That makes syscall success ambiguous for a userspace manager: it needs to read the state back to know whether the QoS request actually took effect. I think SCHED_FLAG_QOS should be sufficient to force the change path.
Second, sched_getattr() uses sched_qos_type from the userspace sched_attr buffer as the selector for which QoS value to report:
if (copy_from_user(&kattr.sched_qos_type,
&uattr->sched_qos_type,
sizeof(kattr.sched_qos_type)))
return -EFAULT;
switch (kattr.sched_qos_type) {
case SCHED_QOS_RAMPUP_MULTIPLIER:
kattr.sched_qos_value = p->sched_qos.rampup_multiplier;
kattr.sched_qos_cookie = 0;
break;
default:
break;
}If this input-selector behavior is intentional, I think it should be documented as part of the query ABI. Otherwise sched_getattr() looks like an output-only operation, and helper code can easily confuse "I did not select a QoS type to query" with "this task has no QoS state".
The same preflight also checked that short sched_attr sizes with SCHED_FLAG_QOS fail predictably. That part does fail today, but indirectly because the short copy leaves sched_qos_type as SCHED_QOS_NONE. It may be clearer to make the required size for SCHED_FLAG_QOS explicit, similar to the util-clamp size check.
With set/readback checks in place, I can observe a narrow scheduler-layer signal in a controlled native transition workload. I would not treat that as a generic Android UI latency result or a Tested-by tag, but the preflight made the set/query semantics above stand out.
Thanks.
Re: [PATCH v2 RFC 08/13] sched/qos: Add a new sched-qos interface
Quoted 26 lines · zhidao su
Quoted 9 lines · Qais Yousef
Provide a generic and extensible interface to describe arbitrary QoS tags to tell the kernel about specific behavior that is doesn't fall into the existing
sched_attr.The interface is broken into three parts:
* Type
* Value
* CookieHi Qais,
I tested the proposed ABI on an Android device running 6.18.20-android17-3-maybe-dirty-4k with this
sched_qosseries carried locally. This was a direct syscall preflight rather than an app-level benchmark:- set
SCHED_FLAG_QOS/ SCHED_QOS_RAMPUP_MULTIPLIER=4 on an existingtask with sched_setattr();- read it back with
sched_getattr()and check type/value;
- repeat with value 0;
- fail the test ifsched_setattr()returns 0 but readback does not match.This exposed two ABI semantics that I think need to be nailed down.
Quoted 8 lines
First, a QoS-only
sched_setattr()can return success without applying the QoS state.In
__sched_setscheduler(), the policy-unchanged fast path checks whether nice, RT priority, DL params, or util-clamp changed before deciding there is nothing to do. It does not treatSCHED_FLAG_QOSas a change there, so a call that only changes sched_qos_type/value can return 0 before reaching__setscheduler_sched_qos().
Oh, this is a bug. I'll fix it in next iteration, thanks for catching it.
Quoted 4 lines
That makes syscall success ambiguous for a userspace manager: it needs to read the state back to know whether the QoS request actually took effect. I think
SCHED_FLAG_QOSshould be sufficient to force the change path.
Yes, we should be only to query the value of a specific QoS.
Quoted 18 lines
Second,
sched_getattr()usessched_qos_typefrom the userspacesched_attrbuffer as the selector for which QoS value to report:if (copy_from_user(&kattr.sched_qos_type, &uattr->sched_qos_type, sizeof(kattr.sched_qos_type))) return -EFAULT; switch (kattr.sched_qos_type) { case SCHED_QOS_RAMPUP_MULTIPLIER: kattr.sched_qos_value = p->sched_qos.rampup_multiplier; kattr.sched_qos_cookie = 0; break; default: break; }
Quoted 4 lines
If this input-selector behavior is intentional, I think it should be documented as part of the query ABI. Otherwise
sched_getattr()looks like an output-only operation, and helper code can easily confuse "I did not select a QoS type to query" with "this task has no QoS state".
It is intentional. If QoS is 0, this is treated as NONE and nothing is reported back. I'll improve the docs, I do try to say that these QoS must be set one at a time, which also means must be read back one at a time too.
I tried to trigger discussion whether I should make this an array of 3 or 5 elements to allow faster writing/reading. I'll keep this an open question that can be added at anytime once we address the remaining areas of supporting cookies etc.
Quoted 6 lines
The same preflight also checked that short
sched_attrsizes withSCHED_FLAG_QOSfail predictably. That part does fail today, but indirectly because the short copy leavessched_qos_typeasSCHED_QOS_NONE. It may be clearer to make the required size forSCHED_FLAG_QOSexplicit, similar to the util-clamp size check.
You mean this uclamp check in sched_copy_attr()?, right?
if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) && size < SCHED_ATTR_SIZE_VER1) return -EINVAL;
Yes, should add this too.
Quoted 7 lines
With set/readback checks in place, I can observe a narrow scheduler-layer signal in a controlled native transition workload. I would not treat that as a generic Android UI latency result or a Tested-by tag, but the preflight made the set/query semantics above stand out.
Thanks.
Thanks!
PATCH v2 9/13 sched/qos: Add rampup multiplier QoS
In reply to Qais YousefBursty tasks are hard to predict. To use resources efficiently, the system would like to be exact as much as possible. But this poses a challenge for these bursty tasks that need to get access to more resources quickly.
The new SCHED_QOS_RAMPUP_MULTIPLIER allows userspace to do that. As the name implies, it only helps them to transition to a higher performance state when they get _busier_. That is perfectly periodic tasks by definition are not going through a transition and will run at a constant performance level. It is the tasks that need to transition from one periodic state to another periodic state that is at a higher level that this rampup_multiplier will help with. It also slows down the ewma decay of util_est which should help those bursty tasks to keep their faster rampup.
This should work complimentary with uclamp. uclamp tells the system about min and max perf requirements which can be applied immediately.
rampup_multiplier is about reactiveness to change in behavior; specifically when a task gets a sudden burst of work and gets busier.
In practice this is found to be a much better control than uclamp_min as it is relative parameter and doesn't require absolute description. It allows the task to go through the motion faster without knowing exactly how busy it can get at any particular point of time.
The intention is for this rampup multiplier to be applied only during a burst. It has no effect on perfectly periodic tasks.
--- Documentation/scheduler/sched-qos.rst | 22 +++++++++ include/linux/sched.h | 7 +++ include/uapi/linux/sched.h | 6 ++- kernel/sched/core.c | 66 +++++++++++++++++++++++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 6 ++- kernel/sched/syscalls.c | 55 +++++++++++++++++++++- 7 files changed, 158 insertions(+), 5 deletions(-)
Documentation/scheduler/sched-qos.rst +22 -0
@@ -42,3 +42,25 @@ need for extension will arise; and when this happen the task should be simpler to add the kernel extension and allow userspace to use readily by setting the newly added flag without having to update the whole of sched_attr. + +2. QoS Tags +=========== + +SCHED_QOS_RAMPUP_MULTIPLIER +--------------------------- + +Controls how fast util signal rises. Affects frequency selection when schedutil +is in use. And affects how fast tasks migrate between clusters on HMP systems. + +It affects bursty tasks only. Perfectly periodic tasks are well described by +util_avg and the rampup multiplier will have no effect on them. + +When set to 0, util_est will be disabled to help further with power saving. +This behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feature. + +Value is not capped to retain flexibility, but it tapers off very quickly to +notice a difference above 16. Roughly it takes ~200ms to reach a util_avg of +1000 starting from 0. With 16 it should take ~12.5ms. A range of 0-8 is +advised for general use. + +Cookie must always be set to 0.
include/linux/sched.h +7 -0
@@ -443,6 +443,11 @@ struct sched_info {#endif /* CONFIG_SCHED_INFO */ }; +struct sched_qos { + DECLARE_BITMAP(user_defined, SCHED_QOS_MAX); +unsigned int rampup_multiplier; +}; +/* * Integer metrics need fixed point arithmetic, e.g., sched/fair * has a few: load, load_avg, util_avg, freq, and capacity.
@@ -954,6 +959,8 @@ struct task_struct {struct sched_info sched_info; +struct sched_qos sched_qos; +struct list_head tasks;struct plist_node pushable_tasks;struct rb_node pushable_dl_tasks;
include/uapi/linux/sched.h +5 -1
@@ -104,6 +104,9 @@ struct clone_args { };enum sched_qos_type { +SCHED_QOS_NONE , +SCHED_QOS_RAMPUP_MULTIPLIER , +SCHED_QOS_MAX , };#endif
@@ -148,7 +151,8 @@ enum sched_qos_type { SCHED_FLAG_RECLAIM | \ SCHED_FLAG_DL_OVERRUN | \ SCHED_FLAG_KEEP_ALL | \ - SCHED_FLAG_UTIL_CLAMP) + SCHED_FLAG_UTIL_CLAMP | \ + SCHED_FLAG_QOS)/* Only for sched_getattr() own flag param, if task is SCHED_DEADLINE */ #define SCHED_GETATTR_FLAG_DL_DYNAMIC 0x01
kernel/sched/core.c +66 -0
96 lines not on this page · raw message
kernel/sched/debug.c +1 -0
@@ -1357,6 +1357,7 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,__PS ("effective uclamp.min" ,uclamp_eff_value (p,UCLAMP_MIN ));__PS ("effective uclamp.max" ,uclamp_eff_value (p,UCLAMP_MAX ));#endif /* CONFIG_UCLAMP_TASK */ +__PS ("sched_qos.rampup_multiplier" , p->sched_qos.rampup_multiplier);P (policy);P (prio);if (task_has_dl_policy (p)) {
kernel/sched/fair.c +4 -2
@@ -5119,7 +5119,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,unsigned int prev_ewma = ewma & ~UTIL_AVG_UNCHANGED ;do_div (delta,1000 ); - ewma =approximate_util_avg (prev_ewma, delta); + ewma =approximate_util_avg (prev_ewma, delta * p->sched_qos.rampup_multiplier);/* * Keep accumulating delta_exec if it is too small to cause * a change.
@@ -5188,6 +5188,8 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,* 0.25, thus making w=1/4 ( >>= UTIL_EST_WEIGHT_SHIFT) */ ewma <<=UTIL_EST_WEIGHT_SHIFT ; +if (p->sched_qos.rampup_multiplier) + last_ewma_diff /= p->sched_qos.rampup_multiplier; ewma -= last_ewma_diff; ewma >>=UTIL_EST_WEIGHT_SHIFT ; done:
@@ -10360,7 +10362,7 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu)* on TICK doesn't end up hurting it as it can happen after we would * have crossed this threshold. * -* To ensure that invaraince is taken into account, we don't scale time +* To ensure that invariance is taken into account, we don't scale time * and use it as-is, approximate_util_avg() will then let us know the * our threshold. */
kernel/sched/syscalls.c +53 -2
79 lines not on this page · raw message
Signature · 1 line
2.34.1
Peter Zijlstra
maintainerRe: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
Quoted 20 lines · Qais Yousef
Documentation/scheduler/sched-qos.rst +12
-0@@ -42,3 +42,25 @@ need for extension will arise; and when this happen the task should be simpler to add the kernel extension and allow userspace to use readily by setting the newly added flag without having to update the whole of sched_attr. + +2. QoS Tags +=========== + +SCHED_QOS_RAMPUP_MULTIPLIER +--------------------------- + +Controls how fast util signal rises. Affects frequency selection when schedutil +is in use. And affects how fast tasks migrate between clusters on HMP systems. + +It affects bursty tasks only. Perfectly periodic tasks are well described by +util_avg and the rampup multiplier will have no effect on them.
Documentation/scheduler/sched-qos.rst need for extension will arise; and when this happen the task should be · line 66
Quoted 10 lines
Documentation/scheduler/sched-qos.rst +10
-0+ +When set to 0, util_est will be disabled to help further with power saving. +This behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feature. + +Value is not capped to retain flexibility, but it tapers off very quickly to +notice a difference above 16. Roughly it takes ~200ms to reach a util_avg of +1000 starting from 0. With 16 it should take ~12.5ms. A range of 0-8 is +advised for general use. + +Cookie must always be set to 0.
So this is a very specific feature. This is made possible by basically having a huge type space, allowing for throw-away hints (as per the previous email).
I suppose having these specific hints is easy, but as per always there is the discussion about describing task behaviour vs implementation details. With the argument being that task behaviour might be a more lasting / stable hint, while implementation details are far easier to actually do.
I'm missing this discussion.
Re: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
Quoted 28 lines · Peter Zijlstra
Quoted 26 lines · Qais Yousef
Documentation/scheduler/sched-qos.rst +18
-0@@ -42,3 +42,25 @@ need for extension will arise; and when this happen the task should be simpler to add the kernel extension and allow userspace to use readily by setting the newly added flag without having to update the whole of sched_attr. + +2. QoS Tags +=========== + +SCHED_QOS_RAMPUP_MULTIPLIER +--------------------------- + +Controls how fast util signal rises. Affects frequency selection when schedutil +is in use. And affects how fast tasks migrate between clusters on HMP systems. + +It affects bursty tasks only. Perfectly periodic tasks are well described by +util_avg and the rampup multiplier will have no effect on them. + +When set to 0, util_est will be disabled to help further with power saving. +This behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feature. + +Value is not capped to retain flexibility, but it tapers off very quickly to +notice a difference above 16. Roughly it takes ~200ms to reach a util_avg of
Quoted 8 lines
Documentation/scheduler/sched-qos.rst need for extension will arise; and when this happen the task should be · line 66
Quoted 4 lines
Documentation/scheduler/sched-qos.rst +4
-0+1000 starting from 0. With 16 it should take ~12.5ms. A range of 0-8 is +advised for general use. + +Cookie must always be set to 0.So this is a very specific feature. This is made possible by basically having a huge type space, allowing for throw-away hints (as per the previous email).
Hmm. It is specific and generic. It is specific in a sense it is about the rise time through performance level and scheduler integration with schedutil. It is generic also because it is about the time it takes scheduler/kernel to move through performance levels. I could change the description to focus on these generic elements of DVFS response time and migration time for HMP systems.
I think if we move away from PELT etc, the concept will still be valid but implemented differently unless the new implementation can't use the concept of a multiplier for some reason to speed up the rise time.
Quoted 8 lines
I suppose having these specific hints is easy, but as per always there is the discussion about describing task behaviour vs implementation details. With the argument being that task behaviour might be a more lasting / stable hint, while implementation details are far easier to actually do.
I'm missing this discussion.
The intention is to describe task behavior. But being practical as well and allow solve real world problems with ease - so if implementation detail description will help us fix problems simply and easily, then I am for it.
The question is how to protect ourselves? :-)
This is where the two levels of QoS can help.
One level is for app developers, which is high level abstraction that is detached from OS internals and details. This is done in schedqos I announced recently. The goal is for users to use the QoS exposed by this service and not to interact directly with scheduler/kernel.
The other level is this one proposed here; which is to enable this smart service to provide a meaningful abstraction for end users, but not directly being used by them - and we can define it whatever we like.
And this brings us to a contentious point, how to protect and enforce this behavior?
I think we need to enforce that these hints are used by some all knowing entity and for sched_attr to be locked down by everyone except it. Vincent was suggesting to use SELinux to lockdown sched_attrs, but given recent issues with tcmalloc I think we must eneforce something at kernel level. CAP_NICE is spread around and we don't want to mix and match how sched_attr and these new QoS are used.
To address this I think we need to introduce a new CAP_PERF_MANAGER (or pick your favourite name here) that can only be set for specific binaries and only one binary is allowed to exec with this capability. If two binaries with this capability try to run, then the second one will fail unless the first one has exited first. And when it is running, we lock down sched_setattr() except for this CAP_PERF_MANAGER.
I am not sure if this is enough, but I think we must enforce the usage pattern else we can end up with a mess. I think we all agree it is hard for applications to use sched_attr in general directly, given the benefit of a hindsight. I commonly see the simple nice value misused in practice for example.
Ideally I'd love to enforce a single trusted binary if that can be done :p
Re: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
Quoted 96 lines · Qais Yousef
Quoted 28 lines · Peter Zijlstra
Quoted 26 lines · Qais Yousef
Documentation/scheduler/sched-qos.rst +18
-0@@ -42,3 +42,25 @@ need for extension will arise; and when this happen the task should be simpler to add the kernel extension and allow userspace to use readily by setting the newly added flag without having to update the whole of sched_attr. + +2. QoS Tags +=========== + +SCHED_QOS_RAMPUP_MULTIPLIER +--------------------------- + +Controls how fast util signal rises. Affects frequency selection when schedutil +is in use. And affects how fast tasks migrate between clusters on HMP systems. + +It affects bursty tasks only. Perfectly periodic tasks are well described by +util_avg and the rampup multiplier will have no effect on them. + +When set to 0, util_est will be disabled to help further with power saving. +This behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feature. + +Value is not capped to retain flexibility, but it tapers off very quickly to +notice a difference above 16. Roughly it takes ~200ms to reach a util_avg ofQuoted 8 lines
Documentation/scheduler/sched-qos.rst need for extension will arise; and when this happen the task should be · line 66
Quoted 4 lines
Documentation/scheduler/sched-qos.rst +4
-0+1000 starting from 0. With 16 it should take ~12.5ms. A range of 0-8 is +advised for general use. + +Cookie must always be set to 0.So this is a very specific feature. This is made possible by basically having a huge type space, allowing for throw-away hints (as per the previous email).
Hmm. It is specific and generic. It is specific in a sense it is about the rise time through performance level and scheduler integration with schedutil. It is generic also because it is about the time it takes scheduler/kernel to move through performance levels. I could change the description to focus on these generic elements of DVFS response time and migration time for HMP systems.
I think if we move away from PELT etc, the concept will still be valid but implemented differently unless the new implementation can't use the concept of a multiplier for some reason to speed up the rise time.
Quoted 8 lines
I suppose having these specific hints is easy, but as per always there is the discussion about describing task behaviour vs implementation details. With the argument being that task behaviour might be a more lasting / stable hint, while implementation details are far easier to actually do.
I'm missing this discussion.
The intention is to describe task behavior. But being practical as well and allow solve real world problems with ease - so if implementation detail description will help us fix problems simply and easily, then I am for it.
The question is how to protect ourselves? :-)
This is where the two levels of QoS can help.
One level is for app developers, which is high level abstraction that is detached from OS internals and details. This is done in schedqos I announced recently. The goal is for users to use the QoS exposed by this service and not to interact directly with scheduler/kernel.
The other level is this one proposed here; which is to enable this smart service to provide a meaningful abstraction for end users, but not directly being used by them - and we can define it whatever we like.
And this brings us to a contentious point, how to protect and enforce this behavior?
I think we need to enforce that these hints are used by some all knowing entity and for
sched_attrto be locked down by everyone except it. Vincent was suggesting to use SELinux to lockdownsched_attrs, but given recent issues with tcmalloc I think we must eneforce something at kernel level.CAP_NICEis spread around and we don't want to mix and match howsched_attrand these new QoS are used.To address this I think we need to introduce a new
CAP_PERF_MANAGER(or pick your favourite name here) that can only be set for specific binaries and only one binary is allowed to exec with this capability. If two binaries with this capability try to run, then the second one will fail unless the first one has exited first. And when it is running, we lock downsched_setattr()except for thisCAP_PERF_MANAGER.>
I am not sure if this is enough, but I think we must enforce the usage pattern else we can end up with a mess. I think we all agree it is hard for applications to usesched_attrin general directly, given the benefit of a hindsight. I commonly see the simple nice value misused in practice for example.
Quoted 2 lines
Ideally I'd love to enforce a single trusted binary if that can be done :p
Just to follow along, does that mean if an application runs with CAP_PERF_MANAGER any other that doesn't have CAP_PERF_MANAGER and calls any of sched_setattr()sched_setscheduler()sched_setparam()nice()setpriority()
would get EPERM? Or silently be dropped?
Either seems error-prone and potentially no longer work as a "Zero API adoption mechanism". Chromium and Unity seem to handle sched_setattr() failing, but unsure what the situation looks like generally.
Re: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
Quoted 109 lines · Christian Loehle
Quoted 96 lines · Qais Yousef
Quoted 28 lines · Peter Zijlstra
Quoted 26 lines · Qais Yousef
Documentation/scheduler/sched-qos.rst +18
-0@@ -42,3 +42,25 @@ need for extension will arise; and when this happen the task should be simpler to add the kernel extension and allow userspace to use readily by setting the newly added flag without having to update the whole of sched_attr. + +2. QoS Tags +=========== + +SCHED_QOS_RAMPUP_MULTIPLIER +--------------------------- + +Controls how fast util signal rises. Affects frequency selection when schedutil +is in use. And affects how fast tasks migrate between clusters on HMP systems. + +It affects bursty tasks only. Perfectly periodic tasks are well described by +util_avg and the rampup multiplier will have no effect on them. + +When set to 0, util_est will be disabled to help further with power saving. +This behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feature. + +Value is not capped to retain flexibility, but it tapers off very quickly to +notice a difference above 16. Roughly it takes ~200ms to reach a util_avg ofQuoted 8 lines
Documentation/scheduler/sched-qos.rst need for extension will arise; and when this happen the task should be · line 66
Quoted 4 lines
Documentation/scheduler/sched-qos.rst +4
-0+1000 starting from 0. With 16 it should take ~12.5ms. A range of 0-8 is +advised for general use. + +Cookie must always be set to 0.So this is a very specific feature. This is made possible by basically having a huge type space, allowing for throw-away hints (as per the previous email).
Hmm. It is specific and generic. It is specific in a sense it is about the rise time through performance level and scheduler integration with schedutil. It is generic also because it is about the time it takes scheduler/kernel to move through performance levels. I could change the description to focus on these generic elements of DVFS response time and migration time for HMP systems.
I think if we move away from PELT etc, the concept will still be valid but implemented differently unless the new implementation can't use the concept of a multiplier for some reason to speed up the rise time.
Quoted 8 lines
I suppose having these specific hints is easy, but as per always there is the discussion about describing task behaviour vs implementation details. With the argument being that task behaviour might be a more lasting / stable hint, while implementation details are far easier to actually do.
I'm missing this discussion.
The intention is to describe task behavior. But being practical as well and allow solve real world problems with ease - so if implementation detail description will help us fix problems simply and easily, then I am for it.
The question is how to protect ourselves? :-)
This is where the two levels of QoS can help.
One level is for app developers, which is high level abstraction that is detached from OS internals and details. This is done in schedqos I announced recently. The goal is for users to use the QoS exposed by this service and not to interact directly with scheduler/kernel.
The other level is this one proposed here; which is to enable this smart service to provide a meaningful abstraction for end users, but not directly being used by them - and we can define it whatever we like.
And this brings us to a contentious point, how to protect and enforce this behavior?
I think we need to enforce that these hints are used by some all knowing entity and for
sched_attrto be locked down by everyone except it. Vincent was suggesting to use SELinux to lockdownsched_attrs, but given recent issues with tcmalloc I think we must eneforce something at kernel level.CAP_NICEis spread around and we don't want to mix and match howsched_attrand these new QoS are used.To address this I think we need to introduce a new
CAP_PERF_MANAGER(or pick your favourite name here) that can only be set for specific binaries and only one binary is allowed to exec with this capability. If two binaries with this capability try to run, then the second one will fail unless the first one has exited first. And when it is running, we lock downsched_setattr()except for thisCAP_PERF_MANAGER.>
I am not sure if this is enough, but I think we must enforce the usage pattern else we can end up with a mess. I think we all agree it is hard for applications to usesched_attrin general directly, given the benefit of a hindsight. I commonly see the simple nice value misused in practice for example.Quoted 2 lines
Ideally I'd love to enforce a single trusted binary if that can be done :p
Just to follow along, does that mean if an application runs with
CAP_PERF_MANAGERany other that doesn't haveCAP_PERF_MANAGERand calls any ofsched_setattr()sched_setscheduler()sched_setparam()nice()setpriority()
Quoted 1 line
would get EPERM? Or silently be dropped?
I think EPERM.
Quoted 1 line
Either seems error-prone and potentially no longer work as a "Zero API adoption mechanism".
How come it is error-prone, could you explain more?
What's the relationship between this and zero api?
Quoted 2 lines
Chromium and Unity seem to handle
sched_setattr()failing, but unsure what the situation looks like generally.
You think they will crash if we block usage? These already can fail if admins block via selinux for example.
Re: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
In reply to Qais YousefHi Qais,
I did a bit of testing on an Android device running 6.18.20-android17 with UTIL_EST and UTIL_EST_RAMPUP_ZERO enabled, and sched_qos_default_rampup_multiplier=0.
At the scheduler level, the behaviour looks as expected. With rampup_multiplier=0, the worker's se.avg.util_est stayed at 0 in my runs. With rampup_multiplier=4, util_est became non-zero immediately in the high phase and reached ~1023.
For end-to-end behaviour, I could not get a useful signal from longer steady CPU-bound phases. q0 tends to catch up via util_avg quickly, and the result is very sensitive to the frequency state at the start of the high phase.
The clearest signal I saw was with a synthetic low-periodic -> short-burst native workload:
low: periodic short work + sleep
high: 5 CPU-bound cycles, no sleep
Each q0/q4 case was gated to start from <= 940800 kHz on CPU4, and the worker set and verified the QoS value in the worker thread.
In that setup, q4 was faster at the 5th high-cycle in 7/8 paired runs. The larger wins also matched q4 reaching a higher sampled CPU frequency during the burst, e.g.
rep3: q0 691200 -> q4 1344000, c5 delta -41.9 ms
rep5: q0 691200 -> q4 3398400, c5 delta -79.2 ms
rep6: q0 691200 -> q4 1344000, c5 delta -91.9 ms
The main negative case was consistent with the sampled frequency state too:
rep1: q0 2083200 -> q4 816000, c5 delta +34.1 ms
So this is only a synthetic transition-workload data point, but it does look consistent with the intended periodic-to-busy transition case. I would not interpret it as a general app benchmark result.
No Tested-by tag from me for now, since this is not broad performance validation.
Thanks,
Zhidao
Re: [PATCH v2 09/13] sched/qos: Add rampup multiplier QoS
Quoted 36 lines · zhidao su (Xiaomi)
Hi Qais,
I did a bit of testing on an Android device running 6.18.20-android17 with
UTIL_ESTandUTIL_EST_RAMPUP_ZEROenabled, and sched_qos_default_rampup_multiplier=0.At the scheduler level, the behaviour looks as expected. With rampup_multiplier=0, the worker's se.avg.util_est stayed at 0 in my runs. With rampup_multiplier=4,
util_estbecame non-zero immediately in the high phase and reached ~1023.For end-to-end behaviour, I could not get a useful signal from longer steady CPU-bound phases. q0 tends to catch up via
util_avgquickly, and the result is very sensitive to the frequency state at the start of the high phase.The clearest signal I saw was with a synthetic low-periodic -> short-burst native workload:
low: periodic short work + sleep
high: 5 CPU-bound cycles, no sleepEach q0/q4 case was gated to start from <= 940800 kHz on CPU4, and the worker set and verified the QoS value in the worker thread.
In that setup, q4 was faster at the 5th high-cycle in 7/8 paired runs. The larger wins also matched q4 reaching a higher sampled CPU frequency during the burst, e.g.
rep3: q0 691200 -> q4 1344000, c5 delta -41.9 ms
rep5: q0 691200 -> q4 3398400, c5 delta -79.2 ms
rep6: q0 691200 -> q4 1344000, c5 delta -91.9 msThe main negative case was consistent with the sampled frequency state too:
Quoted 8 lines
rep1: q0 2083200 -> q4 816000, c5 delta +34.1 ms
So this is only a synthetic transition-workload data point, but it does look consistent with the intended periodic-to-busy transition case. I would not interpret it as a general app benchmark result.
No Tested-by tag from me for now, since this is not broad performance validation.
Thanks for the running the tests. IIUC, you're reporting that all is good so far.
PATCH v2 10/13 sched/fair: Disable util_est when rampup_multiplier is 0
In reply to Qais Yousefutil_est is a great feature to enable busy tasks with long sleep time to maintain their perf level. But it can also be expensive in terms of power for tasks that have no such perf requirements and just happened to be busy in the last activation.
If a task sets its rampup_multiplier to 0, then it indicates that it is happy to glide along with system default response and doesn't require responsiveness. We can use that to further imply that the task is happy to decay its util for long sleep too and disable util_est.
The behavior can be controlled via UTIL_EST_RAMPUP_ZERO sched_feat that is enabled by default.
--- kernel/sched/fair.c | 8 ++++++++ kernel/sched/features.h | 5 +++++ 2 files changed, 13 insertions(+)
kernel/sched/fair.c +8 -0
@@ -5104,6 +5104,14 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,if (!sched_feat (UTIL_EST ))return ; +/* +* rampup_multiplier = 0 indicates util_est is disabled. +*/ +if (sched_feat (UTIL_EST_RAMPUP_ZERO ) && !p->sched_qos.rampup_multiplier) { + ewma =0 ; + goto done; + } +/* Get current estimate of utilization */ ewma =READ_ONCE (p->se.avg.util_est);
kernel/sched/features.h +5 -0
@@ -122,6 +122,11 @@ SCHED_FEAT(WA_BIAS, true)*/ SCHED_FEAT (UTIL_EST , true) +/* +* Disable util_est when rampup_multiplier is 0. + */ +SCHED_FEAT(UTIL_EST_RAMPUP_ZERO, true) +SCHED_FEAT (LATENCY_WARN , false)/*
Signature · 1 line
2.34.1
PATCH v2 11/13 sched/fair: Don't mess with util_avg post init
In reply to Qais YousefThe extrapolation logic for util_avg for newly forked tasks tries to crystal ball the task's demand. This has worked well when the system didn't have the means to help these tasks otherwise. But now we do have util_est that will rampup faster. And uclamp_min to ensure a good starting point if they really care.
Since we really can't crystal ball the behavior, and giving the same starting value for all tasks is more consistent behavior for all forked tasks, and it helps to preserve system resources for tasks to compete to get them if they truly care, set the initial util_avg to be 0 when util_est feature is enabled.
This should not impact workloads that need best single threaded performance (like geekbench) given the previous improvements introduced to help with faster rampup to reach max perf point more coherently and consistently across systems.
The logic can be forced back on using UTIL_EST_FORCE_POST_INIT sched_feat.
--- kernel/sched/fair.c | 19 +++++++++++++++++++ kernel/sched/features.h | 10 ++++++++++ 2 files changed, 29 insertions(+)
kernel/sched/fair.c +19 -0
@@ -1261,6 +1261,19 @@ void init_entity_runnable_average(struct sched_entity *se) }/* +* When util_est is used, the tasks can rampup much faster by default. And with +* the rampup_multiplier, tasks can ask for faster rampup after fork. And with +* uclamp, they can ensure a min perf requirement. Given all these factors, we +* keep util_avg at 0 as we can't crystal ball the task demand after fork. +* Userspace have enough ways to ensure good perf for tasks after fork. Keeping +* the util_avg to 0 is good way to ensure a uniform start for all tasks. And +* it is good to preserve precious resources. Truly busy forked tasks can +* compete for the resources without the need for initial 'cheat' to ramp them +* up automagically. +* +* When util_est is not present, the extrapolation logic below will still +* apply. +* * With new tasks being created, their initial util_avgs are extrapolated * based on the cfs_rq's current util_avg: *
@@ -1310,6 +1323,12 @@ void post_init_entity_util_avg(struct task_struct *p)return ; } +/* +* Tasks can rampup faster with util_est, so don't mess with util_avg. +*/ +if (sched_feat (UTIL_EST ) && !sched_feat (UTIL_EST_FORCE_POST_INIT )) +return ; +if (cap >0 ) {if (cfs_rq->avg.util_avg !=0 ) { sa->util_avg = cfs_rq->avg.util_avg *se_weight (se);
kernel/sched/features.h +10 -0
@@ -127,6 +127,16 @@ SCHED_FEAT(UTIL_EST, true)*/ SCHED_FEAT (UTIL_EST_RAMPUP_ZERO , true) +/* +* Force extrapolating util_avg on fork. +* +* When util_est is enabled the extrapolation is not necessary since tasks can +* rampup faster and can be controlled with a rampup multiplier to get better +* responses making the need for the extrapolation moot. Switch this on to +* force the extrapolation logic. + */ +SCHED_FEAT(UTIL_EST_FORCE_POST_INIT, false) +SCHED_FEAT (LATENCY_WARN , false)/*
Signature · 1 line
2.34.1
PATCH v2 12/13 sched/fair: Call update_util_est() after dequeue_entities()
In reply to Qais Yousefupdate_util_est() reads task_util() at dequeue which is updated in dequeue_entities(). To read the accurate util_avg at dequeue, make sure to do the read after load_avg is updated in dequeue_entities().
util_est for a periodic task before
periodic-3114 util_est.enqueued running
┌───────────────────────────────────────────────────────────────────────────────────────────────┐ 183┤ ▖▗ ▐▖ ▖ ▗▙ ▗ ▗▙▖▖ ▖▖ ▖ ▖▖ ▗ ▟ ▗▄▖ │ 139┤ ▐▛█▜▙▞▀▄▄▞▚▄▟█▞▙█▄▟▀▚▄▄▞▚▄▄▟▀▀▛▄▝▄▄▄▙█▛▛█▛▜▛▄▄▀▄█▙▛▛▛▙▄▀▄▄▖▜▄▟█▟▀▜▟▄▜▀▄▄▟▙▖ │ 95┤ ▐▀ ▘ ▝ ▝ ▝▘ ▘ ▘▘ ▝▘ ▝▘ ▝ ▝ ▀ │ │ ▛ │ 51┤ ▐▘ │ 7┤ ▖▗▗ ▗▄▐ │ └┬─────────┬──────────┬─────────┬──────────┬─────────┬──────────┬─────────┬──────────┬─────────┬┘ 0.00 0.65 1.30 1.96 2.61 3.26 3.91 4.57 5.22 5.87
and after
periodic-2977 util_est.enqueued running
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
157.0┤ ▙▄ ▗▄ ▗▄▄▄ ▗▄ ▗▄▄▄▗▄▄ ▗▄▄▖ ▄ ▄▄▄ ▄ ▄▖▖ ▄▄▄▄▄▖▖▝▙▄▄▄▄▄▄▖ ▗▄ │
119.5┤ ▗▄▌▘▀▀ ▀▀▀ ▝▀▀▘▝▀▀▀ ▝▀▘ ▝▀▀▘ ▀▝▀▘▀▀▀▘▝▀▀▀▀▀▀▀▘▝▝▀▀ ▀ ▝▝▀ ▀ ▀▀▀▀ │
82.0┤ ▟ │
│ ▌ │
44.5┤ ▌ │
7.0┤ ▗ ▗▖ ▌ │
└┬─────────┬─────────┬──────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┬┘
0.00 0.65 1.30 1.95 2.60 3.25 3.90 4.56 5.21 5.86Note how the signal is noisier and can peak to 183 vs 157 now.
--- kernel/sched/fair.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/fair.c +4 -1
@@ -7455,6 +7455,8 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)*/ static bool dequeue_task_fair (struct rq *rq,struct task_struct *p,int flags) { +int ret; +if (task_is_throttled (p)) {dequeue_throttled_task (p, flags);return true;
@@ -7463,8 +7465,9 @@ static bool dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)if (!p->se.sched_delayed)util_est_dequeue (&rq->cfs, p); + ret =dequeue_entities (rq, &p->se, flags);util_est_update (&rq->cfs, p, flags &DEQUEUE_SLEEP ); -if (dequeue_entities (rq, &p->se, flags) <0 ) +if (ret <0 )return false;/*
Signature · 1 line
2.34.1
RFC PATCH v2 13/13 sched/pelt: Always allow load updates
In reply to Qais Yousef1024us period can cause a problem at dequeue if the last udpate (due to tick) has happened less than this period. Running a periodic task I can see the dequeued util_avg changing by 15-20 points due to this variation
- which on HMP system with small cores can mean a big jump in freqs.
Before
periodic-2977 util_avg
┌┬─────────┬─────────┬──────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┬┐
140.0┼┼─▐▀▛▜─▄▄▄▖─────────┼──────────┼─────────┼────────▄▄──▗▄▄▄──▗▄▄▄────────┼─────────┼─────────┼┤
││ ▐ ▌▐ ▌▐ ▌ ▛▜▄ ▄▟▜▄▖ ▐▜▛▌ │▗▄ │ ▌▐ ▐ ▌▐ ▐│▌▐ ▛▙▄ ▗▄ ▐▜ │ ▗▄ ││
│▀▙▟ ▌▐ ▌▐ ▌ ▌▐▐ ▐▜▌█▐▌█▜▛█▐▌▌ │▐▐ │ ▛▜▀▛▜▀▌▐▀▙▟ ▌▐ ▐│▌▐ ▌█▐ ▗▄▛█▐▛█▜▄▟▐ │ ▐▐▀▌▗▄▖ ││
││▌▐ ▌▐▄▌▐ ▌ ▌▐▐ ▐▐▌█▐▌█▐▌█▐▌▌ │▐▐ ▐▀▙▄ ▛▜▄▌▐ ▌▐ ▌▐ ▌▐ ▌▐▄▖▐│▌▐ ▌█▐ ▐▐▌█▐▌█▐▌█▐▛▙▄ ▐▐ ▌▐ ▛▜││
129.5┼┼▌▐─▌▐─▌▐─▌──▌▐▐─▐▐▌█▐▌█▐▌█▐▌▙▄▄▟▐──▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▛▜┼▌▐─▌█▐─▐▐▌█▐▌█▐▌█▐▌▌▐─▐▐─▌▐─▌▐┼┤
││▌▐ ▌▐ ▌▐ ▛▜▀▌▐▐ ▐▐▌█▐▌█▐▌█▐▌█▐│▛▐ ▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐▄▌█▐ ▐▐▌█▐▌█▐▌█▐▌▌▐▀▛▐ ▌▐ ▌▐││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐ ▐▐▌█▐▌█▐▌█▐▌█▐│▌▐▀▙▟ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐ ▐▐▌█▐▌█▐▌█▐▌▌▐ ▌▐ ▙▟ ▌▐││
119.0┼┼▌▐─▌▐─▌▐─▌▐─▌▐▐▛█▐▌█▐▌█▐▌█▐▌█▐┼▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐┼▌▐─▌█▐▄▟▐▌█▐▌█▐▌█▐▌▌▐─▌▐─▌▐─▌▐┼┤
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐▌█▐│▌▐ ▌▐ ▌▐▄▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐▌█▐▌█▐▌█▐▌█▐▌▌▐ ▌▐ ▌▐ ▌▐▀│
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌▛▐▘█▐▌█▐│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐▌█▐▌█▐▌▛▐▘█▐▌▌▐ ▌▐ ▌▐ ▌▐││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌▌▐ █▐▘█▐│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐▌█▐▌█▐▌▌▐ █▐▘▌▐ ▌▐ ▌▐ ▌▐││
108.5┼┼▌▐─▌▐─▌▐─▌▐─▌▐▐▌█▐▌█▐▌▌▐─█▐─▌▐┼▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐┼▌▐─▌█▐▌█▐▌█▐▌▌▐─█▐─▌▐─▌▐─▌▐─▌▐┼┤
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌▌▐ █▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐▌█▐▌█▐▌▌▐ █▐ ▌▐ ▌▐ ▌▐ ▌▐││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌▌▐ █▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌█▐▌█▐▌█▐▌▌▐ █▐ ▌▐ ▌▐ ▌▐ ▌▐││
││ │ ▝ ▘█▐▌█▝▘▘▝ ▀▝ ▘▝│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▘▝ │ │ ▝▐▌█▐▌█▝▘▘▝ ▀▝ ▘▝ ▘▐ ▌▐ ▌▐││
98.0┼┼─────────┼───────▝▘┼──────────┼───▘▝─▌▐─▌▐─▌──────┼─────────┼───────▀▝▘┼─────────┼────▘▝─▘▝┼┤
└┼─────────┼─────────┼──────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┼┘
2.00 2.11 2.22 2.33 2.44 2.56 2.67 2.78 2.89 3.00After
periodic-2968 util_avg
┌┬─────────┬─────────┬──────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┬┐
139.0┼▄▖──▄▄▄▄▄▄▖─────────┼──────────┼─────────┼──────▗▄▄▟▀▛▜▀▛▜▄▖─┼──────────┼─────────┼─────────┼┤
││▛▜▀▌▐ ▌▐ ▛▜▀▙▄ ▄▟▀▛▜▄ │ │ ▐▀▛▜ ▌▐ ▌▐ ▌▐ ▛▜▀▙▄ │ │ ││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐▀▙▟▀▌▐ ▌▐▐▛█▜▛█▜▛█▜▛▙▄ │ ▄▞▜ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐▀▛▜ ▄▄▄▄▟▜▛█▜▛█▜▛█▜▛█▜▄▄▄││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐▛█▜▛█▜▌▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐▀▛▜▀▌▐ ▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▛│
128.2┼┼▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐▐▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌▌▐─▌▐─▌▐─▌▐─▌▐─▌▐┼▌▐─▌▐─▌▐─▌▐─▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌┤
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌│
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌│
117.5┼┼▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐▐▌█▐▌█▐▌█▐▌█▐▌█▐▌█▐▌▌▐─▌▐─▌▐─▌▐─▌▐─▌▐┼▌▐─▌▐─▌▐─▌▐─▌█▐▌█▐▌█▐▌█▐▌▛▐▘█▐▌┤
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐ ▛▐▌█▐▌▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌█▐▌█▐▌▌▐ ▛▐▌│
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐ ▌▐ ▛▐▌▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌█▐▌█▐▌▌▐ ▌▐││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌█▐▌█▐▌█▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌█▐▌█▐▌▌▐ ▌▐││
106.8┼┼▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐▐▌█▐▌▛▐▌█▐▌█▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐─▌▐┼▌▐─▌▐─▌▐─▌▐─▌█▐▌█▐▌▛▐▌█▐▌▌▐─▌▐┼┤
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌▌▐│▌▐▌█▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌▌▐ ▌▐▘▌▐ ▌▐││
││▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐▐▌█▐▌▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▌▐ ▘▝ ▘ ▝ ▌▐│▌▐ ▌▐ ▌▐ ▌▐ ▌█▐▌█▐▌▌▐ ▌▐ ▌▐ ▌▐││
││ │ ▝ ▘▐ ▘│ ▘▀▝▘▘▝│▌▐ ▌▐ ▌▐ ▌▐ ▌▝ │ │ ▝ ▘▝ ▌▐ ▌▐ ▌▜▐▌█▐▌▘▝ ▘▝ ▘▐ ▌▐││
96.0┼┼─────────┼──────▝──┼──────────┼────▝─▘▝─▘▐─▘──────┼─────────┼──────▘▐─▘▝─▘───────┼───────▘─┼┤
└┼─────────┼─────────┼──────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┼┘
2.00 2.11 2.22 2.33 2.44 2.56 2.67 2.78 2.89 3.00Also the new util_est periodic detection logic can be thrown off by this variation. With this fix it now stabilizes pretty well.
Before
periodic-2977 util_est.enqueued running
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
157.0┤ ▙▄ ▗▄ ▗▄▄▄ ▗▄ ▗▄▄▄▗▄▄ ▗▄▄▖ ▄ ▄▄▄ ▄ ▄▖▖ ▄▄▄▄▄▖▖▝▙▄▄▄▄▄▄▖ ▗▄ │
119.5┤ ▗▄▌▘▀▀ ▀▀▀ ▝▀▀▘▝▀▀▀ ▝▀▘ ▝▀▀▘ ▀▝▀▘▀▀▀▘▝▀▀▀▀▀▀▀▘▝▝▀▀ ▀ ▝▝▀ ▀ ▀▀▀▀ │
82.0┤ ▟ │
│ ▌ │
44.5┤ ▌ │
7.0┤ ▗ ▗▖ ▌ │
└┬─────────┬─────────┬──────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┬┘
0.00 0.65 1.30 1.95 2.60 3.25 3.90 4.56 5.21 5.86After
periodic-2968 util_est.enqueued running
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
139.0┤ ▗▟▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ │
106.5┤ ▐▛ │
74.0┤ ▟ │
│ ▌ │
41.5┤ ▌ │
9.0┤ ▗▖ ▗▌ │
└┬─────────┬─────────┬──────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┬┘
0.00 0.65 1.30 1.95 2.60 3.25 3.90 4.55 5.20 5.85---
I tried to do the update every 256us intead of every period, but this didn't help to flatten util_est.
If doing the update always is too much, AND, I didn't miss something else that could be contributing to this problem, would another sched feature to allow those who want accuracy vs those who want minimal overhead take their pick?
kernel/sched/pelt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/pelt.c +1 -2
@@ -224,8 +224,7 @@ ___update_load_sum(u64 now, struct sched_avg *sa,* Step 1: accumulate *_sum since last_update_time. If we haven't * crossed period boundaries, finish. */ -if (!accumulate_sum (delta, sa, load, runnable, running)) -return 0 ; +accumulate_sum (delta, sa, load, runnable, running);return 1 ; }
Signature · 1 line
2.34.1
Quoted 6 lines · Qais Yousef
This is the long delayed follow up to the series sent back in August 2024 [1]. Life got in the way to some extent (I had a baby, and now my time that I used to do upstream work late at night was stolen :). Apologies for those who replied and I didn't get a chance to respond back.
...
Quoted 17 lines
Open questions:
* The details of the QoS interface is the biggest one.
* Would debugfs be better for setting the default rampup multiplier instead of sysctl?
* Patch 13 makes updatingload_avgunconditional not on period boundaries.Patches 1-3 are prepatory patches renaming a function and introducing new ones.
Patches 4-5 handle the magic margin problem but making them dynamic based on actual hardware limitations.
Patches 6-7 fix the black hole problem and teaches the scheduler how to handle bursty and periodic tasks via extending
util_est.Patches 8-9 is where I expect most of the discussion on as I introduce a new
sched_qosinterface to support the newrampup_multiplierto help manage DVFS.
Quoted 6 lines
Patches 10-11 introduces a couple of necessary optimizations to counter the power impact of increased responsiveness by disabling some features that we now know how to handle better.
Patches 12-13 fix a couple of issues causing
util_estandutil_avgvalue to swing for a periodic task. Patch 12 must go via stable.
Just a minor nit, If 12/13 are fixes, should they not be at the front of the series (or possibly sent separately) so they can potentially move forward while the bigger changes in this series are discussed?
thanks
-john
Quoted 29 lines · John Stultz
Quoted 6 lines · Qais Yousef
This is the long delayed follow up to the series sent back in August 2024 [1]. Life got in the way to some extent (I had a baby, and now my time that I used to do upstream work late at night was stolen :). Apologies for those who replied and I didn't get a chance to respond back.
...
Quoted 21 lines
Open questions:
* The details of the QoS interface is the biggest one.
* Would debugfs be better for setting the default rampup multiplier instead of sysctl?
* Patch 13 makes updatingload_avgunconditional not on period boundaries.Patches 1-3 are prepatory patches renaming a function and introducing new ones.
Patches 4-5 handle the magic margin problem but making them dynamic based on actual hardware limitations.
Patches 6-7 fix the black hole problem and teaches the scheduler how to handle bursty and periodic tasks via extending
util_est.Patches 8-9 is where I expect most of the discussion on as I introduce a new
sched_qosinterface to support the newrampup_multiplierto help manage DVFS.Patches 10-11 introduces a couple of necessary optimizations to counter the power impact of increased responsiveness by disabling some features that we now know how to handle better.
Quoted 6 lines
Quoted 2 lines
Patches 12-13 fix a couple of issues causing
util_estandutil_avgvalue to swing for a periodic task. Patch 12 must go via stable.Just a minor nit, If 12/13 are fixes, should they not be at the front of the series (or possibly sent separately) so they can potentially move forward while the bigger changes in this series are discussed?
Yeah my plan was to split it and repost it with proper Fixes tag. I found it while verifying my patches so lumped it at the end. Will repost as soon as I can.
Hi Qais,
I tested your v2 12/13 (sched/fair: Call update_util_est() after dequeue_entities()) and RFC 13/13 (sched/pelt: Always allow load updates) on ARM (Raspberry Pi 5, Cortex-A76, 4-core), combined with Peter Zijlstra's ttwu series (rebased to 7.0.y by marioroy).
Both patches applied cleanly on top of rpi-7.0.y + 10 ttwu patches without conflicts.
Results using stress-ng 0.15.06 pipe stressor (4 workers, 20s):
Kernel Clock pipe bogo ops/s D vs. 6.6 ---------------------------------- --------- ---------------- ---------- 6.6.78-v8-16k+ 2800 MHz 2 487 746 +/-0% (ref) 7.0.0-v8-16k+ stock 2400 MHz 1 694 011 -31.9% 7.0.0-v8-16k+ stock 2800 MHz 1 851 567 -25.6% 7.0.0 + ttwu only (10 patches) 2400 MHz 1 836 006 -26.2% 7.0.0 + ttwu only (10 patches) 2800 MHz 1 934 076 -22.3% 7.0.0 + ttwu + your 2 Qais patches 2400 MHz 1 996 002 -19.8% 7.0.0 + ttwu + your 2 Qais patches 2800 MHz 2 342 144 -5.9%
The ttwu-only set recovers ~3-4% of the regression on ARM. Adding your two patches brings a much larger improvement -- especially under overclocking, where the combined set recovers roughly 94% of the 6.6 baseline. The remaining ~6% gap may be related to ARM-specific DELAY_DEQUEUE interactions.
Device: Raspberry Pi 5 (8 GB, C1-stepping), Bookworm arm64, rpi-7.0.y.
Background: https://github.com/raspberrypi/linux/issues/7308
Thanks for the series -- the ARM results look very promising.
Tom
Hi Tom
Quoted 22 lines · Tom Gebhardt
Hi Qais,
I tested your v2 12/13 (sched/fair: Call
update_util_est()afterdequeue_entities()) and RFC 13/13 (sched/pelt: Always allow load updates) on ARM (Raspberry Pi 5, Cortex-A76, 4-core), combined with Peter Zijlstra's ttwu series (rebased to 7.0.y by marioroy).Both patches applied cleanly on top of rpi-7.0.y + 10 ttwu patches without conflicts.
Results using stress-ng 0.15.06 pipe stressor (4 workers, 20s):
Kernel Clock pipe bogo ops/s D vs. 6.6 ---------------------------------- --------- ---------------- ---------- 6.6.78-v8-16k+ 2800 MHz 2 487 746 +/-0% (ref) 7.0.0-v8-16k+ stock 2400 MHz 1 694 011 -31.9% 7.0.0-v8-16k+ stock 2800 MHz 1 851 567 -25.6% 7.0.0 + ttwu only (10 patches) 2400 MHz 1 836 006 -26.2% 7.0.0 + ttwu only (10 patches) 2800 MHz 1 934 076 -22.3% 7.0.0 + ttwu + your 2 Qais patches 2400 MHz 1 996 002 -19.8% 7.0.0 + ttwu + your 2 Qais patches 2800 MHz 2 342 144 -5.9%
Quoted 5 lines
The ttwu-only set recovers ~3-4% of the regression on ARM. Adding your two patches brings a much larger improvement -- especially under overclocking, where the combined set recovers roughly 94% of the 6.6 baseline. The remaining ~6% gap may be related to ARM-specific
DELAY_DEQUEUEinteractions.
Hmm this is an interesting impact. Did you get a chance to verify if you need the 2 patches or only one of them is enough? Only 12/13 is actually a fix for a change in behavior from 6.6. The last patch is a new addition for a behavior that has always been there.
You have SMP system, so utilization can't be impacting your task placement to potentially being stuck on a little core. And looking at raspberry pi code, it seems they ship with ondemand governor as the default cpufreq governor. Are you using the default one? Assuming yes and you're not using schedutil, then these patches making things better is not expected.
Are you familiar with perfetto? Can you use sched-analyzer [1] to capture a trace and inspect how the pattern changes when things are good and bad?
Output of
sched-analyzer-pp --sched-states $TASK_NAME --freq-residency-task $TASK_NAME \ sched-analyzer.perfetto-trace
would be useful to share. I suspect you have a subtle change of sched pattern that I hope you might be able to visualize directly in ui.perfetto.dev, but the above stats might be a good way to see potential difference between good and bad runs.
Thanks!
[1] https://github.com/qais-yousef/sched-analyzer
Quoted 7 lines
Device: Raspberry Pi 5 (8 GB, C1-stepping), Bookworm arm64, rpi-7.0.y.
Background: https://github.com/raspberrypi/linux/issues/7308Thanks for the series -- the ARM results look very promising.
Tom
Hi Qais,
Thanks for the follow-up. Here are the patch isolation results and answers to your questions.
Regarding the governor:
Yes, I'm running ondemand, not schedutil. My mistake for not mentioning that upfront - I assumed the improvement was due to the util_est path being triggered regardless of the governor. The improvement is clearly measurable even with ondemand, which is surprising given that your patches specifically target schedutil.
Patch isolation -- 12/13 only vs. both:
I re-ran the benchmarks with patch 13/13 (sched/pelt: Always allow load updates) reverted, keeping only patch 12/13 (sched/fair: Call update_util_est() after dequeue_entities()).
Results using stress-ng 0.15.06 pipe stressor (4 workers, 20s):
Kernel Clock pipe bogo ops/s delta vs. 6.6 ----------------------------------- -------- ---------------- ------------- 6.6.78-v8-16k+ 2400 MHz 2 129 330 +/-0% (ref) 6.6.78-v8-16k+ 2800 MHz 2 487 746 +/-0% (ref) 7.0.0-v8-16k+ stock 2400 MHz 1 694 011 -20.5% 7.0.0-v8-16k+ stock 2800 MHz 1 851 567 -25.6% 7.0.0 + ttwu only (10 patches) 2400 MHz 1 836 006 -13.8% 7.0.0 + ttwu only (10 patches) 2800 MHz 1 934 076 -22.3% 7.0.0 + ttwu + patch 12/13 only 2400 MHz 2 054 879 -3.5% 7.0.0 + ttwu + patch 12/13 only 2800 MHz 2 415 617 -2.9% 7.0.0 + ttwu + patches 12+13 2400 MHz 1 996 002 -6.3% 7.0.0 + ttwu + patches 12+13 2800 MHz 2 342 144 -5.9%
The key finding: patch 12/13 alone outperforms the combined set on ARM. Adding patch 13/13 actually hurts performance slightly -- about 3 percentage points -- at both clock speeds. This suggests that sched/pelt: Always allow load updates has a negative interaction on ARM/Cortex-A76, possibly related to how PELT decay is handled without schedutil active, or an ARM-specific DELAY_DEQUEUE interaction.
Patch 12/13 alone closes the gap to just -2.9% vs. 6.6 at 2800 MHz (OC), and -3.5% at nominal 2400 MHz. That is a remarkable recovery from the -31.9% regression in 7.0 stock.
Regarding Perfetto traces:
Unfortunately I cannot provide sched-analyzer traces at this time -- the kernel is not compiled with CONFIG_DEBUG_INFO_BTF=y (pahole/dwarves not available in this build environment), which is required for BPF CO-RE. I can try to arrange that for a future run if it would still be useful.
Device: Raspberry Pi 5 (8 GB, C1-stepping), Bookworm arm64, kernel rpi-7.0.y.
Background: https://github.com/raspberrypi/linux/issues/7308
Tom
Quoted 10 lines · Tom Gebhardt
Hi Qais,
Thanks for the follow-up. Here are the patch isolation results and answers to your questions.
Regarding the governor:
Yes, I'm running
ondemand, notschedutil. My mistake for not mentioning that upfront - I assumed the improvement was due to theutil_estpath being triggered regardless of the governor. The improvement is clearly measurable even withondemand, which is surprising given that your patches specifically targetschedutil.
Something is wrong, as Qais mentioned raspberry pi (SMP) with ondemand shouldn't be affected by util_est changes. In particular with 4 mostly-running workers and 4 CPUs.
Does patch 12 also show similar effects with powersave/performance cpufreq governor? Qais also split patch 12 out separately and Vincent posted a fix, care to give that a try?
https://lore.kernel.org/lkml/agRyoe1wHyZ-vMk9@vingu-cube/
Thanks for testing these, I'll try to reproduce what you're seeing, too.
Quoted 1 line
[snip]
Hi Christian,
Good point -- I ran additional tests with performance and ondemand governors side by side on the same kernel (7.0.0 + ttwu + patch 12 only):
Clock Governor pipe bogo ops/s -------- ------------ ---------------- 2400 MHz performance 2 095 187 2400 MHz ondemand 2 093 221 2800 MHz performance 2 415 817 2800 MHz ondemand 2 415 617
The difference between governors is <0.1% -- well within noise. So you are
right: the effect is not cpufreq-related. Whatever patch 12 changes, it affects the scheduler path directly, not through frequency selection.
I also applied Vincent's fix [1] and benchmarked it:
Kernel Clock pipe bogo ops/s Δ vs. 6.6.78 ---------------------- -------- ---------------- ------------ 6.6.78 2400 MHz 2 129 330 ±0% 6.6.78 2800 MHz 2 487 746 ±0% 7.0 + ttwu + patch 12 2400 MHz 2 093 221 −1.7% 7.0 + ttwu + patch 12 2800 MHz 2 415 617 −2.9% 7.0 + ttwu + Vincent 2400 MHz 2 077 526 −2.4% 7.0 + ttwu + Vincent 2800 MHz 2 458 151 −1.2%
Vincent's fix gets very close to 6.6 at 2800 MHz (−1.2%) and is similar to patch 12 at 2400 MHz. Both are a large improvement over vanilla 7.0+ttwu (−22% at 2800 MHz) and plain 7.0 stock (−26% at 2800 MHz).
Note: [1] applied with a manual context fixup for the DELAY_DEQUEUE hunk -- the rpi-7.0.y tree's dequeue_entity() differs slightly from mainline in that block (no update_entity_lag() call inside the DELAY_DEQUEUE early-return). The semantic intent of the hunk was preserved.
[1] https://lore.kernel.org/lkml/agRyoe1wHyZ-vMk9@vingu-cube/
Thanks for catching that and for offering to reproduce it.
Tom
Quoted 27 lines · Tom Gebhardt
Hi Christian,
Good point -- I ran additional tests with
performanceandondemandgovernors side by side on the same kernel (7.0.0 + ttwu + patch 12 only):Clock Governor pipe bogo ops/s -------- ------------ ---------------- 2400 MHz performance 2 095 187 2400 MHz ondemand 2 093 221 2800 MHz performance 2 415 817 2800 MHz ondemand 2 415 617The difference between governors is <0.1% -- well within noise. So you are
right: the effect is not cpufreq-related. Whatever patch 12 changes, it affects the scheduler path directly, not through frequency selection.I also applied Vincent's fix [1] and benchmarked it:
Kernel Clock pipe bogo ops/s Δ vs. 6.6.78 ---------------------- -------- ---------------- ------------ 6.6.78 2400 MHz 2 129 330 ±0% 6.6.78 2800 MHz 2 487 746 ±0% 7.0 + ttwu + patch 12 2400 MHz 2 093 221 −1.7% 7.0 + ttwu + patch 12 2800 MHz 2 415 617 −2.9% 7.0 + ttwu + Vincent 2400 MHz 2 077 526 −2.4% 7.0 + ttwu + Vincent 2800 MHz 2 458 151 −1.2%
Quoted 3 lines
Vincent's fix gets very close to 6.6 at 2800 MHz (−1.2%) and is similar to patch 12 at 2400 MHz. Both are a large improvement over vanilla 7.0+ttwu (−22% at 2800 MHz) and plain 7.0 stock (−26% at 2800 MHz).
I tried to replicate using orion o6 and offlining all big CPUs leaving
4 little CPUs and an SMP system.
Workload:
for i in $(seq 0 19); do stress-ng --pipe 4 --pipe-ops 5000000 --metrics-brief --timeout 60 ; sleep 60 ; done
Results: (bogo ops/s real time)
7.1-rc3 powersave: 27186.17 ± 813.42
7.1-rc3vingu powersave: 26866.67 ± 899.51
7.1-rc3 performance: 78223.83 ± 4344.88
7.1-rc3vingu performance: 77289.57 ± 3321.10
As expected there's no significant change with Vincent's patch.
I didn't notice anything suspicious in the patch either, looks fine to me. Next suspect is of course some interaction with Peter's ttwu series you've applied. Alternatively you could also push your exact tree somewhere and I'll go and use that myself.
Quoted 11 lines
Note: [1] applied with a manual context fixup for the
DELAY_DEQUEUEhunk -- the rpi-7.0.y tree'sdequeue_entity()differs slightly from mainline in that block (noupdate_entity_lag()call inside theDELAY_DEQUEUEearly-return). The semantic intent of the hunk was preserved.[1] https://lore.kernel.org/lkml/agRyoe1wHyZ-vMk9@vingu-cube/
Thanks for catching that and for offering to reproduce it.
Tom
Hi Christian,
Thanks for trying to replicate -- and your result actually confirms the
picture: without Peter's ttwu series, Vincent's fix has no measurable effect. That's consistent with what I see: the improvement from patch 12 / Vincent's fix only shows up *on top of* the ttwu patches, not standalone.
So the interaction seems to be:
ttwu patches alone → −22% vs. 6.6 at OC ttwu + util_est fix → −1.2% vs. 6.6 at OC (large recovery) vanilla 7.0 (no ttwu) → −26% vs. 6.6 at OC vanilla 7.0 + util_est → no significant change (your result)
This suggests the ttwu series changes something in the dequeue path that exposes the util_est timing issue, and the fix only matters in that context.
I would be happy to push the exact tree so you can reproduce it directly. However, I currently have a hardware issue with the Pi and cannot test or prepare the tree right now. I'll push it to GitHub as soon as I'm back up and let you know here.
Tom
Hi Christian,
Here is the patch I applied on top of rpi-7.0.y:
https://gist.github.com/Kletternaut/640445f82d2c1f50d5b19d2f6803b395
It is a single combined patch containing marioroy's 10-patch ttwu series plus Vincent's util_est refactoring (with a manual context fixup in the DELAY_DEQUEUE hunk -- see previous mail for details).
To reproduce:
git clone https://github.com/raspberrypi/linux.git -b rpi-7.0.y --depth=1 cd linux curl -L https://gist.githubusercontent.com/Kletternaut/640445f82d2c1f50d5b19d2f6803b395/raw/0001-sched-ttwu-patch-series-Vincent-s-util_est-refactori.patch | git apply
The benchmark I used:
stress-ng --pipe 4 --metrics-brief --timeout 20
(stress-ng 0.15.06, 4 workers, 20 s, bogo ops/s real time)
Tom
Quoted 6 lines · Tom Gebhardt
Hi Christian,
Here is the patch I applied on top of rpi-7.0.y:
https://gist.github.com/Kletternaut/640445f82d2c1f50d5b19d2f6803b395
Quoted 9 lines
It is a single combined patch containing marioroy's 10-patch ttwu series plus Vincent's
util_estrefactoring (with a manual context fixup in theDELAY_DEQUEUEhunk -- see previous mail for details).To reproduce:
git clone https://github.com/raspberrypi/linux.git -b rpi-7.0.y --depth=1 cd linux curl -L https://gist.githubusercontent.com/Kletternaut/640445f82d2c1f50d5b19d2f6803b395/raw/0001-sched-ttwu-patch-series-Vincent-s-util_est-refactori.patch | git apply
Unfortunately that branch is not fixed and so the patch doesn't apply :/ What's your base commit?
Hi Christian,
The base commit is:
bb31e96fee23a474a0504a15097d7ee55bed678e
("DTS: set default nvme Host Memory Buffer size to 32MB on BCM2711/2")
So:
git clone https://github.com/raspberrypi/linux.git -b rpi-7.0.y
cd linux
git checkout bb31e96fee23a474a0504a15097d7ee55bed678e
curl -L https://gist.githubusercontent.com/Kletternaut/640445f82d2c1f50d5b19d2f6803b395/raw/0001-sched-ttwu-patch-series-Vincent-s-util_est-refactori.patch | git apply
Sorry for the inconvenience.
Tom
Quoted 37 lines · Tom Gebhardt
Hi Qais,
Thanks for the follow-up. Here are the patch isolation results and answers to your questions.
Regarding the governor:
Yes, I'm running
ondemand, notschedutil. My mistake for not mentioning that upfront - I assumed the improvement was due to theutil_estpath being triggered regardless of the governor. The improvement is clearly measurable even withondemand, which is surprising given that your patches specifically targetschedutil.Patch isolation -- 12/13 only vs. both:
I re-ran the benchmarks with patch 13/13 (
sched/pelt: Always allow load updates) reverted, keeping only patch 12/13 (sched/fair: Call update_util_est() after dequeue_entities()).Results using stress-ng 0.15.06 pipe stressor (4 workers, 20s):
Kernel Clock pipe bogo ops/s delta vs. 6.6 ----------------------------------- -------- ---------------- ------------- 6.6.78-v8-16k+ 2400 MHz 2 129 330 +/-0% (ref) 6.6.78-v8-16k+ 2800 MHz 2 487 746 +/-0% (ref) 7.0.0-v8-16k+ stock 2400 MHz 1 694 011 -20.5% 7.0.0-v8-16k+ stock 2800 MHz 1 851 567 -25.6% 7.0.0 + ttwu only (10 patches) 2400 MHz 1 836 006 -13.8% 7.0.0 + ttwu only (10 patches) 2800 MHz 1 934 076 -22.3% 7.0.0 + ttwu + patch 12/13 only 2400 MHz 2 054 879 -3.5% 7.0.0 + ttwu + patch 12/13 only 2800 MHz 2 415 617 -2.9% 7.0.0 + ttwu + patches 12+13 2400 MHz 1 996 002 -6.3% 7.0.0 + ttwu + patches 12+13 2800 MHz 2 342 144 -5.9%The key finding: patch 12/13 alone outperforms the combined set on ARM. Adding patch 13/13 actually hurts performance slightly -- about 3 percentage points -- at both clock speeds. This suggests that
sched/pelt: Always allow load updateshas a negative interaction on ARM/Cortex-A76, possibly related to how PELT decay is handled withoutschedutilactive, or an ARM-specificDELAY_DEQUEUEinteraction.
Quoted 8 lines
Patch 12/13 alone closes the gap to just -2.9% vs. 6.6 at 2800 MHz (OC), and -3.5% at nominal 2400 MHz. That is a remarkable recovery from the -31.9% regression in 7.0 stock.
Regarding Perfetto traces:
Unfortunately I cannot provide sched-analyzer traces at this time -- the kernel is not compiled with
CONFIG_DEBUG_INFO_BTF=y(pahole/dwarves not available in this build environment), which is required for BPF CO-RE. I can try to arrange that for a future run if it would still be useful.
You don't need to have it enabled in the kernel. I don't need util info, by default if you don't pass any arg it should not cause BPF to be loaded. Note there are binaries in the release page on github, so you don't have to compile it. You can also use regular perfetto command to record a trace and visualize it and the sched-analyzer-pp would be able to analayze it.
I am looking to see if the task placement and running/runnable time pattern has changed significantly to cause the big difference.
It'd be good to perf it too. You might be hitting weird contention that the patch just happens to accidentally hide.
Quoted 5 lines
Device: Raspberry Pi 5 (8 GB, C1-stepping), Bookworm arm64, kernel rpi-7.0.y.
Background: https://github.com/raspberrypi/linux/issues/7308Tom
Hi Qais,
Thanks for the clarification on sched-analyzer -- I'll look at the perfetto approach for task placement traces.
In the meantime, I ran perf stat and perf record -g across three kernels at OC (2800 MHz) with ondemand governor, using the same stress-ng pipe workload (4 workers, 20s).
Device: Raspberry Pi 5 (8 GB, C1-stepping, Cortex-A76), Bookworm arm64.
perf stat results:
Metric 6.6.78 7.0 stock 7.0+ttwu+vincent ------------------ --------- ---------- ---------------- bogo ops/s 2 222 639 1 855 066 2 298 965 IPC 1.72 1.47 1.76 branch-misses 625M 1 270M 1 018M context-switches 15 145 738 22 750 121 18 905 924 cache-miss rate 1.58% 1.74% 1.38%
Key observations:
1. IPC drops 14% on 7.0 stock (1.72 -> 1.47). ttwu+vincent recovers it almost completely (1.76, slightly above 6.6). This is a genuine efficiency loss in the scheduler path, not a throughput/clock artifact.
2. Branch mispredictions double on 7.0 stock (+103% vs 6.6). ttwu+vincent reduces them by ~20% vs stock, but +63% above 6.6 remains -- this likely explains the residual ~1% gap after patching.
3. Context switches increase 50% on 7.0 stock. ttwu+vincent brings this down to +25% vs 6.6.
perf report (-g) highlights:
On 6.6, finish_task_switch is barely visible in call graphs. On 7.0 (both stock and patched), it appears prominently at 5-8% of samples, alongside elevated _raw_spin_unlock_irqrestore time. This points to genuine overhead in the context switch completion path, not lock contention between worker tasks.
Regarding the "weird contention accidentally hidden" concern: I don't see evidence for that. The branch miss explosion and IPC drop on 7.0 stock are consistent with more complex/harder-to-predict scheduler control flow (EEVDF decision tree vs. CFS), not with a workload contention pattern that happens to be masked by task placement changes. ttwu+vincent genuinely reduces branch misses and restores IPC -- it doesn't just move the problem.
I'll try to get perfetto traces for the task placement / running vs. runnable time breakdown. Happy to provide the raw perf.data files if useful.
Tom
Quoted 9 lines · Tom Gebhardt
Hi Qais,
Thanks for the clarification on sched-analyzer -- I'll look at the perfetto approach for task placement traces.
In the meantime, I ran
perf statandperf record -gacross three kernels at OC (2800 MHz) withondemandgovernor, using the same stress-ng pipe workload (4 workers, 20s).
Quoted 7 lines
Device: Raspberry Pi 5 (8 GB, C1-stepping, Cortex-A76), Bookworm arm64.
perf stat results:
Metric 6.6.78 7.0 stock 7.0+ttwu+vincent ------------------ --------- ---------- ---------------- bogo ops/s 2 222 639 1 855 066 2 298 965
7.0+ttwu+vincent is the best, right?
Have you verified your actual workload is seeing benefit? I think when I scanned the github bug you references the original report was observing a regression in some real setup, not this stressng tests. I am wary some of these stress tests don't necessarily represent real cases as it can over stress a particular scenario and amplify minor problems that have no noticeable impact in practice.
Quoted 10 lines
IPC 1.72 1.47 1.76 branch-misses 625M 1 270M 1 018M context-switches 15 145 738 22 750 121 18 905 924 cache-miss rate 1.58% 1.74% 1.38%Key observations:
1. IPC drops 14% on 7.0 stock (1.72 -> 1.47). ttwu+vincent recovers it almost completely (1.76, slightly above 6.6). This is a genuine efficiency loss in the scheduler path, not a throughput/clock artifact.
Due to stalling you reckon?
Quoted 4 lines
2. Branch mispredictions double on 7.0 stock (+103% vs 6.6). ttwu+vincent reduces them by ~20% vs stock, but +63% above 6.6 remains -- this likely explains the residual ~1% gap after patching.
I might not be reading the numbers correctly but they seem higher
Quoted 3 lines
3. Context switches increase 50% on 7.0 stock. ttwu+vincent brings this down to +25% vs 6.6.
I hope that is something perfetto trace will help visualize the pattern that lead to this higher context switching
Quoted 8 lines
perf report (-g) highlights:
On 6.6,
finish_task_switchis barely visible in call graphs. On 7.0 (both stock and patched), it appears prominently at 5-8% of samples, alongside elevated_raw_spin_unlock_irqrestoretime. This points to genuine overhead in the context switch completion path, not lock contention between worker tasks.
Do you have the full (well, most relevant parts of it) output? It would be interesting to use perf diff to see the difference of 7.0 stock vs 6.6 and 7.0+ttwu+vincent vs 6.6.
Maybe there's higher rq lock contention. But this finish_task_switch and __raw_spin_unlock_irqrestore are common to see, especially when there's high context switch rate. It might not necessarily indicate there's a problem.
Quoted 7 lines
Regarding the "weird contention accidentally hidden" concern: I don't see evidence for that. The branch miss explosion and IPC drop on 7.0 stock are consistent with more complex/harder-to-predict scheduler control flow (EEVDF decision tree vs. CFS), not with a workload contention pattern that happens to be masked by task placement changes. ttwu+vincent genuinely reduces branch misses and restores IPC -- it doesn't just move the problem.
Not necessarily a workload contention but a scheduler lock or cache related on a 'hot variable'. See [1] for example. I am hoping perf diff will help see which part has gotten noticeably worse then you can inspect this function to see where in the code the code has gotten slower; hopefully this can shed some light how this unrelated patch is helping..
[1] https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
I'll try to get perfetto traces for the task placement / running vs. runnable time breakdown. Happy to provide the raw perf.data files if useful.
Tom
Quoted 1 line · Qais Yousef
7.0+ttwu+vincent is the best, right?
Yes.
Quoted 3 lines
Have you verified your actual workload is seeing benefit? I think when I scanned the github bug you references the original report was observing a regression in some real setup, not this stressng tests.
I am the reporter. The original issue (#7308) was observed as a drop in camera frame rate when running two parallel IMX477 streams via libcamera on RPi5 under kernel 6.12+. The camera pipeline is pipe-IPC-heavy (GStreamer / libcamera internal queues), so the regression surfaced there first in a real workload. To isolate the cause I moved to synthetic pipe benchmarks (stress-ng), which confirmed and quantified the regression cleanly. A Raspberry Pi developer (popcornmix) also posted IPC benchmark results on the issue, independently confirming the trend across kernel versions (6.6=2065 > 6.18=1805 > 6.12=1662 > 7.0=1570 Kops/s).
The stress-ng pipe stressor is therefore not an artificial worst-case -- it directly exercises the code path that causes the real-world camera regression. That said, I agree stress-ng amplifies the effect, and I cannot give you an exact frame-rate number yet with the ttwu+vincent patches applied.
Quoted 1 line
IPC drops 14% on 7.0 stock. Due to stalling you reckon?
Yes. The branch misprediction rate explains most of it. On Cortex-A76 a branch mispredict costs ~13 cycles. Normalised by instruction count:
Kernel branch-miss rate vs 6.6 ----------------- ----------------- ------ 6.6.78 0.178% ref 7.0.0 stock 0.427% +140% 7.0.0+ttwu+vincent 0.271% +52%
The raw counts I reported yesterday were misleading because the instruction counts differ between kernels (different amounts of useful work). Apologies for not normalising upfront. The rate tells a cleaner story: stock EEVDF causes 2.4× more mispredictions per instruction than CFS, and ttwu+vincent brings that down to 1.5× -- significant improvement but not full recovery.
Quoted 1 line
Do you have the full output? It would be interesting to use perf diff.
A proper perf diff with resolved kernel symbols requires running against the matching kernel. I ran perf report --no-children -s symbol on each .data file while booted on the corresponding kernel. Key findings:
7.0.0 stock (flat, self-overhead):
12.98% finish_task_switch.isra.0
-> __schedule -> schedule
-> anon_pipe_read 5.72%
-> anon_pipe_write 1.38%7.0.0+ttwu+vincent (flat, self-overhead):
19.62% finish_task_switch.isra.0
-> __schedule -> schedule
-> anon_pipe_read 8.22%
-> anon_pipe_write 4.34%The striking difference is in the pipe_write -> schedule() path: 1.38% on stock vs 4.34% with ttwu+vincent. The ttwu patches make pipe writers yield the CPU far more aggressively after each write, allowing the reader to run immediately. Stock EEVDF leaves this to the scheduler's own timing, which results in more latency and lower throughput.
The higher absolute percentage in finish_task_switch for vincent is expected:
vincent completes ~24% more pipe operations in the same wall time, so there are proportionally more context switches completing.
On 6.6 (from the call-graph profile recorded separately), finish_task_switch is not visible as a top-level hotspot at all -- consistent with CFS handling this path much more efficiently.
Quoted 3 lines
Maybe there's higher rq lock contention. But this
finish_task_switchand__raw_spin_unlock_irqrestoreare common to see, especially when there's high context switch rate.
Agreed -- I cannot rule out rq lock contention without perf diff with matched build-IDs. The pattern I see (finish_task_switch dominant, driven by pipe_read/write) is consistent with high context switch rate rather than a pathological lock. But your point about a 'hot variable' like rq->clock is noted -- I cannot confirm or deny that from flat profiles alone.
Quoted 2 lines
I hope perfetto trace will help visualize the pattern that led to this higher context switching.
I will work on getting a perfetto trace. Expecting to have that in a follow-up.
Tom
Quoted 10 lines · Tom Gebhardt
Quoted 1 line · Qais Yousef
7.0+ttwu+vincent is the best, right?
Yes.
Quoted 3 lines
Have you verified your actual workload is seeing benefit? I think when I scanned the github bug you references the original report was observing a regression in some real setup, not this stressng tests.
I am the reporter. The original issue (#7308) was observed as a drop in
Yes, I realized, thanks for taking the time to chase all of this :)
Quoted 8 lines
camera frame rate when running two parallel IMX477 streams via libcamera on RPi5 under kernel 6.12+. The camera pipeline is pipe-IPC-heavy (GStreamer / libcamera internal queues), so the regression surfaced there first in a real workload. To isolate the cause I moved to synthetic pipe benchmarks (stress-ng), which confirmed and quantified the regression cleanly. A Raspberry Pi developer (popcornmix) also posted IPC benchmark results on the issue, independently confirming the trend across kernel versions (6.6=2065 > 6.18=1805 > 6.12=1662 > 7.0=1570 Kops/s).
I was wondering if the real workload is as sensitive
Quoted 5 lines
The stress-ng pipe stressor is therefore not an artificial worst-case -- it directly exercises the code path that causes the real-world camera regression. That said, I agree stress-ng amplifies the effect, and I cannot give you an exact frame-rate number yet with the ttwu+vincent patches applied.
No worries, don't want to ask you to do more work ;-)
Quoted 11 lines
Quoted 2 lines
IPC drops 14% on 7.0 stock. Due to stalling you reckon?
Yes. The branch misprediction rate explains most of it. On Cortex-A76 a branch mispredict costs ~13 cycles. Normalised by instruction count:
Kernel branch-miss rate vs 6.6 ----------------- ----------------- ------ 6.6.78 0.178% ref 7.0.0 stock 0.427% +140% 7.0.0+ttwu+vincent 0.271% +52%
This could potentially be due to the higher ctx switches
Quoted 6 lines
The raw counts I reported yesterday were misleading because the instruction counts differ between kernels (different amounts of useful work). Apologies for not normalising upfront. The rate tells a cleaner story: stock EEVDF causes 2.4× more mispredictions per instruction than CFS, and ttwu+vincent brings that down to 1.5× -- significant improvement but not full recovery.
Note 6.6 kernels are EEVDF too.
Quoted 21 lines
Quoted 2 lines
Do you have the full output? It would be interesting to use perf diff.
A proper perf diff with resolved kernel symbols requires running against the matching kernel. I ran
perf report --no-children -s symbolon each .data file while booted on the corresponding kernel. Key findings:7.0.0 stock (flat, self-overhead):
12.98% finish_task_switch.isra.0
-> __schedule -> schedule -> anon_pipe_read 5.72% -> anon_pipe_write 1.38%7.0.0+ttwu+vincent (flat, self-overhead):
19.62% finish_task_switch.isra.0
-> __schedule -> schedule -> anon_pipe_read 8.22% -> anon_pipe_write 4.34%
Quoted 5 lines
The striking difference is in the
pipe_write->schedule()path: 1.38% on stock vs 4.34% with ttwu+vincent. The ttwu patches make pipe writers yield the CPU far more aggressively after each write, allowing the reader to run immediately. Stock EEVDF leaves this to the scheduler's own timing, which results in more latency and lower throughput.
I collected a trace for stress-ng --pipe 2 on a 2 CPU system (6.8 kernel) and I can see it ends up with 4 tasks, 2 almost always running and 2 that sleep and wake up, rather rapidly.
stress-ng 1: 58% RUNNING, 41% RUNNABLE, ~1% sleeping stress-ng 2: 41.5% RUNNING, 58.5% RUNNABLE, ~1% sleeping stress-ng 3: 40.1% RUNNING, 22.2% RUNNABLE, ~37.6% sleeping stress-ng 4: 59.9% RUNNING, 21.7% RUNNABLE, ~18.5% sleeping
The avg RUNNING time of these tasks is few 10s of us and min is 100s of ns..
It seems the tasks are pinned too, 2 per cpu.
I hope your real workload doesn't behave this way, this is very inefficient :)
Quoted 8 lines
The higher absolute percentage in
finish_task_switchfor vincent is expected:
vincent completes ~24% more pipe operations in the same wall time, so there are proportionally more context switches completing.On 6.6 (from the call-graph profile recorded separately),
finish_task_switchis not visible as a top-level hotspot at all -- consistent with CFS handling this path much more efficiently.
It could also be about the wakeup preemption pattern. The pattern I see is that one task wakes up runs for a bit before the other tasks wakes up rapidly for 4 times. The first 3 it preempts with ~0.5us but the last one it waits behind the original task until it sleeps which takes ~9us.
If I do
echo NO_WAKEUP_PREEMPTION | sudo tee /sys/kernel/debug/features
I can see the bogo ops/s jump by 16%.
The two tasks now interleave equally and the tasks that had ~1% sleeping time now go up to 7 and 10% of sleeping time.
You can achieve the same outcome by running as SCHED_BATCH
chrt -b 0 stress-ng --pipe 4 --timeout 20s --metrics-brief
Quoted 18 lines
Quoted 4 lines
Maybe there's higher rq lock contention. But this
finish_task_switchand__raw_spin_unlock_irqrestoreare common to see, especially when there's high context switch rate.Agreed -- I cannot rule out rq lock contention without perf diff with matched build-IDs. The pattern I see (
finish_task_switchdominant, driven by pipe_read/write) is consistent with high context switch rate rather than a pathological lock. But your point about a 'hot variable' likerq->clockis noted -- I cannot confirm or deny that from flat profiles alone.Quoted 2 lines
I hope perfetto trace will help visualize the pattern that led to this higher context switching.
I will work on getting a perfetto trace. Expecting to have that in a follow-up.
Tom