powertop.h revision 2
/*
* This file is part of PowerTOP
*
* 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>
*/
/*
* Copyright (c) 2009, Intel Corporation.
* All Rights Reserved.
*/
/*
*/
/*
* 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/processor.h>
#include <kstat.h>
#define DBGPRINT
#define DBGPRINT1
#define DBGPRINT2
#define DBGPRINT3
#define MIN(A, B) (((A) < (B)) ? (A) : (B))
#define max(A, B) (((A) < (B)) ? (B) : (A))
#define TITLE "Solaris PowerTOP version 1.3"
#define COPYRIGHT_INTEL "(C) 2009 Intel Corporation"
/*
* 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 0x01
#define FEATURE_PSTATE 0x02
#define FEATURE_EVENTS 0x04
#define FEATURE_TURBO 0x08
#define BIT_DEPTH_BUF 10
#define INTERVAL_DEFAULT 5.0
#define INTERVAL_MAX 30.0
#define INTERVAL_UPDATE(l) \
#define PT_KSTAT_CHAIN_RETRYS 3
#define STATE_NAME_MAX 16
#define EVENT_NAME_MAX 64
#define EVENT_NUM_MAX 100
#define CPU_MAX_PSTATES 64
#define CPU_MAX_CSTATES 16
/*
* Available op modes. The PT_ON_* macros allow for a simple way of checking
* under which mode PowerTOP is operating.
*/
#define PT_MODE_DEFAULT 0x01
#define PT_MODE_DUMP 0x02
#define PT_MODE_VERBOSE 0x04
#define PT_MODE_CPU 0x08
#define PT_MODE_TIME 0x10
#define ID_NO_CPU -1
/*
* This is the value of sizeof ("18446744073709551615"), which is the max
* length that a uint64_t will occupy when rendered as a string,
* including the terminating null byte.
* There is an assertion in the kernel that 21 is the right value
*/
#define MAX_UINT64_STRLEN 21
/*
* Structures and typedefs
*/
struct ktstat_cpu_records {
int cs_state;
int cs_id;
};
struct cpu_snapshot {
int cs_state; /* as in p_online(2) */
};
struct snapshot {
int snap_changed;
struct cpu_snapshot *s_cpus;
};
struct kstat_cpu_records {
int cs_state;
int cs_id;
};
struct snapshot_state {
struct kstat_cpu_records *kstat_cpu_information;
int kstat_cpus_active;
};
struct line {
char *string;
int count;
};
typedef struct event_info {
char offender_name[EVENT_NAME_MAX];
char offense_name[EVENT_NAME_MAX];
} event_info_t;
if (ptr) { \
}
/*
* P/C state information
*/
typedef struct cstate_info {
char name[STATE_NAME_MAX];
typedef struct pstate_info {
typedef struct cpu_power_info {
/*
* Turbo mode information
*/
typedef struct turbo_info {
} turbo_info_t;
/*
* Suggestions
*/
typedef void (sugg_func_t)(void);
typedef struct suggestion {
char *text;
char key;
char *sb_msg;
int weight;
int slice;
struct suggestion *prev;
struct suggestion *next;
} sugg_t;
extern int g_bit_depth;
extern int g_pm_fd;
extern struct snapshot_state g_ss_state_info;
extern kstat_ctl_t *g_kc;
/*
* Event accounting
*/
extern int g_total_events;
extern int g_top_events;
/*
* Command line arguments
*/
extern uint_t g_observed_cpu;
/*
* Event info array
*/
/*
* Lookup table, sequential CPU id to Solaris CPU id
*/
extern processorid_t *g_cpu_table;
/*
*/
extern int g_max_pstates;
extern int g_max_cstates;
/*
* Total time, used to display different idle states
*/
extern hrtime_t g_total_c_time;
/*
* Total time, used to display different active states
*/
extern hrtime_t g_total_p_time;
/*
* Current interval length
*/
extern double g_interval_length;
/*
* nanosleep timespec struct for 200 msec delay
*/
/*
* P/C state info arrays
*/
extern uint_t g_features;
extern uint_t g_ncpus_observed;
extern cpu_power_info_t *g_cpu_power_states;
/*
* Turbo mode related information
*/
extern boolean_t g_turbo_supported;
extern double g_turbo_ratio;
extern sugg_t *g_curr_sugg;
/*
* DTrace scripts for the events report
*/
extern const char *g_dtp_events;
extern const char *g_dtp_events_v;
extern const char *g_dtp_events_c;
/*
* Arguments for dtrace_program_strcompile(). Contents vary according to
* the specified operation mode.
*/
extern char **g_argv;
/*
* Platform specific messages
*/
extern const char *g_msg_cstate;
extern const char *g_msg_pstate;
/*
* Flags for signal handling
*/
extern boolean_t g_sig_resize;
extern void pt_sig_handler(int);
/*
* Suggestions related
*/
extern void pt_cpufreq_suggest(void);
extern void pt_sugg_as_root(void);
/*
* See util.c
*/
extern void pt_error(char *, ...);
extern void pt_set_progname(char *);
extern uint_t pt_enumerate_cpus(void);
extern void pt_usage(void);
extern int pt_get_bit_depth(void);
extern void pt_battery_mod_lookup(void);
extern int pt_event_compare(const void *, const void *);
/*
*/
extern void pt_display_setup(boolean_t);
extern void pt_display_init_curses(void);
extern void pt_display_update(void);
extern void pt_display_title_bar(void);
extern void pt_display_status_bar(void);
extern void pt_display_mod_status_bar(char *);
extern void pt_display_states(void);
extern void pt_display_acpi_power(uint32_t, double, double, double,
uint32_t);
extern void pt_display_wakeups(double);
extern void pt_display_events(double);
extern void pt_display_suggestions(char *);
extern void pt_display_resize(void);
/*
* Suggestions
*/
extern void pt_sugg_add(char *, int, char, char *, sugg_func_t *);
extern int pt_sugg_remove(sugg_func_t *);
extern void pt_sugg_pick(void);
/*
* Battery
*/
extern void pt_battery_print(void);
/*
* DTrace stats
*/
extern int pt_cpufreq_stat_prepare(void);
extern int pt_cpufreq_stat_collect(double);
extern int pt_cpuidle_stat_prepare(void);
extern int pt_cpuidle_stat_collect(double);
extern int pt_events_stat_prepare(void);
/*
* Kstat
*/
int pt_events_stat_collect(void);
extern int g_supported_max_cstates_index;
extern int g_supported_max_pstates_index;
extern int g_current_cstate_index;
extern int g_current_pstate_index;
extern int g_max_pwrcap_index;
extern int g_clock_MHz_index;
extern int g_cstates_nsec_index;
extern int g_cstates_count_index;
extern int g_pstates_nsec_index;
extern int g_supported_freq_index;
extern int g_turbo_supported_index;
extern int g_turbo_mcnt_index;
extern int g_turbo_acnt_index;
extern int g_bif_unit_index;
extern int g_bst_rate_index;
extern int g_bif_last_cap_index;
extern int g_bst_rem_cap_index;
extern int g_bst_state_index;
/*
* Kstat routines
*/
struct cpu_snapshot *c2);
extern kstat_ctl_t *pt_open_kstat(void);
/*
* Turbo mode related routines
*/
extern int pt_turbo_stat_prepare(void);
extern int pt_turbo_stat_collect(void);
#endif /* __INCLUDE_GUARD_POWERTOP_H_ */