Linux Power Management development
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Vishal Badole <Vishal.Badole@amd.com>
Cc: ray.huang@amd.com, rafael@kernel.org, viresh.kumar@linaro.org,
	perry.yuan@amd.com, kprateek.nayak@amd.com, hansg@kernel.org,
	ilpo.jarvinen@linux.intel.com, tglx@kernel.org, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	lenb@kernel.org, peterz@infradead.org,
	ricardo.neri-calderon@linux.intel.com, x86@kernel.org,
	platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: Re: [PATCH v3 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms
Date: Fri, 4 Dec 2026 16:37:23 -0600	[thread overview]
Message-ID: <2064094f-e522-4937-836f-6a5ef1311ccf@amd.com> (raw)
In-Reply-To: <20261204132715.1668516-3-Vishal.Badole@amd.com>



On 12/4/26 07:27, Vishal Badole wrote:
> AMD heterogeneous processors combine multiple core types (e.g.
> performance and efficiency cores) whose maximum sustained performance
> and frequency differ. On such platforms the Linux scheduler relies on
> per-CPU capacity values to place and balance tasks across cores.
> 
> Today amd-pstate does not export any per-CPU capacity information. As a
> result the scheduler sees every CPU as having identical capacity and
> treats performance and efficiency cores as interchangeable. Tasks are
> therefore placed and balanced without regard to core strength, which
> hurts both throughput and energy efficiency on hybrid systems.
> 
> This happens because the scheduler defaults to a uniform
> SCHED_CAPACITY_SCALE when no arch- or driver-supplied capacity exists,
> and amd-pstate never feeds the asymmetry it knows (via CPPC highest
> frequency or the effective highest performance register) into the arch
> hybrid capacity scaling interface.
> 
> Enable capacity aware scheduling by scaling each CPU's capacity relative
> to a reference CPU. Use the maximum attainable frequencies when available
> for both CPUs, or their effective highest performance values otherwise.
> If reference setup fails, keep CAS disabled and continue normal CPUFreq
> registration.
> 
> Capacity aware scheduling is enabled by default on supported hardware and
> can be turned off with the "amd_cas=disable" boot parameter. Its effective
> state is exposed through the "cas" sysfs attribute, and also exported via
> amd_pstate_cas_active() so amd-hfi can stand down when capacity aware
> scheduling owns the heterogeneous cores.
> 
> Signed-off-by: Vishal Badole <Vishal.Badole@amd.com>

Can you have a look at the Sashiko feedback?  It's found quite a bit.

https://sashiko.dev/#/patchset/20261204132715.1668516-1-Vishal.Badole%40amd.com

> ---
>   MAINTAINERS                           |   1 +
>   arch/x86/include/asm/amd/amd-pstate.h |  16 +++
>   arch/x86/include/asm/topology.h       |   6 +
>   arch/x86/kernel/acpi/cppc.c           |   4 +-
>   drivers/cpufreq/amd-pstate.c          | 184 +++++++++++++++++++++++++-
>   5 files changed, 206 insertions(+), 5 deletions(-)
>   create mode 100644 arch/x86/include/asm/amd/amd-pstate.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 44540a1eb2b80..300dce181c1c4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1322,6 +1322,7 @@ R:	K Prateek Nayak <kprateek.nayak@amd.com>
>   L:	linux-pm@vger.kernel.org
>   S:	Supported
>   F:	Documentation/admin-guide/pm/amd-pstate.rst
> +F:	arch/x86/include/asm/amd/amd-pstate.h
>   F:	drivers/cpufreq/amd-pstate*
>   F:	tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
>   
> diff --git a/arch/x86/include/asm/amd/amd-pstate.h b/arch/x86/include/asm/amd/amd-pstate.h
> new file mode 100644
> index 0000000000000..1c0eb56c8f867
> --- /dev/null
> +++ b/arch/x86/include/asm/amd/amd-pstate.h
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Public interface for the AMD P-state driver.
> + */
> +#ifndef _ASM_X86_AMD_PSTATE_H_
> +#define _ASM_X86_AMD_PSTATE_H_
> +
> +#include <linux/types.h>
> +
> +#if IS_ENABLED(CONFIG_X86_AMD_PSTATE)
> +bool amd_pstate_cas_active(void);
> +#else
> +static inline bool amd_pstate_cas_active(void) { return false; }
> +#endif
> +
> +#endif /* _ASM_X86_AMD_PSTATE_H_ */
> diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
> index 1825691af9410..ddcd550e25846 100644
> --- a/arch/x86/include/asm/topology.h
> +++ b/arch/x86/include/asm/topology.h
> @@ -264,6 +264,12 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources);
>   
>   extern bool x86_topology_update;
>   
> +static inline void arch_mark_cpu_topology_changed(void)
> +{
> +	if (IS_ENABLED(CONFIG_SMP))
> +		x86_topology_update = true;
> +}
> +
>   #ifdef CONFIG_SCHED_MC_PRIO
>   #include <asm/percpu.h>
>   #include <linux/cache.h>
> diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c
> index 1c6bf56c3215b..15590e9da2dca 100644
> --- a/arch/x86/kernel/acpi/cppc.c
> +++ b/arch/x86/kernel/acpi/cppc.c
> @@ -248,8 +248,8 @@ int amd_get_effective_highest_perf(unsigned int cpu)
>   	if (ret < 0)
>   		return ret;
>   
> -	/* without preferred cores, return the highest perf register value */
> -	if (!prefcore)
> +	/* Reuse the cached value for homogeneous CPUs without preferred cores. */
> +	if (!prefcore && !cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
>   		return boost_numerator;
>   
>   	/*
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 3e0308f644778..366ba3802f3c8 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -39,10 +39,12 @@
>   #include <linux/power_supply.h>
>   #include <linux/static_call.h>
>   #include <linux/topology.h>
> +#include <linux/cpuset.h>
>   
>   #include <acpi/processor.h>
>   #include <acpi/cppc_acpi.h>
>   
> +#include <asm/amd/amd-pstate.h>
>   #include <asm/msr.h>
>   #include <asm/cpufeature.h>
>   #include <asm/cpu_device_id.h>
> @@ -86,6 +88,9 @@ static struct cpufreq_driver amd_pstate_driver;
>   static struct cpufreq_driver amd_pstate_epp_driver;
>   static int cppc_state = AMD_PSTATE_UNDEFINED;
>   static bool amd_pstate_prefcore = true;
> +static bool amd_pstate_cas = true;
> +static bool amd_pstate_cas_initialized;
> +static u32 amd_pstate_ref_freq_khz;
>   static struct quirk_entry *quirks;
>   
>   /*
> @@ -962,6 +967,142 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
>   	sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu);
>   }
>   
> +bool amd_pstate_cas_active(void)
> +{
> +	return READ_ONCE(amd_pstate_cas_initialized);
> +}
> +EXPORT_SYMBOL_GPL(amd_pstate_cas_active);
> +
> +static bool amd_pstate_update_ref(int offline_cpu)
> +{
> +	u32 ref_max_freq = 0, max_freq, nominal_freq;
> +	struct cppc_perf_caps perf_caps;
> +	int cpu, ret, highest_perf;
> +
> +	for_each_online_cpu(cpu) {
> +		if (cpu == offline_cpu)
> +			continue;
> +
> +		ret = amd_get_max_frequency(cpu);
> +		if (ret < 0) {
> +			pr_warn("Invalid maximum frequency (%d) on CPU%d\n", ret, cpu);
> +			return false;
> +		}
> +
> +		max_freq = (u32)ret * 1000;
> +		if (!max_freq) {
> +			ret = cppc_get_perf_caps(cpu, &perf_caps);
> +			if (ret)
> +				return false;
> +
> +			if (!perf_caps.nominal_freq) {
> +				pr_warn("Missing nominal frequency on CPU%d\n", cpu);
> +				return false;
> +			}
> +
> +			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 false;
> +			}
> +
> +			nominal_freq = perf_caps.nominal_freq * 1000;
> +			max_freq = DIV_ROUND_UP_ULL((u64)nominal_freq * highest_perf,
> +						    perf_caps.nominal_perf);
> +		}
> +
> +		if (max_freq <= ref_max_freq)
> +			continue;
> +
> +		ref_max_freq = max_freq;
> +	}
> +
> +	if (!ref_max_freq) {
> +		pr_warn("No reference CPU available for capacity scaling\n");
> +		return false;
> +	}
> +
> +	amd_pstate_ref_freq_khz = ref_max_freq;
> +
> +	return true;
> +}
> +
> +static void __init amd_pstate_init_cas(void)
> +{
> +	if (!amd_pstate_cas)
> +		return;
> +
> +	amd_pstate_cas = false;
> +	if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES))
> +		return;
> +
> +	if (!amd_pstate_update_ref(nr_cpu_ids))
> +		return;
> +
> +	amd_pstate_cas = arch_enable_hybrid_capacity_scale();
> +}
> +
> +static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data)
> +{
> +	unsigned long max_freq = READ_ONCE(data->max_freq);
> +	int cpu = data->cpu;
> +
> +	arch_set_cpu_capacity(cpu, max_freq, amd_pstate_ref_freq_khz,
> +			      max_freq, amd_pstate_ref_freq_khz);
> +	topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu));
> +}
> +
> +static void __amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata, bool refresh)
> +{
> +	int cpu;
> +
> +	lockdep_assert_cpus_held();
> +	lockdep_assert_held(&sched_domains_mutex);
> +
> +	if (cpudata) {
> +		u32 max_freq = READ_ONCE(cpudata->max_freq);
> +
> +		if (max_freq > amd_pstate_ref_freq_khz) {
> +			amd_pstate_ref_freq_khz = max_freq;
> +			refresh = true;
> +		}
> +	}
> +
> +	if (refresh) {
> +		for_each_online_cpu(cpu) {
> +			struct cpufreq_policy *policy;
> +
> +			if (cpudata && cpu == cpudata->cpu)
> +				continue;
> +
> +			policy = cpufreq_cpu_get_raw(cpu);
> +			if (policy && policy->driver_data)
> +				amd_pstate_update_cpu_capacity(policy->driver_data);
> +		}
> +	}
> +
> +	if (cpudata)
> +		amd_pstate_update_cpu_capacity(cpudata);
> +	WRITE_ONCE(amd_pstate_cas_initialized, true);
> +}
> +
> +static void amd_pstate_refresh_cpu_capacity(struct amd_cpudata *cpudata, int offline_cpu)
> +{
> +	guard(mutex)(&sched_domains_mutex);
> +
> +	if (amd_pstate_update_ref(offline_cpu))
> +		__amd_pstate_set_cpu_capacity(cpudata, true);
> +}
> +
> +static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata)
> +{
> +	guard(mutex)(&sched_domains_mutex);
> +
> +	__amd_pstate_set_cpu_capacity(cpudata, false);
> +	arch_mark_cpu_topology_changed();
> +}
> +
>   static void amd_pstate_update_limits(struct cpufreq_policy *policy)
>   {
>   	struct amd_cpudata *cpudata;
> @@ -1093,6 +1234,9 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
>   			 bios_min_freq, cpudata->cpu);
>   	}
>   
> +	if (amd_pstate_cas)
> +		amd_pstate_set_cpu_capacity(cpudata);
> +
>   	return 0;
>   }
>   
> @@ -1203,6 +1347,7 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
>   	freq_qos_remove_request(&cpudata->req[0]);
>   	policy->fast_switch_possible = false;
>   	kfree(cpudata);
> +	policy->driver_data = NULL;
>   }
>   
>   static int amd_pstate_get_balanced_epp(struct cpufreq_policy *policy)
> @@ -1916,12 +2061,20 @@ static ssize_t prefcore_show(struct device *dev,
>   	return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore));
>   }
>   
> +static ssize_t cas_show(struct device *dev,
> +			struct device_attribute *attr, char *buf)
> +{
> +	return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_cas_active()));
> +}
> +
>   static DEVICE_ATTR_RW(status);
>   static DEVICE_ATTR_RO(prefcore);
> +static DEVICE_ATTR_RO(cas);
>   
>   static struct attribute *pstate_global_attributes[] = {
>   	&dev_attr_status.attr,
>   	&dev_attr_prefcore.attr,
> +	&dev_attr_cas.attr,
>   	NULL
>   };
>   
> @@ -2142,7 +2295,14 @@ static int amd_pstate_cpu_online(struct cpufreq_policy *policy)
>   		return ret;
>   
>   	cached_floor_perf = freq_to_perf(perf, cpudata->nominal_freq, cpudata->floor_freq);
> -	return amd_pstate_set_floor_perf(policy, cached_floor_perf);
> +	ret = amd_pstate_set_floor_perf(policy, cached_floor_perf);
> +	if (ret)
> +		return ret;
> +
> +	if (amd_pstate_cas)
> +		amd_pstate_refresh_cpu_capacity(cpudata, nr_cpu_ids);
> +
> +	return 0;
>   }
>   
>   static int amd_pstate_cpu_offline(struct cpufreq_policy *policy)
> @@ -2151,6 +2311,9 @@ static int amd_pstate_cpu_offline(struct cpufreq_policy *policy)
>   	union perf_cached perf = READ_ONCE(cpudata->perf);
>   	int ret;
>   
> +	if (amd_pstate_cas)
> +		amd_pstate_refresh_cpu_capacity(NULL, cpudata->cpu);
> +
>   	/*
>   	 * Reset CPPC_REQ MSR to the BIOS value, this will allow us to retain the BIOS specified
>   	 * min_perf value across kexec reboots. If this CPU is just onlined normally after this, the
> @@ -2431,8 +2594,10 @@ static int __init amd_pstate_init(void)
>   			return ret;
>   	}
>   
> -	if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
> -	    IS_ENABLED(CONFIG_AMD_HFI))
> +	amd_pstate_init_cas();
> +
> +	if ((cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
> +	     IS_ENABLED(CONFIG_AMD_HFI)) || amd_pstate_cas)
>   		amd_pstate_prefcore = false;
>   
>   	ret = amd_pstate_register_driver(cppc_state);
> @@ -2441,6 +2606,10 @@ static int __init amd_pstate_init(void)
>   		return ret;
>   	}
>   
> +	/* Per-CPU capacities are set during registration; rebuild domains once. */
> +	if (amd_pstate_cas)
> +		rebuild_sched_domains();
> +
>   	dev_root = bus_get_dev_root(&cpu_subsys);
>   	if (dev_root) {
>   		ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group);
> @@ -2481,8 +2650,17 @@ static int __init amd_prefcore_param(char *str)
>   	return 0;
>   }
>   
> +static int __init amd_cas_param(char *str)
> +{
> +	if (!strcmp(str, "disable"))
> +		amd_pstate_cas = false;
> +
> +	return 0;
> +}
> +
>   early_param("amd_pstate", amd_pstate_param);
>   early_param("amd_prefcore", amd_prefcore_param);
> +early_param("amd_cas", amd_cas_param);
>   
>   MODULE_AUTHOR("Huang Rui <ray.huang@amd.com>");
>   MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver");


  reply	other threads:[~2026-12-04 22:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:27 [PATCH v3 0/3] cpufreq: amd-pstate: Capacity Aware Scheduling on hybrid platforms Vishal Badole
2026-12-04 13:27 ` [PATCH v3 1/3] cpufreq: amd-pstate: Finalize prefcore before registration Vishal Badole
2026-12-04 13:27 ` [PATCH v3 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Vishal Badole
2026-12-04 22:37   ` Mario Limonciello [this message]
2026-12-04 13:27 ` [PATCH v3 3/3] platform/x86/amd: hfi: Stand down when amd-pstate CAS is active Vishal Badole

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=2064094f-e522-4937-836f-6a5ef1311ccf@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Vishal.Badole@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kprateek.nayak@amd.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=perry.yuan@amd.com \
    --cc=peterz@infradead.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=ricardo.neri-calderon@linux.intel.com \
    --cc=tglx@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=x86@kernel.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