]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/fair: Move effective_cpu_util() and effective_cpu_util() in fair.c
authorVincent Guittot <vincent.guittot@linaro.org>
Wed, 4 Sep 2024 09:24:17 +0000 (11:24 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 10 Sep 2024 07:51:14 +0000 (09:51 +0200)
Move effective_cpu_util() and sched_cpu_util() functions in fair.c file
with others utilization related functions.

No functional change.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240904092417.20660-1-vincent.guittot@linaro.org
kernel/sched/fair.c
kernel/sched/syscalls.c

index d697a0a3fc73ca1e6e879b0885ff39dfa7a68f8e..9e19009da48fd4626ef1f86c73dec5f920e3e72a 100644 (file)
@@ -8084,6 +8084,105 @@ static unsigned long cpu_util_without(int cpu, struct task_struct *p)
        return cpu_util(cpu, p, -1, 0);
 }
 
+/*
+ * This function computes an effective utilization for the given CPU, to be
+ * used for frequency selection given the linear relation: f = u * f_max.
+ *
+ * The scheduler tracks the following metrics:
+ *
+ *   cpu_util_{cfs,rt,dl,irq}()
+ *   cpu_bw_dl()
+ *
+ * Where the cfs,rt and dl util numbers are tracked with the same metric and
+ * synchronized windows and are thus directly comparable.
+ *
+ * The cfs,rt,dl utilization are the running times measured with rq->clock_task
+ * which excludes things like IRQ and steal-time. These latter are then accrued
+ * in the IRQ utilization.
+ *
+ * The DL bandwidth number OTOH is not a measured metric but a value computed
+ * based on the task model parameters and gives the minimal utilization
+ * required to meet deadlines.
+ */
+unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
+                                unsigned long *min,
+                                unsigned long *max)
+{
+       unsigned long util, irq, scale;
+       struct rq *rq = cpu_rq(cpu);
+
+       scale = arch_scale_cpu_capacity(cpu);
+
+       /*
+        * Early check to see if IRQ/steal time saturates the CPU, can be
+        * because of inaccuracies in how we track these -- see
+        * update_irq_load_avg().
+        */
+       irq = cpu_util_irq(rq);
+       if (unlikely(irq >= scale)) {
+               if (min)
+                       *min = scale;
+               if (max)
+                       *max = scale;
+               return scale;
+       }
+
+       if (min) {
+               /*
+                * The minimum utilization returns the highest level between:
+                * - the computed DL bandwidth needed with the IRQ pressure which
+                *   steals time to the deadline task.
+                * - The minimum performance requirement for CFS and/or RT.
+                */
+               *min = max(irq + cpu_bw_dl(rq), uclamp_rq_get(rq, UCLAMP_MIN));
+
+               /*
+                * When an RT task is runnable and uclamp is not used, we must
+                * ensure that the task will run at maximum compute capacity.
+                */
+               if (!uclamp_is_used() && rt_rq_is_runnable(&rq->rt))
+                       *min = max(*min, scale);
+       }
+
+       /*
+        * Because the time spend on RT/DL tasks is visible as 'lost' time to
+        * CFS tasks and we use the same metric to track the effective
+        * utilization (PELT windows are synchronized) we can directly add them
+        * to obtain the CPU's actual utilization.
+        */
+       util = util_cfs + cpu_util_rt(rq);
+       util += cpu_util_dl(rq);
+
+       /*
+        * The maximum hint is a soft bandwidth requirement, which can be lower
+        * than the actual utilization because of uclamp_max requirements.
+        */
+       if (max)
+               *max = min(scale, uclamp_rq_get(rq, UCLAMP_MAX));
+
+       if (util >= scale)
+               return scale;
+
+       /*
+        * There is still idle time; further improve the number by using the
+        * IRQ metric. Because IRQ/steal time is hidden from the task clock we
+        * need to scale the task numbers:
+        *
+        *              max - irq
+        *   U' = irq + --------- * U
+        *                 max
+        */
+       util = scale_irq_capacity(util, irq, scale);
+       util += irq;
+
+       return min(scale, util);
+}
+
+unsigned long sched_cpu_util(int cpu)
+{
+       return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL);
+}
+
 /*
  * energy_env - Utilization landscape for energy estimation.
  * @task_busy_time: Utilization contribution by the task for which we test the
index 4fae3cf25a3a2dac0a5b906fe1911f0bbca7dc8d..c62acf509b748599c5dd92cdbbae6da510c40964 100644 (file)
@@ -258,107 +258,6 @@ int sched_core_idle_cpu(int cpu)
 
 #endif
 
-#ifdef CONFIG_SMP
-/*
- * This function computes an effective utilization for the given CPU, to be
- * used for frequency selection given the linear relation: f = u * f_max.
- *
- * The scheduler tracks the following metrics:
- *
- *   cpu_util_{cfs,rt,dl,irq}()
- *   cpu_bw_dl()
- *
- * Where the cfs,rt and dl util numbers are tracked with the same metric and
- * synchronized windows and are thus directly comparable.
- *
- * The cfs,rt,dl utilization are the running times measured with rq->clock_task
- * which excludes things like IRQ and steal-time. These latter are then accrued
- * in the IRQ utilization.
- *
- * The DL bandwidth number OTOH is not a measured metric but a value computed
- * based on the task model parameters and gives the minimal utilization
- * required to meet deadlines.
- */
-unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
-                                unsigned long *min,
-                                unsigned long *max)
-{
-       unsigned long util, irq, scale;
-       struct rq *rq = cpu_rq(cpu);
-
-       scale = arch_scale_cpu_capacity(cpu);
-
-       /*
-        * Early check to see if IRQ/steal time saturates the CPU, can be
-        * because of inaccuracies in how we track these -- see
-        * update_irq_load_avg().
-        */
-       irq = cpu_util_irq(rq);
-       if (unlikely(irq >= scale)) {
-               if (min)
-                       *min = scale;
-               if (max)
-                       *max = scale;
-               return scale;
-       }
-
-       if (min) {
-               /*
-                * The minimum utilization returns the highest level between:
-                * - the computed DL bandwidth needed with the IRQ pressure which
-                *   steals time to the deadline task.
-                * - The minimum performance requirement for CFS and/or RT.
-                */
-               *min = max(irq + cpu_bw_dl(rq), uclamp_rq_get(rq, UCLAMP_MIN));
-
-               /*
-                * When an RT task is runnable and uclamp is not used, we must
-                * ensure that the task will run at maximum compute capacity.
-                */
-               if (!uclamp_is_used() && rt_rq_is_runnable(&rq->rt))
-                       *min = max(*min, scale);
-       }
-
-       /*
-        * Because the time spend on RT/DL tasks is visible as 'lost' time to
-        * CFS tasks and we use the same metric to track the effective
-        * utilization (PELT windows are synchronized) we can directly add them
-        * to obtain the CPU's actual utilization.
-        */
-       util = util_cfs + cpu_util_rt(rq);
-       util += cpu_util_dl(rq);
-
-       /*
-        * The maximum hint is a soft bandwidth requirement, which can be lower
-        * than the actual utilization because of uclamp_max requirements.
-        */
-       if (max)
-               *max = min(scale, uclamp_rq_get(rq, UCLAMP_MAX));
-
-       if (util >= scale)
-               return scale;
-
-       /*
-        * There is still idle time; further improve the number by using the
-        * IRQ metric. Because IRQ/steal time is hidden from the task clock we
-        * need to scale the task numbers:
-        *
-        *              max - irq
-        *   U' = irq + --------- * U
-        *                 max
-        */
-       util = scale_irq_capacity(util, irq, scale);
-       util += irq;
-
-       return min(scale, util);
-}
-
-unsigned long sched_cpu_util(int cpu)
-{
-       return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL);
-}
-#endif /* CONFIG_SMP */
-
 /**
  * find_process_by_pid - find a process with a matching PID value.
  * @pid: the pid in question.