mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 00/10] Better manage system response time
@ 2026-11-26  5:14 Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 01/10] sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom Qais Yousef
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

v1 discussion: https://lore.kernel.org/lkml/20240820163512.1096301-1-qyousef@layalina.io/
v2 discussion: https://lore.kernel.org/all/20260504020003.71306-1-qyousef@layalina.io/

I hope this is now in good shape for considering for inclusion.

v1 cover letter has the full details for those interested with the full
background, link available above. LPC discussion from 2024 is available
in [1].

Major changes in this series is dropping the sched_qos interface as this
will be taken on its own discussion now. I also moved away from sysctl
to debugfs interface for setting default rampup_multiplier. Along with
new debugfs entries for fits_capacity_threshold for each CPU to help
understand how these values end up being on different systems if we need
to debug them.

Code changes required reworking how we do the util_est_update_running()
and introduce new running arg to util_est_update(). But other than that
it is exactly the same.

I should have addressed all review comments from last round too,
particularly from Vincent to use us for approximate_runtime() and ensure
that fits_capacity_threshold is updated once; which I attached to
build_sched_domains().

Users can retain the old behavior with these commands (except for
fits_capacity_threshold which I think the new behavior is correct)

	echo 0 | sudo tee /sys/kernel/debug/sched/rampup_multiplier
	echo CONST_DVFS_HEADROOM | sudo tee /sys/kernel/debug/sched/features
	echo NO_UTIL_EST_RAMPUP_ZERO | sudo tee /sys/kernel/debug/sched/features
	echo UTIL_EST_FORCE_POST_INIT | sudo tee /sys/kernel/debug/sched/features

A branch of the changes along side with the sched_qos interface is
available here:

	git clone https://github.com/qais-yousef/linux -b schedqos

schedqos utility [2] has support for this interface on ToT and will
allow per-task control of rampup multiplier to get different response
time for different tasks which is key to get best results in terms of
perf and power. Look at configs/qos_mappings.json - sudo make install
and sudo schedqos restart --daemon.

Testing on 8 CPU SMT2 Ryzen 7 Speedometer 3.1 on Chrome I get the
following results (5 iterations)

tip amd pstate:

	23.3 23.7 23.5 23.9 24.0
	avg: 23.68

tip schedutil:

	20.7 20.5 20.8 20.9 20.3
	avg: 20.64

tip + patch amd pstate:

	23.1 23.9 24.0 23.9 23.8
	avg: 23.74

tip + patch schedutil:

rampup 0:
	13.2 13.2 13.4 13.4 13.2
	avg: 13.28

rampup 1:
	17.5 17.6 17.6 17.7 17.7
	avg: 17.62

rampup 2:
	20.7 20.7 20.6 20.9 20.8
	avg: 20.74

rampup 3:
	21.7 22.0 21.7 21.8 21.5
	avg: 21.74

rampup 4:
	22.5 22.3 22.7 22.4 22.3
	avg: 22.44

rampup 5:
	22.8 22.9 22.8 22.6 22.9
	avg: 22.8

rampup 6:
	23.1 23.1 23.2 23.1 23.2
	avg: 23.14

rampup 7:
	23.4 23.5 23.6 23.4 23.3
	avg: 23.44

rampup 8:
	23.5 23.6 23.5 24.3 24.3
	avg: 23.84

disable cmds (retain old behavior):

	20.7 20.5 20.3 20.5
	avg: 20.5

Notes:
	- rampup 0 and 1 are slower since we no longer have the
	  aggressive const 1.25% dvfs headroom although util signal
	  rises faster for 1. For 0 util_est is completely disabled.
	- rampup 2 we get parity with schedutil.
	- Rampup 8 gives parity with amd pstate behavior, too aggressive
	  for perf. We cross 23 barrier on rampup 6.
	- For rampup 8, battery got low and last 2 iterations ran with
	  power plugged into laptop and this lead to higher score.. Some
	  fimware magic I wasn't aware of and since it was a tedious
	  task I didn't re-run with power plugged.
	- Only 4 iterations for disable cmds

