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

cpupower: Add the function to get the sysfs value from specific table

Expose the helper into cpufreq header, then cpufreq driver can use this
function to get the sysfs value if it has any specific sysfs interfaces.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Huang Rui and committed by
Shuah Khan
e3ede976 083792f3

+28 -7
+16 -7
tools/power/cpupower/lib/cpufreq.c
··· 83 83 [STATS_NUM_TRANSITIONS] = "stats/total_trans" 84 84 }; 85 85 86 - 87 - static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu, 88 - enum cpufreq_value which) 86 + unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 87 + const char **table, 88 + unsigned int index, 89 + unsigned int size) 89 90 { 90 91 unsigned long value; 91 92 unsigned int len; 92 93 char linebuf[MAX_LINE_LEN]; 93 94 char *endp; 94 95 95 - if (which >= MAX_CPUFREQ_VALUE_READ_FILES) 96 + if (!table || index >= size || !table[index]) 96 97 return 0; 97 98 98 - len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which], 99 - linebuf, sizeof(linebuf)); 99 + len = sysfs_cpufreq_read_file(cpu, table[index], linebuf, 100 + sizeof(linebuf)); 100 101 101 102 if (len == 0) 102 103 return 0; ··· 108 107 return 0; 109 108 110 109 return value; 110 + } 111 + 112 + static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu, 113 + enum cpufreq_value which) 114 + { 115 + return cpufreq_get_sysfs_value_from_table(cpu, cpufreq_value_files, 116 + which, 117 + MAX_CPUFREQ_VALUE_READ_FILES); 111 118 } 112 119 113 120 /* read access to files which contain one string */ ··· 133 124 134 125 135 126 static char *sysfs_cpufreq_get_one_string(unsigned int cpu, 136 - enum cpufreq_string which) 127 + enum cpufreq_string which) 137 128 { 138 129 char linebuf[MAX_LINE_LEN]; 139 130 char *result;
+12
tools/power/cpupower/lib/cpufreq.h
··· 203 203 int cpufreq_set_frequency(unsigned int cpu, 204 204 unsigned long target_frequency); 205 205 206 + /* 207 + * get the sysfs value from specific table 208 + * 209 + * Read the value with the sysfs file name from specific table. Does 210 + * only work if the cpufreq driver has the specific sysfs interfaces. 211 + */ 212 + 213 + unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 214 + const char **table, 215 + unsigned int index, 216 + unsigned int size); 217 + 206 218 #ifdef __cplusplus 207 219 } 208 220 #endif