1N/A/*
1N/A * This file is part of PowerTOP
1N/A *
1N/A * This program file is free software; you can redistribute it and/or modify it
1N/A * under the terms of the GNU General Public License as published by the
1N/A * Free Software Foundation; version 2 of the License.
1N/A *
1N/A * This program is distributed in the hope that it will be useful, but WITHOUT
1N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1N/A * for more details.
1N/A *
1N/A * You should have received a copy of the GNU General Public License
1N/A * along with this program in a file named COPYING; if not, write to the
1N/A * Free Software Foundation, Inc.,
1N/A * 51 Franklin Street, Fifth Floor,
1N/A * Boston, MA 02110-1301 USA
1N/A *
1N/A * Authors:
1N/A * Arjan van de Ven <arjan@linux.intel.com>
1N/A * Eric C Saxe <eric.saxe@sun.com>
1N/A * Aubrey Li <aubrey.li@intel.com>
1N/A */
1N/A
1N/A/*
1N/A * Copyright (c) 2009, Intel Corporation.
1N/A * All Rights Reserved.
1N/A */
1N/A
1N/A/*
2N/A * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A
1N/A/*
1N/A * GPL Disclaimer
1N/A *
1N/A * For the avoidance of doubt, except that if any license choice other
1N/A * than GPL or LGPL is available it will apply instead, Sun elects to
1N/A * use only the General Public License version 2 (GPLv2) at this time
1N/A * for any software where a choice of GPL license versions is made
1N/A * available with the language indicating that GPLv2 or any later
1N/A * version may be used, or where a choice of which version of the GPL
1N/A * is applied is otherwise unspecified.
1N/A */
1N/A
1N/A#ifndef __INCLUDE_GUARD_POWERTOP_H_
1N/A#define __INCLUDE_GUARD_POWERTOP_H_
1N/A
1N/A#include <sys/types.h>
1N/A#include <sys/processor.h>
2N/A#include <sys/pset.h>
2N/A#include <sys/time.h>
2N/A#include <kstat.h>
2N/A#define DBGPRINT
2N/A#define DBGPRINT1
2N/A#define DBGPRINT2
2N/A#define DBGPRINT3
1N/A
2N/A#define HZ2MHZ(speed) (((speed) + ((MICROSEC)/2)) / (MICROSEC))
2N/A#define MIN(A, B) (((A) < (B)) ? (A) : (B))
2N/A#define max(A, B) (((A) < (B)) ? (B) : (A))
1N/A
2N/A
2N/A#define TITLE "Solaris PowerTOP version 1.3"
1N/A#define COPYRIGHT_INTEL "(C) 2009 Intel Corporation"
1N/A
1N/A/*
1N/A * Exit values. stdlib.h defines EXIT_SUCCESS as 0 and
1N/A * EXIT_FAILURE as 1
1N/A */
1N/A#define EXIT_USAGE 2
1N/A
1N/A/*
1N/A * PowerTOP Features
1N/A * These may not be available everywhere
1N/A */
1N/A#define FEATURE_CSTATE 0x01
1N/A#define FEATURE_PSTATE 0x02
1N/A#define FEATURE_EVENTS 0x04
1N/A#define FEATURE_TURBO 0x08
1N/A
1N/A#define BIT_DEPTH_BUF 10
1N/A
1N/A#define INTERVAL_DEFAULT 5.0
1N/A#define INTERVAL_MAX 30.0
1N/A#define INTERVAL_UPDATE(l) \
1N/A ((l/INTERVAL_DEFAULT) * INTERVAL_DEFAULT + INTERVAL_DEFAULT)
2N/A#define RETRY_DELAY 200*MICROSEC
2N/A#define PT_KSTAT_CHAIN_RETRYS 3
1N/A
1N/A#define STATE_NAME_MAX 16
1N/A#define EVENT_NAME_MAX 64
1N/A#define EVENT_NUM_MAX 100
2N/A#define CPU_MAX_PSTATES 64
2N/A#define CPU_MAX_CSTATES 16
1N/A
1N/A/*
1N/A * Available op modes. The PT_ON_* macros allow for a simple way of checking
1N/A * under which mode PowerTOP is operating.
1N/A */
1N/A#define PT_MODE_DEFAULT 0x01
1N/A#define PT_MODE_DUMP 0x02
1N/A#define PT_MODE_VERBOSE 0x04
1N/A#define PT_MODE_CPU 0x08
1N/A#define PT_MODE_TIME 0x10
2N/A#define PT_MODE_NOEVENTS 0x20 /* can be patched in by debugger */
1N/A
2N/A#define PT_ON_DEFAULT (g_op_mode & PT_MODE_DEFAULT)
2N/A#define PT_ON_DUMP (g_op_mode & PT_MODE_DUMP)
2N/A#define PT_ON_VERBOSE (g_op_mode & PT_MODE_VERBOSE)
2N/A#define PT_ON_CPU (g_op_mode & PT_MODE_CPU)
2N/A#define PT_ON_TIME (g_op_mode & PT_MODE_TIME)
2N/A#define PT_ON_NOEVENTS (g_op_mode & PT_MODE_NOEVENTS)
2N/A
2N/A#define ID_NO_CPU -1
2N/A#define CPU_ONLINE(s) ((s) == P_ONLINE || (s) == P_NOINTR)
2N/A#define CPU_ACTIVE(c) (CPU_ONLINE((c)->cs_state) && (c)->cs_id != ID_NO_CPU)
2N/A
2N/A/*
2N/A * This is the value of sizeof ("18446744073709551615"), which is the max
2N/A * length that a uint64_t will occupy when rendered as a string,
2N/A * including the terminating null byte.
2N/A * There is an assertion in the kernel that 21 is the right value
2N/A */
2N/A#define MAX_UINT64_STRLEN 21
1N/A
1N/A/*
1N/A * Structures and typedefs
1N/A */
2N/A
2N/Astruct ktstat_cpu_records {
2N/A kstat_t *cpu_info_ksp_ptr;
2N/A int cs_state;
2N/A int cs_id;
2N/A};
2N/A
2N/Astruct cpu_snapshot {
2N/A processorid_t cs_id; /* cpu_id */
2N/A int cs_state; /* as in p_online(2) */
2N/A kstat_t cs_cpu_info; /* stats for this cpu */
2N/A char cstates_nsec[MAX_UINT64_STRLEN * CPU_MAX_CSTATES];
2N/A char cstates_count[MAX_UINT64_STRLEN * CPU_MAX_CSTATES];
2N/A char pstates_nsec[MAX_UINT64_STRLEN * CPU_MAX_PSTATES];
2N/A};
2N/A
2N/Astruct snapshot {
2N/A int snap_changed;
2N/A size_t s_num_cpus;
2N/A struct cpu_snapshot *s_cpus;
2N/A};
2N/Astruct kstat_cpu_records {
2N/A kstat_t *cpu_info_ksp_ptr;
2N/A int cs_state;
2N/A int cs_id;
2N/A};
2N/A
2N/Astruct snapshot_state {
2N/A struct kstat_cpu_records *kstat_cpu_information;
2N/A int kstat_cpus_active;
2N/A};
2N/A
1N/Astruct line {
1N/A char *string;
1N/A int count;
1N/A};
1N/A
1N/Atypedef struct event_info {
1N/A char offender_name[EVENT_NAME_MAX];
1N/A char offense_name[EVENT_NAME_MAX];
1N/A uint64_t total_count;
1N/A} event_info_t;
1N/A
2N/A#define SAFE_FREE(ptr, size) \
2N/A if (ptr) { \
2N/A bzero(ptr, size); \
2N/A free((void *) ptr); \
2N/A ptr = NULL; \
2N/A }
2N/A
1N/A/*
1N/A * P/C state information
1N/A */
2N/Atypedef struct cstate_info {
1N/A char name[STATE_NAME_MAX];
1N/A hrtime_t total_time;
1N/A hrtime_t last_time;
1N/A uint64_t events;
2N/A} cstate_info_t;
1N/A
2N/Atypedef struct pstate_info {
1N/A uint64_t speed;
1N/A hrtime_t total_time;
2N/A} pstate_info_t;
1N/A
1N/Atypedef struct cpu_power_info {
1N/A uint64_t current_pstate;
1N/A uint64_t speed_accounted;
1N/A hrtime_t time_accounted;
1N/A hrtime_t dtrace_time;
1N/A} cpu_power_info_t;
1N/A
1N/A/*
1N/A * Turbo mode information
1N/A */
1N/Atypedef struct turbo_info {
1N/A uint64_t t_mcnt;
1N/A uint64_t t_acnt;
1N/A} turbo_info_t;
1N/A
1N/A/*
1N/A * Suggestions
1N/A */
1N/Atypedef void (sugg_func_t)(void);
1N/A
1N/Atypedef struct suggestion {
1N/A char *text;
1N/A char key;
1N/A char *sb_msg;
1N/A int weight;
1N/A int slice;
1N/A sugg_func_t *func;
1N/A struct suggestion *prev;
1N/A struct suggestion *next;
1N/A} sugg_t;
1N/A
1N/Aextern int g_bit_depth;
2N/Aextern int g_pm_fd;
1N/A
2N/Aextern struct snapshot_state g_ss_state_info;
2N/Aextern kstat_ctl_t *g_kc;
1N/A/*
1N/A * Event accounting
1N/A */
1N/Aextern int g_total_events;
1N/Aextern int g_top_events;
1N/A
1N/A/*
1N/A * Command line arguments
1N/A */
1N/Aextern uchar_t g_op_mode;
1N/Aextern uint_t g_observed_cpu;
1N/Aextern boolean_t g_gui;
1N/A/*
1N/A * Event info array
1N/A */
2N/Aextern event_info_t g_event_info[EVENT_NUM_MAX];
1N/A
1N/A/*
1N/A * Lookup table, sequential CPU id to Solaris CPU id
1N/A */
1N/Aextern processorid_t *g_cpu_table;
1N/A
1N/A/*
1N/A * Number of idle/frequency states
1N/A */
2N/Aextern int g_max_pstates;
2N/Aextern int g_max_cstates;
1N/A
1N/A/*
1N/A * Total time, used to display different idle states
1N/A */
1N/Aextern hrtime_t g_total_c_time;
2N/A/*
2N/A * Total time, used to display different active states
2N/A */
2N/Aextern hrtime_t g_total_p_time;
1N/A
1N/A/*
1N/A * Current interval length
1N/A */
1N/Aextern double g_interval_length;
2N/A/*
2N/A * nanosleep timespec struct for 200 msec delay
2N/A */
2N/Aextern struct timespec g_rqtp;
1N/A
1N/A/*
1N/A * P/C state info arrays
1N/A */
2N/Aextern cstate_info_t g_cstate_info[CPU_MAX_CSTATES];
2N/Aextern pstate_info_t g_pstate_info[CPU_MAX_PSTATES];
1N/A
1N/Aextern uint_t g_features;
1N/Aextern uint_t g_ncpus;
1N/Aextern uint_t g_ncpus_observed;
1N/A
1N/Aextern cpu_power_info_t *g_cpu_power_states;
1N/A
1N/A/*
1N/A * Turbo mode related information
1N/A */
1N/Aextern boolean_t g_turbo_supported;
1N/Aextern double g_turbo_ratio;
1N/A
1N/Aextern sugg_t *g_curr_sugg;
1N/A
1N/A/*
1N/A * DTrace scripts for the events report
1N/A */
1N/Aextern const char *g_dtp_events;
1N/Aextern const char *g_dtp_events_v;
1N/Aextern const char *g_dtp_events_c;
1N/A
1N/A/*
1N/A * Arguments for dtrace_program_strcompile(). Contents vary according to
1N/A * the specified operation mode.
1N/A */
1N/Aextern uint_t g_argc;
1N/Aextern char **g_argv;
1N/A
1N/A/*
1N/A * Platform specific messages
1N/A */
2N/Aextern const char *g_msg_cstate;
2N/Aextern const char *g_msg_pstate;
1N/A
1N/A/*
1N/A * Flags for signal handling
1N/A */
1N/Aextern boolean_t g_sig_resize;
1N/A
1N/Aextern void pt_sig_handler(int);
1N/A
1N/A/*
1N/A * Suggestions related
1N/A */
1N/Aextern void pt_cpufreq_suggest(void);
1N/Aextern void pt_sugg_as_root(void);
1N/A
1N/A/*
1N/A * See util.c
1N/A */
1N/Aextern void pt_error(char *, ...);
1N/Aextern void pt_set_progname(char *);
1N/Aextern uint_t pt_enumerate_cpus(void);
1N/Aextern void pt_usage(void);
1N/Aextern int pt_get_bit_depth(void);
1N/Aextern void pt_battery_mod_lookup(void);
1N/Aextern int pt_event_compare(const void *, const void *);
1N/A
1N/A/*
1N/A * Display/curses related
1N/A */
1N/Aextern void pt_display_setup(boolean_t);
1N/Aextern void pt_display_init_curses(void);
1N/Aextern void pt_display_update(void);
1N/Aextern void pt_display_title_bar(void);
1N/Aextern void pt_display_status_bar(void);
1N/Aextern void pt_display_mod_status_bar(char *);
1N/Aextern void pt_display_states(void);
1N/Aextern void pt_display_acpi_power(uint32_t, double, double, double,
1N/A uint32_t);
1N/Aextern void pt_display_wakeups(double);
1N/Aextern void pt_display_events(double);
1N/Aextern void pt_display_suggestions(char *);
1N/Aextern void pt_display_resize(void);
1N/A
1N/A/*
1N/A * Suggestions
1N/A */
1N/Aextern void pt_sugg_add(char *, int, char, char *, sugg_func_t *);
1N/Aextern int pt_sugg_remove(sugg_func_t *);
1N/Aextern void pt_sugg_pick(void);
1N/A/*
1N/A * Battery
1N/A */
1N/Aextern void pt_battery_print(void);
1N/A
1N/A/*
1N/A * DTrace stats
1N/A */
2N/A
1N/Aextern int pt_cpufreq_stat_prepare(void);
1N/Aextern int pt_cpufreq_stat_collect(double);
1N/Aextern int pt_cpuidle_stat_prepare(void);
1N/Aextern int pt_cpuidle_stat_collect(double);
1N/Aextern int pt_events_stat_prepare(void);
2N/A/*
2N/A * Kstat
2N/A */
2N/Aextern void pt_cpufreq_kstat_account_all(struct snapshot *old,
2N/A struct snapshot *new);
2N/Aextern void pt_cpufreq_kstat_account_one(struct snapshot *old,
2N/A struct snapshot *new);
2N/Aint pt_events_stat_collect(void);
2N/A
2N/Aextern struct snapshot *g_new_ssp;
2N/Aextern struct snapshot *g_old_ssp;
2N/Aextern int g_supported_max_cstates_index;
2N/Aextern int g_supported_max_pstates_index;
2N/Aextern int g_current_cstate_index;
2N/Aextern int g_current_pstate_index;
2N/Aextern int g_max_pwrcap_index;
2N/Aextern int g_clock_MHz_index;
2N/Aextern int g_cstates_nsec_index;
2N/Aextern int g_cstates_count_index;
2N/Aextern int g_pstates_nsec_index;
2N/Aextern int g_supported_freq_index;
2N/Aextern int g_turbo_supported_index;
2N/Aextern int g_turbo_mcnt_index;
2N/Aextern int g_turbo_acnt_index;
2N/Aextern int g_bif_unit_index;
2N/Aextern int g_bst_rate_index;
2N/Aextern int g_bif_last_cap_index;
2N/Aextern int g_bst_rem_cap_index;
2N/Aextern int g_bst_state_index;
2N/A
2N/A/*
2N/A * Kstat routines
2N/A */
2N/Atypedef void (*snapshot_cb)(void *old, void *new);
2N/A
2N/Aextern void pt_kstat_cpu_walk(struct snapshot *old, struct snapshot *new);
2N/Aextern void pt_update_cpu_kstats(struct cpu_snapshot *c1,
2N/A struct cpu_snapshot *c2);
2N/Aextern int pt_generate_cpu_information(kstat_ctl_t *kc);
2N/Aextern int pt_acquire_cpu(struct snapshot *ss, kstat_ctl_t *kc);
2N/Aextern int pt_acquire_cpus(struct snapshot *ss, kstat_ctl_t *kc);
2N/Aextern struct snapshot *pt_acquire_kstat_snapshot(kstat_ctl_t **kc_passed);
2N/Aextern void pt_free_snapshot(struct snapshot *ss);
2N/Aextern kstat_ctl_t *pt_open_kstat(void);
2N/Aextern void *pt_safe_alloc(size_t size);
2N/A
2N/Aextern int pt_delta_str(char *s1, char *s2, uint64_t *delta, int max);
2N/Aextern long pt_kstat_long(kstat_t *ksp, char *name, int *index);
2N/Aextern int pt_kstat_copy(const kstat_t *src, kstat_t *dst);
2N/Aextern void *pt_kstat_data_lookup(kstat_t *ksp, char *name, int *index_ptr);
1N/A
1N/A/*
1N/A * Turbo mode related routines
1N/A */
1N/Aextern int pt_turbo_stat_prepare(void);
1N/Aextern int pt_turbo_stat_collect(void);
1N/A
1N/A#endif /* __INCLUDE_GUARD_POWERTOP_H_ */