}
 }
 
+/**
+ * get_capacity_ref_freq - get the reference frequency that has been used to
+ * correlate frequency and compute capacity for a given cpufreq policy. We use
+ * the CPU managing it for the arch_scale_freq_ref() call in the function.
+ * @policy: the cpufreq policy of the CPU in question.
+ *
+ * Return: the reference CPU frequency to compute a capacity.
+ */
+static __always_inline
+unsigned long get_capacity_ref_freq(struct cpufreq_policy *policy)
+{
+       unsigned int freq = arch_scale_freq_ref(policy->cpu);
+
+       if (freq)
+               return freq;
+
+       if (arch_scale_freq_invariant())
+               return policy->cpuinfo.max_freq;
+
+       return policy->cur;
+}
+
 /**
  * get_next_freq - Compute a new frequency for a given cpufreq policy.
  * @sg_policy: schedutil policy object to compute the new frequency for.
                                  unsigned long util, unsigned long max)
 {
        struct cpufreq_policy *policy = sg_policy->policy;
-       unsigned int freq = arch_scale_freq_invariant() ?
-                               policy->cpuinfo.max_freq : policy->cur;
+       unsigned int freq;
 
+       freq = get_capacity_ref_freq(policy);
        freq = map_util_freq(util, freq, max);
 
        if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)