Re: [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
From: K Prateek Nayak
Date: Mon Nov 30 2026 - 03:24:27 EST
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?
Say you have:
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?
> +
> + 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?
> + 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.
> + 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"?
> + }
> + }
> +
> + 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;
--
Thanks and Regards,
Prateek