cpufreq/cppc: Set the frequency used for computing the capacity
authorVincent Guittot <vincent.guittot@linaro.org>
Mon, 11 Dec 2023 10:48:54 +0000 (11:48 +0100)
committerIngo Molnar <mingo@kernel.org>
Sat, 23 Dec 2023 14:52:36 +0000 (15:52 +0100)
Save the frequency associated to the performance that has been used when
initializing the capacity of CPUs.

Also, cppc cpufreq driver can register an artificial energy model. In such
case, it needs the frequency for this compute capacity.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/20231211104855.558096-7-vincent.guittot@linaro.org
drivers/base/arch_topology.c

index 0c9ae5b157b17db5d876b3bc0debb10709b369e5..1aa76b5c96c2433d3c3f4085af79beea72492169 100644 (file)
@@ -349,6 +349,7 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
 
 void topology_init_cpu_capacity_cppc(void)
 {
+       u64 capacity, capacity_scale = 0;
        struct cppc_perf_caps perf_caps;
        int cpu;
 
@@ -365,6 +366,10 @@ void topology_init_cpu_capacity_cppc(void)
                    (perf_caps.highest_perf >= perf_caps.nominal_perf) &&
                    (perf_caps.highest_perf >= perf_caps.lowest_perf)) {
                        raw_capacity[cpu] = perf_caps.highest_perf;
+                       capacity_scale = max_t(u64, capacity_scale, raw_capacity[cpu]);
+
+                       per_cpu(capacity_freq_ref, cpu) = cppc_perf_to_khz(&perf_caps, raw_capacity[cpu]);
+
                        pr_debug("cpu_capacity: CPU%d cpu_capacity=%u (raw).\n",
                                 cpu, raw_capacity[cpu]);
                        continue;
@@ -375,7 +380,15 @@ void topology_init_cpu_capacity_cppc(void)
                goto exit;
        }
 
-       topology_normalize_cpu_scale();
+       for_each_possible_cpu(cpu) {
+               capacity = raw_capacity[cpu];
+               capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT,
+                                    capacity_scale);
+               topology_set_cpu_scale(cpu, capacity);
+               pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n",
+                       cpu, topology_get_cpu_scale(cpu));
+       }
+
        schedule_work(&update_topology_flags_work);
        pr_debug("cpu_capacity: cpu_capacity initialization done\n");