]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cpupower: Add the function to get the sysfs value from specific table
authorHuang Rui <ray.huang@amd.com>
Tue, 22 Feb 2022 15:34:20 +0000 (23:34 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Wed, 23 Feb 2022 01:36:44 +0000 (18:36 -0700)
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>
tools/power/cpupower/lib/cpufreq.c
tools/power/cpupower/lib/cpufreq.h

index c3b56db8b92149f52b6cc0a8764d89f4309b4ed9..1516d23c17c98c73aa605f6b684da064893744d7 100644 (file)
@@ -83,20 +83,21 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = {
        [STATS_NUM_TRANSITIONS] = "stats/total_trans"
 };
 
-
-static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
-                                                enum cpufreq_value which)
+unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
+                                                const char **table,
+                                                unsigned int index,
+                                                unsigned int size)
 {
        unsigned long value;
        unsigned int len;
        char linebuf[MAX_LINE_LEN];
        char *endp;
 
-       if (which >= MAX_CPUFREQ_VALUE_READ_FILES)
+       if (!table || index >= size || !table[index])
                return 0;
 
-       len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which],
-                               linebuf, sizeof(linebuf));
+       len = sysfs_cpufreq_read_file(cpu, table[index], linebuf,
+                                     sizeof(linebuf));
 
        if (len == 0)
                return 0;
@@ -109,6 +110,14 @@ static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
        return value;
 }
 
+static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
+                                                enum cpufreq_value which)
+{
+       return cpufreq_get_sysfs_value_from_table(cpu, cpufreq_value_files,
+                                                 which,
+                                                 MAX_CPUFREQ_VALUE_READ_FILES);
+}
+
 /* read access to files which contain one string */
 
 enum cpufreq_string {
@@ -124,7 +133,7 @@ static const char *cpufreq_string_files[MAX_CPUFREQ_STRING_FILES] = {
 
 
 static char *sysfs_cpufreq_get_one_string(unsigned int cpu,
-                                          enum cpufreq_string which)
+                                         enum cpufreq_string which)
 {
        char linebuf[MAX_LINE_LEN];
        char *result;
index 95f4fd9e2656c31f09dbf3ee37cd3851090790a3..2f3c840358063c17348efcc13621d6b5d71bdb79 100644 (file)
@@ -203,6 +203,18 @@ int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
 int cpufreq_set_frequency(unsigned int cpu,
                                unsigned long target_frequency);
 
+/*
+ * get the sysfs value from specific table
+ *
+ * Read the value with the sysfs file name from specific table. Does
+ * only work if the cpufreq driver has the specific sysfs interfaces.
+ */
+
+unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
+                                                const char **table,
+                                                unsigned int index,
+                                                unsigned int size);
+
 #ifdef __cplusplus
 }
 #endif