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

cpupowerutils: helpers - ConfigStyle bugfixes

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

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