mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-07 15:18:15 +00:00
tools/power turbostat: graceful fail on garbage input
When invald MSR's are specified on the command line, turbostat should simply print an error and exit. Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
39300ffb9b
commit
d91bb17c2a
1 changed files with 18 additions and 8 deletions
|
@ -206,8 +206,10 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr)
|
||||||
retval = pread(fd, msr, sizeof *msr, offset);
|
retval = pread(fd, msr, sizeof *msr, offset);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (retval != sizeof *msr)
|
if (retval != sizeof *msr) {
|
||||||
|
fprintf(stderr, "%s offset 0x%zx read failed\n", pathname, offset);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1103,9 @@ void turbostat_loop()
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
|
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
|
||||||
if (retval) {
|
if (retval < -1) {
|
||||||
|
exit(retval);
|
||||||
|
} else if (retval == -1) {
|
||||||
re_initialize();
|
re_initialize();
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
@ -1114,7 +1118,9 @@ restart:
|
||||||
}
|
}
|
||||||
sleep(interval_sec);
|
sleep(interval_sec);
|
||||||
retval = for_all_cpus(get_counters, ODD_COUNTERS);
|
retval = for_all_cpus(get_counters, ODD_COUNTERS);
|
||||||
if (retval) {
|
if (retval < -1) {
|
||||||
|
exit(retval);
|
||||||
|
} else if (retval == -1) {
|
||||||
re_initialize();
|
re_initialize();
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
@ -1126,7 +1132,9 @@ restart:
|
||||||
flush_stdout();
|
flush_stdout();
|
||||||
sleep(interval_sec);
|
sleep(interval_sec);
|
||||||
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
|
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
|
||||||
if (retval) {
|
if (retval < -1) {
|
||||||
|
exit(retval);
|
||||||
|
} else if (retval == -1) {
|
||||||
re_initialize();
|
re_initialize();
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
@ -1545,8 +1553,11 @@ void turbostat_init()
|
||||||
int fork_it(char **argv)
|
int fork_it(char **argv)
|
||||||
{
|
{
|
||||||
pid_t child_pid;
|
pid_t child_pid;
|
||||||
|
int status;
|
||||||
|
|
||||||
for_all_cpus(get_counters, EVEN_COUNTERS);
|
status = for_all_cpus(get_counters, EVEN_COUNTERS);
|
||||||
|
if (status)
|
||||||
|
exit(status);
|
||||||
/* clear affinity side-effect of get_counters() */
|
/* clear affinity side-effect of get_counters() */
|
||||||
sched_setaffinity(0, cpu_present_setsize, cpu_present_set);
|
sched_setaffinity(0, cpu_present_setsize, cpu_present_set);
|
||||||
gettimeofday(&tv_even, (struct timezone *)NULL);
|
gettimeofday(&tv_even, (struct timezone *)NULL);
|
||||||
|
@ -1556,7 +1567,6 @@ int fork_it(char **argv)
|
||||||
/* child */
|
/* child */
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
} else {
|
} else {
|
||||||
int status;
|
|
||||||
|
|
||||||
/* parent */
|
/* parent */
|
||||||
if (child_pid == -1) {
|
if (child_pid == -1) {
|
||||||
|
@ -1568,7 +1578,7 @@ int fork_it(char **argv)
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
if (waitpid(child_pid, &status, 0) == -1) {
|
if (waitpid(child_pid, &status, 0) == -1) {
|
||||||
perror("wait");
|
perror("wait");
|
||||||
exit(1);
|
exit(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -1585,7 +1595,7 @@ int fork_it(char **argv)
|
||||||
|
|
||||||
fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);
|
fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);
|
||||||
|
|
||||||
return 0;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdline(int argc, char **argv)
|
void cmdline(int argc, char **argv)
|
||||||
|
|
Loading…
Add table
Reference in a new issue