I picked the default rampup_multiplier to be 4 based on this results.
There's power trade-off to be had with different values which I can't
evaluate. Having a per task sched_qos interface to set these values
- which is the intention and final goal - makes this trade-off a lot
easier to be made since as you can see rampup 1 and 0 will get slower
behavior.

This result is based on few weeks old tip/sched/core. Current
tip/sched/core has runnable_avg bug that causes schedutil to run at max
all the time. I managed to workaround it and numbers look different
(higher) but I think the result above are more or less correct in terms
of rampup multiplier value to get parity. Once this bug is fixed I'll
recollect the data.

[1] https://lpc.events/event/18/contributions/1880/
[2] https://github.com/qais-yousef/schedqos

Qais Yousef (10):
  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/debugfs: Add rampup_multiplier to debugfs
  sched/fair: Disable util_est when rampup_multiplier is 0
  sched/fair: Don't mess with util_avg post init

 include/linux/sched.h            |   3 +
 include/linux/sched/cpufreq.h    |   5 --
 kernel/sched/core.c              |   5 ++
 kernel/sched/cpufreq_schedutil.c |  41 +++++++++++-
 kernel/sched/debug.c             |  12 +++-
 kernel/sched/fair.c              | 107 ++++++++++++++++++++++++++++---
 kernel/sched/features.h          |  21 ++++++
 kernel/sched/pelt.c              |  44 +++++++++++++
 kernel/sched/sched.h             |  38 +++++++++++
 kernel/sched/topology.c          |   1 +
 10 files changed, 259 insertions(+), 18 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 01/10] sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 02/10] sched/pelt: Add a new function to approximate the future util_avg value Qais Yousef
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef,
	Christian Loehle

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.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 include/linux/sched/cpufreq.h    |  5 -----
 kernel/sched/cpufreq_schedutil.c | 20 +++++++++++++++++++-
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h
index bdd31ab93bc51..d01755d3142f1 100644
--- a/include/linux/sched/cpufreq.h
+++ b/include/linux/sched/cpufreq.h
@@ -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 */
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 14405a6149911..4d781b394baa8 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -230,12 +230,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;
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 02/10] sched/pelt: Add a new function to approximate the future util_avg value
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 01/10] sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util Qais Yousef
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

Given 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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/pelt.c  | 20 ++++++++++++++++++++
 kernel/sched/sched.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
index d10d57b6b8ec7..0870fced6ac04 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -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 || util >= SCHED_CAPACITY_SCALE))
+		return util;
+
+	accumulate_sum(delta, &sa, 1, 0, 1);
+	___update_load_avg(&sa, 0);
+
+	return sa.util_avg;
+}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 32f76551a0c5e..e3108a241c12b 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3777,6 +3777,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
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 01/10] sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 02/10] sched/pelt: Add a new function to approximate the future util_avg value Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26 10:50   ` Li kunyu
  2026-11-26  5:14 ` [PATCH v3 04/10] sched/fair: Remove magic hardcoded margin in fits_capacity() Qais Yousef
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, 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 <qyousef@layalina.io>
---
 kernel/sched/pelt.c  | 24 ++++++++++++++++++++++++
 kernel/sched/sched.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
index 0870fced6ac04..7adb329a2f919 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -508,3 +508,27 @@ unsigned long approximate_util_avg(unsigned long util, u64 delta)
 
 	return sa.util_avg;
 }
