From: "zhenglifeng (A)" <zhenglifeng1@huawei.com>
To: Sumit Gupta <sumitg@nvidia.com>, <pierre.gondois@arm.com>
Cc: <rafael@kernel.org>, <viresh.kumar@linaro.org>,
<ionela.voinescu@arm.com>, <lenb@kernel.org>,
<robert.moore@intel.com>, <corbet@lwn.net>,
<rdunlap@infradead.org>, <ray.huang@amd.com>,
<gautham.shenoy@amd.com>, <mario.limonciello@amd.com>,
<perry.yuan@amd.com>, <zhanjie9@hisilicon.com>,
<linux-pm@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <acpica-devel@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
<treding@nvidia.com>, <jonathanh@nvidia.com>, <vsethi@nvidia.com>,
<ksitaraman@nvidia.com>, <sanjayc@nvidia.com>,
<nhartman@nvidia.com>, <bbasu@nvidia.com>
Subject: Re: [PATCH v7 4/7] ACPI: CPPC: add APIs and sysfs interface for min/max_perf
Date: Sat, 31 Jan 2026 12:06:48 +0800 [thread overview]
Message-ID: <4432fa04-e67c-422a-aae4-2938be431985@huawei.com> (raw)
In-Reply-To: <20260129104817.3752340-5-sumitg@nvidia.com>
Hi Sumit,
I am thinking that maybe it is better to call these two sysfs interface
'min_freq' and 'max_freq' as users read and write khz instead of raw value.
On 2026/1/29 18:48, Sumit Gupta wrote:
> Add cppc_get/set_min_perf() and cppc_get/set_max_perf() APIs to read and
> write the MIN_PERF and MAX_PERF registers.
>
> Also add sysfs interfaces (min_perf, max_perf) in cppc_cpufreq driver
> to expose these controls to userspace. The sysfs values are in frequency
> (kHz) for consistency with other cpufreq sysfs files.
>
> Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
> ---
> drivers/acpi/cppc_acpi.c | 44 +++++++++
> drivers/cpufreq/cppc_cpufreq.c | 165 +++++++++++++++++++++++++++++++++
> include/acpi/cppc_acpi.h | 20 ++++
> 3 files changed, 229 insertions(+)
>
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index 08e62b58eb83..b2b8daab69ed 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -1753,6 +1753,50 @@ int cppc_set_auto_sel(int cpu, bool enable)
> }
> EXPORT_SYMBOL_GPL(cppc_set_auto_sel);
>
> +/**
> + * cppc_get_min_perf - Read minimum performance register.
> + * @cpu: CPU from which to read register.
> + * @min_perf: Return address.
> + */
> +int cppc_get_min_perf(int cpu, u64 *min_perf)
> +{
> + return cppc_get_reg_val(cpu, MIN_PERF, min_perf);
> +}
> +EXPORT_SYMBOL_GPL(cppc_get_min_perf);
> +
> +/**
> + * cppc_set_min_perf - Write minimum performance register.
> + * @cpu: CPU to which to write register.
> + * @min_perf: the desired minimum performance value to be updated.
> + */
> +int cppc_set_min_perf(int cpu, u32 min_perf)
> +{
> + return cppc_set_reg_val(cpu, MIN_PERF, min_perf);
> +}
> +EXPORT_SYMBOL_GPL(cppc_set_min_perf);
> +
> +/**
> + * cppc_get_max_perf - Read maximum performance register.
> + * @cpu: CPU from which to read register.
> + * @max_perf: Return address.
> + */
> +int cppc_get_max_perf(int cpu, u64 *max_perf)
> +{
> + return cppc_get_reg_val(cpu, MAX_PERF, max_perf);
> +}
> +EXPORT_SYMBOL_GPL(cppc_get_max_perf);
> +
> +/**
> + * cppc_set_max_perf - Write maximum performance register.
> + * @cpu: CPU to which to write register.
> + * @max_perf: the desired maximum performance value to be updated.
> + */
> +int cppc_set_max_perf(int cpu, u32 max_perf)
> +{
> + return cppc_set_reg_val(cpu, MAX_PERF, max_perf);
> +}
> +EXPORT_SYMBOL_GPL(cppc_set_max_perf);
> +
> /**
> * cppc_set_enable - Set to enable CPPC on the processor by writing the
> * Continuous Performance Control package EnableRegister field.
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 1421f30e87e4..8787185cd8b0 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -570,6 +570,35 @@ static void populate_efficiency_class(void)
> }
> #endif
>
> +/* Set min/max performance HW register and cache the value */
> +static int cppc_cpufreq_set_mperf_reg(struct cpufreq_policy *policy,
> + u64 val, bool is_min)
> +{
> + struct cppc_cpudata *cpu_data = policy->driver_data;
> + struct cppc_perf_caps *caps = &cpu_data->perf_caps;
> + unsigned int cpu = policy->cpu;
> + u32 perf;
> + int ret;
> +
> + perf = clamp(val, caps->lowest_perf, caps->highest_perf);
> +
> + ret = is_min ? cppc_set_min_perf(cpu, perf) :
> + cppc_set_max_perf(cpu, perf);
> + if (ret) {
> + if (ret != -EOPNOTSUPP)
> + pr_warn("CPU%d: set %s_perf=%u failed (%d)\n",
> + cpu, is_min ? "min" : "max", perf, ret);
> + return ret;
> + }
> +
> + if (is_min)
> + cpu_data->perf_ctrls.min_perf = perf;
> + else
> + cpu_data->perf_ctrls.max_perf = perf;
> +
> + return 0;
> +}
> +
> static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(unsigned int cpu)
> {
> struct cppc_cpudata *cpu_data;
> @@ -919,16 +948,152 @@ CPPC_CPUFREQ_ATTR_RW_U64(auto_act_window, cppc_get_auto_act_window,
> CPPC_CPUFREQ_ATTR_RW_U64(energy_performance_preference_val,
> cppc_get_epp_perf, cppc_set_epp)
>
> +/**
> + * show_min_perf - Show minimum performance as frequency (kHz)
> + * @policy: cpufreq policy
> + * @buf: buffer to write the frequency value to
> + *
> + * Reads the MIN_PERF register and converts the performance value to
> + * frequency (kHz).
> + */
> +static ssize_t show_min_perf(struct cpufreq_policy *policy, char *buf)
> +{
> + struct cppc_cpudata *cpu_data = policy->driver_data;
> + struct cppc_perf_caps *caps = &cpu_data->perf_caps;
> + u64 perf;
> + int ret;
> +
> + ret = cppc_get_min_perf(policy->cpu, &perf);
> + if (ret == -EOPNOTSUPP)
> + return sysfs_emit(buf, "<unsupported>\n");
> + if (ret)
> + return ret;
> +
> + /* Use lowest_perf if register is uninitialized or out of range */
> + if (perf == 0 || perf < caps->lowest_perf)
> + perf = caps->lowest_perf;
> +
> + /* Convert performance to frequency (kHz) for user */
> + return sysfs_emit(buf, "%u\n", cppc_perf_to_khz(caps, perf));
> +}
> +
> +/**
> + * store_min_perf - Set minimum performance from frequency (kHz)
> + * @policy: cpufreq policy
> + * @buf: buffer containing the frequency value
> + * @count: size of @buf
> + *
> + * Converts the user-provided frequency (kHz) to a performance value
> + * and writes it to the MIN_PERF register.
> + */
> +static ssize_t store_min_perf(struct cpufreq_policy *policy, const char *buf,
> + size_t count)
> +{
> + struct cppc_cpudata *cpu_data = policy->driver_data;
> + unsigned int freq_khz;
> + u64 perf;
> + int ret;
> +
> + ret = kstrtouint(buf, 0, &freq_khz);
> + if (ret)
> + return ret;
> +
> + /* Convert frequency (kHz) to performance value */
> + perf = cppc_khz_to_perf(&cpu_data->perf_caps, freq_khz);
> +
> + /*
> + * min_perf must be less than or equal to max_perf.
> + * Skip check if max_perf is 0 (uninitialized).
> + */
> + if (cpu_data->perf_ctrls.max_perf &&
> + perf > cpu_data->perf_ctrls.max_perf)
> + return -EINVAL;
> +
> + ret = cppc_cpufreq_set_mperf_reg(policy, perf, true);
> + if (ret)
> + return ret;
> +
> + return count;
> +}
> +
> +/**
> + * show_max_perf - Show maximum performance as frequency (kHz)
> + * @policy: cpufreq policy
> + * @buf: buffer to write the frequency value to
> + *
> + * Reads the MAX_PERF register and converts the performance value to
> + * frequency (kHz).
> + */
> +static ssize_t show_max_perf(struct cpufreq_policy *policy, char *buf)
> +{
> + struct cppc_cpudata *cpu_data = policy->driver_data;
> + struct cppc_perf_caps *caps = &cpu_data->perf_caps;
> + u64 perf;
> + int ret;
> +
> + ret = cppc_get_max_perf(policy->cpu, &perf);
> + if (ret == -EOPNOTSUPP)
> + return sysfs_emit(buf, "<unsupported>\n");
> + if (ret)
> + return ret;
> +
> + /* Use highest_perf if register is uninitialized or out of range */
> + if (perf == 0 || perf > caps->highest_perf)
> + perf = caps->highest_perf;
> +
> + /* Convert performance to frequency (kHz) for user */
> + return sysfs_emit(buf, "%u\n", cppc_perf_to_khz(caps, perf));
> +}
> +
> +/**
> + * store_max_perf - Set maximum performance from frequency (kHz)
> + * @policy: cpufreq policy
> + * @buf: buffer containing the frequency value
> + * @count: size of @buf
> + *
> + * Converts the user-provided frequency (kHz) to a performance value
> + * and writes it to the MAX_PERF register.
> + */
> +static ssize_t store_max_perf(struct cpufreq_policy *policy, const char *buf,
> + size_t count)
> +{
> + struct cppc_cpudata *cpu_data = policy->driver_data;
> + unsigned int freq_khz;
> + u64 perf;
> + int ret;
> +
> + ret = kstrtouint(buf, 0, &freq_khz);
> + if (ret)
> + return ret;
> +
> + /* Convert frequency (kHz) to performance value */
> + perf = cppc_khz_to_perf(&cpu_data->perf_caps, freq_khz);
> +
> + /* max_perf must be greater than or equal to min_perf */
> + if (perf < cpu_data->perf_ctrls.min_perf)
> + return -EINVAL;
> +
> + ret = cppc_cpufreq_set_mperf_reg(policy, perf, false);
> + if (ret)
> + return ret;
> +
> + return count;
> +}
> +
> cpufreq_freq_attr_ro(freqdomain_cpus);
> cpufreq_freq_attr_rw(auto_select);
> cpufreq_freq_attr_rw(auto_act_window);
> cpufreq_freq_attr_rw(energy_performance_preference_val);
> +cpufreq_freq_attr_rw(min_perf);
> +cpufreq_freq_attr_rw(max_perf);
>
> static struct freq_attr *cppc_cpufreq_attr[] = {
> &freqdomain_cpus,
> &auto_select,
> &auto_act_window,
> &energy_performance_preference_val,
> + &min_perf,
> + &max_perf,
> NULL,
> };
>
> diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
> index 3fc796c0d902..b358440cd0e2 100644
> --- a/include/acpi/cppc_acpi.h
> +++ b/include/acpi/cppc_acpi.h
> @@ -174,6 +174,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);
> extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window);
> extern int cppc_get_auto_sel(int cpu, bool *enable);
> extern int cppc_set_auto_sel(int cpu, bool enable);
> +extern int cppc_get_min_perf(int cpu, u64 *min_perf);
> +extern int cppc_set_min_perf(int cpu, u32 min_perf);
> +extern int cppc_get_max_perf(int cpu, u64 *max_perf);
> +extern int cppc_set_max_perf(int cpu, u32 max_perf);
> extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
> extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
> extern int amd_detect_prefcore(bool *detected);
> @@ -270,6 +274,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enable)
> {
> return -EOPNOTSUPP;
> }
> +static inline int cppc_get_min_perf(int cpu, u64 *min_perf)
> +{
> + return -EOPNOTSUPP;
> +}
> +static inline int cppc_set_min_perf(int cpu, u32 min_perf)
> +{
> + return -EOPNOTSUPP;
> +}
> +static inline int cppc_get_max_perf(int cpu, u64 *max_perf)
> +{
> + return -EOPNOTSUPP;
> +}
> +static inline int cppc_set_max_perf(int cpu, u32 max_perf)
> +{
> + return -EOPNOTSUPP;
> +}
> static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
> {
> return -ENODEV;
next prev parent reply other threads:[~2026-01-31 4:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 10:48 [PATCH v7 0/7] Enhanced autonomous selection and improvements Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 1/7] ACPI: CPPC: Add cppc_get_perf() API to read performance controls Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 2/7] ACPI: CPPC: Warn on missing mandatory DESIRED_PERF register Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 3/7] ACPI: CPPC: Extend cppc_set_epp_perf() for FFH/SystemMemory Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 4/7] ACPI: CPPC: add APIs and sysfs interface for min/max_perf Sumit Gupta
2026-01-31 4:06 ` zhenglifeng (A) [this message]
2026-01-31 13:58 ` Sumit Gupta
2026-02-03 1:36 ` Russell Haley
2026-02-03 9:41 ` Sumit Gupta
2026-02-03 12:45 ` Rafael J. Wysocki
2026-02-03 12:54 ` Rafael J. Wysocki
2026-02-03 14:31 ` Sumit Gupta
2026-02-03 20:24 ` Rafael J. Wysocki
2026-02-03 20:28 ` Mario Limonciello
2026-02-04 9:51 ` Sumit Gupta
2026-02-04 13:02 ` Rafael J. Wysocki
2026-02-05 19:21 ` Sumit Gupta
2026-02-05 19:27 ` Rafael J. Wysocki
2026-02-03 12:43 ` Rafael J. Wysocki
2026-02-03 12:50 ` Rafael J. Wysocki
2026-02-05 13:10 ` Artem Bityutskiy
2026-01-29 10:48 ` [PATCH v7 5/7] ACPI: CPPC: add APIs and sysfs interface for perf_limited Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 6/7] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Sumit Gupta
2026-01-29 10:48 ` [PATCH v7 7/7] cpufreq: CPPC: Update cached perf_ctrls on sysfs write Sumit Gupta
2026-01-30 8:23 ` [PATCH v7 0/7] Enhanced autonomous selection and improvements Pierre Gondois
2026-01-31 2:58 ` zhenglifeng (A)
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=4432fa04-e67c-422a-aae4-2938be431985@huawei.com \
--to=zhenglifeng1@huawei.com \
--cc=acpica-devel@lists.linux.dev \
--cc=bbasu@nvidia.com \
--cc=corbet@lwn.net \
--cc=gautham.shenoy@amd.com \
--cc=ionela.voinescu@arm.com \
--cc=jonathanh@nvidia.com \
--cc=ksitaraman@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nhartman@nvidia.com \
--cc=perry.yuan@amd.com \
--cc=pierre.gondois@arm.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=rdunlap@infradead.org \
--cc=robert.moore@intel.com \
--cc=sanjayc@nvidia.com \
--cc=sumitg@nvidia.com \
--cc=treding@nvidia.com \
--cc=viresh.kumar@linaro.org \
--cc=vsethi@nvidia.com \
--cc=zhanjie9@hisilicon.com \
/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