Skip to content

Commit e3ede97

Browse files
huangruishuahkh
authored andcommitted
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>
1 parent 083792f commit e3ede97

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

tools/power/cpupower/lib/cpufreq.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,21 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = {
8383
[STATS_NUM_TRANSITIONS] = "stats/total_trans"
8484
};
8585

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)
8990
{
9091
unsigned long value;
9192
unsigned int len;
9293
char linebuf[MAX_LINE_LEN];
9394
char *endp;
9495

95-
if (which >= MAX_CPUFREQ_VALUE_READ_FILES)
96+
if (!table || index >= size || !table[index])
9697
return 0;
9798

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));
100101

101102
if (len == 0)
102103
return 0;
@@ -109,6 +110,14 @@ static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
109110
return value;
110111
}
111112

113+
static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
114+
enum cpufreq_value which)
115+
{
116+
return cpufreq_get_sysfs_value_from_table(cpu, cpufreq_value_files,
117+
which,
118+
MAX_CPUFREQ_VALUE_READ_FILES);
119+
}
120+
112121
/* read access to files which contain one string */
113122

114123
enum cpufreq_string {
@@ -124,7 +133,7 @@ static const char *cpufreq_string_files[MAX_CPUFREQ_STRING_FILES] = {
124133

125134

126135
static char *sysfs_cpufreq_get_one_string(unsigned int cpu,
127-
enum cpufreq_string which)
136+
enum cpufreq_string which)
128137
{
129138
char linebuf[MAX_LINE_LEN];
130139
char *result;

tools/power/cpupower/lib/cpufreq.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
203203
int cpufreq_set_frequency(unsigned int cpu,
204204
unsigned long target_frequency);
205205

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+
206218
#ifdef __cplusplus
207219
}
208220
#endif

0 commit comments

Comments
 (0)