turbostat.c (39300ffb9b6666714c60735cf854e1280e4e75f4) turbostat.c (d91bb17c2a874493603c4d99db305d8caf2d180c)
1/*
2 * turbostat -- show CPU frequency and C-state residency
3 * on modern Intel turbo-capable processors.
4 *
5 * Copyright (c) 2012 Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 192 unchanged lines hidden (view full) ---

201 sprintf(pathname, "/dev/cpu/%d/msr", cpu);
202 fd = open(pathname, O_RDONLY);
203 if (fd < 0)
204 return -1;
205
206 retval = pread(fd, msr, sizeof *msr, offset);
207 close(fd);
208
1/*
2 * turbostat -- show CPU frequency and C-state residency
3 * on modern Intel turbo-capable processors.
4 *
5 * Copyright (c) 2012 Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 192 unchanged lines hidden (view full) ---

201 sprintf(pathname, "/dev/cpu/%d/msr", cpu);
202 fd = open(pathname, O_RDONLY);
203 if (fd < 0)
204 return -1;
205
206 retval = pread(fd, msr, sizeof *msr, offset);
207 close(fd);
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
212 return 0;
213}
214
215void print_header(void)
216{
217 if (show_pkg)
218 outp += sprintf(outp, "pk");

--- 877 unchanged lines hidden (view full) ---

1096}
1097
1098void turbostat_loop()
1099{
1100 int retval;
1101
1102restart:
1103 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
213
214 return 0;
215}
216
217void print_header(void)
218{
219 if (show_pkg)
220 outp += sprintf(outp, "pk");

--- 877 unchanged lines hidden (view full) ---

1098}
1099
1100void turbostat_loop()
1101{
1102 int retval;
1103
1104restart:
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();
1106 goto restart;
1107 }
1108 gettimeofday(&tv_even, (struct timezone *)NULL);
1109
1110 while (1) {
1111 if (for_all_proc_cpus(cpu_is_not_present)) {
1112 re_initialize();
1113 goto restart;
1114 }
1115 sleep(interval_sec);
1116 retval = for_all_cpus(get_counters, ODD_COUNTERS);
1109 re_initialize();
1110 goto restart;
1111 }
1112 gettimeofday(&tv_even, (struct timezone *)NULL);
1113
1114 while (1) {
1115 if (for_all_proc_cpus(cpu_is_not_present)) {
1116 re_initialize();
1117 goto restart;
1118 }
1119 sleep(interval_sec);
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();
1119 goto restart;
1120 }
1121 gettimeofday(&tv_odd, (struct timezone *)NULL);
1122 timersub(&tv_odd, &tv_even, &tv_delta);
1123 for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS);
1124 compute_average(EVEN_COUNTERS);
1125 format_all_counters(EVEN_COUNTERS);
1126 flush_stdout();
1127 sleep(interval_sec);
1128 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
1124 re_initialize();
1125 goto restart;
1126 }
1127 gettimeofday(&tv_odd, (struct timezone *)NULL);
1128 timersub(&tv_odd, &tv_even, &tv_delta);
1129 for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS);
1130 compute_average(EVEN_COUNTERS);
1131 format_all_counters(EVEN_COUNTERS);
1132 flush_stdout();
1133 sleep(interval_sec);
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();
1131 goto restart;
1132 }
1133 gettimeofday(&tv_even, (struct timezone *)NULL);
1134 timersub(&tv_even, &tv_odd, &tv_delta);
1135 for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS);
1136 compute_average(ODD_COUNTERS);
1137 format_all_counters(ODD_COUNTERS);

--- 402 unchanged lines hidden (view full) ---

1540
1541 if (verbose)
1542 print_verbose_header();
1543}
1544
1545int fork_it(char **argv)
1546{
1547 pid_t child_pid;
1138 re_initialize();
1139 goto restart;
1140 }
1141 gettimeofday(&tv_even, (struct timezone *)NULL);
1142 timersub(&tv_even, &tv_odd, &tv_delta);
1143 for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS);
1144 compute_average(ODD_COUNTERS);
1145 format_all_counters(ODD_COUNTERS);

--- 402 unchanged lines hidden (view full) ---

1548
1549 if (verbose)
1550 print_verbose_header();
1551}
1552
1553int fork_it(char **argv)
1554{
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() */
1551 sched_setaffinity(0, cpu_present_setsize, cpu_present_set);
1552 gettimeofday(&tv_even, (struct timezone *)NULL);
1553
1554 child_pid = fork();
1555 if (!child_pid) {
1556 /* child */
1557 execvp(argv[0], argv);
1558 } else {
1561 /* clear affinity side-effect of get_counters() */
1562 sched_setaffinity(0, cpu_present_setsize, cpu_present_set);
1563 gettimeofday(&tv_even, (struct timezone *)NULL);
1564
1565 child_pid = fork();
1566 if (!child_pid) {
1567 /* child */
1568 execvp(argv[0], argv);
1569 } else {
1559 int status;
1560
1561 /* parent */
1562 if (child_pid == -1) {
1563 perror("fork");
1564 exit(1);
1565 }
1566
1567 signal(SIGINT, SIG_IGN);
1568 signal(SIGQUIT, SIG_IGN);
1569 if (waitpid(child_pid, &status, 0) == -1) {
1570 perror("wait");
1570
1571 /* parent */
1572 if (child_pid == -1) {
1573 perror("fork");
1574 exit(1);
1575 }
1576
1577 signal(SIGINT, SIG_IGN);
1578 signal(SIGQUIT, SIG_IGN);
1579 if (waitpid(child_pid, &status, 0) == -1) {
1580 perror("wait");
1571 exit(1);
1581 exit(status);
1572 }
1573 }
1574 /*
1575 * n.b. fork_it() does not check for errors from for_all_cpus()
1576 * because re-starting is problematic when forking
1577 */
1578 for_all_cpus(get_counters, ODD_COUNTERS);
1579 gettimeofday(&tv_odd, (struct timezone *)NULL);
1580 timersub(&tv_odd, &tv_even, &tv_delta);
1581 for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS);
1582 compute_average(EVEN_COUNTERS);
1583 format_all_counters(EVEN_COUNTERS);
1584 flush_stderr();
1585
1586 fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);
1587
1582 }
1583 }
1584 /*
1585 * n.b. fork_it() does not check for errors from for_all_cpus()
1586 * because re-starting is problematic when forking
1587 */
1588 for_all_cpus(get_counters, ODD_COUNTERS);
1589 gettimeofday(&tv_odd, (struct timezone *)NULL);
1590 timersub(&tv_odd, &tv_even, &tv_delta);
1591 for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS);
1592 compute_average(EVEN_COUNTERS);
1593 format_all_counters(EVEN_COUNTERS);
1594 flush_stderr();
1595
1596 fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);
1597
1588 return 0;
1598 return status;
1589}
1590
1591void cmdline(int argc, char **argv)
1592{
1593 int opt;
1594
1595 progname = argv[0];
1596

--- 58 unchanged lines hidden ---
1599}
1600
1601void cmdline(int argc, char **argv)
1602{
1603 int opt;
1604
1605 progname = argv[0];
1606

--- 58 unchanged lines hidden ---