Re: [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
From: Badole, Vishal
Date: Tue Dec 01 2026 - 04:18:52 EST
On 11/30/2026 1:54 PM, K Prateek Nayak wrote:
Hello Vishal,
On 11/25/2026 10:50 PM, Vishal Badole wrote:
+bool amd_pstate_cas_active(void)
+{
+ return READ_ONCE(amd_pstate_cas_initialized);
+}
+EXPORT_SYMBOL_GPL(amd_pstate_cas_active);
+
+static void __init amd_pstate_init_cas(void)
+{
+ int ref_highest_perf = 0, ref_max_freq = 0;
+ int cpu, highest_perf, max_freq;
+
+ if (!amd_pstate_cas)
+ return;
+
+ amd_pstate_cas = false;
+ if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
+ return;
+
+ for_each_online_cpu(cpu) {
+ highest_perf = amd_get_effective_highest_perf(cpu);
+ if (highest_perf <= 0) {
+ pr_warn("Invalid highest performance (%d) on CPU%d\n",
+ highest_perf, cpu);
+ return;
+ }
+
+ max_freq = amd_get_max_frequency(cpu);
+ if (max_freq < 0 || (u32)max_freq > U32_MAX / 1000) {
+ pr_warn("Invalid maximum frequency (%d) on CPU%d\n",
+ max_freq, cpu);
+ return;
+ }
+
+ if (highest_perf < ref_highest_perf ||
+ (highest_perf == ref_highest_perf && max_freq <= ref_max_freq))
So I don't get the second part of this condition. There can be CPUs with
same highest_perf bit different max_freq?
No, CPUs with the same highest_perf are not expected to have different maximum frequencies on the supported platforms. I will remove the maximum-frequency tie-breaker in the next revision.
Say you have:Yes, when maximum-frequency data is unavailable for this CPU, this expression is equivalent to data->max_freq, which was calculated using perf_to_freq().
Performance Core : max_perf = 196; max_freq = 3000000KHz
Efficiency Core : max_perf = 196; max_freq = 2000000KHz
(Hypothetical numbers)
In this case, you'll have:
amd_pstate_ref_highest_perf = 196
amd_pstate_ref_freq_khz = 30000000KHz
Continued below ...
+ continue;
+
+ ref_highest_perf = highest_perf;
+ ref_max_freq = max_freq;
+ }
+
+ if (!ref_highest_perf) {
+ pr_warn("No reference CPU available for capacity scaling\n");
+ return;
+ }
+
+ amd_pstate_ref_highest_perf = ref_highest_perf;
+ amd_pstate_ref_freq_khz = ref_max_freq * 1000U;
+
+ amd_pstate_cas = arch_enable_hybrid_capacity_scale();
+}
+
+static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data,
+ bool highest_freq_available)
+{
+ unsigned long capacity, max_capacity, capacity_freq, base_freq;
+ int cpu = data->cpu;
+
+ lockdep_assert_held(&sched_domains_mutex);
+
+ if (highest_freq_available && amd_pstate_ref_freq_khz) {
+ capacity = data->max_freq;
+ max_capacity = amd_pstate_ref_freq_khz;
+ capacity_freq = capacity;
+ base_freq = max_capacity;
+ } else {
+ union perf_cached perf = READ_ONCE(data->perf);
+
+ capacity = perf.highest_perf;
+ max_capacity = amd_pstate_ref_highest_perf;
+ capacity_freq = perf_to_freq(perf, data->nominal_freq, perf.highest_perf);
So this is literally "data->max_freq"
+ base_freq = perf_to_freq(perf, data->nominal_freq, max_capacity);
And this would likely be equal to "amd_pstate_ref_freq_khz"
+ }
Making both those branch pretty much the same. Why isn't just the
frequency reference enough?
However, that is a frequency estimate derived from CPPC performance values, not necessarily the CPU’s actual maximum attainable frequency. In the frequency-based branch, data->max_freq comes from amd_get_max_frequency() and represents the maximum attainable frequency independently of those performance values.
On older hardware, the highest-performance values of 196 for performance cores and 130 for efficiency cores aligned reasonably with their relative maximum frequencies. On newer hardware, these values are 255 and 252, which no longer reflect the Fmax difference between the core types. Performance-based scaling therefore gives almost equal capacities, whereas using the maximum attainable frequencies gives capacities of 1024 and 718.
Also, the fallback branch can be entered when only the reference CPU lacks frequency data. In that case, the current CPU’s data->max_freq may contain an actual Fmax, so it is not always interchangeable with this perf_to_freq() calculation.
255/254 for performance core and 252 efficiency core.+
+ arch_set_cpu_capacity(cpu, capacity, max_capacity, capacity_freq, base_freq);
...
And that means they'll have same capacity, but different frequency scale.
That reads a bit wrong to me. Different frequency scale will help cap the
PELT tracking but the CPUs themself will appear as same capacity which
would do the wrong thing.
What do these highest_perf numbers look like on real hardware btw?
If performance cores are kept offline at boot using maxcpus=, the current logic already handles this by selecting the highest-performance online CPU as the reference.+ topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu));
+}
+
+static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata,
+ bool highest_freq_available)
+{
+ union perf_cached perf = READ_ONCE(cpudata->perf);
+ int cpu;
+
+ lockdep_assert_cpus_held();
+
+ guard(mutex)(&sched_domains_mutex);
+
+ if (perf.highest_perf > amd_pstate_ref_highest_perf) {
Btw there is other side to this where all CPUs of the highest
capacity are offlined and you'll need to recaliberate the
reference again if you have efficiency and low-power cores.
For runtime offlining, I don't think recalibration is necessary. Offlining performance cores does not change the maximum capabilities of the remaining efficiency and low-power cores. Keeping the existing reference preserves their relative capacities, even if no online CPU then has a capacity of 1024.
Is there a scheduler requirement that the highest-capacity online CPU must always be normalized to 1024?
Ack, you're right. On the supported platforms, if maximum-frequency information is available for one CPU, it is available for all CPUs. I'll simplify the availability handling in the next patch revision.+ amd_pstate_ref_highest_perf = perf.highest_perf;
+ amd_pstate_ref_freq_khz = highest_freq_available ? cpudata->max_freq : 0;
+
+ for_each_possible_cpu(cpu) {
+ struct cpufreq_policy *policy;
+
+ if (cpu == cpudata->cpu)
+ continue;
+
+ policy = cpufreq_cpu_policy(cpu);
+ if (policy && policy->driver_data)
+ amd_pstate_update_cpu_capacity(policy->driver_data,
+ amd_pstate_ref_freq_khz &&
+ amd_get_max_frequency(cpu) > 0);
This is the most convoluted condition ^^^^
If this CPU has "highest_freq_available", doesn't that mean all the CPUs
in this system have "highest_freq_available"?
Thanks for the suggestion. Let me check whether an arch-side helper would simplify this and allow the redundant CONFIG_SMP checks to be removed.+ }
+ }
+
+ amd_pstate_update_cpu_capacity(cpudata, highest_freq_available);
+ x86_topology_update = true;
I think this really calls for an arch side helper rather seting it
openly here. That should get rid of that CONFIG_SMP checks everywhere.
+ WRITE_ONCE(amd_pstate_cas_initialized, true);
+}
+
static void amd_pstate_update_limits(struct cpufreq_policy *policy)
{
struct amd_cpudata *cpudata;