dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / powertop / common / powertop.h
blob3a3104d003ea6cc41460ee79f99908be46e9c1ed
1 /*
2 * Copyright 2009, Intel Corporation
3 * Copyright 2009, Sun Microsystems, Inc
5 * This file is part of PowerTOP
7 * This program file is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program in a file named COPYING; if not, write to the
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
22 * Authors:
23 * Arjan van de Ven <arjan@linux.intel.com>
24 * Eric C Saxe <eric.saxe@sun.com>
25 * Aubrey Li <aubrey.li@intel.com>
29 * GPL Disclaimer
31 * For the avoidance of doubt, except that if any license choice other
32 * than GPL or LGPL is available it will apply instead, Sun elects to
33 * use only the General Public License version 2 (GPLv2) at this time
34 * for any software where a choice of GPL license versions is made
35 * available with the language indicating that GPLv2 or any later
36 * version may be used, or where a choice of which version of the GPL
37 * is applied is otherwise unspecified.
40 #ifndef __INCLUDE_GUARD_POWERTOP_H_
41 #define __INCLUDE_GUARD_POWERTOP_H_
43 #include <sys/types.h>
44 #include <sys/processor.h>
46 #define max(A, B) (((A) < (B)) ? (B) : (A))
48 #define TITLE "OpenSolaris PowerTOP version 1.2"
49 #define COPYRIGHT_INTEL "(C) 2009 Intel Corporation"
52 * Exit values. stdlib.h defines EXIT_SUCCESS as 0 and
53 * EXIT_FAILURE as 1
55 #define EXIT_USAGE 2
58 * PowerTOP Features
59 * These may not be available everywhere
61 #define FEATURE_CSTATE 0x01
62 #define FEATURE_PSTATE 0x02
63 #define FEATURE_EVENTS 0x04
64 #define FEATURE_TURBO 0x08
66 #define BIT_DEPTH_BUF 10
68 #define INTERVAL_DEFAULT 5.0
69 #define INTERVAL_MAX 30.0
70 #define INTERVAL_UPDATE(l) \
71 ((l/INTERVAL_DEFAULT) * INTERVAL_DEFAULT + INTERVAL_DEFAULT)
73 #define STATE_NAME_MAX 16
74 #define EVENT_NAME_MAX 64
75 #define EVENT_NUM_MAX 100
76 #define NSTATES 32
79 * Available op modes. The PT_ON_* macros allow for a simple way of checking
80 * under which mode PowerTOP is operating.
82 #define PT_MODE_DEFAULT 0x01
83 #define PT_MODE_DUMP 0x02
84 #define PT_MODE_VERBOSE 0x04
85 #define PT_MODE_CPU 0x08
86 #define PT_MODE_TIME 0x10
88 #define PT_ON_DEFAULT (g_op_mode & PT_MODE_DEFAULT)
89 #define PT_ON_DUMP (g_op_mode & PT_MODE_DUMP)
90 #define PT_ON_VERBOSE (g_op_mode & PT_MODE_VERBOSE)
91 #define PT_ON_CPU (g_op_mode & PT_MODE_CPU)
92 #define PT_ON_TIME (g_op_mode & PT_MODE_TIME)
95 * Structures and typedefs
97 struct line {
98 char *string;
99 int count;
102 typedef struct event_info {
103 char offender_name[EVENT_NAME_MAX];
104 char offense_name[EVENT_NAME_MAX];
105 uint64_t total_count;
106 } event_info_t;
109 * P/C state information
111 typedef struct state_info {
112 char name[STATE_NAME_MAX];
113 hrtime_t total_time;
114 hrtime_t last_time;
115 uint64_t events;
116 } state_info_t;
118 typedef struct freq_state_info {
119 uint64_t speed;
120 hrtime_t total_time;
121 } freq_state_info_t;
123 typedef struct cpu_power_info {
124 uint64_t current_pstate;
125 uint64_t speed_accounted;
126 hrtime_t time_accounted;
127 hrtime_t dtrace_time;
128 } cpu_power_info_t;
131 * Turbo mode information
133 typedef struct turbo_info {
134 uint64_t t_mcnt;
135 uint64_t t_acnt;
136 } turbo_info_t;
139 * Suggestions
141 typedef void (sugg_func_t)(void);
143 typedef struct suggestion {
144 char *text;
145 char key;
146 char *sb_msg;
147 int weight;
148 int slice;
149 sugg_func_t *func;
150 struct suggestion *prev;
151 struct suggestion *next;
152 } sugg_t;
154 extern int g_bit_depth;
157 * Event accounting
159 extern int g_total_events;
160 extern int g_top_events;
163 * Command line arguments
165 extern uchar_t g_op_mode;
166 extern uint_t g_observed_cpu;
167 extern boolean_t g_gui;
169 * Event info array
171 extern event_info_t g_event_info[EVENT_NUM_MAX];
174 * Lookup table, sequential CPU id to Solaris CPU id
176 extern processorid_t *g_cpu_table;
179 * Number of idle/frequency states
181 extern int g_npstates;
182 extern int g_max_cstate;
183 extern int g_longest_cstate;
186 * Total time, used to display different idle states
188 extern hrtime_t g_total_c_time;
191 * Current interval length
193 extern double g_interval_length;
196 * P/C state info arrays
198 extern state_info_t g_cstate_info[NSTATES];
199 extern freq_state_info_t g_pstate_info[NSTATES];
201 extern uint_t g_features;
202 extern uint_t g_ncpus;
203 extern uint_t g_ncpus_observed;
205 extern cpu_power_info_t *g_cpu_power_states;
208 * Turbo mode related information
210 extern boolean_t g_turbo_supported;
211 extern double g_turbo_ratio;
213 extern sugg_t *g_curr_sugg;
216 * DTrace scripts for the events report
218 extern const char *g_dtp_events;
219 extern const char *g_dtp_events_v;
220 extern const char *g_dtp_events_c;
223 * Arguments for dtrace_program_strcompile(). Contents vary according to
224 * the specified operation mode.
226 extern uint_t g_argc;
227 extern char **g_argv;
230 * Platform specific messages
232 extern const char *g_msg_idle_state;
233 extern const char *g_msg_freq_state;
234 extern const char *g_msg_freq_enable;
237 * Flags for signal handling
239 extern boolean_t g_sig_resize;
241 extern void pt_sig_handler(int);
244 * Suggestions related
246 extern void pt_cpufreq_suggest(void);
247 extern void pt_sugg_as_root(void);
250 * See util.c
252 extern void pt_error(char *, ...);
253 extern void pt_set_progname(char *);
254 extern uint_t pt_enumerate_cpus(void);
255 extern void pt_usage(void);
256 extern int pt_get_bit_depth(void);
257 extern void pt_battery_mod_lookup(void);
258 extern int pt_event_compare(const void *, const void *);
261 * Display/curses related
263 extern void pt_display_setup(boolean_t);
264 extern void pt_display_init_curses(void);
265 extern void pt_display_update(void);
266 extern void pt_display_title_bar(void);
267 extern void pt_display_status_bar(void);
268 extern void pt_display_mod_status_bar(char *);
269 extern void pt_display_states(void);
270 extern void pt_display_acpi_power(uint32_t, double, double, double,
271 uint32_t);
272 extern void pt_display_wakeups(double);
273 extern void pt_display_events(double);
274 extern void pt_display_suggestions(char *);
275 extern void pt_display_resize(void);
278 * Suggestions
280 extern void pt_sugg_add(char *, int, char, char *, sugg_func_t *);
281 extern int pt_sugg_remove(sugg_func_t *);
282 extern void pt_sugg_pick(void);
285 * Battery
287 extern void pt_battery_print(void);
290 * DTrace stats
292 extern int pt_cpufreq_stat_prepare(void);
293 extern int pt_cpufreq_stat_collect(double);
294 extern int pt_cpuidle_stat_prepare(void);
295 extern int pt_cpuidle_stat_collect(double);
296 extern int pt_events_stat_prepare(void);
297 extern int pt_events_stat_collect(void);
300 * Turbo mode related routines
302 extern int pt_turbo_stat_prepare(void);
303 extern int pt_turbo_stat_collect(void);
305 #endif /* __INCLUDE_GUARD_POWERTOP_H_ */