xref: /illumos-gate/usr/src/cmd/powertop/common/powertop.h (revision a799b1e741b6f59012a469e6b57c40cb8061127b)
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.2"
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  * Available op modes
83  */
84 #define	PT_MODE_DEFAULT		0x01
85 #define	PT_MODE_DUMP		0x02
86 #define	PT_MODE_VERBOSE		0x04
87 #define	PT_MODE_CPU		0x08
88 
89 #define	PT_ON_DEFAULT		(g_op_mode & PT_MODE_DEFAULT)
90 #define	PT_ON_DUMP		(g_op_mode & PT_MODE_DUMP)
91 #define	PT_ON_VERBOSE		(g_op_mode & PT_MODE_VERBOSE)
92 #define	PT_ON_CPU		(g_op_mode & PT_MODE_CPU)
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  * Interval
164  */
165 extern double 			g_ticktime, g_ticktime_usr;
166 extern double 			g_interval;
167 
168 /*
169  * Command line arguments
170  */
171 extern uchar_t			g_op_mode;
172 extern uint_t			g_observed_cpu;
173 extern boolean_t		g_gui;
174 /*
175  * Event info array
176  */
177 extern event_info_t    		g_event_info[EVENT_NUM_MAX];
178 
179 /*
180  * Lookup table, sequential CPU id to Solaris CPU id
181  */
182 extern processorid_t 		*g_cpu_table;
183 
184 /*
185  * Number of idle/frequency states
186  */
187 extern int			g_npstates;
188 extern int			g_max_cstate;
189 extern int			g_longest_cstate;
190 
191 /*
192  * Total time, used to display different idle states
193  */
194 extern hrtime_t			g_total_c_time;
195 
196 /*
197  * P/C state info arrays
198  */
199 extern state_info_t		g_cstate_info[NSTATES];
200 extern freq_state_info_t	g_pstate_info[NSTATES];
201 
202 extern uint_t			g_features;
203 extern uint_t			g_ncpus;
204 extern uint_t			g_ncpus_observed;
205 
206 extern cpu_power_info_t		*g_cpu_power_states;
207 
208 /*
209  * Turbo mode related information
210  */
211 extern boolean_t		g_turbo_supported;
212 extern double			g_turbo_ratio;
213 
214 extern sugg_t			*g_curr_sugg;
215 
216 /*
217  * DTrace scripts for the events report
218  */
219 extern const char		*g_dtp_events;
220 extern const char		*g_dtp_events_v;
221 extern const char		*g_dtp_events_c;
222 
223 /*
224  * Arguments for dtrace_program_strcompile(). Contents vary according to
225  * the specified operation mode.
226  */
227 extern uint_t			g_argc;
228 extern char			**g_argv;
229 
230 /*
231  * Platform specific messages
232  */
233 extern const char		*g_msg_idle_state;
234 extern const char		*g_msg_freq_state;
235 extern const char		*g_msg_freq_enable;
236 
237 /*
238  * Suggestions related
239  */
240 extern void 		pt_cpufreq_suggest(void);
241 extern void		pt_sugg_as_root(void);
242 
243 /*
244  * See util.c
245  */
246 extern void 		pt_error(char *, ...);
247 extern void 		pt_set_progname(char *);
248 extern uint_t		enumerate_cpus(void);
249 extern void		usage(void);
250 extern int		get_bit_depth(void);
251 extern void		battery_mod_lookup(void);
252 extern int		event_compare(const void *, const void *);
253 
254 /*
255  * Display/curses related
256  */
257 extern void		pt_display_setup(boolean_t);
258 extern void 		pt_display_init_curses(void);
259 extern void		pt_display_update(void);
260 extern void 		pt_display_title_bar(void);
261 extern void		pt_display_status_bar(void);
262 extern void		pt_display_mod_status_bar(char *);
263 extern void 		pt_display_states(void);
264 extern void		pt_display_acpi_power(uint32_t, double, double, double,
265 	uint32_t);
266 extern void 		pt_display_wakeups(double);
267 extern void 		pt_display_events(double);
268 extern void 		pt_display_suggestions(char *);
269 
270 /*
271  * Suggestions
272  */
273 extern void 		pt_sugg_add(char *, int, char, char *, sugg_func_t *);
274 extern int		pt_sugg_remove(sugg_func_t *);
275 extern void 		pt_sugg_pick(void);
276 
277 /*
278  * Battery
279  */
280 extern void 		pt_battery_print(void);
281 
282 /*
283  * DTrace stats
284  */
285 extern int 		pt_cpufreq_stat_prepare(void);
286 extern int 		pt_cpufreq_stat_collect(double);
287 extern int 		pt_cpuidle_stat_prepare(void);
288 extern int 		pt_cpuidle_stat_collect(double);
289 extern int 		pt_events_stat_prepare(void);
290 extern int 		pt_events_stat_collect(void);
291 
292 /*
293  * Turbo mode related routines
294  */
295 extern int		pt_turbo_stat_prepare(void);
296 extern int		pt_turbo_stat_collect(void);
297 
298 #endif /* __INCLUDE_GUARD_POWERTOP_H_ */
299