···5353 if (family == 0x11)5454 t = 0x8;55555656- return ((100 * (fid + t)) >> did);5757- }5656+ return (100 * (fid + t)) >> did;5757+}58585959/* Needs:6060 * cpu -> the cpu that gets evaluated···7474{7575 int i, psmax, pscur;7676 union msr_pstate pstate;7777- unsigned long long val;7777+ unsigned long long val;78787979 /* Only read out frequencies from HW when CPU might be boostable8080 to keep the code as short and clean as possible.···95959696 pscur += boost_states;9797 psmax += boost_states;9898- for (i=0; i<=psmax; i++) {9898+ for (i = 0; i <= psmax; i++) {9999 if (i >= MAX_HW_PSTATES) {100100 fprintf(stderr, "HW pstates [%d] exceeding max [%d]\n",101101 psmax, MAX_HW_PSTATES);
+7-5
tools/power/cpupower/utils/helpers/bitmask.c
···88#define bitsperlong (8 * sizeof(unsigned long))991010/* howmany(a,b) : how many elements of size b needed to hold all of a */1111-#define howmany(x,y) (((x)+((y)-1))/(y))1111+#define howmany(x, y) (((x)+((y)-1))/(y))12121313/* How many longs in mask of n bits */1414#define longsperbits(n) howmany(n, bitsperlong)15151616-#define max(a,b) ((a) > (b) ? (a) : (b))1616+#define max(a, b) ((a) > (b) ? (a) : (b))17171818/*1919 * Allocate and free `struct bitmask *`···7373 if (v)7474 bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong);7575 else7676- bmp->maskp[n/bitsperlong] &= ~(1UL << (n % bitsperlong));7676+ bmp->maskp[n/bitsperlong] &=7777+ ~(1UL << (n % bitsperlong));7778 }7879}7980···186185 * 0-3 0,1,2,3187186 * 0-7:2 0,2,4,6188187 * 1,3,5-7 1,3,5,6,7189189- * 0-3:2,8-15:4 0,2,8,12 188188+ * 0-3:2,8-15:4 0,2,8,12190189 */191190int bitmask_parselist(const char *buf, struct bitmask *bmp)192191{···252251 if (rbot == rtop)253252 len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot);254253 else255255- len += snprintf(buf + len, max(buflen - len, 0), "%d-%d", rbot, rtop);254254+ len += snprintf(buf + len, max(buflen - len, 0), "%d-%d",255255+ rbot, rtop);256256 return len;257257}258258
+6-8
tools/power/cpupower/utils/helpers/cpuid.c
···6767 continue;6868 value[63 - 1] = '\0';69697070- if (!strncmp(value, "processor\t: ", 12)) {7070+ if (!strncmp(value, "processor\t: ", 12))7171 sscanf(value, "processor\t: %u", &proc);7272- }7272+7373 if (proc != cpu)7474 continue;75757676 /* Get CPU vendor */7777- if (!strncmp(value, "vendor_id", 9))7777+ if (!strncmp(value, "vendor_id", 9)) {7878 for (x = 1; x < X86_VENDOR_MAX; x++) {7979 if (strstr(value, cpu_vendor_table[x]))8080 cpu_info->vendor = x;8181 }8282 /* Get CPU family, etc. */8383- else if (!strncmp(value, "cpu family\t: ", 13)) {8383+ } else if (!strncmp(value, "cpu family\t: ", 13)) {8484 sscanf(value, "cpu family\t: %u",8585 &cpu_info->family);8686- }8787- else if (!strncmp(value, "model\t\t: ", 9)) {8686+ } else if (!strncmp(value, "model\t\t: ", 9)) {8887 sscanf(value, "model\t\t: %u",8988 &cpu_info->model);9090- }9191- else if (!strncmp(value, "stepping\t: ", 10)) {8989+ } else if (!strncmp(value, "stepping\t: ", 10)) {9290 sscanf(value, "stepping\t: %u",9391 &cpu_info->stepping);9492
···2233#include "helpers/helpers.h"4455-int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, int * states)55+int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,66+ int *states)67{78 struct cpupower_cpu_info cpu_info;89 int ret;
+1-1
tools/power/cpupower/utils/helpers/pci.c
···33333434 for (i = 0; dev_ids[i] != 0; i++) {3535 filter_nb_link.device = dev_ids[i];3636- for (device=(*pacc)->devices; device; device = device->next) {3636+ for (device = (*pacc)->devices; device; device = device->next) {3737 if (pci_filter_match(&filter_nb_link, device))3838 return device;3939 }
+60-52
tools/power/cpupower/utils/helpers/sysfs.c
···1919unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)2020{2121 int fd;2222- size_t numread;2222+ ssize_t numread;23232424- if ( ( fd = open(path, O_RDONLY) ) == -1 )2424+ fd = open(path, O_RDONLY);2525+ if (fd == -1)2526 return 0;26272728 numread = read(fd, buf, buflen - 1);2828- if ( numread < 1 )2929- {2929+ if (numread < 1) {3030 close(fd);3131 return 0;3232 }···3434 buf[numread] = '\0';3535 close(fd);36363737- return numread;3737+ return (unsigned int) numread;3838}39394040static unsigned int sysfs_write_file(const char *path,4141 const char *value, size_t len)4242{4343 int fd;4444- size_t numwrite;4444+ ssize_t numwrite;45454646- if ( ( fd = open(path, O_WRONLY) ) == -1 )4646+ fd = open(path, O_WRONLY);4747+ if (fd == -1)4748 return 0;48494950 numwrite = write(fd, value, len);5050- if ( numwrite < 1 )5151- {5151+ if (numwrite < 1) {5252 close(fd);5353 return 0;5454 }5555 close(fd);5656- return numwrite;5656+ return (unsigned int) numwrite;5757}58585959/* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */···6969{7070 char path[SYSFS_PATH_MAX];7171 int fd;7272- size_t numread;7272+ ssize_t numread;73737474 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",7575 cpu, idlestate, fname);76767777- if ( ( fd = open(path, O_RDONLY) ) == -1 )7777+ fd = open(path, O_RDONLY);7878+ if (fd == -1)7879 return 0;79808081 numread = read(fd, buf, buflen - 1);8181- if ( numread < 1 )8282- {8282+ if (numread < 1) {8383 close(fd);8484 return 0;8585 }···8787 buf[numread] = '\0';8888 close(fd);89899090- return numread;9090+ return (unsigned int) numread;9191}92929393/* read access to files which contain one numeric value */···116116 char linebuf[MAX_LINE_LEN];117117 char *endp;118118119119- if ( which >= MAX_IDLESTATE_VALUE_FILES )119119+ if (which >= MAX_IDLESTATE_VALUE_FILES)120120 return 0;121121122122- if ( ( len = sysfs_idlestate_read_file(cpu, idlestate,123123- idlestate_value_files[which],124124- linebuf, sizeof(linebuf))) == 0 )125125- {122122+ len = sysfs_idlestate_read_file(cpu, idlestate,123123+ idlestate_value_files[which],124124+ linebuf, sizeof(linebuf));125125+ if (len == 0)126126 return 0;127127- }128127129128 value = strtoull(linebuf, &endp, 0);130129131131- if ( endp == linebuf || errno == ERANGE )130130+ if (endp == linebuf || errno == ERANGE)132131 return 0;133132134133 return value;···147148};148149149150150150-static char * sysfs_idlestate_get_one_string(unsigned int cpu,151151- unsigned int idlestate,152152- enum idlestate_string which)151151+static char *sysfs_idlestate_get_one_string(unsigned int cpu,152152+ unsigned int idlestate,153153+ enum idlestate_string which)153154{154155 char linebuf[MAX_LINE_LEN];155156 char *result;···158159 if (which >= MAX_IDLESTATE_STRING_FILES)159160 return NULL;160161161161- if ( ( len = sysfs_idlestate_read_file(cpu, idlestate,162162- idlestate_string_files[which],163163- linebuf, sizeof(linebuf))) == 0 )162162+ len = sysfs_idlestate_read_file(cpu, idlestate,163163+ idlestate_string_files[which],164164+ linebuf, sizeof(linebuf));165165+ if (len == 0)164166 return NULL;165167166166- if ( ( result = strdup(linebuf) ) == NULL )168168+ result = strdup(linebuf);169169+ if (result == NULL)167170 return NULL;168171169172 if (result[strlen(result) - 1] == '\n')···174173 return result;175174}176175177177-unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate)176176+unsigned long sysfs_get_idlestate_latency(unsigned int cpu,177177+ unsigned int idlestate)178178{179179 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY);180180}181181182182-unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate)182182+unsigned long sysfs_get_idlestate_usage(unsigned int cpu,183183+ unsigned int idlestate)183184{184185 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE);185186}186187187187-unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate)188188+unsigned long long sysfs_get_idlestate_time(unsigned int cpu,189189+ unsigned int idlestate)188190{189191 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME);190192}191193192192-char * sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate)194194+char *sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate)193195{194196 return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_NAME);195197}196198197197-char * sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate)199199+char *sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate)198200{199201 return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_DESC);200202}···215211216212217213 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpuidle");218218- if ( stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))214214+ if (stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))219215 return -ENODEV;220216221217 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu);222222- if ( stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))218218+ if (stat(file, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))223219 return 0;224220225225- while(stat(file, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {221221+ while (stat(file, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {226222 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU227223 "cpu%u/cpuidle/state%d", cpu, idlestates);228224 idlestates++;···265261};266262267263268268-static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)264264+static char *sysfs_cpuidle_get_one_string(enum cpuidle_string which)269265{270266 char linebuf[MAX_LINE_LEN];271267 char *result;···274270 if (which >= MAX_CPUIDLE_STRING_FILES)275271 return NULL;276272277277- if ( ( len = sysfs_cpuidle_read_file(cpuidle_string_files[which],278278- linebuf, sizeof(linebuf))) == 0 )273273+ len = sysfs_cpuidle_read_file(cpuidle_string_files[which],274274+ linebuf, sizeof(linebuf));275275+ if (len == 0)279276 return NULL;280277281281- if ( ( result = strdup(linebuf) ) == NULL )278278+ result = strdup(linebuf);279279+ if (result == NULL)282280 return NULL;283281284282 if (result[strlen(result) - 1] == '\n')···289283 return result;290284}291285292292-char * sysfs_get_cpuidle_governor(void)286286+char *sysfs_get_cpuidle_governor(void)293287{294288 char *tmp = sysfs_cpuidle_get_one_string(CPUIDLE_GOVERNOR_RO);295289 if (!tmp)···298292 return tmp;299293}300294301301-char * sysfs_get_cpuidle_driver(void)295295+char *sysfs_get_cpuidle_driver(void)302296{303297 return sysfs_cpuidle_get_one_string(CPUIDLE_DRIVER);304298}···310304 *311305 * Returns negative value on failure312306 */313313-int sysfs_get_sched(const char* smt_mc)307307+int sysfs_get_sched(const char *smt_mc)314308{315315- unsigned long value;309309+ unsigned long value;316310 char linebuf[MAX_LINE_LEN];317311 char *endp;318312 char path[SYSFS_PATH_MAX];···320314 if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc))321315 return -EINVAL;322316323323- snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc);324324- if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0 )317317+ snprintf(path, sizeof(path),318318+ PATH_TO_CPU "sched_%s_power_savings", smt_mc);319319+ if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0)325320 return -1;326321 value = strtoul(linebuf, &endp, 0);327327- if ( endp == linebuf || errno == ERANGE )322322+ if (endp == linebuf || errno == ERANGE)328323 return -1;329324 return value;330325}···336329 *337330 * Returns negative value on failure338331 */339339-int sysfs_set_sched(const char* smt_mc, int val)332332+int sysfs_set_sched(const char *smt_mc, int val)340333{341334 char linebuf[MAX_LINE_LEN];342335 char path[SYSFS_PATH_MAX];···345338 if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc))346339 return -EINVAL;347340348348- snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc);341341+ snprintf(path, sizeof(path),342342+ PATH_TO_CPU "sched_%s_power_savings", smt_mc);349343 sprintf(linebuf, "%d", val);350344351351- if ( stat(path, &statbuf) != 0 )345345+ if (stat(path, &statbuf) != 0)352346 return -ENODEV;353347354354- if (sysfs_write_file(path, linebuf, MAX_LINE_LEN) == 0 )348348+ if (sysfs_write_file(path, linebuf, MAX_LINE_LEN) == 0)355349 return -1;356350 return 0;357351}
+14-9
tools/power/cpupower/utils/helpers/sysfs.h
···7788extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen);991010-extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate);1111-extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate);1212-extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate);1313-extern char * sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate);1414-extern char * sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate);1010+extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu,1111+ unsigned int idlestate);1212+extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu,1313+ unsigned int idlestate);1414+extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu,1515+ unsigned int idlestate);1616+extern char *sysfs_get_idlestate_name(unsigned int cpu,1717+ unsigned int idlestate);1818+extern char *sysfs_get_idlestate_desc(unsigned int cpu,1919+ unsigned int idlestate);1520extern int sysfs_get_idlestate_count(unsigned int cpu);16211717-extern char * sysfs_get_cpuidle_governor(void);1818-extern char * sysfs_get_cpuidle_driver(void);2222+extern char *sysfs_get_cpuidle_governor(void);2323+extern char *sysfs_get_cpuidle_driver(void);19242020-extern int sysfs_get_sched(const char* smt_mc);2121-extern int sysfs_set_sched(const char* smt_mc, int val);2525+extern int sysfs_get_sched(const char *smt_mc);2626+extern int sysfs_set_sched(const char *smt_mc, int val);22272328#endif /* __CPUPOWER_HELPERS_SYSFS_H__ */
+3-3
tools/power/cpupower/utils/helpers/topology.c
···2222/* returns -1 on failure, 0 on success */2323int sysfs_topology_read_file(unsigned int cpu, const char *fname)2424{2525- unsigned long value;2525+ unsigned long value;2626 char linebuf[MAX_LINE_LEN];2727 char *endp;2828 char path[SYSFS_PATH_MAX];29293030 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s",3131 cpu, fname);3232- if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0 )3232+ if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0)3333 return -1;3434 value = strtoul(linebuf, &endp, 0);3535- if ( endp == linebuf || errno == ERANGE )3535+ if (endp == linebuf || errno == ERANGE)3636 return -1;3737 return value;3838}