xref: /illumos-gate/usr/src/cmd/powertop/common/powertop.h (revision bda1f129971950880940a17bab0bf096d5744b0c)
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	PT_BAR_NSLOTS		10
102 #define	PT_BAR_LENGTH		40
103 
104 /*
105  * Available op modes
106  */
107 #define	PT_MODE_DEFAULT		0x01
108 #define	PT_MODE_DUMP		0x02
109 #define	PT_MODE_VERBOSE		0x04
110 #define	PT_MODE_CPU		0x08
111 
112 #define	PT_ON_DEFAULT		(g_op_mode & PT_MODE_DEFAULT)
113 #define	PT_ON_DUMP		(g_op_mode & PT_MODE_DUMP)
114 #define	PT_ON_VERBOSE		(g_op_mode & PT_MODE_VERBOSE)
115 #define	PT_ON_CPU		(g_op_mode & PT_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 	uint64_t	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 	uint64_t	speed_accounted;
149 	hrtime_t	time_accounted;
150 	hrtime_t	dtrace_time;
151 } cpu_power_info_t;
152 
153 /*
154  * Turbo mode information
155  */
156 typedef struct turbo_info {
157 	uint64_t	t_mcnt;
158 	uint64_t	t_acnt;
159 } turbo_info_t;
160 
161 typedef	void			(suggestion_func)(void);
162 
163 /*
164  * Global variables
165  */
166 extern double			g_displaytime;
167 
168 extern int			g_bit_depth;
169 
170 /*
171  * Event accounting
172  */
173 extern int 			g_total_events;
174 extern int 			g_top_events;
175 
176 /*
177  * Interval
178  */
179 extern double 			g_ticktime, g_ticktime_usr;
180 extern double 			g_interval;
181 
182 /*
183  * Command line arguments
184  */
185 extern uchar_t			g_op_mode;
186 extern uint_t			g_observed_cpu;
187 extern boolean_t		g_gui;
188 /*
189  * Event info array
190  */
191 extern event_info_t    		g_event_info[EVENT_NUM_MAX];
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[PT_BAR_NSLOTS]
220 	[PT_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, double, double, double,
276 	uint32_t);
277 extern void 		show_cstates();
278 extern void 		show_wakeups(double);
279 extern void 		show_eventstats(double);
280 extern void 		show_suggestion(char *);
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 *, int, char, char *,
289 	suggestion_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);
299 extern int 		pt_cpuidle_stat_prepare(void);
300 extern int 		pt_cpuidle_stat_collect(double);
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