Skip to content

Commit 004b500

Browse files
ionela-voinescuctmarinas
authored andcommitted
arch_topology: init capacity_freq_ref to 0
It's useful to have capacity_freq_ref initialized to 0 for users of arch_scale_freq_ref() to detect when capacity_freq_ref was not yet set. The only scenario affected by this change in the init value is when a cpufreq driver is never loaded. As a result, the only setter of a cpu scale factor remains the call of topology_normalize_cpu_scale() from parse_dt_topology(). There we cannot use the value 0 of capacity_freq_ref so we have to compensate for its uninitialized state. Signed-off-by: Ionela Voinescu <ionela.voinescu@arm.com> Signed-off-by: Beata Michalska <beata.michalska@arm.com> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://lore.kernel.org/r/20240827154818.1195849-1-ionela.voinescu@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 0ad2507 commit 004b500

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/base/arch_topology.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data);
2929
static struct cpumask scale_freq_counters_mask;
3030
static bool scale_freq_invariant;
31-
DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 1;
31+
DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 0;
3232
EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref);
3333

3434
static bool supports_scale_freq_counters(const struct cpumask *cpus)
@@ -293,13 +293,15 @@ void topology_normalize_cpu_scale(void)
293293

294294
capacity_scale = 1;
295295
for_each_possible_cpu(cpu) {
296-
capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu);
296+
capacity = raw_capacity[cpu] *
297+
(per_cpu(capacity_freq_ref, cpu) ?: 1);
297298
capacity_scale = max(capacity, capacity_scale);
298299
}
299300

300301
pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale);
301302
for_each_possible_cpu(cpu) {
302-
capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu);
303+
capacity = raw_capacity[cpu] *
304+
(per_cpu(capacity_freq_ref, cpu) ?: 1);
303305
capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT,
304306
capacity_scale);
305307
topology_set_cpu_scale(cpu, capacity);

0 commit comments

Comments
 (0)