diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2011-04-19 14:16:05 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2011-07-29 12:35:39 -0400 |
commit | 2cd005cac6d586b8ca324814a9c58ed0c08ffe40 (patch) | |
tree | 6c5fb6c321598dff913ab0e948bab809859c9756 /tools/power | |
parent | b510b54127a4d4112a9a3f200339719bcb463c15 (diff) |
cpupowerutils: helpers - ConfigStyle bugfixes
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'tools/power')
-rw-r--r-- | tools/power/cpupower/utils/helpers/amd.c | 8 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/bitmask.c | 12 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/cpuid.c | 14 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/helpers.h | 6 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/misc.c | 3 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/pci.c | 2 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/sysfs.c | 112 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/sysfs.h | 23 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/topology.c | 6 |
9 files changed, 100 insertions, 86 deletions
diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c index 5e44e31fc7f9..87d5605bdda8 100644 --- a/tools/power/cpupower/utils/helpers/amd.c +++ b/tools/power/cpupower/utils/helpers/amd.c | |||
@@ -53,8 +53,8 @@ static int get_cof(int family, union msr_pstate pstate) | |||
53 | if (family == 0x11) | 53 | if (family == 0x11) |
54 | t = 0x8; | 54 | t = 0x8; |
55 | 55 | ||
56 | return ((100 * (fid + t)) >> did); | 56 | return (100 * (fid + t)) >> did; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* Needs: | 59 | /* Needs: |
60 | * cpu -> the cpu that gets evaluated | 60 | * cpu -> the cpu that gets evaluated |
@@ -74,7 +74,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family, | |||
74 | { | 74 | { |
75 | int i, psmax, pscur; | 75 | int i, psmax, pscur; |
76 | union msr_pstate pstate; | 76 | union msr_pstate pstate; |
77 | unsigned long long val; | 77 | unsigned long long val; |
78 | 78 | ||
79 | /* Only read out frequencies from HW when CPU might be boostable | 79 | /* Only read out frequencies from HW when CPU might be boostable |
80 | to keep the code as short and clean as possible. | 80 | to keep the code as short and clean as possible. |
@@ -95,7 +95,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family, | |||
95 | 95 | ||
96 | pscur += boost_states; | 96 | pscur += boost_states; |
97 | psmax += boost_states; | 97 | psmax += boost_states; |
98 | for (i=0; i<=psmax; i++) { | 98 | for (i = 0; i <= psmax; i++) { |
99 | if (i >= MAX_HW_PSTATES) { | 99 | if (i >= MAX_HW_PSTATES) { |
100 | fprintf(stderr, "HW pstates [%d] exceeding max [%d]\n", | 100 | fprintf(stderr, "HW pstates [%d] exceeding max [%d]\n", |
101 | psmax, MAX_HW_PSTATES); | 101 | psmax, MAX_HW_PSTATES); |
diff --git a/tools/power/cpupower/utils/helpers/bitmask.c b/tools/power/cpupower/utils/helpers/bitmask.c index 60f4d69bb20d..5c074c60f904 100644 --- a/tools/power/cpupower/utils/helpers/bitmask.c +++ b/tools/power/cpupower/utils/helpers/bitmask.c | |||
@@ -8,12 +8,12 @@ | |||
8 | #define bitsperlong (8 * sizeof(unsigned long)) | 8 | #define bitsperlong (8 * sizeof(unsigned long)) |
9 | 9 | ||
10 | /* howmany(a,b) : how many elements of size b needed to hold all of a */ | 10 | /* howmany(a,b) : how many elements of size b needed to hold all of a */ |
11 | #define howmany(x,y) (((x)+((y)-1))/(y)) | 11 | #define howmany(x, y) (((x)+((y)-1))/(y)) |
12 | 12 | ||
13 | /* How many longs in mask of n bits */ | 13 | /* How many longs in mask of n bits */ |
14 | #define longsperbits(n) howmany(n, bitsperlong) | 14 | #define longsperbits(n) howmany(n, bitsperlong) |
15 | 15 | ||
16 | #define max(a,b) ((a) > (b) ? (a) : (b)) | 16 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
17 | 17 | ||
18 | /* | 18 | /* |
19 | * Allocate and free `struct bitmask *` | 19 | * Allocate and free `struct bitmask *` |
@@ -73,7 +73,8 @@ static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v) | |||
73 | if (v) | 73 | if (v) |
74 | bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong); | 74 | bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong); |
75 | else | 75 | else |
76 | bmp->maskp[n/bitsperlong] &= ~(1UL << (n % bitsperlong)); | 76 | bmp->maskp[n/bitsperlong] &= |
77 | ~(1UL << (n % bitsperlong)); | ||
77 | } | 78 | } |
78 | } | 79 | } |
79 | 80 | ||
@@ -185,7 +186,7 @@ unsigned int bitmask_next(const struct bitmask *bmp, unsigned int i) | |||
185 | * 0-3 0,1,2,3 | 186 | * 0-3 0,1,2,3 |
186 | * 0-7:2 0,2,4,6 | 187 | * 0-7:2 0,2,4,6 |
187 | * 1,3,5-7 1,3,5,6,7 | 188 | * 1,3,5-7 1,3,5,6,7 |
188 | * 0-3:2,8-15:4 0,2,8,12 | 189 | * 0-3:2,8-15:4 0,2,8,12 |
189 | */ | 190 | */ |
190 | int bitmask_parselist(const char *buf, struct bitmask *bmp) | 191 | int bitmask_parselist(const char *buf, struct bitmask *bmp) |
191 | { | 192 | { |
@@ -251,7 +252,8 @@ static inline int emit(char *buf, int buflen, int rbot, int rtop, int len) | |||
251 | if (rbot == rtop) | 252 | if (rbot == rtop) |
252 | len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot); | 253 | len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot); |
253 | else | 254 | else |
254 | len += snprintf(buf + len, max(buflen - len, 0), "%d-%d", rbot, rtop); | 255 | len += snprintf(buf + len, max(buflen - len, 0), "%d-%d", |
256 | rbot, rtop); | ||
255 | return len; | 257 | return len; |
256 | } | 258 | } |
257 | 259 | ||
diff --git a/tools/power/cpupower/utils/helpers/cpuid.c b/tools/power/cpupower/utils/helpers/cpuid.c index 71021f3bb69d..944b2c1659d8 100644 --- a/tools/power/cpupower/utils/helpers/cpuid.c +++ b/tools/power/cpupower/utils/helpers/cpuid.c | |||
@@ -67,28 +67,26 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info) | |||
67 | continue; | 67 | continue; |
68 | value[63 - 1] = '\0'; | 68 | value[63 - 1] = '\0'; |
69 | 69 | ||
70 | if (!strncmp(value, "processor\t: ", 12)) { | 70 | if (!strncmp(value, "processor\t: ", 12)) |
71 | sscanf(value, "processor\t: %u", &proc); | 71 | sscanf(value, "processor\t: %u", &proc); |
72 | } | 72 | |
73 | if (proc != cpu) | 73 | if (proc != cpu) |
74 | continue; | 74 | continue; |
75 | 75 | ||
76 | /* Get CPU vendor */ | 76 | /* Get CPU vendor */ |
77 | if (!strncmp(value, "vendor_id", 9)) | 77 | if (!strncmp(value, "vendor_id", 9)) { |
78 | for (x = 1; x < X86_VENDOR_MAX; x++) { | 78 | for (x = 1; x < X86_VENDOR_MAX; x++) { |
79 | if (strstr(value, cpu_vendor_table[x])) | 79 | if (strstr(value, cpu_vendor_table[x])) |
80 | cpu_info->vendor = x; | 80 | cpu_info->vendor = x; |
81 | } | 81 | } |
82 | /* Get CPU family, etc. */ | 82 | /* Get CPU family, etc. */ |
83 | else if (!strncmp(value, "cpu family\t: ", 13)) { | 83 | } else if (!strncmp(value, "cpu family\t: ", 13)) { |
84 | sscanf(value, "cpu family\t: %u", | 84 | sscanf(value, "cpu family\t: %u", |
85 | &cpu_info->family); | 85 | &cpu_info->family); |
86 | } | 86 | } else if (!strncmp(value, "model\t\t: ", 9)) { |
87 | else if (!strncmp(value, "model\t\t: ", 9)) { | ||
88 | sscanf(value, "model\t\t: %u", | 87 | sscanf(value, "model\t\t: %u", |
89 | &cpu_info->model); | 88 | &cpu_info->model); |
90 | } | 89 | } else if (!strncmp(value, "stepping\t: ", 10)) { |
91 | else if (!strncmp(value, "stepping\t: ", 10)) { | ||
92 | sscanf(value, "stepping\t: %u", | 90 | sscanf(value, "stepping\t: %u", |
93 | &cpu_info->stepping); | 91 | &cpu_info->stepping); |
94 | 92 | ||
diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h index a487dadb4cf0..048f065925c9 100644 --- a/tools/power/cpupower/utils/helpers/helpers.h +++ b/tools/power/cpupower/utils/helpers/helpers.h | |||
@@ -20,7 +20,7 @@ | |||
20 | #ifndef gettext_noop | 20 | #ifndef gettext_noop |
21 | #define gettext_noop(String) String | 21 | #define gettext_noop(String) String |
22 | #endif | 22 | #endif |
23 | #define N_(String) gettext_noop (String) | 23 | #define N_(String) gettext_noop(String) |
24 | /* Internationalization ****************************/ | 24 | /* Internationalization ****************************/ |
25 | 25 | ||
26 | extern int run_as_root; | 26 | extern int run_as_root; |
@@ -39,11 +39,11 @@ extern int be_verbose; | |||
39 | #define dprint(fmt, ...) { \ | 39 | #define dprint(fmt, ...) { \ |
40 | if (be_verbose) { \ | 40 | if (be_verbose) { \ |
41 | fprintf(stderr, "%s: " fmt, \ | 41 | fprintf(stderr, "%s: " fmt, \ |
42 | __FUNCTION__, ##__VA_ARGS__); \ | 42 | __func__, ##__VA_ARGS__); \ |
43 | } \ | 43 | } \ |
44 | } | 44 | } |
45 | #else | 45 | #else |
46 | static inline void dprint(const char *fmt, ...) { } | 46 | static inline void dprint(const char *fmt, ...) { } |
47 | #endif | 47 | #endif |
48 | extern int be_verbose; | 48 | extern int be_verbose; |
49 | /* Global verbose (-v) stuff *********************************/ | 49 | /* Global verbose (-v) stuff *********************************/ |
diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index c1566e93e0ec..e8b3140cc6b8 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | #include "helpers/helpers.h" | 3 | #include "helpers/helpers.h" |
4 | 4 | ||
5 | int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, int * states) | 5 | int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, |
6 | int *states) | ||
6 | { | 7 | { |
7 | struct cpupower_cpu_info cpu_info; | 8 | struct cpupower_cpu_info cpu_info; |
8 | int ret; | 9 | int ret; |
diff --git a/tools/power/cpupower/utils/helpers/pci.c b/tools/power/cpupower/utils/helpers/pci.c index 8dcc93813716..cd2eb6fe41c4 100644 --- a/tools/power/cpupower/utils/helpers/pci.c +++ b/tools/power/cpupower/utils/helpers/pci.c | |||
@@ -33,7 +33,7 @@ struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id, | |||
33 | 33 | ||
34 | for (i = 0; dev_ids[i] != 0; i++) { | 34 | for (i = 0; dev_ids[i] != 0; i++) { |
35 | filter_nb_link.device = dev_ids[i]; | 35 | filter_nb_link.device = dev_ids[i]; |
36 | for (device=(*pacc)->devices; device; device = device->next) { | 36 | for (device = (*pacc)->devices; device; device = device->next) { |
37 | if (pci_filter_match(&filter_nb_link, device)) | 37 | if (pci_filter_match(&filter_nb_link, device)) |
38 | return device; | 38 | return device; |
39 | } | 39 | } |
diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c index 0c534e79652b..55e2466674c6 100644 --- a/tools/power/cpupower/utils/helpers/sysfs.c +++ b/tools/power/cpupower/utils/helpers/sysfs.c | |||
@@ -19,14 +19,14 @@ | |||
19 | unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen) | 19 | unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen) |
20 | { | 20 | { |
21 | int fd; | 21 | int fd; |
22 | size_t numread; | 22 | ssize_t numread; |
23 | 23 | ||
24 | if ( ( fd = open(path, O_RDONLY) ) == -1 ) | 24 | fd = open(path, O_RDONLY); |
25 | if (fd == -1) | ||
25 | return 0; | 26 | return 0; |
26 | 27 | ||
27 | numread = read(fd, buf, buflen - 1); | 28 | numread = read(fd, buf, buflen - 1); |
28 | if ( numread < 1 ) | 29 | if (numread < 1) { |
29 | { | ||
30 | close(fd); | 30 | close(fd); |
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
@@ -34,26 +34,26 @@ unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen) | |||
34 | buf[numread] = '\0'; | 34 | buf[numread] = '\0'; |
35 | close(fd); | 35 | close(fd); |
36 | 36 | ||
37 | return numread; | 37 | return (unsigned int) numread; |
38 | } | 38 | } |
39 | 39 | ||
40 | static unsigned int sysfs_write_file(const char *path, | 40 | static unsigned int sysfs_write_file(const char *path, |
41 | const char *value, size_t len) | 41 | const char *value, size_t len) |
42 | { | 42 | { |
43 | int fd; | 43 | int fd; |
44 | size_t numwrite; | 44 | ssize_t numwrite; |
45 | 45 | ||
46 | if ( ( fd = open(path, O_WRONLY) ) == -1 ) | 46 | fd = open(path, O_WRONLY); |
47 | if (fd == -1) | ||
47 | return 0; | 48 | return 0; |
48 | 49 | ||
49 | numwrite = write(fd, value, len); | 50 | numwrite = write(fd, value, len); |
50 | if ( numwrite < 1 ) | 51 | if (numwrite < 1) { |
51 | { | ||
52 | close(fd); | 52 | close(fd); |
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | close(fd); | 55 | close(fd); |
56 | return numwrite; | 56 | return (unsigned int) numwrite; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ | 59 | /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ |
@@ -69,17 +69,17 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate, | |||
69 | { | 69 | { |
70 | char path[SYSFS_PATH_MAX]; | 70 | char path[SYSFS_PATH_MAX]; |
71 | int fd; | 71 | int fd; |
72 | size_t numread; | 72 | ssize_t numread; |
73 | 73 | ||
74 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", | 74 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", |
75 | cpu, idlestate, fname); | 75 | cpu, idlestate, fname); |
76 | 76 | ||
77 | if ( ( fd = open(path, O_RDONLY) ) == -1 ) | 77 | fd = open(path, O_RDONLY); |
78 | if (fd == -1) | ||
78 | return 0; | 79 | return 0; |
79 | 80 | ||
80 | numread = read(fd, buf, buflen - 1); | 81 | numread = read(fd, buf, buflen - 1); |
81 | if ( numread < 1 ) | 82 | if (numread < 1) { |
82 | { | ||
83 | close(fd); | 83 | close(fd); |
84 | return 0; | 84 | return 0; |
85 | } | 85 | } |
@@ -87,7 +87,7 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate, | |||
87 | buf[numread] = '\0'; | 87 | buf[numread] = '\0'; |
88 | close(fd); | 88 | close(fd); |
89 | 89 | ||
90 | return numread; | 90 | return (unsigned int) numread; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* read access to files which contain one numeric value */ | 93 | /* read access to files which contain one numeric value */ |
@@ -116,19 +116,18 @@ static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu, | |||
116 | char linebuf[MAX_LINE_LEN]; | 116 | char linebuf[MAX_LINE_LEN]; |
117 | char *endp; | 117 | char *endp; |
118 | 118 | ||
119 | if ( which >= MAX_IDLESTATE_VALUE_FILES ) | 119 | if (which >= MAX_IDLESTATE_VALUE_FILES) |
120 | return 0; | 120 | return 0; |
121 | 121 | ||
122 | if ( ( len = sysfs_idlestate_read_file(cpu, idlestate, | 122 | len = sysfs_idlestate_read_file(cpu, idlestate, |
123 | idlestate_value_files[which], | 123 | idlestate_value_files[which], |
124 | linebuf, sizeof(linebuf))) == 0 ) | 124 | linebuf, sizeof(linebuf)); |
125 | { | 125 | if (len == 0) |
126 | return 0; | 126 | return 0; |
127 | } | ||
128 | 127 | ||
129 | value = strtoull(linebuf, &endp, 0); | 128 | value = strtoull(linebuf, &endp, 0); |
130 | 129 | ||
131 | if ( endp == linebuf || errno == ERANGE ) | 130 | if (endp == linebuf || errno == ERANGE) |
132 | return 0; | 131 | return 0; |
133 | 132 | ||
134 | return value; | 133 | return value; |
@@ -148,9 +147,9 @@ static const char *idlestate_string_files[MAX_IDLESTATE_STRING_FILES] = { | |||
148 | }; | 147 | }; |
149 | 148 | ||
150 | 149 | ||
151 | static char * sysfs_idlestate_get_one_string(unsigned int cpu, | 150 | static char *sysfs_idlestate_get_one_string(unsigned int cpu, |
152 | unsigned int idlestate, | 151 | unsigned int idlestate, |
153 | enum idlestate_string which) | 152 | enum idlestate_string which) |
154 | { | 153 | { |
155 | char linebuf[MAX_LINE_LEN]; | 154 | char linebuf[MAX_LINE_LEN]; |
156 | char *result; | 155 | char *result; |
@@ -159,12 +158,14 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu, | |||
159 | if (which >= MAX_IDLESTATE_STRING_FILES) | 158 | if (which >= MAX_IDLESTATE_STRING_FILES) |
160 | return NULL; | 159 | return NULL; |
161 | 160 | ||
162 | if ( ( len = sysfs_idlestate_read_file(cpu, idlestate, | 161 | len = sysfs_idlestate_read_file(cpu, idlestate, |
163 | idlestate_string_files[which], | 162 | idlestate_string_files[which], |
164 | linebuf, sizeof(linebuf))) == 0 ) | 163 | linebuf, sizeof(linebuf)); |
164 | if (len == 0) | ||
165 | return NULL; | 165 | return NULL; |
166 | 166 | ||
167 | if ( ( result = strdup(linebuf) ) == NULL ) | 167 | result = strdup(linebuf); |
168 | if (result == NULL) | ||
168 | return NULL; | 169 | return NULL; |
169 | 170 | ||
170 | if (result[strlen(result) - 1] == '\n') | 171 | if (result[strlen(result) - 1] == '\n') |
@@ -173,27 +174,30 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu, | |||
173 | return result; | 174 | return result; |
174 | } | 175 | } |
175 | 176 | ||
176 | unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate) | 177 | unsigned long sysfs_get_idlestate_latency(unsigned int cpu, |
178 | unsigned int idlestate) | ||
177 | { | 179 | { |
178 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); | 180 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); |
179 | } | 181 | } |
180 | 182 | ||
181 | unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate) | 183 | unsigned long sysfs_get_idlestate_usage(unsigned int cpu, |
184 | unsigned int idlestate) | ||
182 | { | 185 | { |
183 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE); | 186 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE); |
184 | } | 187 | } |
185 | 188 | ||
186 | unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate) | 189 | unsigned long long sysfs_get_idlestate_time(unsigned int cpu, |
190 | unsigned int idlestate) | ||
187 | { | 191 | { |
188 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME); | 192 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME); |
189 | } | 193 | } |
190 | 194 | ||
191 | char * sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate) | 195 | char *sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate) |
192 | { | 196 | { |
193 | return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_NAME); | 197 | return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_NAME); |
194 | } | 198 | } |
195 | 199 | ||
196 | char * sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate) | 200 | char *sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate) |
197 | { | 201 | { |
198 | return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_DESC); | 202 | return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_DESC); |
199 | } | 203 | } |
@@ -211,14 +215,14 @@ int sysfs_get_idlestate_count(unsigned int cpu) | |||
211 | 215 | ||
212 | 216 | ||
213 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpuidle"); | 217 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpuidle"); |
214 | if ( stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) | 218 | if (stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) |
215 | return -ENODEV; | 219 | return -ENODEV; |
216 | 220 | ||
217 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu); | 221 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu); |
218 | if ( stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) | 222 | if (stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) |
219 | return 0; | 223 | return 0; |
220 | 224 | ||
221 | while(stat(file, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) { | 225 | while (stat(file, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) { |
222 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU | 226 | snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU |
223 | "cpu%u/cpuidle/state%d", cpu, idlestates); | 227 | "cpu%u/cpuidle/state%d", cpu, idlestates); |
224 | idlestates++; | 228 | idlestates++; |
@@ -261,7 +265,7 @@ static const char *cpuidle_string_files[MAX_CPUIDLE_STRING_FILES] = { | |||
261 | }; | 265 | }; |
262 | 266 | ||
263 | 267 | ||
264 | static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which) | 268 | static char *sysfs_cpuidle_get_one_string(enum cpuidle_string which) |
265 | { | 269 | { |
266 | char linebuf[MAX_LINE_LEN]; | 270 | char linebuf[MAX_LINE_LEN]; |
267 | char *result; | 271 | char *result; |
@@ -270,11 +274,13 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which) | |||
270 | if (which >= MAX_CPUIDLE_STRING_FILES) | 274 | if (which >= MAX_CPUIDLE_STRING_FILES) |
271 | return NULL; | 275 | return NULL; |
272 | 276 | ||
273 | if ( ( len = sysfs_cpuidle_read_file(cpuidle_string_files[which], | 277 | len = sysfs_cpuidle_read_file(cpuidle_string_files[which], |
274 | linebuf, sizeof(linebuf))) == 0 ) | 278 | linebuf, sizeof(linebuf)); |
279 | if (len == 0) | ||
275 | return NULL; | 280 | return NULL; |
276 | 281 | ||
277 | if ( ( result = strdup(linebuf) ) == NULL ) | 282 | result = strdup(linebuf); |
283 | if (result == NULL) | ||
278 | return NULL; | 284 | return NULL; |
279 | 285 | ||
280 | if (result[strlen(result) - 1] == '\n') | 286 | if (result[strlen(result) - 1] == '\n') |
@@ -283,7 +289,7 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which) | |||
283 | return result; | 289 | return result; |
284 | } | 290 | } |
285 | 291 | ||
286 | char * sysfs_get_cpuidle_governor(void) | 292 | char *sysfs_get_cpuidle_governor(void) |
287 | { | 293 | { |
288 | char *tmp = sysfs_cpuidle_get_one_string(CPUIDLE_GOVERNOR_RO); | 294 | char *tmp = sysfs_cpuidle_get_one_string(CPUIDLE_GOVERNOR_RO); |
289 | if (!tmp) | 295 | if (!tmp) |
@@ -292,7 +298,7 @@ char * sysfs_get_cpuidle_governor(void) | |||
292 | return tmp; | 298 | return tmp; |
293 | } | 299 | } |
294 | 300 | ||
295 | char * sysfs_get_cpuidle_driver(void) | 301 | char *sysfs_get_cpuidle_driver(void) |
296 | { | 302 | { |
297 | return sysfs_cpuidle_get_one_string(CPUIDLE_DRIVER); | 303 | return sysfs_cpuidle_get_one_string(CPUIDLE_DRIVER); |
298 | } | 304 | } |
@@ -304,9 +310,9 @@ char * sysfs_get_cpuidle_driver(void) | |||
304 | * | 310 | * |
305 | * Returns negative value on failure | 311 | * Returns negative value on failure |
306 | */ | 312 | */ |
307 | int sysfs_get_sched(const char* smt_mc) | 313 | int sysfs_get_sched(const char *smt_mc) |
308 | { | 314 | { |
309 | unsigned long value; | 315 | unsigned long value; |
310 | char linebuf[MAX_LINE_LEN]; | 316 | char linebuf[MAX_LINE_LEN]; |
311 | char *endp; | 317 | char *endp; |
312 | char path[SYSFS_PATH_MAX]; | 318 | char path[SYSFS_PATH_MAX]; |
@@ -314,11 +320,12 @@ int sysfs_get_sched(const char* smt_mc) | |||
314 | if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) | 320 | if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) |
315 | return -EINVAL; | 321 | return -EINVAL; |
316 | 322 | ||
317 | snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc); | 323 | snprintf(path, sizeof(path), |
318 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0 ) | 324 | PATH_TO_CPU "sched_%s_power_savings", smt_mc); |
325 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0) | ||
319 | return -1; | 326 | return -1; |
320 | value = strtoul(linebuf, &endp, 0); | 327 | value = strtoul(linebuf, &endp, 0); |
321 | if ( endp == linebuf || errno == ERANGE ) | 328 | if (endp == linebuf || errno == ERANGE) |
322 | return -1; | 329 | return -1; |
323 | return value; | 330 | return value; |
324 | } | 331 | } |
@@ -329,7 +336,7 @@ int sysfs_get_sched(const char* smt_mc) | |||
329 | * | 336 | * |
330 | * Returns negative value on failure | 337 | * Returns negative value on failure |
331 | */ | 338 | */ |
332 | int sysfs_set_sched(const char* smt_mc, int val) | 339 | int sysfs_set_sched(const char *smt_mc, int val) |
333 | { | 340 | { |
334 | char linebuf[MAX_LINE_LEN]; | 341 | char linebuf[MAX_LINE_LEN]; |
335 | char path[SYSFS_PATH_MAX]; | 342 | char path[SYSFS_PATH_MAX]; |
@@ -338,13 +345,14 @@ int sysfs_set_sched(const char* smt_mc, int val) | |||
338 | if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) | 345 | if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) |
339 | return -EINVAL; | 346 | return -EINVAL; |
340 | 347 | ||
341 | snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc); | 348 | snprintf(path, sizeof(path), |
349 | PATH_TO_CPU "sched_%s_power_savings", smt_mc); | ||
342 | sprintf(linebuf, "%d", val); | 350 | sprintf(linebuf, "%d", val); |
343 | 351 | ||
344 | if ( stat(path, &statbuf) != 0 ) | 352 | if (stat(path, &statbuf) != 0) |
345 | return -ENODEV; | 353 | return -ENODEV; |
346 | 354 | ||
347 | if (sysfs_write_file(path, linebuf, MAX_LINE_LEN) == 0 ) | 355 | if (sysfs_write_file(path, linebuf, MAX_LINE_LEN) == 0) |
348 | return -1; | 356 | return -1; |
349 | return 0; | 357 | return 0; |
350 | } | 358 | } |
diff --git a/tools/power/cpupower/utils/helpers/sysfs.h b/tools/power/cpupower/utils/helpers/sysfs.h index 5d02d2fc70e1..f9373e090637 100644 --- a/tools/power/cpupower/utils/helpers/sysfs.h +++ b/tools/power/cpupower/utils/helpers/sysfs.h | |||
@@ -7,17 +7,22 @@ | |||
7 | 7 | ||
8 | extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen); | 8 | extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen); |
9 | 9 | ||
10 | extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate); | 10 | extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, |
11 | extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate); | 11 | unsigned int idlestate); |
12 | extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate); | 12 | extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, |
13 | extern char * sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate); | 13 | unsigned int idlestate); |
14 | extern char * sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate); | 14 | extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu, |
15 | unsigned int idlestate); | ||
16 | extern char *sysfs_get_idlestate_name(unsigned int cpu, | ||
17 | unsigned int idlestate); | ||
18 | extern char *sysfs_get_idlestate_desc(unsigned int cpu, | ||
19 | unsigned int idlestate); | ||
15 | extern int sysfs_get_idlestate_count(unsigned int cpu); | 20 | extern int sysfs_get_idlestate_count(unsigned int cpu); |
16 | 21 | ||
17 | extern char * sysfs_get_cpuidle_governor(void); | 22 | extern char *sysfs_get_cpuidle_governor(void); |
18 | extern char * sysfs_get_cpuidle_driver(void); | 23 | extern char *sysfs_get_cpuidle_driver(void); |
19 | 24 | ||
20 | extern int sysfs_get_sched(const char* smt_mc); | 25 | extern int sysfs_get_sched(const char *smt_mc); |
21 | extern int sysfs_set_sched(const char* smt_mc, int val); | 26 | extern int sysfs_set_sched(const char *smt_mc, int val); |
22 | 27 | ||
23 | #endif /* __CPUPOWER_HELPERS_SYSFS_H__ */ | 28 | #endif /* __CPUPOWER_HELPERS_SYSFS_H__ */ |
diff --git a/tools/power/cpupower/utils/helpers/topology.c b/tools/power/cpupower/utils/helpers/topology.c index 5ad842b956bb..385ee5c7570c 100644 --- a/tools/power/cpupower/utils/helpers/topology.c +++ b/tools/power/cpupower/utils/helpers/topology.c | |||
@@ -22,17 +22,17 @@ | |||
22 | /* returns -1 on failure, 0 on success */ | 22 | /* returns -1 on failure, 0 on success */ |
23 | int sysfs_topology_read_file(unsigned int cpu, const char *fname) | 23 | int sysfs_topology_read_file(unsigned int cpu, const char *fname) |
24 | { | 24 | { |
25 | unsigned long value; | 25 | unsigned long value; |
26 | char linebuf[MAX_LINE_LEN]; | 26 | char linebuf[MAX_LINE_LEN]; |
27 | char *endp; | 27 | char *endp; |
28 | char path[SYSFS_PATH_MAX]; | 28 | char path[SYSFS_PATH_MAX]; |
29 | 29 | ||
30 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s", | 30 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s", |
31 | cpu, fname); | 31 | cpu, fname); |
32 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0 ) | 32 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0) |
33 | return -1; | 33 | return -1; |
34 | value = strtoul(linebuf, &endp, 0); | 34 | value = strtoul(linebuf, &endp, 0); |
35 | if ( endp == linebuf || errno == ERANGE ) | 35 | if (endp == linebuf || errno == ERANGE) |
36 | return -1; | 36 | return -1; |
37 | return value; | 37 | return value; |
38 | } | 38 | } |