Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc. |
| 3 | * |
| 4 | * Licensed under the terms of the GNU GPL License version 2. |
| 5 | * |
| 6 | * Output format inspired by Len Brown's <lenb@kernel.org> turbostat tool. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <unistd.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | #include <time.h> |
| 16 | #include <signal.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/wait.h> |
| 19 | #include <libgen.h> |
| 20 | |
| 21 | #include "idle_monitor/cpupower-monitor.h" |
| 22 | #include "idle_monitor/idle_monitors.h" |
| 23 | #include "helpers/helpers.h" |
| 24 | |
| 25 | /* Define pointers to all monitors. */ |
| 26 | #define DEF(x) & x ## _monitor , |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 27 | struct cpuidle_monitor *all_monitors[] = { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 28 | #include "idle_monitors.def" |
| 29 | 0 |
| 30 | }; |
| 31 | |
Mike Gilbert | 85e8b90 | 2020-02-26 14:33:59 -0500 | [diff] [blame] | 32 | int cpu_count; |
| 33 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 34 | static struct cpuidle_monitor *monitors[MONITORS_MAX]; |
| 35 | static unsigned int avail_monitors; |
| 36 | |
| 37 | static char *progname; |
| 38 | |
| 39 | enum operation_mode_e { list = 1, show, show_all }; |
| 40 | static int mode; |
| 41 | static int interval = 1; |
| 42 | static char *show_monitors_param; |
| 43 | static struct cpupower_topology cpu_top; |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 44 | static unsigned int wake_cpus; |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 45 | |
| 46 | /* ToDo: Document this in the manpage */ |
| 47 | static char range_abbr[RANGE_MAX] = { 'T', 'C', 'P', 'M', }; |
| 48 | |
Dominik Brodowski | 498ca79 | 2011-08-06 18:11:43 +0200 | [diff] [blame] | 49 | static void print_wrong_arg_exit(void) |
| 50 | { |
| 51 | printf(_("invalid or unknown argument\n")); |
| 52 | exit(EXIT_FAILURE); |
| 53 | } |
| 54 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 55 | long long timespec_diff_us(struct timespec start, struct timespec end) |
| 56 | { |
| 57 | struct timespec temp; |
| 58 | if ((end.tv_nsec - start.tv_nsec) < 0) { |
| 59 | temp.tv_sec = end.tv_sec - start.tv_sec - 1; |
| 60 | temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; |
| 61 | } else { |
| 62 | temp.tv_sec = end.tv_sec - start.tv_sec; |
| 63 | temp.tv_nsec = end.tv_nsec - start.tv_nsec; |
| 64 | } |
| 65 | return (temp.tv_sec * 1000000) + (temp.tv_nsec / 1000); |
| 66 | } |
| 67 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 68 | void print_n_spaces(int n) |
| 69 | { |
| 70 | int x; |
| 71 | for (x = 0; x < n; x++) |
| 72 | printf(" "); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 73 | } |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 74 | |
| 75 | /* size of s must be at least n + 1 */ |
| 76 | int fill_string_with_spaces(char *s, int n) |
| 77 | { |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 78 | int len = strlen(s); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 79 | if (len > n) |
| 80 | return -1; |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 81 | for (; len < n; len++) |
| 82 | s[len] = ' '; |
| 83 | s[len] = '\0'; |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 84 | return 0; |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 85 | } |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 86 | |
| 87 | void print_header(int topology_depth) |
| 88 | { |
| 89 | int unsigned mon; |
Palmer Cox | fb8eaeb | 2012-11-27 13:17:44 +0100 | [diff] [blame] | 90 | int state, need_len; |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 91 | cstate_t s; |
| 92 | char buf[128] = ""; |
| 93 | int percent_width = 4; |
| 94 | |
| 95 | fill_string_with_spaces(buf, topology_depth * 5 - 1); |
| 96 | printf("%s|", buf); |
| 97 | |
| 98 | for (mon = 0; mon < avail_monitors; mon++) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 99 | need_len = monitors[mon]->hw_states_num * (percent_width + 3) |
| 100 | - 1; |
| 101 | if (mon != 0) { |
| 102 | printf("|| "); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 103 | need_len--; |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 104 | } |
| 105 | sprintf(buf, "%s", monitors[mon]->name); |
| 106 | fill_string_with_spaces(buf, need_len); |
| 107 | printf("%s", buf); |
| 108 | } |
| 109 | printf("\n"); |
| 110 | |
| 111 | if (topology_depth > 2) |
| 112 | printf("PKG |"); |
| 113 | if (topology_depth > 1) |
| 114 | printf("CORE|"); |
| 115 | if (topology_depth > 0) |
| 116 | printf("CPU |"); |
| 117 | |
| 118 | for (mon = 0; mon < avail_monitors; mon++) { |
| 119 | if (mon != 0) |
| 120 | printf("|| "); |
| 121 | else |
| 122 | printf(" "); |
| 123 | for (state = 0; state < monitors[mon]->hw_states_num; state++) { |
| 124 | if (state != 0) |
| 125 | printf(" | "); |
| 126 | s = monitors[mon]->hw_states[state]; |
| 127 | sprintf(buf, "%s", s.name); |
| 128 | fill_string_with_spaces(buf, percent_width); |
| 129 | printf("%s", buf); |
| 130 | } |
| 131 | printf(" "); |
| 132 | } |
| 133 | printf("\n"); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void print_results(int topology_depth, int cpu) |
| 138 | { |
| 139 | unsigned int mon; |
| 140 | int state, ret; |
| 141 | double percent; |
| 142 | unsigned long long result; |
| 143 | cstate_t s; |
| 144 | |
Thomas Renninger | 9ee31f6 | 2011-08-12 01:11:38 +0200 | [diff] [blame] | 145 | /* Be careful CPUs may got resorted for pkg value do not just use cpu */ |
| 146 | if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) |
| 147 | return; |
Jacob Tanenbaum | 20102ac | 2015-10-22 17:17:05 +0200 | [diff] [blame] | 148 | if (!cpu_top.core_info[cpu].is_online && |
| 149 | cpu_top.core_info[cpu].pkg == -1) |
| 150 | return; |
Thomas Renninger | 9ee31f6 | 2011-08-12 01:11:38 +0200 | [diff] [blame] | 151 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 152 | if (topology_depth > 2) |
| 153 | printf("%4d|", cpu_top.core_info[cpu].pkg); |
| 154 | if (topology_depth > 1) |
| 155 | printf("%4d|", cpu_top.core_info[cpu].core); |
| 156 | if (topology_depth > 0) |
| 157 | printf("%4d|", cpu_top.core_info[cpu].cpu); |
| 158 | |
| 159 | for (mon = 0; mon < avail_monitors; mon++) { |
| 160 | if (mon != 0) |
| 161 | printf("||"); |
| 162 | |
| 163 | for (state = 0; state < monitors[mon]->hw_states_num; state++) { |
| 164 | if (state != 0) |
| 165 | printf("|"); |
| 166 | |
| 167 | s = monitors[mon]->hw_states[state]; |
| 168 | |
| 169 | if (s.get_count_percent) { |
| 170 | ret = s.get_count_percent(s.id, &percent, |
| 171 | cpu_top.core_info[cpu].cpu); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 172 | if (ret) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 173 | printf("******"); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 174 | else if (percent >= 100.0) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 175 | printf("%6.1f", percent); |
| 176 | else |
| 177 | printf("%6.2f", percent); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 178 | } else if (s.get_count) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 179 | ret = s.get_count(s.id, &result, |
| 180 | cpu_top.core_info[cpu].cpu); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 181 | if (ret) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 182 | printf("******"); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 183 | else |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 184 | printf("%6llu", result); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 185 | } else { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 186 | printf(_("Monitor %s, Counter %s has no count " |
| 187 | "function. Implementation error\n"), |
| 188 | monitors[mon]->name, s.name); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 189 | exit(EXIT_FAILURE); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
Thomas Renninger | 7c74d2b | 2011-08-12 01:11:37 +0200 | [diff] [blame] | 193 | /* |
| 194 | * The monitor could still provide useful data, for example |
| 195 | * AMD HW counters partly sit in PCI config space. |
| 196 | * It's up to the monitor plug-in to check .is_online, this one |
| 197 | * is just for additional info. |
| 198 | */ |
Jacob Tanenbaum | 20102ac | 2015-10-22 17:17:05 +0200 | [diff] [blame] | 199 | if (!cpu_top.core_info[cpu].is_online && |
| 200 | cpu_top.core_info[cpu].pkg != -1) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 201 | printf(_(" *is offline\n")); |
| 202 | return; |
| 203 | } else |
| 204 | printf("\n"); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /* param: string passed by -m param (The list of monitors to show) |
| 209 | * |
| 210 | * Monitors must have been registered already, matching monitors |
| 211 | * are picked out and available monitors array is overridden |
| 212 | * with matching ones |
| 213 | * |
| 214 | * Monitors get sorted in the same order the user passes them |
| 215 | */ |
| 216 | |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 217 | static void parse_monitor_param(char *param) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 218 | { |
| 219 | unsigned int num; |
| 220 | int mon, hits = 0; |
| 221 | char *tmp = param, *token; |
| 222 | struct cpuidle_monitor *tmp_mons[MONITORS_MAX]; |
| 223 | |
| 224 | |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 225 | for (mon = 0; mon < MONITORS_MAX; mon++, tmp = NULL) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 226 | token = strtok(tmp, ","); |
| 227 | if (token == NULL) |
| 228 | break; |
| 229 | if (strlen(token) >= MONITOR_NAME_LEN) { |
| 230 | printf(_("%s: max monitor name length" |
| 231 | " (%d) exceeded\n"), token, MONITOR_NAME_LEN); |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | for (num = 0; num < avail_monitors; num++) { |
| 236 | if (!strcmp(monitors[num]->name, token)) { |
| 237 | dprint("Found requested monitor: %s\n", token); |
| 238 | tmp_mons[hits] = monitors[num]; |
| 239 | hits++; |
| 240 | } |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 241 | } |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 242 | } |
| 243 | if (hits == 0) { |
| 244 | printf(_("No matching monitor found in %s, " |
| 245 | "try -l option\n"), param); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 246 | exit(EXIT_FAILURE); |
| 247 | } |
| 248 | /* Override detected/registerd monitors array with requested one */ |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 249 | memcpy(monitors, tmp_mons, |
| 250 | sizeof(struct cpuidle_monitor *) * MONITORS_MAX); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 251 | avail_monitors = hits; |
| 252 | } |
| 253 | |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 254 | void list_monitors(void) |
| 255 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 256 | unsigned int mon; |
| 257 | int state; |
| 258 | cstate_t s; |
| 259 | |
| 260 | for (mon = 0; mon < avail_monitors; mon++) { |
| 261 | printf(_("Monitor \"%s\" (%d states) - Might overflow after %u " |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 262 | "s\n"), |
| 263 | monitors[mon]->name, monitors[mon]->hw_states_num, |
| 264 | monitors[mon]->overflow_s); |
| 265 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 266 | for (state = 0; state < monitors[mon]->hw_states_num; state++) { |
| 267 | s = monitors[mon]->hw_states[state]; |
| 268 | /* |
| 269 | * ToDo show more state capabilities: |
| 270 | * percent, time (granlarity) |
| 271 | */ |
| 272 | printf("%s\t[%c] -> %s\n", s.name, range_abbr[s.range], |
| 273 | gettext(s.desc)); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | int fork_it(char **argv) |
| 279 | { |
| 280 | int status; |
| 281 | unsigned int num; |
| 282 | unsigned long long timediff; |
| 283 | pid_t child_pid; |
| 284 | struct timespec start, end; |
| 285 | |
| 286 | child_pid = fork(); |
| 287 | clock_gettime(CLOCK_REALTIME, &start); |
| 288 | |
| 289 | for (num = 0; num < avail_monitors; num++) |
| 290 | monitors[num]->start(); |
| 291 | |
| 292 | if (!child_pid) { |
| 293 | /* child */ |
| 294 | execvp(argv[0], argv); |
| 295 | } else { |
| 296 | /* parent */ |
| 297 | if (child_pid == -1) { |
| 298 | perror("fork"); |
| 299 | exit(1); |
| 300 | } |
| 301 | |
| 302 | signal(SIGINT, SIG_IGN); |
| 303 | signal(SIGQUIT, SIG_IGN); |
| 304 | if (waitpid(child_pid, &status, 0) == -1) { |
| 305 | perror("wait"); |
| 306 | exit(1); |
| 307 | } |
| 308 | } |
| 309 | clock_gettime(CLOCK_REALTIME, &end); |
| 310 | for (num = 0; num < avail_monitors; num++) |
| 311 | monitors[num]->stop(); |
| 312 | |
| 313 | timediff = timespec_diff_us(start, end); |
| 314 | if (WIFEXITED(status)) |
| 315 | printf(_("%s took %.5f seconds and exited with status %d\n"), |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 316 | argv[0], timediff / (1000.0 * 1000), |
| 317 | WEXITSTATUS(status)); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | int do_interval_measure(int i) |
| 322 | { |
| 323 | unsigned int num; |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 324 | int cpu; |
| 325 | |
| 326 | if (wake_cpus) |
| 327 | for (cpu = 0; cpu < cpu_count; cpu++) |
| 328 | bind_cpu(cpu); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 329 | |
| 330 | for (num = 0; num < avail_monitors; num++) { |
| 331 | dprint("HW C-state residency monitor: %s - States: %d\n", |
| 332 | monitors[num]->name, monitors[num]->hw_states_num); |
| 333 | monitors[num]->start(); |
| 334 | } |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 335 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 336 | sleep(i); |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 337 | |
| 338 | if (wake_cpus) |
| 339 | for (cpu = 0; cpu < cpu_count; cpu++) |
| 340 | bind_cpu(cpu); |
| 341 | |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 342 | for (num = 0; num < avail_monitors; num++) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 343 | monitors[num]->stop(); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 344 | |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 345 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static void cmdline(int argc, char *argv[]) |
| 350 | { |
| 351 | int opt; |
| 352 | progname = basename(argv[0]); |
| 353 | |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 354 | while ((opt = getopt(argc, argv, "+lci:m:")) != -1) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 355 | switch (opt) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 356 | case 'l': |
Dominik Brodowski | 498ca79 | 2011-08-06 18:11:43 +0200 | [diff] [blame] | 357 | if (mode) |
| 358 | print_wrong_arg_exit(); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 359 | mode = list; |
| 360 | break; |
| 361 | case 'i': |
| 362 | /* only allow -i with -m or no option */ |
Dominik Brodowski | 498ca79 | 2011-08-06 18:11:43 +0200 | [diff] [blame] | 363 | if (mode && mode != show) |
| 364 | print_wrong_arg_exit(); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 365 | interval = atoi(optarg); |
| 366 | break; |
| 367 | case 'm': |
Dominik Brodowski | 498ca79 | 2011-08-06 18:11:43 +0200 | [diff] [blame] | 368 | if (mode) |
| 369 | print_wrong_arg_exit(); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 370 | mode = show; |
| 371 | show_monitors_param = optarg; |
| 372 | break; |
Thomas Renninger | c8cfc3c | 2012-11-27 13:17:48 +0100 | [diff] [blame] | 373 | case 'c': |
| 374 | wake_cpus = 1; |
| 375 | break; |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 376 | default: |
Dominik Brodowski | 498ca79 | 2011-08-06 18:11:43 +0200 | [diff] [blame] | 377 | print_wrong_arg_exit(); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | if (!mode) |
| 381 | mode = show_all; |
| 382 | } |
| 383 | |
| 384 | int cmd_monitor(int argc, char **argv) |
| 385 | { |
| 386 | unsigned int num; |
| 387 | struct cpuidle_monitor *test_mon; |
| 388 | int cpu; |
| 389 | |
| 390 | cmdline(argc, argv); |
| 391 | cpu_count = get_cpu_topology(&cpu_top); |
| 392 | if (cpu_count < 0) { |
| 393 | printf(_("Cannot read number of available processors\n")); |
| 394 | return EXIT_FAILURE; |
| 395 | } |
| 396 | |
Jacob Tanenbaum | 20102ac | 2015-10-22 17:17:05 +0200 | [diff] [blame] | 397 | if (!cpu_top.core_info[0].is_online) |
| 398 | printf("WARNING: at least one cpu is offline\n"); |
| 399 | |
Thomas Renninger | 9ee31f6 | 2011-08-12 01:11:38 +0200 | [diff] [blame] | 400 | /* Default is: monitor all CPUs */ |
| 401 | if (bitmask_isallclear(cpus_chosen)) |
| 402 | bitmask_setall(cpus_chosen); |
| 403 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 404 | dprint("System has up to %d CPU cores\n", cpu_count); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 405 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 406 | for (num = 0; all_monitors[num]; num++) { |
| 407 | dprint("Try to register: %s\n", all_monitors[num]->name); |
| 408 | test_mon = all_monitors[num]->do_register(); |
| 409 | if (test_mon) { |
| 410 | if (test_mon->needs_root && !run_as_root) { |
| 411 | fprintf(stderr, _("Available monitor %s needs " |
| 412 | "root access\n"), test_mon->name); |
| 413 | continue; |
| 414 | } |
| 415 | monitors[avail_monitors] = test_mon; |
| 416 | dprint("%s registered\n", all_monitors[num]->name); |
| 417 | avail_monitors++; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (avail_monitors == 0) { |
| 422 | printf(_("No HW Cstate monitors found\n")); |
| 423 | return 1; |
| 424 | } |
| 425 | |
| 426 | if (mode == list) { |
| 427 | list_monitors(); |
| 428 | exit(EXIT_SUCCESS); |
| 429 | } |
| 430 | |
| 431 | if (mode == show) |
| 432 | parse_monitor_param(show_monitors_param); |
| 433 | |
| 434 | dprint("Packages: %d - Cores: %d - CPUs: %d\n", |
| 435 | cpu_top.pkgs, cpu_top.cores, cpu_count); |
| 436 | |
| 437 | /* |
| 438 | * if any params left, it must be a command to fork |
| 439 | */ |
| 440 | if (argc - optind) |
| 441 | fork_it(argv + optind); |
| 442 | else |
| 443 | do_interval_measure(interval); |
| 444 | |
| 445 | /* ToDo: Topology parsing needs fixing first to do |
| 446 | this more generically */ |
| 447 | if (cpu_top.pkgs > 1) |
| 448 | print_header(3); |
| 449 | else |
| 450 | print_header(1); |
| 451 | |
| 452 | for (cpu = 0; cpu < cpu_count; cpu++) { |
| 453 | if (cpu_top.pkgs > 1) |
| 454 | print_results(3, cpu); |
| 455 | else |
| 456 | print_results(1, cpu); |
| 457 | } |
| 458 | |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 459 | for (num = 0; num < avail_monitors; num++) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 460 | monitors[num]->unregister(); |
Dominik Brodowski | b510b54 | 2011-04-19 19:58:59 +0200 | [diff] [blame] | 461 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 462 | cpu_topology_release(cpu_top); |
| 463 | return 0; |
| 464 | } |