mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: K Prateek Nayak <kprateek.nayak@amd.com>,
	Vishal Badole <Vishal.Badole@amd.com>,
	ray.huang@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: Mon, 30 Nov 2026 09:40:25 -0600	[thread overview]
Message-ID: <79d7dbcf-8bad-4977-aa99-4a05d094f8fe@amd.com> (raw)
In-Reply-To: <7fb17998-e523-4264-91af-0af3c25b0143@amd.com>



On 11/30/26 02:24, 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?
> 
> 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 ...

I don't think this combination is real.

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


  reply	other threads:[~2026-11-30 15:40 UTC|newest]

Thread overview: 8+ 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 [this message]
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=79d7dbcf-8bad-4977-aa99-4a05d094f8fe@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=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=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®