Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Sumit Gupta and committed by
Rafael J. Wysocki
4a1cf5ed b753c320

+27 -45
+27 -45
drivers/cpufreq/cppc_cpufreq.c
··· 863 863 return count; 864 864 } 865 865 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) 867 869 { 868 870 u64 val; 869 - int ret; 871 + int ret = get_func((int)cpu, &val); 870 872 871 - ret = cppc_get_auto_act_window(policy->cpu, &val); 872 - 873 - /* show "<unsupported>" when this register is not supported by cpc */ 874 873 if (ret == -EOPNOTSUPP) 875 874 return sysfs_emit(buf, "<unsupported>\n"); 876 875 ··· 879 880 return sysfs_emit(buf, "%llu\n", val); 880 881 } 881 882 882 - static ssize_t store_auto_act_window(struct cpufreq_policy *policy, 883 - const char *buf, size_t count) 884 - { 885 - u64 usec; 886 - int ret; 887 - 888 - ret = kstrtou64(buf, 0, &usec); 889 - if (ret) 890 - return ret; 891 - 892 - ret = cppc_set_auto_act_window(policy->cpu, usec); 893 - if (ret) 894 - return ret; 895 - 896 - return count; 897 - } 898 - 899 - static ssize_t show_energy_performance_preference_val(struct cpufreq_policy *policy, char *buf) 900 - { 901 - u64 val; 902 - int ret; 903 - 904 - ret = cppc_get_epp_perf(policy->cpu, &val); 905 - 906 - /* show "<unsupported>" when this register is not supported by cpc */ 907 - if (ret == -EOPNOTSUPP) 908 - return sysfs_emit(buf, "<unsupported>\n"); 909 - 910 - if (ret) 911 - return ret; 912 - 913 - return sysfs_emit(buf, "%llu\n", val); 914 - } 915 - 916 - static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *policy, 917 - const char *buf, size_t count) 883 + static ssize_t cppc_cpufreq_sysfs_store_u64(unsigned int cpu, 884 + int (*set_func)(int, u64), 885 + const char *buf, size_t count) 918 886 { 919 887 u64 val; 920 888 int ret; ··· 890 924 if (ret) 891 925 return ret; 892 926 893 - ret = cppc_set_epp(policy->cpu, val); 894 - if (ret) 895 - return ret; 927 + ret = set_func((int)cpu, val); 896 928 897 - return count; 929 + return ret ? ret : count; 898 930 } 931 + 932 + #define CPPC_CPUFREQ_ATTR_RW_U64(_name, _get_func, _set_func) \ 933 + static ssize_t show_##_name(struct cpufreq_policy *policy, char *buf) \ 934 + { \ 935 + return cppc_cpufreq_sysfs_show_u64(policy->cpu, _get_func, buf);\ 936 + } \ 937 + static ssize_t store_##_name(struct cpufreq_policy *policy, \ 938 + const char *buf, size_t count) \ 939 + { \ 940 + return cppc_cpufreq_sysfs_store_u64(policy->cpu, _set_func, \ 941 + buf, count); \ 942 + } 943 + 944 + CPPC_CPUFREQ_ATTR_RW_U64(auto_act_window, cppc_get_auto_act_window, 945 + cppc_set_auto_act_window) 946 + 947 + CPPC_CPUFREQ_ATTR_RW_U64(energy_performance_preference_val, 948 + cppc_get_epp_perf, cppc_set_epp) 899 949 900 950 cpufreq_freq_attr_ro(freqdomain_cpus); 901 951 cpufreq_freq_attr_rw(auto_select);