diff options
| author | Len Brown <len.brown@intel.com> | 2012-11-01 00:08:19 -0400 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2012-11-01 00:22:00 -0400 |
| commit | d91bb17c2a874493603c4d99db305d8caf2d180c (patch) | |
| tree | b09943d6cd825c0f451c34b14dd69b8e7c62b2cc | |
| parent | 39300ffb9b6666714c60735cf854e1280e4e75f4 (diff) | |
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>
| -rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 9942dee3df41..ea095abbe97e 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
| @@ -206,8 +206,10 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr) | |||
| 206 | retval = pread(fd, msr, sizeof *msr, offset); | 206 | retval = pread(fd, msr, sizeof *msr, offset); |
| 207 | close(fd); | 207 | close(fd); |
| 208 | 208 | ||
| 209 | if (retval != sizeof *msr) | 209 | if (retval != sizeof *msr) { |
| 210 | fprintf(stderr, "%s offset 0x%zx read failed\n", pathname, offset); | ||
| 210 | return -1; | 211 | return -1; |
| 212 | } | ||
| 211 | 213 | ||
| 212 | return 0; | 214 | return 0; |
| 213 | } | 215 | } |
| @@ -1101,7 +1103,9 @@ void turbostat_loop() | |||
| 1101 | 1103 | ||
| 1102 | restart: | 1104 | restart: |
| 1103 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); | 1105 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 1104 | if (retval) { | 1106 | if (retval < -1) { |
| 1107 | exit(retval); | ||
| 1108 | } else if (retval == -1) { | ||
| 1105 | re_initialize(); | 1109 | re_initialize(); |
| 1106 | goto restart; | 1110 | goto restart; |
| 1107 | } | 1111 | } |
| @@ -1114,7 +1118,9 @@ restart: | |||
| 1114 | } | 1118 | } |
| 1115 | sleep(interval_sec); | 1119 | sleep(interval_sec); |
| 1116 | retval = for_all_cpus(get_counters, ODD_COUNTERS); | 1120 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
| 1117 | if (retval) { | 1121 | if (retval < -1) { |
| 1122 | exit(retval); | ||
| 1123 | } else if (retval == -1) { | ||
| 1118 | re_initialize(); | 1124 | re_initialize(); |
| 1119 | goto restart; | 1125 | goto restart; |
| 1120 | } | 1126 | } |
| @@ -1126,7 +1132,9 @@ restart: | |||
| 1126 | flush_stdout(); | 1132 | flush_stdout(); |
| 1127 | sleep(interval_sec); | 1133 | sleep(interval_sec); |
| 1128 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); | 1134 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 1129 | if (retval) { | 1135 | if (retval < -1) { |
| 1136 | exit(retval); | ||
| 1137 | } else if (retval == -1) { | ||
| 1130 | re_initialize(); | 1138 | re_initialize(); |
| 1131 | goto restart; | 1139 | goto restart; |
| 1132 | } | 1140 | } |
| @@ -1545,8 +1553,11 @@ void turbostat_init() | |||
| 1545 | int fork_it(char **argv) | 1553 | int fork_it(char **argv) |
| 1546 | { | 1554 | { |
| 1547 | pid_t child_pid; | 1555 | pid_t child_pid; |
| 1556 | int status; | ||
| 1548 | 1557 | ||
| 1549 | for_all_cpus(get_counters, EVEN_COUNTERS); | 1558 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 1559 | if (status) | ||
| 1560 | exit(status); | ||
| 1550 | /* clear affinity side-effect of get_counters() */ | 1561 | /* clear affinity side-effect of get_counters() */ |
| 1551 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); | 1562 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
| 1552 | gettimeofday(&tv_even, (struct timezone *)NULL); | 1563 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| @@ -1556,7 +1567,6 @@ int fork_it(char **argv) | |||
| 1556 | /* child */ | 1567 | /* child */ |
| 1557 | execvp(argv[0], argv); | 1568 | execvp(argv[0], argv); |
| 1558 | } else { | 1569 | } else { |
| 1559 | int status; | ||
| 1560 | 1570 | ||
| 1561 | /* parent */ | 1571 | /* parent */ |
| 1562 | if (child_pid == -1) { | 1572 | if (child_pid == -1) { |
| @@ -1568,7 +1578,7 @@ int fork_it(char **argv) | |||
| 1568 | signal(SIGQUIT, SIG_IGN); | 1578 | signal(SIGQUIT, SIG_IGN); |
| 1569 | if (waitpid(child_pid, &status, 0) == -1) { | 1579 | if (waitpid(child_pid, &status, 0) == -1) { |
| 1570 | perror("wait"); | 1580 | perror("wait"); |
| 1571 | exit(1); | 1581 | exit(status); |
| 1572 | } | 1582 | } |
| 1573 | } | 1583 | } |
| 1574 | /* | 1584 | /* |
| @@ -1585,7 +1595,7 @@ int fork_it(char **argv) | |||
| 1585 | 1595 | ||
| 1586 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); | 1596 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 1587 | 1597 | ||
| 1588 | return 0; | 1598 | return status; |
| 1589 | } | 1599 | } |
| 1590 | 1600 | ||
| 1591 | void cmdline(int argc, char **argv) | 1601 | void cmdline(int argc, char **argv) |
