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

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

46#include <errno.h>
47
48char *proc_stat = "/proc/stat";
49FILE *outf;
50int *fd_percpu;
51struct timeval interval_tv = {5, 0};
52struct timespec interval_ts = {5, 0};
53struct timespec one_msec = {0, 1000000};
1/*
2 * turbostat -- show CPU frequency and C-state residency
3 * on modern Intel turbo-capable processors.
4 *
5 * Copyright (c) 2013 Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it

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

46#include <errno.h>
47
48char *proc_stat = "/proc/stat";
49FILE *outf;
50int *fd_percpu;
51struct timeval interval_tv = {5, 0};
52struct timespec interval_ts = {5, 0};
53struct timespec one_msec = {0, 1000000};
54unsigned int num_iterations;
54unsigned int debug;
55unsigned int quiet;
56unsigned int shown;
57unsigned int sums_need_wide_columns;
58unsigned int rapl_joules;
59unsigned int summary_only;
60unsigned int list_header_only;
61unsigned int dump_only;

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

491 "--add add a counter\n"
492 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n"
493 "--cpu cpu-set limit output to summary plus cpu-set:\n"
494 " {core | package | j,k,l..m,n-p }\n"
495 "--quiet skip decoding system configuration header\n"
496 "--interval sec.subsec Override default 5-second measurement interval\n"
497 "--help print this help message\n"
498 "--list list column headers only\n"
55unsigned int debug;
56unsigned int quiet;
57unsigned int shown;
58unsigned int sums_need_wide_columns;
59unsigned int rapl_joules;
60unsigned int summary_only;
61unsigned int list_header_only;
62unsigned int dump_only;

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

492 "--add add a counter\n"
493 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n"
494 "--cpu cpu-set limit output to summary plus cpu-set:\n"
495 " {core | package | j,k,l..m,n-p }\n"
496 "--quiet skip decoding system configuration header\n"
497 "--interval sec.subsec Override default 5-second measurement interval\n"
498 "--help print this help message\n"
499 "--list list column headers only\n"
500 "--num_iterations num number of the measurement iterations\n"
499 "--out file create or truncate \"file\" for all output\n"
500 "--version print version information\n"
501 "\n"
502 "For more help, run \"man turbostat\"\n");
503}
504
505/*
506 * bic_lookup

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

2758 nanosleep(&one_msec, NULL);
2759 }
2760}
2761
2762void turbostat_loop()
2763{
2764 int retval;
2765 int restarted = 0;
501 "--out file create or truncate \"file\" for all output\n"
502 "--version print version information\n"
503 "\n"
504 "For more help, run \"man turbostat\"\n");
505}
506
507/*
508 * bic_lookup

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

2760 nanosleep(&one_msec, NULL);
2761 }
2762}
2763
2764void turbostat_loop()
2765{
2766 int retval;
2767 int restarted = 0;
2768 int done_iters = 0;
2766
2767 setup_signal_handler();
2768
2769restart:
2770 restarted++;
2771
2772 snapshot_proc_sysfs_files();
2773 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
2774 if (retval < -1) {
2775 exit(retval);
2776 } else if (retval == -1) {
2777 if (restarted > 1) {
2778 exit(retval);
2779 }
2780 re_initialize();
2781 goto restart;
2782 }
2783 restarted = 0;
2769
2770 setup_signal_handler();
2771
2772restart:
2773 restarted++;
2774
2775 snapshot_proc_sysfs_files();
2776 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
2777 if (retval < -1) {
2778 exit(retval);
2779 } else if (retval == -1) {
2780 if (restarted > 1) {
2781 exit(retval);
2782 }
2783 re_initialize();
2784 goto restart;
2785 }
2786 restarted = 0;
2787 done_iters = 0;
2784 gettimeofday(&tv_even, (struct timezone *)NULL);
2785
2786 while (1) {
2787 if (for_all_proc_cpus(cpu_is_not_present)) {
2788 re_initialize();
2789 goto restart;
2790 }
2791 do_sleep();

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

2804 re_initialize();
2805 goto restart;
2806 }
2807 compute_average(EVEN_COUNTERS);
2808 format_all_counters(EVEN_COUNTERS);
2809 flush_output_stdout();
2810 if (exit_requested)
2811 break;
2788 gettimeofday(&tv_even, (struct timezone *)NULL);
2789
2790 while (1) {
2791 if (for_all_proc_cpus(cpu_is_not_present)) {
2792 re_initialize();
2793 goto restart;
2794 }
2795 do_sleep();

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

2808 re_initialize();
2809 goto restart;
2810 }
2811 compute_average(EVEN_COUNTERS);
2812 format_all_counters(EVEN_COUNTERS);
2813 flush_output_stdout();
2814 if (exit_requested)
2815 break;
2816 if (num_iterations && ++done_iters >= num_iterations)
2817 break;
2812 do_sleep();
2813 if (snapshot_proc_sysfs_files())
2814 goto restart;
2815 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
2816 if (retval < -1) {
2817 exit(retval);
2818 } else if (retval == -1) {
2819 re_initialize();

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

2825 re_initialize();
2826 goto restart;
2827 }
2828 compute_average(ODD_COUNTERS);
2829 format_all_counters(ODD_COUNTERS);
2830 flush_output_stdout();
2831 if (exit_requested)
2832 break;
2818 do_sleep();
2819 if (snapshot_proc_sysfs_files())
2820 goto restart;
2821 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
2822 if (retval < -1) {
2823 exit(retval);
2824 } else if (retval == -1) {
2825 re_initialize();

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

2831 re_initialize();
2832 goto restart;
2833 }
2834 compute_average(ODD_COUNTERS);
2835 format_all_counters(ODD_COUNTERS);
2836 flush_output_stdout();
2837 if (exit_requested)
2838 break;
2839 if (num_iterations && ++done_iters >= num_iterations)
2840 break;
2833 }
2834}
2835
2836void check_dev_msr()
2837{
2838 struct stat sb;
2839 char pathname[32];
2840

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

5207 int option_index = 0;
5208 static struct option long_options[] = {
5209 {"add", required_argument, 0, 'a'},
5210 {"cpu", required_argument, 0, 'c'},
5211 {"Dump", no_argument, 0, 'D'},
5212 {"debug", no_argument, 0, 'd'}, /* internal, not documented */
5213 {"enable", required_argument, 0, 'e'},
5214 {"interval", required_argument, 0, 'i'},
2841 }
2842}
2843
2844void check_dev_msr()
2845{
2846 struct stat sb;
2847 char pathname[32];
2848

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

5215 int option_index = 0;
5216 static struct option long_options[] = {
5217 {"add", required_argument, 0, 'a'},
5218 {"cpu", required_argument, 0, 'c'},
5219 {"Dump", no_argument, 0, 'D'},
5220 {"debug", no_argument, 0, 'd'}, /* internal, not documented */
5221 {"enable", required_argument, 0, 'e'},
5222 {"interval", required_argument, 0, 'i'},
5223 {"num_iterations", required_argument, 0, 'n'},
5215 {"help", no_argument, 0, 'h'},
5216 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
5217 {"Joules", no_argument, 0, 'J'},
5218 {"list", no_argument, 0, 'l'},
5219 {"out", required_argument, 0, 'o'},
5220 {"quiet", no_argument, 0, 'q'},
5221 {"show", required_argument, 0, 's'},
5222 {"Summary", no_argument, 0, 'S'},
5223 {"TCC", required_argument, 0, 'T'},
5224 {"version", no_argument, 0, 'v' },
5225 {0, 0, 0, 0 }
5226 };
5227
5228 progname = argv[0];
5229
5224 {"help", no_argument, 0, 'h'},
5225 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
5226 {"Joules", no_argument, 0, 'J'},
5227 {"list", no_argument, 0, 'l'},
5228 {"out", required_argument, 0, 'o'},
5229 {"quiet", no_argument, 0, 'q'},
5230 {"show", required_argument, 0, 's'},
5231 {"Summary", no_argument, 0, 'S'},
5232 {"TCC", required_argument, 0, 'T'},
5233 {"version", no_argument, 0, 'v' },
5234 {0, 0, 0, 0 }
5235 };
5236
5237 progname = argv[0];
5238
5230 while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jo:qST:v",
5239 while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v",
5231 long_options, &option_index)) != -1) {
5232 switch (opt) {
5233 case 'a':
5234 parse_add_command(optarg);
5235 break;
5236 case 'c':
5237 parse_cpu_command(optarg);
5238 break;

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

5282 quiet++;
5283 break;
5284 case 'o':
5285 outf = fopen_or_die(optarg, "w");
5286 break;
5287 case 'q':
5288 quiet = 1;
5289 break;
5240 long_options, &option_index)) != -1) {
5241 switch (opt) {
5242 case 'a':
5243 parse_add_command(optarg);
5244 break;
5245 case 'c':
5246 parse_cpu_command(optarg);
5247 break;

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

5291 quiet++;
5292 break;
5293 case 'o':
5294 outf = fopen_or_die(optarg, "w");
5295 break;
5296 case 'q':
5297 quiet = 1;
5298 break;
5299 case 'n':
5300 num_iterations = strtod(optarg, NULL);
5301
5302 if (num_iterations <= 0) {
5303 fprintf(outf, "iterations %d should be positive number\n",
5304 num_iterations);
5305 exit(2);
5306 }
5307 break;
5290 case 's':
5291 /*
5292 * --show: show only those specified
5293 * The 1st invocation will clear and replace the enabled mask
5294 * subsequent invocations can add to it.
5295 */
5296 if (shown == 0)
5297 bic_enabled = bic_lookup(optarg, SHOW_LIST);

--- 52 unchanged lines hidden ---
5308 case 's':
5309 /*
5310 * --show: show only those specified
5311 * The 1st invocation will clear and replace the enabled mask
5312 * subsequent invocations can add to it.
5313 */
5314 if (shown == 0)
5315 bic_enabled = bic_lookup(optarg, SHOW_LIST);

--- 52 unchanged lines hidden ---