Skip to content

Commit

Permalink
Merge branch 'pm-tools'
Browse files Browse the repository at this point in the history
* pm-tools:
  cpupower: Remove redundant error check
  cpupower: bench: parse.c: Fix several minor errors
  cpupower: mperf monitor: Correct use of ! and &
  cpupower: Adjust MAINTAINERS file
  PM / tools: cpupower: drop negativity check on unsigned value
  • Loading branch information
rafaeljw committed Aug 5, 2014
2 parents ddbe8db + 059802f commit 49c68fd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2521,8 +2521,8 @@ F: arch/x86/kernel/cpuid.c
F: arch/x86/kernel/msr.c

CPU POWER MONITORING SUBSYSTEM
M: Dominik Brodowski <[email protected]>
M: Thomas Renninger <[email protected]>
L: [email protected]
S: Maintained
F: tools/power/cpupower/

Expand Down
39 changes: 21 additions & 18 deletions tools/power/cpupower/bench/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ struct config *prepare_default_config()
int prepare_config(const char *path, struct config *config)
{
size_t len = 0;
char *opt, *val, *line = NULL;
FILE *configfile = fopen(path, "r");
char opt[16], val[32], *line = NULL;
FILE *configfile;

if (config == NULL) {
fprintf(stderr, "error: config is NULL\n");
return 1;
}

configfile = fopen(path, "r");
if (configfile == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to read configfile\n");
Expand All @@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config)
}

while (getline(&line, &len, configfile) != -1) {
if (line[0] == '#' || line[0] == ' ')
if (line[0] == '#' || line[0] == ' ' || line[0] == '\n')
continue;

sscanf(line, "%as = %as", &opt, &val);
if (sscanf(line, "%14s = %30s", opt, val) < 2)
continue;

dprintf("parsing: %s -> %s\n", opt, val);

if (strncmp("sleep", opt, strlen(opt)) == 0)
if (strcmp("sleep", opt) == 0)
sscanf(val, "%li", &config->sleep);

else if (strncmp("load", opt, strlen(opt)) == 0)
else if (strcmp("load", opt) == 0)
sscanf(val, "%li", &config->load);

else if (strncmp("load_step", opt, strlen(opt)) == 0)
else if (strcmp("load_step", opt) == 0)
sscanf(val, "%li", &config->load_step);

else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
else if (strcmp("sleep_step", opt) == 0)
sscanf(val, "%li", &config->sleep_step);

else if (strncmp("cycles", opt, strlen(opt)) == 0)
else if (strcmp("cycles", opt) == 0)
sscanf(val, "%u", &config->cycles);

else if (strncmp("rounds", opt, strlen(opt)) == 0)
else if (strcmp("rounds", opt) == 0)
sscanf(val, "%u", &config->rounds);

else if (strncmp("verbose", opt, strlen(opt)) == 0)
else if (strcmp("verbose", opt) == 0)
sscanf(val, "%u", &config->verbose);

else if (strncmp("output", opt, strlen(opt)) == 0)
else if (strcmp("output", opt) == 0)
config->output = prepare_output(val);

else if (strncmp("cpu", opt, strlen(opt)) == 0)
else if (strcmp("cpu", opt) == 0)
sscanf(val, "%u", &config->cpu);

else if (strncmp("governor", opt, 14) == 0)
strncpy(config->governor, val, 14);
else if (strcmp("governor", opt) == 0) {
strncpy(config->governor, val,
sizeof(config->governor));
config->governor[sizeof(config->governor) - 1] = '\0';
}

else if (strncmp("priority", opt, strlen(opt)) == 0) {
else if (strcmp("priority", opt) == 0) {
if (string_to_prio(val) != SCHED_ERR)
config->prio = string_to_prio(val);
}
}

free(line);
free(opt);
free(val);

return 0;
}
11 changes: 5 additions & 6 deletions tools/power/cpupower/utils/cpufreq-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,11 @@ int cmd_freq_set(int argc, char **argv)

printf(_("Setting cpu: %d\n"), cpu);
ret = do_one_cpu(cpu, &new_pol, freq, policychange);
if (ret)
break;
if (ret) {
print_error();
return ret;
}
}

if (ret)
print_error();

return ret;
return 0;
}
2 changes: 1 addition & 1 deletion tools/power/cpupower/utils/helpers/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int sysfs_is_cpu_online(unsigned int cpu)
close(fd);

value = strtoull(linebuf, &endp, 0);
if (value > 1 || value < 0)
if (value > 1)
return -EINVAL;

return value;
Expand Down
2 changes: 1 addition & 1 deletion tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static int init_maxfreq_mode(void)
unsigned long long hwcr;
unsigned long min;

if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)
if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC))
goto use_sysfs;

if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) {
Expand Down

0 comments on commit 49c68fd

Please sign in to comment.