Hi Rafael,

        This is excellent!  Thank you very much for such a descriptive man  
page.  I've made just a couple of comments below for your consideration.

Thanks,
Pat

On Apr 7, 2008, at 4:41 PM, Rafael Vanoni wrote:
> Hi all
>
> I've made the following changes:
>
> - added the -i option, which implements what we've been talking  
> about correlating cyclic events with idle state transitions
>
> - allows users with dtrace privileges to run powertop. Root is  
> required for suggestions. A message is printed in case a non-priv,  
> non-dtrace-able user tries to run the tool
>
> - chased the few remaining usability bugs. I've (arbitrarily) set a  
> upper limit of 100 seconds for measuring interval
>
> - removed a couple of redundant calls and references to suggestions  
> routines
>
> I'm attaching the export and the new drafted man page. If you guys  
> are okay with it, I'd like to put it on the project page as well.
>
> thanks
> Rafael
>
> NAME
>       PowerTOP - report and analyze events that effect power management
>
> SYNOPSIS
>       powertop [-d] [-t] [interval] [-h] [-i]
>
> DESCRIPTION
>       PowerTOP is an observability tool that shows how effectively your
>       system is taking advantage of the CPU's power management features.
>       By running the tool on an otherwise idle system, you can see how much
        This is a bit of a nit, but would it be more accurate to keep the  
description out of the first and second person?  I appreciate the  
informal feel the text gives by using "your" and "you", but my wife  
(the English teacher) would probably suggest keeping it in the third  
person. :)

>       time the CPUs are spending running in lower power states. Ideally, an
>       unutilized (idle) system will spend 100% of its time running at the
>       lowest power CPU states, but because of background user and kernel
>       activity (random software periodically waking to poll status), idle
>       systems typically consume more power than they should.
>
>       The tool analyzes system activity periodically and displays a summary
>       of how long the processor is executing at each supported power state.
>       It also displays the top processes responsible for causing the CPU to
>       wake up and use more energy. This allows the user to identify and
>       diagnose problematic areas of the system and optimize its power
>       efficiency.
        Would it be appropriate to include a "see also" or  some other  
reference to psrinfo(1) so the user can find out what power states  
are supported?  If I remember right, changes are, or have been, made  
to psrinfo(1) to describe at what frequency a socket runs.
>
>       PowerTOP averages the amount of activity that is preventing the  
> CPU from
>       entering a lower power state and presents it on the "Wakeups-from- 
> idle
>       per second" field. This value represents the total number of events
>       divided by the current interval. Notice that not all events are
>       displayed on the screen at all times.
>
>       The -d option analyzes the system once and prints a list of the top
>       applications and/or kernel services that are causing CPU wakeups. The
>       -t option allows the user to specify the interval under which  
> PowerTOP
>       will analyze the system. This value ranges between 1 and 100 seconds.
>       The -h option prints the available options and the -i option will  
> cause
>       the tool to report cyclic events if they cause the CPU to transition
>       from the idle to the normal state of operation.
        This is redundant to what's provided in the OPTIONS section.  I'd  
think this paragraph could be omitted.
>
>       During execution, the user can force a refresh of the analyzis by
        Just a typo here; "analyzis" should be "analysis."
>       typing the R key. The interval time will be restored to the  
> default or
>       to a specified interval. To leave the application, the user must type
>       the Q key.
>
>       If running as root (superuser), the tool will make suggestions as how
>       the system can be improved from a power management perspective.
>
> OPTIONS
>       -d
>
>               Dumps the results of a one time analysis of system activity.
        I think "one time" should be "one-time" here.
>
>       -t interval
>
>               Specifies the interval under which the tool will analyze system
>               activity. The possible values are between 1 and 100, the
>               default is 5 seconds.
>
>       -h
>
>               Prints the available options on the screen.
>
>       -i
>
>               Changes the event report so that cyclic events will only be
>               identified if they result in a transition from the idle to
>               normal CPU state of operation.
>
> OPERANDS
>      interval
>
>          Specifies the sampling interval in seconds; the  default
>          interval is 5 seconds.
>
> EXAMPLES
>       Example 1 Setting the Interval Time to 2 Seconds
        I don't think you need to capitalize "Interval", "Time", or "Seconds."
