cpupowerutils: helpers - ConfigStyle bugfixes

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
Dominik Brodowski
2011-04-19 20:16:05 +02:00
parent b510b54127
commit 2cd005cac6
9 changed files with 100 additions and 86 deletions

View File

@@ -53,7 +53,7 @@ static int get_cof(int family, union msr_pstate pstate)
if (family == 0x11) if (family == 0x11)
t = 0x8; t = 0x8;
return ((100 * (fid + t)) >> did); return (100 * (fid + t)) >> did;
} }
/* Needs: /* Needs:

View File

@@ -73,7 +73,8 @@ static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v)
if (v) if (v)
bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong); bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong);
else else
bmp->maskp[n/bitsperlong] &= ~(1UL << (n % bitsperlong)); bmp->maskp[n/bitsperlong] &=
~(1UL << (n % bitsperlong));
} }
} }
@@ -251,7 +252,8 @@ static inline int emit(char *buf, int buflen, int rbot, int rtop, int len)
if (rbot == rtop) if (rbot == rtop)
len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot); len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot);
else else
len += snprintf(buf + len, max(buflen - len, 0), "%d-%d", rbot, rtop); len += snprintf(buf + len, max(buflen - len, 0), "%d-%d",
rbot, rtop);
return len; return len;
} }

View File

@@ -67,28 +67,26 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
continue; continue;
value[63 - 1] = '\0'; value[63 - 1] = '\0';
if (!strncmp(value, "processor\t: ", 12)) { if (!strncmp(value, "processor\t: ", 12))
sscanf(value, "processor\t: %u", &proc); sscanf(value, "processor\t: %u", &proc);
}
if (proc != cpu) if (proc != cpu)
continue; continue;
/* Get CPU vendor */ /* Get CPU vendor */
if (!strncmp(value, "vendor_id", 9)) if (!strncmp(value, "vendor_id", 9)) {
for (x = 1; x < X86_VENDOR_MAX; x++) { for (x = 1; x < X86_VENDOR_MAX; x++) {
if (strstr(value, cpu_vendor_table[x])) if (strstr(value, cpu_vendor_table[x]))
cpu_info->vendor = x; cpu_info->vendor = x;
} }
/* Get CPU family, etc. */ /* Get CPU family, etc. */
else if (!strncmp(value, "cpu family\t: ", 13)) { } else if (!strncmp(value, "cpu family\t: ", 13)) {
sscanf(value, "cpu family\t: %u", sscanf(value, "cpu family\t: %u",
&cpu_info->family); &cpu_info->family);
} } else if (!strncmp(value, "model\t\t: ", 9)) {
else if (!strncmp(value, "model\t\t: ", 9)) {
sscanf(value, "model\t\t: %u", sscanf(value, "model\t\t: %u",
&cpu_info->model); &cpu_info->model);
} } else if (!strncmp(value, "stepping\t: ", 10)) {
else if (!strncmp(value, "stepping\t: ", 10)) {
sscanf(value, "stepping\t: %u", sscanf(value, "stepping\t: %u",
&cpu_info->stepping); &cpu_info->stepping);

View File

@@ -39,7 +39,7 @@ extern int be_verbose;
#define dprint(fmt, ...) { \ #define dprint(fmt, ...) { \
if (be_verbose) { \ if (be_verbose) { \
fprintf(stderr, "%s: " fmt, \ fprintf(stderr, "%s: " fmt, \
__FUNCTION__, ##__VA_ARGS__); \ __func__, ##__VA_ARGS__); \
} \ } \
} }
#else #else

View File

@@ -2,7 +2,8 @@
#include "helpers/helpers.h" #include "helpers/helpers.h"
int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, int * states) int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
int *states)
{ {
struct cpupower_cpu_info cpu_info; struct cpupower_cpu_info cpu_info;
int ret; int ret;

View File

@@ -19,14 +19,14 @@
unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen) unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
{ {
int fd; int fd;
size_t numread; ssize_t numread;
if ( ( fd = open(path, O_RDONLY) ) == -1 ) fd = open(path, O_RDONLY);
if (fd == -1)
return 0; return 0;
numread = read(fd, buf, buflen - 1); numread = read(fd, buf, buflen - 1);
if ( numread < 1 ) if (numread < 1) {
{
close(fd); close(fd);
return 0; return 0;
} }
@@ -34,26 +34,26 @@ unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
buf[numread] = '\0'; buf[numread] = '\0';
close(fd); close(fd);
return numread; return (unsigned int) numread;
} }
static unsigned int sysfs_write_file(const char *path, static unsigned int sysfs_write_file(const char *path,
const char *value, size_t len) const char *value, size_t len)
{ {
int fd; int fd;
size_t numwrite; ssize_t numwrite;
if ( ( fd = open(path, O_WRONLY) ) == -1 ) fd = open(path, O_WRONLY);
if (fd == -1)
return 0; return 0;
numwrite = write(fd, value, len); numwrite = write(fd, value, len);
if ( numwrite < 1 ) if (numwrite < 1) {
{
close(fd); close(fd);
return 0; return 0;
} }
close(fd); close(fd);
return numwrite; return (unsigned int) numwrite;
} }
/* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ /* 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,
{ {
char path[SYSFS_PATH_MAX]; char path[SYSFS_PATH_MAX];
int fd; int fd;
size_t numread; ssize_t numread;
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",
cpu, idlestate, fname); cpu, idlestate, fname);
if ( ( fd = open(path, O_RDONLY) ) == -1 ) fd = open(path, O_RDONLY);
if (fd == -1)
return 0; return 0;
numread = read(fd, buf, buflen - 1); numread = read(fd, buf, buflen - 1);
if ( numread < 1 ) if (numread < 1) {
{
close(fd); close(fd);
return 0; return 0;
} }
@@ -87,7 +87,7 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
buf[numread] = '\0'; buf[numread] = '\0';
close(fd); close(fd);
return numread; return (unsigned int) numread;
} }
/* read access to files which contain one numeric value */ /* read access to files which contain one numeric value */
@@ -119,12 +119,11 @@ static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu,
if (which >= MAX_IDLESTATE_VALUE_FILES) if (which >= MAX_IDLESTATE_VALUE_FILES)
return 0; return 0;
if ( ( len = sysfs_idlestate_read_file(cpu, idlestate, len = sysfs_idlestate_read_file(cpu, idlestate,
idlestate_value_files[which], idlestate_value_files[which],
linebuf, sizeof(linebuf))) == 0 ) linebuf, sizeof(linebuf));
{ if (len == 0)
return 0; return 0;
}
value = strtoull(linebuf, &endp, 0); value = strtoull(linebuf, &endp, 0);
@@ -159,12 +158,14 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
if (which >= MAX_IDLESTATE_STRING_FILES) if (which >= MAX_IDLESTATE_STRING_FILES)
return NULL; return NULL;
if ( ( len = sysfs_idlestate_read_file(cpu, idlestate, len = sysfs_idlestate_read_file(cpu, idlestate,
idlestate_string_files[which], idlestate_string_files[which],
linebuf, sizeof(linebuf))) == 0 ) linebuf, sizeof(linebuf));
if (len == 0)
return NULL; return NULL;
if ( ( result = strdup(linebuf) ) == NULL ) result = strdup(linebuf);
if (result == NULL)
return NULL; return NULL;
if (result[strlen(result) - 1] == '\n') if (result[strlen(result) - 1] == '\n')
@@ -173,17 +174,20 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
return result; return result;
} }
unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate) unsigned long sysfs_get_idlestate_latency(unsigned int cpu,
unsigned int idlestate)
{ {
return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY);
} }
unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate) unsigned long sysfs_get_idlestate_usage(unsigned int cpu,
unsigned int idlestate)
{ {
return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE); return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE);
} }
unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate) unsigned long long sysfs_get_idlestate_time(unsigned int cpu,
unsigned int idlestate)
{ {
return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME); return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME);
} }
@@ -270,11 +274,13 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
if (which >= MAX_CPUIDLE_STRING_FILES) if (which >= MAX_CPUIDLE_STRING_FILES)
return NULL; return NULL;
if ( ( len = sysfs_cpuidle_read_file(cpuidle_string_files[which], len = sysfs_cpuidle_read_file(cpuidle_string_files[which],
linebuf, sizeof(linebuf))) == 0 ) linebuf, sizeof(linebuf));
if (len == 0)
return NULL; return NULL;
if ( ( result = strdup(linebuf) ) == NULL ) result = strdup(linebuf);
if (result == NULL)
return NULL; return NULL;
if (result[strlen(result) - 1] == '\n') if (result[strlen(result) - 1] == '\n')
@@ -314,7 +320,8 @@ int sysfs_get_sched(const char* smt_mc)
if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc))
return -EINVAL; return -EINVAL;
snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc); snprintf(path, sizeof(path),
PATH_TO_CPU "sched_%s_power_savings", smt_mc);
if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0) if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0)
return -1; return -1;
value = strtoul(linebuf, &endp, 0); value = strtoul(linebuf, &endp, 0);
@@ -338,7 +345,8 @@ int sysfs_set_sched(const char* smt_mc, int val)
if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc)) if (strcmp("mc", smt_mc) && strcmp("smt", smt_mc))
return -EINVAL; return -EINVAL;
snprintf(path, sizeof(path), PATH_TO_CPU "sched_%s_power_savings", smt_mc); snprintf(path, sizeof(path),
PATH_TO_CPU "sched_%s_power_savings", smt_mc);
sprintf(linebuf, "%d", val); sprintf(linebuf, "%d", val);
if (stat(path, &statbuf) != 0) if (stat(path, &statbuf) != 0)

View File

@@ -7,11 +7,16 @@
extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen); extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen);
extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, unsigned int idlestate); extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu,
extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, unsigned int idlestate); unsigned int idlestate);
extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu, unsigned int idlestate); extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu,
extern char * sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate); unsigned int idlestate);
extern char * sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate); extern unsigned long long sysfs_get_idlestate_time(unsigned int cpu,
unsigned int idlestate);
extern char *sysfs_get_idlestate_name(unsigned int cpu,
unsigned int idlestate);
extern char *sysfs_get_idlestate_desc(unsigned int cpu,
unsigned int idlestate);
extern int sysfs_get_idlestate_count(unsigned int cpu); extern int sysfs_get_idlestate_count(unsigned int cpu);
extern char *sysfs_get_cpuidle_governor(void); extern char *sysfs_get_cpuidle_governor(void);