+
+/*
+ * Approximate the required amount of runtime in us 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;
+
+	if (unlikely(WARN_ON_ONCE(util > SCHED_CAPACITY_SCALE)))
+		util = SCHED_CAPACITY_SCALE;
+
+	while (sa.util_avg < util) {
+		accumulate_sum(delta, &sa, 1, 0, 1);
+		___update_load_avg(&sa, 0);
+		runtime++;
+	}
+
+	return runtime * 1024;
+}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e3108a241c12b..50cf07c364727 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3778,6 +3778,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.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 04/10] sched/fair: Remove magic hardcoded margin in fits_capacity()
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (2 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 05/10] sched: cpufreq: Remove magic 1.25 headroom from sugov_apply_dvfs_headroom() Qais Yousef
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, 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.

On many systems the little cores are under powered and the 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 tick 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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/core.c     |  1 +
 kernel/sched/debug.c    | 10 +++++++++-
 kernel/sched/fair.c     | 15 +++++++++------
 kernel/sched/sched.h    | 26 ++++++++++++++++++++++++++
 kernel/sched/topology.c |  1 +
 5 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ea89471d4743c..5dd53cef22117 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9071,6 +9071,7 @@ void __init sched_init(void)
 		RCU_INIT_POINTER(rq->sd, NULL);
 		RCU_INIT_POINTER(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;
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 869bea87d2ce0..94e65208807dd 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -736,7 +736,8 @@ static __init void debugfs_cpu_init(void)
 
 static __init int sched_init_debug(void)
 {
-	struct dentry __maybe_unused *numa, *llc;
+	struct dentry __maybe_unused *numa, *llc, *fct;
+	int cpu;
 
 	debugfs_sched = debugfs_create_dir("sched", NULL);
 
@@ -785,6 +786,13 @@ static __init int sched_init_debug(void)
 			   &llc_imb_pct);
 #endif
 
+	fct = debugfs_create_dir("fits_capacity_threshold", debugfs_sched);
+	for_each_possible_cpu(cpu) {
+		char name[16] = {};
+		sprintf(name, "cpu%d", cpu);
+		debugfs_create_ulong(name, 0644, fct, &cpu_rq(cpu)->fits_capacity_threshold);
+	}
+
 	debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 731d78155e654..e92b923b769ac 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -103,11 +103,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 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.
@@ -6213,14 +6217,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;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 50cf07c364727..f4e6e85d45a07 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1324,6 +1324,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 */
@@ -3780,6 +3781,31 @@ 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);
 
+static inline void update_fits_capacity_threshold(int cpu)
+{
+	struct rq *rq = cpu_rq(cpu);
+	u64 limit;
+
+	/*
+	 * 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.
+	 *
+	 * If capacity is too small that limit is less than TICK_USEC, this is
+	 * bad configuration and we'd have to skip this CPU always from
+	 * performance point of view.
+	 */
+	limit = approximate_runtime(arch_scale_cpu_capacity(cpu));
+	limit = limit > TICK_USEC ? limit - TICK_USEC : 0;
+	rq->fits_capacity_threshold = approximate_util_avg(0, limit);
+}
+
 /*
  * 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.
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 99878da03bce7..53ba488955a28 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -842,6 +842,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
 	destroy_sched_domains(tmp);
 
 	update_top_cache_domain(cpu);
+	update_fits_capacity_threshold(cpu);
 }
 
 struct s_data {
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 05/10] sched: cpufreq: Remove magic 1.25 headroom from sugov_apply_dvfs_headroom()
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (3 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 04/10] sched/fair: Remove magic hardcoded margin in fits_capacity() Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 06/10] sched/fair: Extend util_est to improve rampup time Qais Yousef
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

Replace 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
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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/core.c              |  1 +
 kernel/sched/cpufreq_schedutil.c | 31 +++++++++++++++++++++++++------
 kernel/sched/features.h          |  6 ++++++
 kernel/sched/sched.h             |  9 +++++++++
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5dd53cef22117..97d3cceba22c0 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -128,6 +128,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_server_start_tp);
 EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_server_stop_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
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 4d781b394baa8..04d0182759609 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -239,13 +239,25 @@ 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 TICK_USEC, whichever is higher.
  *
- * At the moment it is a constant multiplication with 1.25.
+ * Ideally we should pick max(dvfs_updae_delay, min(curr.se.slice, TICK_USEC)),
+ * but reading curr.se.slice requires holding the rq_lock which is hard/not
+ * feasible.
+ *
+ * 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);
+	u64 delay;
+
+	if (sched_feat(CONST_DVFS_HEADROOM))
+		return util + (util >> 2);
+
+	delay = max(TICK_USEC, per_cpu(dvfs_update_delay, cpu));
+
+	return approximate_util_avg(util, delay);
 }
 
 unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual,
@@ -253,7 +265,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;
@@ -642,15 +654,20 @@ rate_limit_us_store(struct gov_attr_set *attr_set, const char *buf, size_t count
 	struct 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) {
 		sugov_update_rate_limit_us(sg_policy);
 
+		for_each_cpu(cpu, sg_policy->policy->cpus)
+			per_cpu(dvfs_update_delay, cpu) = rate_limit_us;
+	}
+
 	return count;
 }
 
@@ -913,6 +930,8 @@ 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;
 	}
 
 	/*
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index 8f0dee8fc4755..500ece3e341fe 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -142,3 +142,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)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index f4e6e85d45a07..27c18701de35c 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3806,6 +3806,15 @@ static inline void update_fits_capacity_threshold(int cpu)
 	rq->fits_capacity_threshold = approximate_util_avg(0, limit);
 }
 
+/*
+ * 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.
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 06/10] sched/fair: Extend util_est to improve rampup time
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (4 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 05/10] sched: cpufreq: Remove magic 1.25 headroom from sugov_apply_dvfs_headroom() Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 07/10] sched/fair: util_est: Take into account periodic tasks Qais Yousef
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

Utilization invariance can cause big delays. When tasks are running,
accumulate non-invariant 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 should
still behave the same at enqueue/dequeue.

Before this patch 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

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 include/linux/sched.h |  1 +
 kernel/sched/core.c   |  1 +
 kernel/sched/fair.c   | 45 +++++++++++++++++++++++++++++++++++++++----
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7cd8df8f463c9..d54117ab4c882 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -588,6 +588,7 @@ struct sched_entity {
 					/* hole */
 
 	u64				exec_start;