>
>               example% powertop -t 2
>
>
>       Example 2 Dumping system activity to the standard output
>
>               example% powertop -d
>
>       Example 3 PowerTOP reporting cyclic events that result in processor
>       state transitions
>
>               example% powertop -i
>
> EXIT STATUS
>      The following exit values are returned:
>
>      0
>
>          Successful completion.
>
>      -1
>
>          An error occurred.
>
> USAGE
>         The user must have DTrace privileges to run PowerTOP and root
>       (superuser) privileges for the tool to suggest improvements to the
>       system.
>
> FILES
>       /etc/power.conf
>
>               Power management configuration file.
>
> ATTRIBUTES
>      See attributes(5) for descriptions of the  following  attri-
>      butes:
>
>      ____________________________________________________________
>     |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
>     |_____________________________|_____________________________|
>     | Architecture                | x86, SPARC                  |
>     |_____________________________|_____________________________|
>     | Availability                | SUNWpowertop                |
>     |_____________________________|_____________________________|
>
> SEE ALSO
>       pmconfig(1M), powerd(1M), uadmin(2), libdevinfo(3LIB), attributes(5),
>       cpr(7), pm(7D), pm-components(9P), removable-media(9P)
>
>
>
> # HG changeset patch
> # User rafael.vanoni at sun.com
> # Date 1207607816 -3600
> # Node ID 6f2460153e8eabe71255637acae4ee9350f9bf9f
> # Parent  f6c64140a2a59bbbbd924c1de263497f9e6f3b3e
> New -i option, non-priv user, bug fixes and comments
>
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/cpufreq.c
> --- a/usr/src/cmd/powertop/cpufreq.c  Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/cpufreq.c  Mon Apr 07 23:36:56 2008 +0100
> @@ -319,6 +319,10 @@ pt_cpufreq_dtrace_walk(const dtrace_aggd
>       return (DTRACE_AGGWALK_NEXT);
>  }
>
> +/*
> + * Used as a suggestion, sets PM in /etc/power.conf and
> + * a 1sec threshold, then calls /usr/sbin/pmconfig
> + */
>  void
>  enable_p_state(void)
>  {
> @@ -327,7 +331,10 @@ enable_p_state(void)
>       system(default_pmconf);
>  }
>
> -void
> +/*
> + * Checks if PM is enabled in /etc/power.conf, enabling if not
> + */
> +int
>  suggest_p_state(void)
>  {
>       char    line[1024];
> @@ -336,18 +343,20 @@ suggest_p_state(void)
>       file = fopen(default_conf, "r");
>
>       if (!file)
> -             return;
> +             return 0;
>
>       memset(line, 0, 1024);
>
>       while(fgets(line, 1023, file)) {
>               if (strstr(line, "cpupm")) {
>                       if (strstr(line, "enable"))
> -                             return;
> +                             return 1;
>               }
>       }
>
>       add_suggestion("Suggestion: enable CPU power management by "
>           "pressing the P key",  40, 'P', "P - Enable p-state",
>           enable_p_state);
> +
> +     return 1;
>  }
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/display.c
> --- a/usr/src/cmd/powertop/display.c  Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/display.c  Mon Apr 07 23:36:56 2008 +0100
> @@ -55,10 +55,33 @@ static WINDOW     *status_bar_window;
>        } while (0)
>
>  char         status_bar_slots[10][40];
> +int  maxx, maxy;
> +int  maxtimerstats = 50;
> +int  maxwidth = 200;
>
> -void
> -cleanup_curses(void) {
> -     endwin();
> +/*
> + * Sorts events using (gulp) global variables
> + */
> +static void
> +event_bubblesort()
> +{
> +     event_info_t    tmp;
> +     int             i,j;
> +     int             exchange;
> +
> +     for (i = 0; i < top_events - 1; i++) {
> +             exchange = 0;
> +             for (j = top_events - 2; j >= i; j--) {
> +                     if (event_info[j + 1].total_count > 
> event_info[j].total_count) {
> +                             memcpy(&tmp, &event_info[j], 
> sizeof(event_info_t));
> +                             memcpy(&event_info[j], &event_info[j+1], 
> sizeof(event_info_t));
> +                             memcpy(&event_info[j+1], &tmp, 
> sizeof(event_info_t));
> +                             exchange = 1;
> +                     }
> +             }
> +             if (!exchange)
> +                     return;
> +     }
>  }
>
>  static void
> @@ -94,9 +117,10 @@ zap_windows(void)
>       }
>  }
>
> -int  maxx, maxy;
> -int  maxtimerstats = 50;
> -int  maxwidth = 200;
> +void
> +cleanup_curses(void) {
> +     endwin();
> +}
>
>  void
>  setup_windows(void)
> @@ -162,7 +186,7 @@ show_title_bar(void)
>       werase(status_bar_window);
>
>       x = 0;
> -     for (i=0; i<10; i++) {
> +     for (i = 0; i < 10; i++) {
>               if (strlen(status_bar_slots[i])==0)
>                       continue;
>               wattron(status_bar_window, A_REVERSE);
> @@ -309,25 +333,3 @@ show_suggestion(char *sug)
>       print(suggestion_window, 0, 0, "%s", sug);
>       wrefresh(suggestion_window);
>  }
> -
> -void
> -event_bubblesort()
> -{
> -     event_info_t    tmp;
> -     int             i,j;
> -     int             exchange;
> -
> -     for (i = 0; i < top_events - 1; i++) {
> -             exchange = 0;
> -             for (j = top_events - 2; j >= i; j--) {
> -                     if (event_info[j + 1].total_count > 
> event_info[j].total_count) {
> -                             memcpy(&tmp, &event_info[j], 
> sizeof(event_info_t));
> -                             memcpy(&event_info[j], &event_info[j+1], 
> sizeof(event_info_t));
> -                             memcpy(&event_info[j+1], &tmp, 
> sizeof(event_info_t));
> -                             exchange = 1;
> -                     }
> -             }
> -             if (!exchange)
> -                     return;
> -     }
> -}
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/events.c
> --- a/usr/src/cmd/powertop/events.c   Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/events.c   Mon Apr 07 23:36:56 2008 +0100
> @@ -42,8 +42,12 @@
>  #include "powertop.h"
>
>  static dtrace_hdl_t *g_dtp;
> -
> -static const char *g_prog =
> +/*
> + * DTrace scripts for observing interrupts, callouts and cyclic  
> events
> + * that cause CPU activity. Such activity prevents the processor from
> + * entering lower power states and reducing power consumption.
> + */
> +static const char *g_prog_A =
>  "interrupt-complete"
>  "/arg0 != NULL && arg3 !=0/"
>  "{"
> @@ -68,6 +72,46 @@ static const char *g_prog =
>  "sdt:::cyclic-start"
>  "/(caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t) 
> &`dtrace_state_deadman &&"
>  " (caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t) 
> &`dtrace_state_clean/"
> +"{"
> +"    @events_k[(caddr_t)((cyclic_t *)arg0)->cy_handler] = count();"
> +"}";
> +
> +/*
> + * This script is similar to the above, except that it only reports
> + * cyclic events that resulted in a transition from an idle to
> + * a normal processor state.
> + */
> +static const char *g_prog_B =
> +"interrupt-complete"
> +"/arg0 != NULL && arg3 !=0/"
> +"{"
> +"    this->devi = (struct dev_info *)arg0;"
> +"    @interrupts[stringof(`devnamesp[this->devi->devi_major].dn_name),"
> +"         this->devi->devi_instance] = count();"
> +"}"
> +""
> +"sdt:::callout-start"
> +"/(caddr_t)((callout_t *)arg0)->c_func == (caddr_t)&`setrun/"
> +"{"
> +"       this->thr = (kthread_t *)(((callout_t *)arg0)->c_arg);"
> +"       @events_u[stringof(this->thr->t_procp->p_user.u_comm)] =  
> count();"
> +"}"
> +""
> +"sdt:::callout-start"
> +"/(caddr_t)((callout_t *)arg0)->c_func != (caddr_t)&`setrun/"
> +"{"
> +"       @events_k[(caddr_t)((callout_t *)arg0)->c_func] = count();"
> +"}"
> +""
> +"sdt:::cyclic-start"
> +"/(caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t) 
> &`dtrace_state_deadman &&"
> +" (caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t) 
> &`dtrace_state_clean/"
> +"{"
> +"    self->cyc = (cyclic_t *)arg0;"
> +"}"
> +""
> +"idle-state-transition"
> +"/self->cyc/"
>  "{"
>  "    @events_k[(caddr_t)((cyclic_t *)arg0)->cy_handler] = count();"
>  "}";
> @@ -147,7 +191,7 @@ walk(const dtrace_aggdata_t *data, void
>  }
>
>  int
> -prepare_event_stats(void)
> +pt_events_stat_prepare(void)
>  {
>       dtrace_prog_t           *prog;
>       dtrace_proginfo_t       info;
> @@ -164,29 +208,39 @@ prepare_event_stats(void)
>               return (-1);
>       }
>
> -     if ((prog = dtrace_program_strcompile(g_dtp, g_prog,
> -                 DTRACE_PROBESPEC_NAME, 0, 0, NULL)) == NULL) {
> -             printf("events: invalid DTrace program\n");
> +     /*
> +      * If the '-i' option was specified, use g_prog_B, else
> +      * default to g_prog_A
> +      */
> +     if (observe_idle)
> +         prog = dtrace_program_strcompile(g_dtp, g_prog_B,
> +                 DTRACE_PROBESPEC_NAME, 0, 0, NULL);
> +     else
> +         prog = dtrace_program_strcompile(g_dtp, g_prog_A,
> +                 DTRACE_PROBESPEC_NAME, 0, 0, NULL);
> +
> +     if (prog == NULL) {
> +             printf("Events: invalid DTrace program\n");
>               return (-1);
>       }
>       if (dtrace_program_exec(g_dtp, prog, &info) == -1) {
> -             printf("events: failed to enable probes");
> +             printf("Events: failed to enable probes");
>               return (-1);
>       }
>       if (dtrace_setopt(g_dtp, "aggsize", "128k") == -1) {
> -             printf("events: failed to set 'aggsize'");
> +             printf("Events: failed to set 'aggsize'");
>               return (-1);
>       }
>       if (dtrace_setopt(g_dtp, "aggrate", "0") == -1) {
> -             printf("events: failed to set 'aggrate'");
> +             printf("Events: failed to set 'aggrate'");
>               return (-1);
>       }
>       if (dtrace_setopt(g_dtp, "aggpercpu", 0) == -1) {
> -             printf("events: failed to set 'aggpercpu'");
> +             printf("Events: failed to set 'aggpercpu'");
>               return (-1);
>       }
>       if (dtrace_go(g_dtp) != 0) {
> -             printf("events: dtrace_go() failed");
> +             printf("Events: dtrace_go() failed");
>               return (-1);
>       }
>       if (dtrace_getopt(g_dtp, "statusrate", &statustime) == -1) {
> @@ -197,7 +251,7 @@ prepare_event_stats(void)
>  }
>
>  void
> -do_event_stats(void)
> +pt_events_stat_collect(void)
>  {
>       p_event         = event_info;
>       top_events      = 0;
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/powertop.c
> --- a/usr/src/cmd/powertop/powertop.c Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/powertop.c Mon Apr 07 23:36:56 2008 +0100
> @@ -40,27 +40,15 @@
>  #include <kstat.h>
>  #include <libgen.h>
>  #include <sys/types.h>
> +#include <errno.h>
>
>  #include "powertop.h"
>
> -uint_t               features = 0;
> -int          dump = 0;
>  void                 enumerate_cpus(void);
> -double               displaytime = 0.0;
>
>  int          g_ncpus;
>  processorid_t        *cpu_table;
>  static char  *prog_name;
> -
> -void
> -usage()
> -{
> -     printf("Usage: powertop [OPTION...]\n");
> -     printf("  -d, --dump            read wakeups once and print list  
> of top offenders\n");
> -     printf("  -t, --time=DOUBLE     default time to gather data in  
> seconds\n");
> -     printf("  -h, --help            Show this help message\n");
> -     exit(0);
> -}
>
>  /*
>   * Return a pointer to the name of this program
> @@ -74,13 +62,15 @@ int
>  int
>  main(int argc, char **argv)
>  {
> +     hrtime_t        last, now;
> +     uint_t          features = 0, p_state_sug = 0;
>       int             ncursesinited = 0, index2 = 0, c;
> -     hrtime_t        last, now;
>
>       static struct option opts[] = {
>               { "dump", 0, NULL, 'd' },
>               { "time", 1, NULL, 't' },
>               { "help", 0, NULL, 'h' },
> +             { "idle", 0, NULL, 'i' },
>               { 0, 0, NULL, 0 }
>       };
>
> @@ -91,36 +81,37 @@ main(int argc, char **argv)
>       pt_set_progname(argv[0]);
>
>       ticktime = ticktime_usr = 5.0;
> +     displaytime     = 0.0;
> +     observe_idle    = 0;
> +     dump            = 0;
> +     p_state_sug     = 0;
>
> -     while ((c = getopt_long(argc, argv, "dt:h", opts, &index2)) !=  
> EOF) {
> +     while ((c = getopt_long(argc, argv, "dit:h", opts, &index2)) !=  
> EOF) {
>               if (c == -1)
>                       break;
> -             
> +
>               switch (c) {
>               case 'd':
>                       dump = 1;
>                       break;
>               case 't':
> -                     ticktime = ticktime_usr = strtod(optarg, NULL);
> -                     if (ticktime < 1) {
> +                     ticktime = ticktime_usr = (double)strtod(optarg, NULL);
> +                     if (ticktime < 1 || ticktime > MAX_INTERVAL) {
>                               usage();
>                               return -1;
>                       }
>                       break;
> +             case 'i':
> +                     observe_idle = 1;
> +                     break;
>               case 'h':
> -                     usage();
> -                     break;
> -             default:
> +             default:
>                       usage();
>                       return -1;
>               }
>       }
>
>       printf("Solaris PowerTOP 1.0   (C) 2007 Intel Corporation \n\n");
> -     if (geteuid() != 0) {
> -             printf(_("PowerTOP needs to be run as root to collect 
> information 
> \n"));
> -             return 0;
> -     }
>
>       /*
>        * Enumerate the system's CPUs
> @@ -128,16 +119,28 @@ main(int argc, char **argv)
>        */
>       enumerate_cpus();
>
> -     /* XXX Prepare C-state statistics */
> +     /* Prepare C-state statistics */
>       if (pt_cpuidle_stat_prepare() != -1)
>               features |= FEATURE_CSTATE;
>
> -     /* XXX Prepare P-state statistics */
> +     /*
> +      * PowerTOP requires DTrace privileges to collect information
> +      * and root to enable PM through /etc/power.conf
> +      * If pt_cpuidle_stat_prepare() failed, the user lacks privileges
> +      * and we should return
> +      */
> +     if (!features) {
> +         printf(_("\n PowerTOP needs DTrace privileges to run\n"));
> +         printf(_(" Please contact your system administrator\n\n"));
> +         return -1;
> +     }
> +
> +     /* Prepare P-state statistics */
>       if (pt_cpufreq_stat_prepare() != -1)
>               features |= FEATURE_PSTATE;
>
>       /* Prepare event statistics */
> -     if (prepare_event_stats() != -1)
> +     if (pt_events_stat_prepare() != -1)
>               features |= FEATURE_EVENTS;
>
>       printf(_("Collecting data for %i second(s) \n"), (int)ticktime);
> @@ -148,7 +151,7 @@ main(int argc, char **argv)
>               fd_set  rfds;
>               struct  timeval tv;
>               int     key, i = 0;
> -             char    *c,     keychar;
> +             char    *c, keychar;
>
>               /*
>                * Sleep for a while waiting either for
> @@ -171,9 +174,10 @@ main(int argc, char **argv)
>
>               memset(event_info, EVENT_NUM_MAX * sizeof (event_info_t), 0);
>               memset(cstate_info, 2 * sizeof(state_info_t), 0);
> +
>               /*
> -              * Initialize curses if we're not dumping and we
> -              * haven't already
> +              * Initialize curses if we're not dumping and
> +              * haven't already done it
>                */
>               if (!dump) {
>                       if (!ncursesinited) {
> @@ -183,26 +187,25 @@ main(int argc, char **argv)
>                       setup_windows();
>                       show_title_bar();
>               }
> +             /* Collect idle state transition stats */
>               if (features & FEATURE_CSTATE)
>                       pt_cpuidle_stat_collect(g_interval);
>
> +             /* Collect frequency change stats */
>               if (features & FEATURE_PSTATE)
>                       pt_cpufreq_stat_collect(g_interval);
>
> -             /*
> -              * Do event statistics
> -              */
> +             /* Collect event statistics */
>               if (features & FEATURE_EVENTS)
> -                     do_event_stats();
> +                     pt_events_stat_collect();
>
> -             /* show C/P-state */
> +             /* Show CPU power states */
>               if (features & FEATURE_CSTATE)
>                       show_cstates(g_interval);
>
> +             /* Show wakeups events affecting PM */
>               if (features & FEATURE_EVENTS) {
>                       show_wakeups(g_interval);
> -
> -                     /* Display the events */
>                       show_eventstats(g_interval);
>               }
>
> @@ -211,40 +214,38 @@ main(int argc, char **argv)
>               if (key) {
>                       keychar = toupper(fgetc(stdin));
>                       
> -                     if (keychar == 'Q'){
> +                     switch(keychar) {
> +                     case 'Q':
>                               cleanup_curses();
>                               exit(EXIT_SUCCESS);
> -                     }
> -                     if (keychar == 'R')
> +                             break;
> +                     case 'R':
>                               ticktime = 3;
> -                     if (keychar == suggestion_key && suggestion_activate) {
> -                             suggestion_activate();
> -                             ticktime = 2;
> -                             displaytime = -1.0;
> +                             break;
>                       }
>               }
> -             reset_suggestions();
> -             suggest_p_state();
> +             /* Checks/suggests PM */
> +             if (!p_state_sug && geteuid() == 0)
> +                 p_state_sug = suggest_p_state();
>
> +             /* Exits if user requested a dump */
>               if (dump) {
>                       print_all_suggestions();
>                       exit(EXIT_SUCCESS);
>               }
>
> +             /* No key pressed, will suggest something */
>               if (!key)
>                       pick_suggestion();
>
> -             /*
> -              * Next follows suggestions
> -              * Let's focus on looking at stuff first, then fixing stuff
> -              * later.
> -              */
> -
> +             /* Refresh display */
>               show_title_bar();
> -
>               fflush(stdout);
>
> -             if (!key && ticktime >= 4.8) {  /* quiet down the effects of 
> any  
> IO to xterms */
> +             /*
> +              * Quiet down the effects of any IO to xterms
> +              */
> +             if (!key && ticktime >= 4.8) {
>                       FD_ZERO(&rfds);
>                       FD_SET(0, &rfds);
>                       tv.tv_sec = 3;
> @@ -252,6 +253,9 @@ main(int argc, char **argv)
>                       key = select(1, &rfds, NULL, NULL, &tv);
>               }
>
> +             /*
> +              * Restore user specified time after a refresh
> +              */
>               if (keychar == 'R')
>                       ticktime = ticktime_usr;
>       }
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/powertop.h
> --- a/usr/src/cmd/powertop/powertop.h Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/powertop.h Mon Apr 07 23:36:56 2008 +0100
> @@ -38,12 +38,11 @@ struct line {
>
>  typedef void (suggestion_func)(void);
>
> -extern struct line     *lines;
> -extern int             linehead;
> -extern int             linesize;
> -extern int             linectotal;
> -
> -extern double        displaytime;
> +extern struct line           *lines;
> +extern int                   linehead;
> +extern int                   linesize;
> +extern int                   linectotal;
> +double                       displaytime;
>
>  void         suggest_process_death(char *process_match, char *process_name,
>      struct line *slines, int linecount, double minwakeups, char  
> *comment,
> @@ -64,7 +63,7 @@ void        suggest_WOL_off(void);
>  void         suggest_WOL_off(void);
>  void         suggest_writeback_time(void);
>  void         suggest_usb_autosuspend(void);
> -void         suggest_p_state(void);
> +int  suggest_p_state(void);
>
>  extern int g_ncpus;
>
> @@ -79,6 +78,10 @@ extern int g_ncpus;
>  #define      FEATURE_PSTATE  0x2
>  #define FEATURE_EVENTS       0x4
>
> +/*
> + * Enabling PM through /etc/power.conf
> + * See suggest_p_state()
> + */
>  static char default_conf[]   = "/etc/power.conf";
>  static char default_pmconf[]         = "/usr/sbin/pmconfig";
>  static char cpupm_enable[]   = " echo cpupm enable >> /etc/ 
> power.conf";
> @@ -90,10 +93,24 @@ typedef struct event_info {
>       uint64_t        total_count;
>  } event_info_t;
>
> +/*
> + * Event accounting
> + */
>  int  total_events;
> -int  top_events;             /* Number of events being tracked */
> +int  top_events;
> +
> +/*
> + * Interval
> + */
> +#define      MAX_INTERVAL    100
>  double       ticktime, ticktime_usr;
>  double       g_interval;
> +
> +/*
> + * Command line arguments
> + */
> +int  observe_idle;
> +int  dump;
>
>  /*
>   * Event info array
> @@ -162,7 +179,7 @@ extern suggestion_func    *suggestion_acti
>          (void) (&_x == &_y); \
>          _x < _y ? _x : _y; })
>
> -#define _(STRING)                    gettext(STRING)
> +#define _(STRING)            gettext(STRING)
>
>  #define PT_COLOR_DEFAULT    1
>  #define PT_COLOR_HEADER_BAR 2
> @@ -175,10 +192,17 @@ extern suggestion_func  *suggestion_acti
>
>  extern int   maxwidth;
>
> +/*
> + * See util.c
> + */
>  extern void  pt_error(char *, ...);
>  extern void  pt_set_progname(char *);
> +extern void  enumerate_cpus(void);
> +extern void  usage(void);
>
> -void         event_bubblesort(void);
> +/*
> + * Display/curses related
> + */
>  void         show_title_bar(void);
>  void         setup_windows(void);
>  void         initialize_curses(void);
> @@ -189,7 +213,11 @@ void     show_eventstats(double interval);
>  void         show_eventstats(double interval);
>  void         show_interrupts(void);
>  void         show_suggestion(char *sug);
> +void         cleanup_curses(void);
>
> +/*
> + * Routines for PM suggestions
> + */
>  void         pick_suggestion(void);
>  void         add_suggestion(char *text, int weight, char key, char  
> *keystring,
>      suggestion_func *func);
> @@ -198,17 +226,14 @@ void    push_line(char *string, int count)
>  void         push_line(char *string, int count);
>  void         print_battery(void);
>
> +/*
> + * DTrace stats
> + */
>  int  pt_cpufreq_stat_prepare(void);
>  void         pt_cpufreq_stat_collect(double interval);
> -
>  int  pt_cpuidle_stat_prepare();
>  void         pt_cpuidle_stat_collect(double interval);
> -
> -int  prepare_event_stats(void);
> -void         do_event_stats(void);
> -void         count_usb_urbs(void);
> -
> -void         cleanup_curses(void);
> -void         enumerate_cpus(void);
> +int  pt_events_stat_prepare(void);
> +void         pt_events_stat_collect(void);
>
>  #endif
> diff -r f6c64140a2a5 -r 6f2460153e8e usr/src/cmd/powertop/util.c
> --- a/usr/src/cmd/powertop/util.c     Mon Mar 31 14:09:08 2008 +0100
> +++ b/usr/src/cmd/powertop/util.c     Mon Apr 07 23:36:56 2008 +0100
> @@ -86,3 +86,14 @@ enumerate_cpus()
>       }
>       g_ncpus = ncpus;
>  }
> +
> +void
> +usage()
> +{
> +     printf("Usage: powertop [OPTION...]\n");
> +     printf("  -d, --dump            Read wakeups once and print list  
> of top offenders\n");
> +     printf("  -t, --time=DOUBLE     Default time to gather data in  
> seconds, ranging between 1 and 100s\n");
> +     printf("  -h, --help            Show this help message\n");
> +     printf("  -i, --idle            Only report cyclic events that  
> cause idle state transitions\n");
> +     exit(0);
> +}
> _______________________________________________
> tesla-dev mailing list
> tesla-dev at opensolaris.org
> http://mail.opensolaris.org/mailman/listinfo/tesla-dev


Reply via email to