xref: /titanic_52/usr/src/cmd/powertop/common/powertop.h (revision 7014882c6a3672fd0e5d60200af8643ae53c5928)
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 <sys/processor.h>
45 
46 #define	max(A, B)		(((A) < (B)) ? (B) : (A))
47 
48 #define	TITLE			"OpenSolaris PowerTOP version 1.2"
49 #define	COPYRIGHT_INTEL		"(C) 2009 Intel Corporation"
50 
51 /*
52  * Exit values. stdlib.h defines EXIT_SUCCESS as 0 and
53  * EXIT_FAILURE as 1
54  */
55 #define	EXIT_USAGE		2
56 
57 /*
58  * PowerTOP Features
59  * These may not be available everywhere
60  */
61 #define	FEATURE_CSTATE		0x01
62 #define	FEATURE_PSTATE		0x02
63 #define	FEATURE_EVENTS		0x04
64 #define	FEATURE_TURBO		0x08
65 
66 #define	BIT_DEPTH_BUF		10
67 
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)
72 
73 #define	STATE_NAME_MAX		16
74 #define	EVENT_NAME_MAX 		64
75 #define	EVENT_NUM_MAX 		100
76 #define	NSTATES			32
77 
78 /*
79  * Available op modes. The PT_ON_* macros allow for a simple way of checking
80  * under which mode PowerTOP is operating.
81  */
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
87 
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)
93 
94 /*
95  * Structures and typedefs
96  */
97 struct line {
98 	char		*string;
99 	int		count;
100 };
101 
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;
107 
108 /*
109  * P/C state information
110  */
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;
117 
118 typedef struct freq_state_info {
119 	uint64_t	speed;
120 	hrtime_t	total_time;
121 } freq_state_info_t;
122 
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;
129 
130 /*
131  * Turbo mode information
132  */
133 typedef struct turbo_info {
134 	uint64_t	t_mcnt;
135 	uint64_t	t_acnt;
136 } turbo_info_t;
137 
138 /*
139  * Suggestions
140  */
141 typedef	void		(sugg_func_t)(void);
142 
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;
153 
154 extern int			g_bit_depth;
155 
156 /*
157  * Event accounting
158  */
159 extern int 			g_total_events;
160 extern int 			g_top_events;
161 
162 /*
163  * Command line arguments
164  */
165 extern uchar_t			g_op_mode;
166 extern uint_t			g_observed_cpu;
167 extern boolean_t		g_gui;
168 /*
169  * Event info array
170  */
171 extern event_info_t    		g_event_info[EVENT_NUM_MAX];
172 
173 /*
174  * Lookup table, sequential CPU id to Solaris CPU id
175  */
176 extern processorid_t 		*g_cpu_table;
177 
178 /*
179  * Number of idle/frequency states
180  */
181 extern int			g_npstates;
182 extern int			g_max_cstate;
183 extern int			g_longest_cstate;
184 
185 /*
186  * Total time, used to display different idle states
187  */
188 extern hrtime_t			g_total_c_time;
189 
190 /*
191  * Current interval length
192  */
193 extern double			g_interval_length;
194 
195 /*
196  * P/C state info arrays
197  */
198 extern state_info_t		g_cstate_info[NSTATES];
199 extern freq_state_info_t	g_pstate_info[NSTATES];
200 
201 extern uint_t			g_features;
202 extern uint_t			g_ncpus;
203 extern uint_t			g_ncpus_observed;
204 
205 extern cpu_power_info_t		*g_cpu_power_states;
206 
207 /*
208  * Turbo mode related information
209  */
210 extern boolean_t		g_turbo_supported;
211 extern double			g_turbo_ratio;
212 
213 extern sugg_t			*g_curr_sugg;
214 
215 /*
216  * DTrace scripts for the events report
217  */
218 extern const char		*g_dtp_events;
219 extern const char		*g_dtp_events_v;
220 extern const char		*g_dtp_events_c;
221 
222 /*
223  * Arguments for dtrace_program_strcompile(). Contents vary according to
224  * the specified operation mode.
225  */
226 extern uint_t			g_argc;
227 extern char			**g_argv;
228 
229 /*
230  * Platform specific messages
231  */
232 extern const char		*g_msg_idle_state;
233 extern const char		*g_msg_freq_state;
234 extern const char		*g_msg_freq_enable;
235 
236 /*
237  * Flags for signal handling
238  */
239 extern boolean_t		g_sig_resize;
240 
241 extern void		pt_sig_handler(int);
242 
243 /*
244  * Suggestions related
245  */
246 extern void 		pt_cpufreq_suggest(void);
247 extern void		pt_sugg_as_root(void);
248 
249 /*
250  * See util.c
251  */
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 *);
259 
260 /*
261  * Display/curses related
262  */
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);
276 
277 /*
278  * Suggestions
279  */
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);
283 
284 /*
285  * Battery
286  */
287 extern void 		pt_battery_print(void);
288 
289 /*
290  * DTrace stats
291  */
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);
298 
299 /*
300  * Turbo mode related routines
301  */
302 extern int		pt_turbo_stat_prepare(void);
303 extern int		pt_turbo_stat_collect(void);
304 
305 #endif /* __INCLUDE_GUARD_POWERTOP_H_ */
306