+	u64				delta_exec;
 	u64				sum_exec_runtime;
 	u64				prev_sum_exec_runtime;
 	u64				vruntime;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 97d3cceba22c0..b8c0cf9153768 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4669,6 +4669,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;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e92b923b769ac..a8dbd81e71590 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1385,6 +1385,7 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
 		 */
 		running->se.exec_start = now;
 		running->se.sum_exec_runtime += delta_exec;
+		running->se.delta_exec += delta_exec;
 
 		trace_sched_stat_runtime(running, delta_exec);
 		account_group_exec_runtime(running, delta_exec);
@@ -1403,7 +1404,6 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
 		__schedstat_set(stats->exec_max,
 				max(delta_exec, stats->exec_max));
 	}
-
 	return delta_exec;
 }
 
@@ -5980,9 +5980,10 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
 
 #define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100)
 
-static inline void util_est_update(struct sched_entity *se)
+static inline void util_est_update(struct sched_entity *se, bool running)
 {
 	unsigned int ewma, dequeued, last_ewma_diff;
+	struct task_struct *p = task_of(se);
 
 	if (!sched_feat(UTIL_EST))
 		return;
@@ -5990,6 +5991,28 @@ static inline void util_est_update(struct sched_entity *se)
 	/* Get current estimate of utilization */
 	ewma = READ_ONCE(se->avg.util_est);
 
+	/*
+	 * If a task is running, update util_est ignoring utilization
+	 * invariance so that if the task suddenly becomes busy we will rampup
+	 * quickly to settle down to our new util_avg.
+	 */
+	if (running) {
+		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_running;
+	} else {
+		p->se.delta_exec = 0;
+	}
+
 	/*
 	 * If the PELT values haven't changed since enqueue time,
 	 * skip the util_est update.
@@ -6045,6 +6068,7 @@ static inline void util_est_update(struct sched_entity *se)
 	ewma >>= UTIL_EST_WEIGHT_SHIFT;
 done:
 	ewma |= UTIL_AVG_UNCHANGED;
+done_running:
 	WRITE_ONCE(se->avg.util_est, ewma);
 
 	trace_sched_util_est_se_tp(se);
@@ -6102,7 +6126,7 @@ static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
 	}
 
 	if (flags & UPDATE_UTIL_EST)
-		util_est_update(se);
+		util_est_update(se, false);
 }
 
 /*
@@ -6203,6 +6227,14 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
 	trace_sched_util_est_cfs_tp(cfs_rq);
 }
 
+static inline void util_est_update_running(struct cfs_rq *cfs_rq,
+					   struct task_struct *p)
+{
+	util_est_dequeue(cfs_rq, p);
+	util_est_update(&p->se, true);
+	util_est_enqueue(cfs_rq, p);
+}
+
 static inline unsigned long get_actual_cpu_capacity(int cpu)
 {
 	unsigned long capacity = arch_scale_cpu_capacity(cpu);
@@ -10421,8 +10453,11 @@ static void put_prev_task_fair(struct rq *rq, struct task_struct *prev, struct t
 	se = &prev->se;
 	WARN_ON_ONCE(cfs_rq->curr != se);
 	cfs_rq->curr = NULL;
-	if (se->on_rq)
+	if (se->on_rq) {
 		__enqueue_entity(cfs_rq, se);
+		if (!se->sched_delayed)
+			util_est_update_running(cfs_rq, prev);
+	}
 }
 
 /*
@@ -15401,6 +15436,8 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int hrtick)
 		}
 	}
 
+	util_est_update_running(&rq->cfs, curr);
+
 	if (hrtick)
 		return;
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 07/10] sched/fair: util_est: Take into account periodic tasks
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (5 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 06/10] sched/fair: Extend util_est to improve rampup time Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 08/10] sched/debugfs: Add rampup_multiplier to debugfs Qais Yousef
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

The 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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 include/linux/sched.h |  2 ++
 kernel/sched/core.c   |  2 ++
 kernel/sched/fair.c   | 37 ++++++++++++++++++++++++++-----------
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index d54117ab4c882..ea3af512006ad 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -928,6 +928,8 @@ struct task_struct {
 	struct uclamp_se		uclamp[UCLAMP_CNT];
 #endif
 
+	unsigned long			util_avg_dequeued;
+
 	struct sched_statistics         stats;
 
 #ifdef CONFIG_PREEMPT_NOTIFIERS
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b8c0cf9153768..13a66045c5be5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4689,6 +4689,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));
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index a8dbd81e71590..7129347746436 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5980,6 +5980,9 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
 
 #define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100)
 
+static inline unsigned long task_util(struct task_struct *p);
+static inline unsigned long task_util_dequeued(struct task_struct *p);
+
 static inline void util_est_update(struct sched_entity *se, bool running)
 {
 	unsigned int ewma, dequeued, last_ewma_diff;
@@ -5997,18 +6000,22 @@ static inline void util_est_update(struct sched_entity *se, bool running)
 	 * quickly to settle down to our new util_avg.
 	 */
 	if (running) {
-		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_running;
+			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;
 	}
@@ -6023,6 +6030,9 @@ static inline void util_est_update(struct sched_entity *se, bool running)
 	/* Get utilization at dequeue */
 	dequeued = READ_ONCE(se->avg.util_avg);
 
+	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.
@@ -6185,6 +6195,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_util_est(struct task_struct *p)
 {
 	return READ_ONCE(p->se.avg.util_est) & ~UTIL_AVG_UNCHANGED;
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 08/10] sched/debugfs: Add rampup_multiplier to debugfs
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (6 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 07/10] sched/fair: util_est: Take into account periodic tasks Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 09/10] sched/fair: Disable util_est when rampup_multiplier is 0 Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 10/10] sched/fair: Don't mess with util_avg post init Qais Yousef
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

