summaryrefslogtreecommitdiff
path: root/usr/src/cmd/powertop/powertop.h
blob: 464e114fc58a4ac007bf3994fb0c8a4f1846c47b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
 * Copyright 2009, Intel Corporation
 * Copyright 2009, Sun Microsystems, Inc
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authors:
 *	Arjan van de Ven <arjan@linux.intel.com>
 *	Eric C Saxe <eric.saxe@sun.com>
 *	Aubrey Li <aubrey.li@intel.com>
 */

/*
 * GPL Disclaimer
 *
 * For the avoidance of doubt, except that if any license choice other
 * than GPL or LGPL is available it will apply instead, Sun elects to
 * use only the General Public License version 2 (GPLv2) at this time
 * for any software where a choice of GPL license versions is made
 * available with the language indicating that GPLv2 or any later
 * version may be used, or where a choice of which version of the GPL
 * is applied is otherwise unspecified.
 */

#ifndef __INCLUDE_GUARD_POWERTOP_H_
#define	__INCLUDE_GUARD_POWERTOP_H_

#include <sys/types.h>
#include <libintl.h>
#include <sys/processor.h>

#define	max(A, B)		(((A) < (B)) ? (B) : (A))

#define	_(STRING)		gettext(STRING)

#define	TITLE			"OpenSolaris PowerTOP version 1.1"

/*
 * Exit values. stdlib.h defines EXIT_SUCCESS as 0 and
 * EXIT_FAILURE as 1
 */
#define	EXIT_USAGE		2

/*
 * PowerTop Features
 * These may not be available everywhere
 */
#define	FEATURE_CSTATE		0x1
#define	FEATURE_PSTATE		0x2
#define	FEATURE_EVENTS		0x4
#define	FEATURE_TURBO		0x8

#define	BIT_DEPTH_BUF		10

#define	INTERVAL_DEFAULT	5.0
#define	INTERVAL_MAX		100.0
#define	INTERVAL_UPDATE(l)						\
	((l/INTERVAL_DEFAULT) * INTERVAL_DEFAULT + INTERVAL_DEFAULT)

#define	STATE_NAME_MAX		16
#define	EVENT_NAME_MAX 		64
#define	EVENT_NUM_MAX 		100
#define	NSTATES			32

/*
 * Display colors
 */
#define	PT_COLOR_DEFAULT	1
#define	PT_COLOR_HEADER_BAR	2
#define	PT_COLOR_ERROR		3
#define	PT_COLOR_RED		4
#define	PT_COLOR_YELLOW		5
#define	PT_COLOR_GREEN		6
#define	PT_COLOR_BRIGHT		7
#define	PT_COLOR_BLUE		8

/*
 * Constants for setup_windows()
 */
#define	SINGLE_LINE_SW 		1
#define	LENGTH_SUGG_SW		2
#define	TITLE_LINE		1
#define	BLANK_LINE		1
#define	NEXT_LINE		1

/*
 * Structures and typedefs
 */
struct line {
	char		*string;
	int		count;
};

typedef struct event_info {
	char		offender_name[EVENT_NAME_MAX];
	char		offense_name[EVENT_NAME_MAX];
	uint64_t	total_count;
} event_info_t;

/*
 * P/C state information
 */
typedef struct state_info {
	char		name[STATE_NAME_MAX];
	hrtime_t	total_time;
	hrtime_t	last_time;
	double		events;
} state_info_t;

typedef struct pstate_info {
	uint64_t	speed;
	hrtime_t	total_time;
} pstate_info_t;

typedef struct cpu_power_info {
	uint64_t	current_pstate;
	hrtime_t	time_accounted;
	hrtime_t	dtrace_time;
} cpu_power_info_t;

/*
 * turbo information
 */
typedef struct turbo_info {
	uint64_t	t_mcnt;
	uint64_t	t_acnt;
} turbo_info_t;


typedef	void		(suggestion_func)(void);

/*
 * Global variables
 */
double			displaytime;

int			bit_depth;

/*
 * Event accounting
 */
int 			total_events;
int 			top_events;

/*
 * Interval
 */
double 			ticktime, ticktime_usr;
double 			g_interval;

/*
 * Command line arguments
 */
int 			dump;
char			event_mode;
extern boolean_t	gui;

/*
 * Event info array
 */
event_info_t    	event_info[EVENT_NUM_MAX];
event_info_t		*p_event;

/*
 * Lookup table, sequential CPU id to Solaris CPU id
 */
processorid_t 		*cpu_table;

/*
 * Number of idle/frequency states
 */
int			npstates;
int			max_cstate;
int			longest_cstate;

/*
 * Total time, used to display different idle states
 */
hrtime_t		total_c_time;

/*
 * P/C state info arrays
 */
state_info_t		cstate_info[NSTATES];
pstate_info_t		pstate_info[NSTATES];

/*
 * Per CPU power state information
 */
cpu_power_info_t	*cpu_power_states;

/*
 * Turbo mode related information
 */
extern boolean_t	g_turbo_supported;
extern double		g_turbo_ratio;

/*
 * Extern declarations
 */
extern struct line	*lines;
extern int		linehead;
extern int		linesize;
extern int		linectotal;

extern	int		g_ncpus;

/*
 * kstat's battery module
 */
extern char		*kstat_batt_mod[3];
extern uint_t		kstat_batt_idx;

extern int 		topcstate;
extern int 		topfreq;
extern int 		dump;

extern char 		*prog;

extern char 		status_bar_slots[10][40];

extern const int	true, false;

extern char 		suggestion_key;
extern suggestion_func 	*suggestion_activate;

/*
 * Suggestions related
 */
extern void 		suggest_p_state(void);
extern void		suggest_as_root(void);

/*
 * See util.c
 */
extern void 		pt_error(char *, ...);
extern void 		pt_set_progname(char *);
extern void		enumerate_cpus(void);
extern void		usage(void);
extern	int		get_bit_depth(void);
extern void		battery_mod_lookup(void);
extern	int		event_compare(const void *, const void *);

/*
 * Display/curses related
 */
extern	void 		show_title_bar(void);
extern	void 		setup_windows(void);
extern	void 		initialize_curses(void);
extern	void		show_acpi_power_line(uint32_t flag, double rate,
    double rem_cap, double cap, uint32_t state);
extern	void 		show_cstates();
extern	void 		show_wakeups(double interval);
extern	void 		show_eventstats(double interval);
extern	void 		show_suggestion(char *sug);
extern	void 		cleanup_curses(void);
extern	void		update_windows(void);

/*
 * Suggestions
 */
extern	void 		pick_suggestion(void);
extern	void 		add_suggestion(char *text, int weight, char key,
    char *keystring, suggestion_func *func);
extern	void 		reset_suggestions(void);
extern	void 		print_all_suggestions(void);
extern	void 		print_battery(void);

/*
 * DTrace stats
 */
extern	int 		pt_cpufreq_stat_prepare(void);
extern	int 		pt_cpufreq_stat_collect(double interval);
extern	int 		pt_cpuidle_stat_prepare(void);
extern	int 		pt_cpuidle_stat_collect(double interval);
extern	int 		pt_events_stat_prepare(void);
extern	int 		pt_events_stat_collect(void);

/*
 * turbo related
 */
extern	int		pt_turbo_stat_prepare(void);
extern	int		pt_turbo_stat_collect(void);

#endif /* __INCLUDE_GUARD_POWERTOP_H_ */