From: "zhenglifeng (A)" <zhenglifeng1@huawei.com>
To: Sumit Gupta <sumitg@nvidia.com>, <rafael@kernel.org>,
<viresh.kumar@linaro.org>, <lenb@kernel.org>,
<robert.moore@intel.com>, <corbet@lwn.net>,
<pierre.gondois@arm.com>, <rdunlap@infradead.org>,
<ray.huang@amd.com>, <gautham.shenoy@amd.com>,
<mario.limonciello@amd.com>, <perry.yuan@amd.com>,
<ionela.voinescu@arm.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>
Cc: <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 v5 01/11] cpufreq: CPPC: Add generic helpers for sysfs show/store
Date: Thu, 25 Dec 2025 11:41:19 +0800 [thread overview]
Message-ID: <dbbbdb83-24d4-465e-99bb-689cd6e37460@huawei.com> (raw)
In-Reply-To: <20251223121307.711773-2-sumitg@nvidia.com>
On 2025/12/23 20:12, Sumit Gupta wrote:
> Add generic show/store helper functions for u64 sysfs attributes:
> - cppc_cpufreq_sysfs_show_u64()
> - cppc_cpufreq_sysfs_store_u64()
>
> Refactor auto_act_window and energy_performance_preference_val
> attributes to use these helpers, eliminating code duplication.
How about adding a macro to generate show_xxx and store_xxx in one line?
Just a suggestion.
>
> No functional changes.
>
> Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
> ---
> drivers/cpufreq/cppc_cpufreq.c | 71 +++++++++++++++-------------------
> 1 file changed, 31 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 9eac77c4f294..7c26ce554e29 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -831,72 +831,63 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
> return count;
> }
>
> -static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *buf)
> +static ssize_t cppc_cpufreq_sysfs_show_u64(unsigned int cpu,
> + int (*get_func)(int, u64 *),
> + char *buf)
> {
> u64 val;
> - int ret;
> -
> - ret = cppc_get_auto_act_window(policy->cpu, &val);
> + int ret = get_func((int)cpu, &val);
>
> - /* show "<unsupported>" when this register is not supported by cpc */
> if (ret == -EOPNOTSUPP)
> return sysfs_emit(buf, "<unsupported>\n");
> -
> if (ret)
> return ret;
>
> return sysfs_emit(buf, "%llu\n", val);
> }
>
> -static ssize_t store_auto_act_window(struct cpufreq_policy *policy,
> - const char *buf, size_t count)
> +static ssize_t cppc_cpufreq_sysfs_store_u64(unsigned int cpu,
> + int (*set_func)(int, u64),
> + const char *buf, size_t count)
> {
> - u64 usec;
> + u64 val;
> int ret;
>
> - ret = kstrtou64(buf, 0, &usec);
> + ret = kstrtou64(buf, 0, &val);
> if (ret)
> return ret;
>
> - ret = cppc_set_auto_act_window(policy->cpu, usec);
> - if (ret)
> - return ret;
> + ret = set_func((int)cpu, val);
>
> - return count;
> + return ret ? ret : count;
> }
>
> -static ssize_t show_energy_performance_preference_val(struct cpufreq_policy *policy, char *buf)
> +static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *buf)
> {
> - u64 val;
> - int ret;
> -
> - ret = cppc_get_epp_perf(policy->cpu, &val);
> -
> - /* show "<unsupported>" when this register is not supported by cpc */
> - if (ret == -EOPNOTSUPP)
> - return sysfs_emit(buf, "<unsupported>\n");
> -
> - if (ret)
> - return ret;
> -
> - return sysfs_emit(buf, "%llu\n", val);
> + return cppc_cpufreq_sysfs_show_u64(policy->cpu,
> + cppc_get_auto_act_window, buf);
> }
>
> -static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *policy,
> - const char *buf, size_t count)
> +static ssize_t store_auto_act_window(struct cpufreq_policy *policy,
> + const char *buf, size_t count)
> {
> - u64 val;
> - int ret;
> -
> - ret = kstrtou64(buf, 0, &val);
> - if (ret)
> - return ret;
> + return cppc_cpufreq_sysfs_store_u64(policy->cpu,
> + cppc_set_auto_act_window,
> + buf, count);
> +}
>
> - ret = cppc_set_epp(policy->cpu, val);
> - if (ret)
> - return ret;
> +static ssize_t
> +show_energy_performance_preference_val(struct cpufreq_policy *policy, char *buf)
> +{
> + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_epp_perf, buf);
> +}
>
> - return count;
> +static ssize_t
> +store_energy_performance_preference_val(struct cpufreq_policy *policy,
> + const char *buf, size_t count)
> +{
> + return cppc_cpufreq_sysfs_store_u64(policy->cpu, cppc_set_epp,
> + buf, count);
> }
>
> cpufreq_freq_attr_ro(freqdomain_cpus);
next prev parent reply other threads:[~2025-12-25 3:41 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 12:12 [PATCH v5 00/11] Enhanced autonomous selection and improvements Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 01/11] cpufreq: CPPC: Add generic helpers for sysfs show/store Sumit Gupta
2025-12-25 3:41 ` zhenglifeng (A) [this message]
2026-01-08 13:31 ` Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 02/11] ACPI: CPPC: Clean up cppc_perf_caps and cppc_perf_ctrls structs Sumit Gupta
2026-01-08 13:43 ` Pierre Gondois
2025-12-23 12:12 ` [PATCH v5 03/11] ACPI: CPPC: Add cppc_get_perf() API to read performance controls Sumit Gupta
2025-12-25 8:21 ` zhenglifeng (A)
2026-01-08 13:36 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 04/11] ACPI: CPPC: Extend cppc_set_epp_perf() to support auto_sel and epp Sumit Gupta
2025-12-25 3:56 ` zhenglifeng (A)
2026-01-08 13:39 ` Sumit Gupta
2026-01-16 15:59 ` Pierre Gondois
2025-12-23 12:13 ` [PATCH v5 05/11] ACPI: CPPC: add APIs and sysfs interface for min/max_perf Sumit Gupta
2025-12-25 9:03 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 06/11] ACPI: CPPC: add APIs and sysfs interface for perf_limited Sumit Gupta
2025-12-25 12:06 ` zhenglifeng (A)
2026-01-08 14:38 ` Sumit Gupta
2026-01-15 8:01 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 07/11] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Sumit Gupta
2025-12-24 18:32 ` kernel test robot
2025-12-26 0:20 ` Bagas Sanjaya
2026-01-08 14:30 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 08/11] cpufreq: CPPC: sync policy limits when updating min/max_perf Sumit Gupta
2025-12-25 13:56 ` zhenglifeng (A)
2026-01-08 13:53 ` Sumit Gupta
2026-01-15 8:20 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 09/11] cpufreq: CPPC: sync policy limits when toggling auto_select Sumit Gupta
2025-12-26 2:55 ` zhenglifeng (A)
2026-01-08 14:21 ` Sumit Gupta
2026-01-15 8:57 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 10/11] cpufreq: CPPC: make scaling_min/max_freq read-only when auto_sel enabled Sumit Gupta
2025-12-26 3:26 ` zhenglifeng (A)
2026-01-08 14:01 ` Sumit Gupta
2026-01-08 16:46 ` Pierre Gondois
2026-01-09 14:37 ` Sumit Gupta
2026-01-12 11:44 ` Pierre Gondois
2026-01-15 12:32 ` zhenglifeng (A)
2026-01-15 15:22 ` Sumit Gupta
2026-01-16 17:05 ` Pierre Gondois
2026-01-15 15:15 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 11/11] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2025-12-26 8:03 ` zhenglifeng (A)
2026-01-08 14:04 ` Sumit Gupta
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=dbbbdb83-24d4-465e-99bb-689cd6e37460@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