Bursty 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 sysctl_sched_qos_default_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.

This is purely to set the default behavior. The intention is to provide
per task interface later on.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/debug.c | 2 ++
 kernel/sched/fair.c  | 7 ++++++-
 kernel/sched/sched.h | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 94e65208807dd..56d520f076dd4 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -756,6 +756,8 @@ static __init int sched_init_debug(void)
 	debugfs_create_u32("migration_cost_ns", 0644, debugfs_sched, &sysctl_sched_migration_cost);
 	debugfs_create_u32("nr_migrate", 0644, debugfs_sched, &sysctl_sched_nr_migrate);
 
+	debugfs_create_u32("rampup_multiplier", 0644, debugfs_sched, &sysctl_sched_qos_default_rampup_multiplier);
+
 	sched_domains_mutex_lock();
 	update_sched_domain_debugfs();
 	sched_domains_mutex_unlock();
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7129347746436..8af44a20fb423 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -87,6 +87,8 @@ static unsigned int normalized_sysctl_sched_base_slice	= 700000ULL;
 
 __read_mostly unsigned int sysctl_sched_migration_cost	= 500000UL;
 
+__read_mostly unsigned int sysctl_sched_qos_default_rampup_multiplier	= 4;
+
 static int __init setup_sched_thermal_decay_shift(char *str)
 {
 	pr_warn("Ignoring the deprecated sched_thermal_decay_shift= option\n");
@@ -5985,6 +5987,7 @@ static inline unsigned long task_util_dequeued(struct task_struct *p);
 
 static inline void util_est_update(struct sched_entity *se, bool running)
 {
+	unsigned long rampup_multiplier = READ_ONCE(sysctl_sched_qos_default_rampup_multiplier);
 	unsigned int ewma, dequeued, last_ewma_diff;
 	struct task_struct *p = task_of(se);
 
@@ -6006,7 +6009,7 @@ static inline void util_est_update(struct sched_entity *se, bool running)
 			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 * rampup_multiplier);
 			/*
 			 * Keep accumulating delta_exec if it is too small to cause
 			 * a change.
@@ -6074,6 +6077,8 @@ static inline void util_est_update(struct sched_entity *se, bool running)
 	 * 0.25, thus making w=1/4 ( >>= UTIL_EST_WEIGHT_SHIFT)
 	 */
 	ewma <<= UTIL_EST_WEIGHT_SHIFT;
+	if (rampup_multiplier)
+		last_ewma_diff /= rampup_multiplier;
 	ewma  -= last_ewma_diff;
 	ewma >>= UTIL_EST_WEIGHT_SHIFT;
 done:
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 27c18701de35c..eea6129c5cba7 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3270,6 +3270,7 @@ static inline void __attach_tasks(struct rq *rq, struct list_head *tasks)
 
 extern __read_mostly unsigned int sysctl_sched_nr_migrate;
 extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_qos_default_rampup_multiplier;
 
 extern unsigned int sysctl_sched_base_slice;
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 09/10] sched/fair: Disable util_est when rampup_multiplier is 0
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (7 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 08/10] sched/debugfs: Add rampup_multiplier to debugfs Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  2026-11-26  5:14 ` [PATCH v3 10/10] sched/fair: Don't mess with util_avg post init Qais Yousef
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

util_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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/fair.c     | 8 ++++++++
 kernel/sched/features.h | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8af44a20fb423..88072e346aecf 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5994,6 +5994,14 @@ static inline void util_est_update(struct sched_entity *se, bool running)
 	if (!sched_feat(UTIL_EST))
 		return;
 
+	/*
+	 * rampup_multiplier = 0 indicates util_est is disabled.
+	 */
+	if (sched_feat(UTIL_EST_RAMPUP_ZERO) && !rampup_multiplier) {
+		ewma = 0;
+		goto done;
+	}
+
 	/* Get current estimate of utilization */
 	ewma = READ_ONCE(se->avg.util_est);
 
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index 500ece3e341fe..75d9d4595c4de 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -135,6 +135,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)
 
 /*
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 10/10] sched/fair: Don't mess with util_avg post init
  2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
                   ` (8 preceding siblings ...)
  2026-11-26  5:14 ` [PATCH v3 09/10] sched/fair: Disable util_est when rampup_multiplier is 0 Qais Yousef
@ 2026-11-26  5:14 ` Qais Yousef
  9 siblings, 0 replies; 12+ messages in thread
