summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2017-07-19 19:28:37 -0400
committerLen Brown <len.brown@intel.com>2018-06-01 12:13:05 -0400
commitb9ad8ee0da54b2b4d2f8cd50fc9ce5200d61e7d1 (patch)
tree17ff7a6c8915a232d68cc3abfa9ae217ee2b4063 /tools/power
parent072119606a239557bf8532c70af9c211d1028dff (diff)
tools/power turbostat: end current interval upon newline input
In turbostat interval mode, a newline typed on standard input will now conclude the current interval. Data will immediately be collected and printed for that interval, and the next interval will be started. This is similar to the recently added SIGUSR1 feature. But that is for use by programs, while this is for interactive use. Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/turbostat/turbostat.87
-rw-r--r--tools/power/x86/turbostat/turbostat.c43
2 files changed, 44 insertions, 6 deletions
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
index f99bddf16b8b..4cffa4a5a2b7 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -267,6 +267,13 @@ CPU PRF_CTRL
267 267
268.fi 268.fi
269 269
270.SH INPUT
271
272For interval-mode, turbostat will immediately end the current interval
273when it sees a newline on standard input.
274turbostat will then start the next interval.
275Control-C will be send a SIGINT to turbostat,
276which will immediately abort the program with no further processing.
270.SH SIGNALS 277.SH SIGNALS
271 278
272SIGINT will interrupt interval-mode. 279SIGINT will interrupt interval-mode.
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index dd9b2efbbb2a..1d4ba4ade6fa 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -29,6 +29,7 @@
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/wait.h> 30#include <sys/wait.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32#include <sys/select.h>
32#include <sys/resource.h> 33#include <sys/resource.h>
33#include <fcntl.h> 34#include <fcntl.h>
34#include <signal.h> 35#include <signal.h>
@@ -47,7 +48,8 @@
47char *proc_stat = "/proc/stat"; 48char *proc_stat = "/proc/stat";
48FILE *outf; 49FILE *outf;
49int *fd_percpu; 50int *fd_percpu;
50struct timespec interval_ts = {5, 0}; 51struct timeval interval_tv = {5, 0};
52struct timespec one_msec = {0, 1000000};
51unsigned int debug; 53unsigned int debug;
52unsigned int quiet; 54unsigned int quiet;
53unsigned int shown; 55unsigned int shown;
@@ -478,7 +480,7 @@ void help(void)
478 "--cpu cpu-set limit output to summary plus cpu-set:\n" 480 "--cpu cpu-set limit output to summary plus cpu-set:\n"
479 " {core | package | j,k,l..m,n-p }\n" 481 " {core | package | j,k,l..m,n-p }\n"
480 "--quiet skip decoding system configuration header\n" 482 "--quiet skip decoding system configuration header\n"
481 "--interval sec Override default 5-second measurement interval\n" 483 "--interval sec.subsec Override default 5-second measurement interval\n"
482 "--help print this help message\n" 484 "--help print this help message\n"
483 "--list list column headers only\n" 485 "--list list column headers only\n"
484 "--out file create or truncate \"file\" for all output\n" 486 "--out file create or truncate \"file\" for all output\n"
@@ -2615,6 +2617,8 @@ static void signal_handler (int signal)
2615 fprintf(stderr, "SIGUSR1\n"); 2617 fprintf(stderr, "SIGUSR1\n");
2616 break; 2618 break;
2617 } 2619 }
2620 /* make sure this manually-invoked interval is at least 1ms long */
2621 nanosleep(&one_msec, NULL);
2618} 2622}
2619 2623
2620void setup_signal_handler(void) 2624void setup_signal_handler(void)
@@ -2630,6 +2634,33 @@ void setup_signal_handler(void)
2630 if (sigaction(SIGUSR1, &sa, NULL) < 0) 2634 if (sigaction(SIGUSR1, &sa, NULL) < 0)
2631 err(1, "sigaction SIGUSR1"); 2635 err(1, "sigaction SIGUSR1");
2632} 2636}
2637
2638int do_sleep(void)
2639{
2640 struct timeval select_timeout;
2641 fd_set readfds;
2642 int retval;
2643
2644 FD_ZERO(&readfds);
2645 FD_SET(0, &readfds);
2646
2647 select_timeout = interval_tv;
2648
2649 retval = select(1, &readfds, NULL, NULL, &select_timeout);
2650
2651 if (retval == 1) {
2652
2653 switch (getc(stdin)) {
2654 case 'q':
2655 exit_requested = 1;
2656 break;
2657 }
2658 /* make sure this manually-invoked interval is at least 1ms long */
2659 nanosleep(&one_msec, NULL);
2660 }
2661
2662 return retval;
2663}
2633void turbostat_loop() 2664void turbostat_loop()
2634{ 2665{
2635 int retval; 2666 int retval;
@@ -2659,7 +2690,7 @@ restart:
2659 re_initialize(); 2690 re_initialize();
2660 goto restart; 2691 goto restart;
2661 } 2692 }
2662 nanosleep(&interval_ts, NULL); 2693 do_sleep();
2663 if (snapshot_proc_sysfs_files()) 2694 if (snapshot_proc_sysfs_files())
2664 goto restart; 2695 goto restart;
2665 retval = for_all_cpus(get_counters, ODD_COUNTERS); 2696 retval = for_all_cpus(get_counters, ODD_COUNTERS);
@@ -2680,7 +2711,7 @@ restart:
2680 flush_output_stdout(); 2711 flush_output_stdout();
2681 if (exit_requested) 2712 if (exit_requested)
2682 break; 2713 break;
2683 nanosleep(&interval_ts, NULL); 2714 do_sleep();
2684 if (snapshot_proc_sysfs_files()) 2715 if (snapshot_proc_sysfs_files())
2685 goto restart; 2716 goto restart;
2686 retval = for_all_cpus(get_counters, EVEN_COUNTERS); 2717 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
@@ -5103,8 +5134,8 @@ void cmdline(int argc, char **argv)
5103 exit(2); 5134 exit(2);
5104 } 5135 }
5105 5136
5106 interval_ts.tv_sec = interval; 5137 interval_tv.tv_sec = interval;
5107 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; 5138 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000;
5108 } 5139 }
5109 break; 5140 break;
5110 case 'J': 5141 case 'J':