diff mbox series

[3/4] sched: cpufreq: Move apply_dvfs_headroom() to sched.h

Message ID 20230820210640.585311-4-qyousef@layalina.io (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series Fix dvfs_headroom escaping uclamp constraints | expand

Commit Message

Qais Yousef Aug. 20, 2023, 9:06 p.m. UTC
This function relies on updating util signal appropriately to give
a headroom to grow. This is more of a scheduler functionality than
cpufreq. Move it to sched.h where all the other util handling code
belongs.

Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io>
---
 include/linux/sched/cpufreq.h | 30 ------------------------------
 kernel/sched/sched.h          | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 30 deletions(-)

Comments

Dietmar Eggemann Aug. 21, 2023, 4:40 p.m. UTC | #1
On 20/08/2023 23:06, Qais Yousef wrote:
> This function relies on updating util signal appropriately to give
> a headroom to grow. This is more of a scheduler functionality than
> cpufreq. Move it to sched.h where all the other util handling code
> belongs.

To me map_util_freq() is the power counterpart to fits_capacity()
[fair.c] which is used in schedutil (cpufreq) and EM to do the same*
thing as EAS in the task scheduler (fair.c).

* With the already (PATCH 1/4) mentioned difference that EAS deals with
`util_cfs` vs `capacity` whereas power deals with `util` vs `capacity_orig`.

[...]
diff mbox series

Patch

diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h
index f0069b354ac8..d01755d3142f 100644
--- a/include/linux/sched/cpufreq.h
+++ b/include/linux/sched/cpufreq.h
@@ -28,36 +28,6 @@  static inline unsigned long map_util_freq(unsigned long util,
 {
 	return freq * util / cap;
 }
-
-/*
- * 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.
- *
- * TODO: The headroom should be a function of the delay. 25% is too high
- * especially on powerful systems. For example, if the delay is 500us, it makes
- * more sense to give a small headroom as the next decision point is not far
- * away and will follow the util if it continues to rise. On the other hand if
- * the delay is 10ms, then we need a bigger headroom so the CPU won't struggle
- * at a lower frequency if it never goes to idle until then.
- */
-static inline unsigned long apply_dvfs_headroom(unsigned long util)
-{
-	return util + (util >> 2);
-}
-#else
-static inline unsigned long apply_dvfs_headroom(unsigned long util)
-{
-	return util;
-}
 #endif /* CONFIG_CPU_FREQ */
 
 #endif /* _LINUX_SCHED_CPUFREQ_H */
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 3a01b7a2bf66..56eeb5b05b50 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2997,6 +2997,30 @@  enum cpu_util_type {
 unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
 				 enum cpu_util_type type,
 				 struct task_struct *p);
+/*
+ * 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.
+ *
+ * TODO: The headroom should be a function of the delay. 25% is too high
+ * especially on powerful systems. For example, if the delay is 500us, it makes
+ * more sense to give a small headroom as the next decision point is not far
+ * away and will follow the util if it continues to rise. On the other hand if
+ * the delay is 10ms, then we need a bigger headroom so the CPU won't struggle
+ * at a lower frequency if it never goes to idle until then.
+ */
+static inline unsigned long apply_dvfs_headroom(unsigned long util)
+{
+	return util + (util >> 2);
+}
 
 /*
  * Verify the fitness of task @p to run on @cpu taking into account the