Skip to content

Commit 4a1cf5e

Browse files
Sumit Guptarafaeljw
authored andcommitted
cpufreq: CPPC: Add generic helpers for sysfs show/store
Add generic helper functions for u64 sysfs attributes that follow the common pattern of calling CPPC get/set APIs: - cppc_cpufreq_sysfs_show_u64(): reads value and handles -EOPNOTSUPP - cppc_cpufreq_sysfs_store_u64(): parses input and calls set function Add CPPC_CPUFREQ_ATTR_RW_U64() macro to generate show/store functions using these helpers, reducing boilerplate for simple attributes. Convert auto_act_window and energy_performance_preference_val to use the new macro. No functional changes. Signed-off-by: Sumit Gupta <sumitg@nvidia.com> Reviewed-by: Lifeng Zheng <zhenglifeng1@huawei.com> [ rjw: Retained empty code line after a conditional ] Link: https://patch.msgid.link/20260120145623.2959636-2-sumitg@nvidia.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent b753c32 commit 4a1cf5e

1 file changed

Lines changed: 25 additions & 43 deletions

File tree

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,13 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
863863
return count;
864864
}
865865

866-
static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *buf)
866+
static ssize_t cppc_cpufreq_sysfs_show_u64(unsigned int cpu,
867+
int (*get_func)(int, u64 *),
868+
char *buf)
867869
{
868870
u64 val;
869-
int ret;
870-
871-
ret = cppc_get_auto_act_window(policy->cpu, &val);
871+
int ret = get_func((int)cpu, &val);
872872

873-
/* show "<unsupported>" when this register is not supported by cpc */
874873
if (ret == -EOPNOTSUPP)
875874
return sysfs_emit(buf, "<unsupported>\n");
876875

@@ -880,56 +879,39 @@ static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *buf)
880879
return sysfs_emit(buf, "%llu\n", val);
881880
}
882881

883-
static ssize_t store_auto_act_window(struct cpufreq_policy *policy,
884-
const char *buf, size_t count)
882+
static ssize_t cppc_cpufreq_sysfs_store_u64(unsigned int cpu,
883+
int (*set_func)(int, u64),
884+
const char *buf, size_t count)
885885
{
886-
u64 usec;
886+
u64 val;
887887
int ret;
888888

889-
ret = kstrtou64(buf, 0, &usec);
889+
ret = kstrtou64(buf, 0, &val);
890890
if (ret)
891891
return ret;
892892

893-
ret = cppc_set_auto_act_window(policy->cpu, usec);
894-
if (ret)
895-
return ret;
893+
ret = set_func((int)cpu, val);
896894

897-
return count;
895+
return ret ? ret : count;
898896
}
899897

900-
static ssize_t show_energy_performance_preference_val(struct cpufreq_policy *policy, char *buf)
901-
{
902-
u64 val;
903-
int ret;
904-
905-
ret = cppc_get_epp_perf(policy->cpu, &val);
906-
907-
/* show "<unsupported>" when this register is not supported by cpc */
908-
if (ret == -EOPNOTSUPP)
909-
return sysfs_emit(buf, "<unsupported>\n");
910-
911-
if (ret)
912-
return ret;
913-
914-
return sysfs_emit(buf, "%llu\n", val);
898+
#define CPPC_CPUFREQ_ATTR_RW_U64(_name, _get_func, _set_func) \
899+
static ssize_t show_##_name(struct cpufreq_policy *policy, char *buf) \
900+
{ \
901+
return cppc_cpufreq_sysfs_show_u64(policy->cpu, _get_func, buf);\
902+
} \
903+
static ssize_t store_##_name(struct cpufreq_policy *policy, \
904+
const char *buf, size_t count) \
905+
{ \
906+
return cppc_cpufreq_sysfs_store_u64(policy->cpu, _set_func, \
907+
buf, count); \
915908
}
916909

917-
static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *policy,
918-
const char *buf, size_t count)
919-
{
920-
u64 val;
921-
int ret;
922-
923-
ret = kstrtou64(buf, 0, &val);
924-
if (ret)
925-
return ret;
926-
927-
ret = cppc_set_epp(policy->cpu, val);
928-
if (ret)
929-
return ret;
910+
CPPC_CPUFREQ_ATTR_RW_U64(auto_act_window, cppc_get_auto_act_window,
911+
cppc_set_auto_act_window)
930912

931-
return count;
932-
}
913+
CPPC_CPUFREQ_ATTR_RW_U64(energy_performance_preference_val,
914+
cppc_get_epp_perf, cppc_set_epp)
933915

934916
cpufreq_freq_attr_ro(freqdomain_cpus);
935917
cpufreq_freq_attr_rw(auto_select);

0 commit comments

Comments
 (0)