xref: /illumos-gate/usr/src/cmd/powertop/common/powertop.h (revision 56e2cc86321ec889bf83a888d902c60d6fb2ef8d)
1 /*
2  * Copyright 2009, Intel Corporation
3  * Copyright 2009, Sun Microsystems, Inc
4  *
5  * This file is part of PowerTOP
6  *
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.
10  *
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.
15  *
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
21  *
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>
26  */
27 
28 /*
29  * GPL Disclaimer
30  *
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.
38  */
39 
40 #ifndef __INCLUDE_GUARD_POWERTOP_H_
41 #define	__INCLUDE_GUARD_POWERTOP_H_
42 
43 #include <sys/types.h>
44 #include <libintl.h>
45 #include <sys/processor.h>
46 
47 #define	max(A, B)		(((A) < (B)) ? (B) : (A))
48 
49 #define	_(STRING)		gettext(STRING)
50 
51 #define	TITLE			"OpenSolaris PowerTOP version 1.1"
52 #define	COPYRIGHT_INTEL		"(C) 2009 Intel Corporation"
53 
54 /*
55  * Exit values. stdlib.h defines EXIT_SUCCESS as 0 and
56  * EXIT_FAILURE as 1
57  */
58 #define	EXIT_USAGE		2
59 
60 /*
61  * PowerTOP Features
62  * These may not be available everywhere
63  */
64 #define	FEATURE_CSTATE		0x01
65 #define	FEATURE_PSTATE		0x02
66 #define	FEATURE_EVENTS		0x04
67 #define	FEATURE_TURBO		0x08
68 
69 #define	BIT_DEPTH_BUF		10
70 
71 #define	INTERVAL_DEFAULT	5.0
72 #define	INTERVAL_MAX		100.0
73 #define	INTERVAL_UPDATE(l)						\
74 	((l/INTERVAL_DEFAULT) * INTERVAL_DEFAULT + INTERVAL_DEFAULT)
75 
76 #define	STATE_NAME_MAX		16
77 #define	EVENT_NAME_MAX 		64
78 #define	EVENT_NUM_MAX 		100
79 #define	NSTATES			32
80 
81 /*
82  * Display colors
83  */
84 #define	PT_COLOR_DEFAULT	1
85 #define	PT_COLOR_HEADER_BAR	2
86 #define	PT_COLOR_ERROR		3
87 #define	PT_COLOR_RED		4
88 #define	PT_COLOR_YELLOW		5
89 #define	PT_COLOR_GREEN		6
90 #define	PT_COLOR_BRIGHT		7
91 #define	PT_COLOR_BLUE		8
92 
93 /*
94  * Constants for setup_windows()
95  */
96 #define	SINGLE_LINE_SW 		1
97 #define	LENGTH_SUGG_SW		2
98 #define	TITLE_LINE		1
99 #define	BLANK_LINE		1
100 #define	NEXT_LINE		1
101 #define	PTOP_BAR_NSLOTS		10
102 #define	PTOP_BAR_LENGTH		40
103 
104 /*
105  * Available op modes
106  */
107 #define	PTOP_MODE_DEFAULT	0x01
108 #define	PTOP_MODE_DUMP		0x02
109 #define	PTOP_MODE_VERBOSE	0x04
110 #define	PTOP_MODE_CPU		0x08
111 
112 #define	PTOP_ON_DEFAULT		(g_op_mode & PTOP_MODE_DEFAULT)
113 #define	PTOP_ON_DUMP		(g_op_mode & PTOP_MODE_DUMP)
114 #define	PTOP_ON_VERBOSE		(g_op_mode & PTOP_MODE_VERBOSE)
115 #define	PTOP_ON_CPU		(g_op_mode & PTOP_MODE_CPU)
116 
117 /*
118  * Structures and typedefs
119  */
120 struct line {
121 	char		*string;
122 	int		count;
123 };
124 
125 typedef struct event_info {
126 	char		offender_name[EVENT_NAME_MAX];
127 	char		offense_name[EVENT_NAME_MAX];
128 	uint64_t	total_count;
129 } event_info_t;
130 
131 /*
132  * P/C state information
133  */
134 typedef struct state_info {
135 	char		name[STATE_NAME_MAX];
136 	hrtime_t	total_time;
137 	hrtime_t	last_time;
138 	double		events;
139 } state_info_t;
140 
141 typedef struct freq_state_info {
142 	uint64_t	speed;
143 	hrtime_t	total_time;
144 } freq_state_info_t;
145 
146 typedef struct cpu_power_info {
147 	uint64_t	current_pstate;
148 	hrtime_t	time_accounted;
149 	hrtime_t	dtrace_time;
150 } cpu_power_info_t;
151 
152 /*
153  * Turbo mode information
154  */
155 typedef struct turbo_info {
156 	uint64_t	t_mcnt;
157 	uint64_t	t_acnt;
158 } turbo_info_t;
159 
160 typedef	void		(suggestion_func)(void);
161 
162 /*
163  * Global variables
164  */
165 extern double			g_displaytime;
166 
167 extern int			g_bit_depth;
168 
169 /*
170  * Event accounting
171  */
172 extern int 			g_total_events;
173 extern int 			g_tog_p_events;
174 
175 /*
176  * Interval
177  */
178 extern double 			g_ticktime, g_ticktime_usr;
179 extern double 			g_interval;
180 
181 /*
182  * Command line arguments
183  */
184 extern uchar_t			g_op_mode;
185 extern uint_t			g_observed_cpu;
186 extern boolean_t		g_gui;
187 /*
188  * Event info array
189  */
190 extern event_info_t    		g_event_info[EVENT_NUM_MAX];
191 extern event_info_t		*g_p_event;
192 
193 /*
194  * Lookup table, sequential CPU id to Solaris CPU id
195  */
196 extern processorid_t 		*g_cpu_table;
197 
198 /*
199  * Number of idle/frequency states
200  */
201 extern int			g_npstates;
202 extern int			g_max_cstate;
203 extern int			g_longest_cstate;
204 
205 /*
206  * Total time, used to display different idle states
207  */
208 extern hrtime_t			g_total_c_time;
209 
210 /*
211  * P/C state info arrays
212  */
213 extern state_info_t		g_cstate_info[NSTATES];
214 extern freq_state_info_t	g_pstate_info[NSTATES];
215 
216 extern uint_t			g_ncpus;
217 extern uint_t			g_ncpus_observed;
218 
219 extern char 			g_status_bar_slots[PTOP_BAR_NSLOTS]
220 	[PTOP_BAR_LENGTH];
221 
222 extern cpu_power_info_t		*g_cpu_power_states;
223 
224 /*
225  * Turbo mode related information
226  */
227 extern boolean_t	g_turbo_supported;
228 extern double		g_turbo_ratio;
229 
230 extern char 			g_suggestion_key;
231 extern suggestion_func 		*g_suggestion_activate;
232 
233 /*
234  * DTrace scripts for the events report
235  */
236 extern const char		*g_dtp_events;
237 extern const char		*g_dtp_events_v;
238 extern const char		*g_dtp_events_c;
239 
240 /*
241  * Arguments for dtrace_program_strcompile(). Contents vary according to
242  * the specified operation mode.
243  */
244 extern uint_t			g_argc;
245 extern char			**g_argv;
246 
247 /*
248  * Platform specific messages
249  */
250 extern const char *g_msg_idle_state;
251 extern const char *g_msg_freq_state;
252 /*
253  * Suggestions related
254  */
255 extern void 		suggest_p_state(void);
256 extern void		suggest_as_root(void);
257 
258 /*
259  * See util.c
260  */
261 extern void 		pt_error(char *, ...);
262 extern void 		pt_set_progname(char *);
263 extern uint_t		enumerate_cpus(void);
264 extern void		usage(void);
265 extern int		get_bit_depth(void);
266 extern void		battery_mod_lookup(void);
267 extern int		event_compare(const void *, const void *);
268 
269 /*
270  * Display/curses related
271  */
272 extern void 		show_title_bar(void);
273 extern void 		setup_windows(void);
274 extern void 		initialize_curses(void);
275 extern void		show_acpi_power_line(uint32_t flag, double rate,
276     double rem_cap, double cap, uint32_t state);
277 extern void 		show_cstates();
278 extern void 		show_wakeups(double interval);
279 extern void 		show_eventstats(double interval);
280 extern void 		show_suggestion(char *sug);
281 extern void 		cleanup_curses(void);
282 extern void		update_windows(void);
283 
284 /*
285  * Suggestions
286  */
287 extern void 		pick_suggestion(void);
288 extern void 		add_suggestion(char *text, int weight, char key,
289     char *keystring, suggestion_func *func);
290 extern void 		reset_suggestions(void);
291 extern void 		print_all_suggestions(void);
292 extern void 		print_battery(void);
293 
294 /*
295  * DTrace stats
296  */
297 extern int 		pt_cpufreq_stat_prepare(void);
298 extern int 		pt_cpufreq_stat_collect(double interval);
299 extern int 		pt_cpuidle_stat_prepare(void);
300 extern int 		pt_cpuidle_stat_collect(double interval);
301 extern int 		pt_events_stat_prepare(void);
302 extern int 		pt_events_stat_collect(void);
303 
304 /*
305  * Turbo mode related routines
306  */
307 extern int		pt_turbo_stat_prepare(void);
308 extern int		pt_turbo_stat_collect(void);
309 
310 #endif /* __INCLUDE_GUARD_POWERTOP_H_ */
311