From: Qais Yousef @ 2026-11-26  5:14 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Rafael J. Wysocki,
	Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel, Qais Yousef

The 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.

Signed-off-by: Qais Yousef <qyousef@layalina.io>
---
 kernel/sched/fair.c     | 19 +++++++++++++++++++
 kernel/sched/features.h | 10 ++++++++++
 2 files changed, 29 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 88072e346aecf..bcac1acb6393e 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1303,6 +1303,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:
  *
@@ -1352,6 +1365,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);
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index 75d9d4595c4de..7ca90842d06ab 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -140,6 +140,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)
 
 /*
-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util
  2026-11-26  5:14 ` [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util Qais Yousef
@ 2026-11-26 10:50   ` Li kunyu
  0 siblings, 0 replies; 12+ messages in thread
From: Li kunyu @ 2026-11-26 10:50 UTC (permalink / raw)
  To: Qais Yousef, Ingo Molnar, Peter Zijlstra, Vincent Guittot,
	Rafael J. Wysocki, Viresh Kumar
  Cc: Juri Lelli, Steven Rostedt, John Stultz, Dietmar Eggemann,
	Tim Chen, Chen, Yu C, Thomas Gleixner, linux-kernel

Hi Qais,

On 2026/11/26 13:14, Qais Yousef wrote:
> +
> +/*
> + * Approximate the required amount of runtime in us required to reach @util.
> + */
> +u64 approximate_runtime(unsigned long util)
> +{
> +	struct sched_avg sa = {};
> +	u64 delta = 1024; // period = 1024 = ~1ms

Would it be clearer to name this period as the base unit? A delta of 1024
corresponds to one full period:

u64 period = 1024; /* one period = 1024 delta units */

> +	u64 runtime = 0;
> +
> +	if (unlikely(!util))
> +		return runtime;
> +
> +	if (unlikely(WARN_ON_ONCE(util > SCHED_CAPACITY_SCALE)))
> +		util = SCHED_CAPACITY_SCALE;
> +
> +	while (sa.util_avg < util) {
> +		accumulate_sum(delta, &sa, 1, 0, 1);

accumulate_sum(period, &sa, 1, 0, 1);

> +		___update_load_avg(&sa, 0);
> +		runtime++;
> +	}
> +
> +	return runtime * 1024;

return runtime * period;

> +}

