cpupowerutils: helpers - ConfigStyle bugfixes
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
parent
b510b54127
commit
2cd005cac6
9 changed files with 100 additions and 86 deletions
|
@ -53,7 +53,7 @@ static int get_cof(int family, union msr_pstate pstate)
|
|||
if (family == 0x11)
|
||||
t = 0x8;
|
||||
|
||||
return ((100 * (fid + t)) >> did);
|
||||
return (100 * (fid + t)) >> did;
|
||||
}
|
||||
|
||||
/* Needs:
|
||||
|
|
|
@ -73,7 +73,8 @@ static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v)
|
|||
if (v)
|
||||
bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong);
|
||||
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)
|
||||
len += snprintf(buf + len, max(buflen - len, 0), "%d", rbot);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,28 +67,26 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
|
|||
continue;
|
||||
value[63 - 1] = '\0';
|
||||
|
||||
if (!strncmp(value, "processor\t: ", 12)) {
|
||||
if (!strncmp(value, "processor\t: ", 12))
|
||||
sscanf(value, "processor\t: %u", &proc);
|
||||
}
|
||||
|
||||
if (proc != cpu)
|
||||
continue;
|
||||
|
||||
/* Get CPU vendor */
|
||||
if (!strncmp(value, "vendor_id", 9))
|
||||
if (!strncmp(value, "vendor_id", 9)) {
|
||||
for (x = 1; x < X86_VENDOR_MAX; x++) {
|
||||
if (strstr(value, cpu_vendor_table[x]))
|
||||
cpu_info->vendor = x;
|
||||
}
|
||||
/* 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",
|
||||
&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",
|
||||
&cpu_info->model);
|
||||
}
|
||||
else if (!strncmp(value, "stepping\t: ", 10)) {
|
||||
} else if (!strncmp(value, "stepping\t: ", 10)) {
|
||||
sscanf(value, "stepping\t: %u",
|
||||
&cpu_info->stepping);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ extern int be_verbose;
|
|||
#define dprint(fmt, ...) { \
|
||||
if (be_verbose) { \
|
||||
fprintf(stderr, "%s: " fmt, \
|
||||
__FUNCTION__, ##__VA_ARGS__); \
|
||||
__func__, ##__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#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;
|
||||
int ret;
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
|
||||
{
|
||||
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;
|
||||
|
||||
numread = read(fd, buf, buflen - 1);
|
||||
if ( numread < 1 )
|
||||
{
|
||||
if (numread < 1) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,26 +34,26 @@ unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
|
|||
buf[numread] = '\0';
|
||||
close(fd);
|
||||
|
||||
return numread;
|
||||
return (unsigned int) numread;
|
||||
}
|
||||
|
||||
static unsigned int sysfs_write_file(const char *path,
|
||||
const char *value, size_t len)
|
||||
{
|
||||
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;
|
||||
|
||||
numwrite = write(fd, value, len);
|
||||
if ( numwrite < 1 )
|
||||
{
|
||||
if (numwrite < 1) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
return numwrite;
|
||||
return (unsigned int) numwrite;
|
||||
}
|
||||
|
||||
/* 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];
|
||||
int fd;
|
||||
size_t numread;
|
||||
ssize_t numread;
|
||||
|
||||
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",
|
||||
cpu, idlestate, fname);
|
||||
|
||||
if ( ( fd = open(path, O_RDONLY) ) == -1 )
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
|
||||
numread = read(fd, buf, buflen - 1);
|
||||
if ( numread < 1 )
|
||||
{
|
||||
if (numread < 1) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
|
|||
buf[numread] = '\0';
|
||||
close(fd);
|
||||
|
||||
return numread;
|
||||
return (unsigned int) numread;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
return 0;
|
||||
|
||||
if ( ( len = sysfs_idlestate_read_file(cpu, idlestate,
|
||||
len = sysfs_idlestate_read_file(cpu, idlestate,
|
||||
idlestate_value_files[which],
|
||||
linebuf, sizeof(linebuf))) == 0 )
|
||||
{
|
||||
linebuf, sizeof(linebuf));
|
||||
if (len == 0)
|
||||
return 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)
|
||||
return NULL;
|
||||
|
||||
if ( ( len = sysfs_idlestate_read_file(cpu, idlestate,
|
||||
len = sysfs_idlestate_read_file(cpu, idlestate,
|
||||
idlestate_string_files[which],
|
||||
linebuf, sizeof(linebuf))) == 0 )
|
||||
linebuf, sizeof(linebuf));
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
|
||||
if ( ( result = strdup(linebuf) ) == NULL )
|
||||
result = strdup(linebuf);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
if (result[strlen(result) - 1] == '\n')
|
||||
|
@ -173,17 +174,20 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -270,11 +274,13 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
|
|||
if (which >= MAX_CPUIDLE_STRING_FILES)
|
||||
return NULL;
|
||||
|
||||
if ( ( len = sysfs_cpuidle_read_file(cpuidle_string_files[which],
|
||||
linebuf, sizeof(linebuf))) == 0 )
|
||||
len = sysfs_cpuidle_read_file(cpuidle_string_files[which],
|
||||
linebuf, sizeof(linebuf));
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
|
||||
if ( ( result = strdup(linebuf) ) == NULL )
|
||||
result = strdup(linebuf);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
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))
|
||||
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)
|
||||
return -1;
|
||||
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))
|
||||
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);
|
||||
|
||||
if (stat(path, &statbuf) != 0)
|
||||
|
|
|
@ -7,11 +7,16 @@
|
|||
|
||||
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_usage(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 unsigned long sysfs_get_idlestate_latency(unsigned int cpu,
|
||||
unsigned int idlestate);
|
||||
extern unsigned long sysfs_get_idlestate_usage(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 char *sysfs_get_cpuidle_governor(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue