mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Badole, Vishal" <vishal.badole@amd.com>
To: K Prateek Nayak <kprateek.nayak@amd.com>,
	ray.huang@amd.com, mario.limonciello@amd.com, rafael@kernel.org,
	viresh.kumar@linaro.org, perry.yuan@amd.com, hansg@kernel.org,
	ilpo.jarvinen@linux.intel.com,
	platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
Date: Tue, 1 Dec 2026 14:48:07 +0530	[thread overview]
Message-ID: <955f1ea8-65da-4100-93dd-11bfebc4954c@amd.com> (raw)
In-Reply-To: <7fb17998-e523-4264-91af-0af3c25b0143@amd.com>



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:
> 
>    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?
> 
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().

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.

>> +
>> +	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?
> 
255/254 for performance core and 252 efficiency core.

>> +	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.
> 
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.

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?

>> +		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"?
> 
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_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.
> 
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.

>> +	WRITE_ONCE(amd_pstate_cas_initialized, true);
>> +}
>> +
>>   static void amd_pstate_update_limits(struct cpufreq_policy *policy)
>>   {
>>   	struct amd_cpudata *cpudata;
> 


  parent reply	other threads:[~2026-12-01  9:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 17:20 [PATCH v2 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling " Vishal Badole
2026-11-25 17:20 ` [PATCH v2 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
2026-11-30 15:38   ` Mario Limonciello
2026-11-25 17:20 ` [PATCH v2 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
2026-11-30  8:24   ` K Prateek Nayak
2026-11-30 15:40     ` Mario Limonciello
2026-12-01  9:18     ` Badole, Vishal [this message]
2026-12-01  9:40       ` K Prateek Nayak
2026-11-25 17:20 ` [PATCH v2 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole
2026-11-30 15:39   ` Mario Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=955f1ea8-65da-4100-93dd-11bfebc4954c@amd.com \
    --to=vishal.badole@amd.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®