Would the overall effect be better this way? Or is my understanding somewhat off?

-- 
thanks,
kunyu

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-26 10:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  5:14 [PATCH v3 00/10] Better manage system response time Qais Yousef
2026-11-26  5:14 ` [PATCH v3 01/10] sched: cpufreq: Rename map_util_perf to sugov_apply_dvfs_headroom Qais Yousef
2026-11-26  5:14 ` [PATCH v3 02/10] sched/pelt: Add a new function to approximate the future util_avg value Qais Yousef
2026-11-26  5:14 ` [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util Qais Yousef
2026-11-26 10:50   ` Li kunyu
2026-11-26  5:14 ` [PATCH v3 04/10] sched/fair: Remove magic hardcoded margin in fits_capacity() Qais Yousef
2026-11-26  5:14 ` [PATCH v3 05/10] sched: cpufreq: Remove magic 1.25 headroom from sugov_apply_dvfs_headroom() Qais Yousef
2026-11-26  5:14 ` [PATCH v3 06/10] sched/fair: Extend util_est to improve rampup time Qais Yousef
2026-11-26  5:14 ` [PATCH v3 07/10] sched/fair: util_est: Take into account periodic tasks Qais Yousef
2026-11-26  5:14 ` [PATCH v3 08/10] sched/debugfs: Add rampup_multiplier to debugfs Qais Yousef
2026-11-26  5:14 ` [PATCH v3 09/10] sched/fair: Disable util_est when rampup_multiplier is 0 Qais Yousef
2026-11-26  5:14 ` [PATCH v3 10/10] sched/fair: Don't mess with util_avg post init Qais Yousef

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®