29#define HANDLE_STRING_ERROR {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}
32typedef struct _powercap_register {
36typedef struct _powercap_native_event_entry {
48typedef struct _powercap_reg_alloc {
62#define PKG_MAX_ENERGY_RANGE 1
63#define PKG_MAX_POWER_A 2
64#define PKG_POWER_LIMIT_A 3
65#define PKG_TIME_WINDOW_A 4
66#define PKG_MAX_POWER_B 5
67#define PKG_POWER_LIMIT_B 6
68#define PKG_TIME_WINDOW_B 7
72#define PKG_NUM_EVENTS 10
74static char *
pkg_event_names[
PKG_NUM_EVENTS] = {
"ENERGY_UJ",
"MAX_ENERGY_RANGE_UJ",
"MAX_POWER_A_UW",
"POWER_LIMIT_A_UW",
"TIME_WINDOW_A_US",
"MAX_POWER_B_UW",
"POWER_LIMIT_B_UW",
"TIME_WINDOW_B",
"ENABLED",
"NAME"};
75static char *
pkg_sys_names[
PKG_NUM_EVENTS] = {
"energy_uj",
"max_energy_range_uj",
"constraint_0_max_power_uw",
"constraint_0_power_limit_uw",
"constraint_0_time_window_us",
"constraint_1_max_power_uw",
"constraint_1_power_limit_uw",
"constraint_1_time_window_us",
"enabled",
"name"};
76static mode_t
pkg_sys_flags[
PKG_NUM_EVENTS] = {O_RDONLY, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDONLY};
80#define COMPONENT_ENERGY 10
81#define COMPONENT_MAX_ENERGY_RANGE 11
82#define COMPONENT_MAX_POWER_A 12
83#define COMPONENT_POWER_LIMIT_A 13
84#define COMPONENT_TIME_WINDOW_A 14
85#define COMPONENT_ENABLED 15
86#define COMPONENT_NAME 16
88#define COMPONENT_NUM_EVENTS 7
91static char *
component_sys_names[
COMPONENT_NUM_EVENTS] = {
"energy_uj",
"max_energy_range_uj",
"constraint_0_max_power_uw",
"constraint_0_power_limit_uw",
"constraint_0_time_window_us",
"enabled",
"name"};
94#define POWERCAP_MAX_COUNTERS (2 * (PKG_NUM_EVENTS + (3 * COMPONENT_NUM_EVENTS)))
100typedef struct _powercap_control_state {
108typedef struct _powercap_context {
129 char *
retval = strncpy( dst, src, size );
130 if ( size>0 ) dst[size-1] =
'\0';
147 perror(
"Error in pwrite(): ");
169 int num_sockets = -1;
170 int s = -1, e = -1,
c = -1;
171 long unsigned int strErr;
173 char events_dir[128];
174 char event_path[128];
195 for(
s = 0;
s < num_sockets;
s++) {
199 int s_dir, found = 0;
200 for(s_dir = 0; ; s_dir++) {
201 strErr=snprintf(event_path,
sizeof(event_path),
"/sys/class/powercap/intel-rapl:%d/%s", s_dir,
pkg_sys_names[
PKG_NAME]);
202 event_path[
sizeof(event_path)-1]=0;
213 if (strncmp(
read_buff,
"package-", strlen(
"package-")) == 0 && strtol(
read_buff + strlen(
"package-"), NULL, 10) ==
s) {
218 if (!found) {
continue; }
221 strErr=snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d/", s_dir);
222 events_dir[
sizeof(events_dir)-1]=0;
226 events = opendir(events_dir);
229 if (
events == NULL) {
continue; }
236 strErr=snprintf(event_path,
sizeof(event_path),
"%s%s", events_dir,
pkg_sys_names[e]);
237 event_path[
sizeof(event_path)-1]=0;
241 if (access(event_path, R_OK) == -1) {
continue; }
274 strErr=snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d:%d/", s_dir,
c);
275 events_dir[
sizeof(events_dir)-1]=0;
277 while((
events = opendir(events_dir)) != NULL) {
284 strErr=snprintf(event_path,
sizeof(event_path),
"%s%s", events_dir,
component_sys_names[e]);
285 event_path[
sizeof(event_path)-1]=0;
289 if (access(event_path, R_OK) == -1) {
continue; }
324 strErr=snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d:%d/", s_dir,
c);
325 events_dir[
sizeof(events_dir)-1]=0;
399 long long **
events,
int flags )
401 SUBDBG(
"Enter _powercap_read\n");
407 long long start_val = 0;
408 long long curr_val = 0;
416 SUBDBG(
"%d, start value: %lld, current value %lld\n",
i, start_val, curr_val);
424 if(start_val > curr_val) {
425 SUBDBG(
"Wraparound!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
431 curr_val += (0x100000000 - start_val);
436 else if (start_val < curr_val) {
437 SUBDBG(
"Normal subtraction!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
438 curr_val -= start_val;
440 SUBDBG(
"Final value: %lld\n", curr_val);
444 control->
count[
c]=curr_val;
490 SUBDBG(
"Enter: ctx: %p\n", ctx );
544 switch ( modifier ) {
551 *EventCode = *EventCode + 1;
580 int index = EventCode;
590 int index = EventCode;
607 .short_name =
"powercap",
608 .description =
"Linux powercap energy measurements",
int open(const char *pathname, int flags, mode_t mode)
static const PAPI_hw_info_t * hw_info
struct papi_vectors * _papi_hwd[]
#define PAPI_VENDOR_INTEL
#define PAPI_DATATYPE_UINT64
char events[MAX_EVENTS][BUFSIZ]
static long long values[NUM_EVENTS]
static double b[MATRIX_SIZE][MATRIX_SIZE]
static double c[MATRIX_SIZE][MATRIX_SIZE]
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
static char read_buff[PAPI_MAX_STR_LEN]
#define PKG_POWER_LIMIT_B
static int _powercap_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
static int _powercap_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
papi_vector_t _powercap_vector
static int _powercap_ntv_enum_events(unsigned int *EventCode, int modifier)
static char * component_event_names[COMPONENT_NUM_EVENTS]
#define POWERCAP_MAX_COUNTERS
static int _powercap_shutdown_thread(hwd_context_t *ctx)
#define PKG_MAX_ENERGY_RANGE
static int _powercap_set_domain(hwd_control_state_t *ctl, int domain)
static long long max_component_energy_count
#define COMPONENT_POWER_LIMIT_A
static int _powercap_init_thread(hwd_context_t *ctx)
static char * _local_strlcpy(char *dst, const char *src, size_t size)
#define COMPONENT_ENABLED
static int component_events[COMPONENT_NUM_EVENTS]
static long long map_index_to_counter(hwd_control_state_t *ctl, int index)
static char * pkg_event_names[PKG_NUM_EVENTS]
static long long read_powercap_value(int index)
static int _powercap_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
static int event_fds[POWERCAP_MAX_COUNTERS]
static char * pkg_sys_names[PKG_NUM_EVENTS]
static int _powercap_write(hwd_context_t *ctx, hwd_control_state_t *ctl, long long *values)
static mode_t pkg_sys_flags[PKG_NUM_EVENTS]
static int pkg_events[PKG_NUM_EVENTS]
static int write_powercap_value(int index, long long value)
static char write_buff[PAPI_MAX_STR_LEN]
static int _powercap_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
#define COMPONENT_MAX_ENERGY_RANGE
#define COMPONENT_NUM_EVENTS
#define PKG_TIME_WINDOW_A
static int _powercap_init_control_state(hwd_control_state_t *ctl)
static int _powercap_ntv_code_to_info(unsigned int EventCode, PAPI_event_info_t *info)
static char * component_sys_names[COMPONENT_NUM_EVENTS]
static int _powercap_shutdown_component(void)
#define PKG_TIME_WINDOW_B
static long long max_pkg_energy_count
#define PKG_POWER_LIMIT_A
static mode_t component_sys_flags[COMPONENT_NUM_EVENTS]
static int _powercap_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
#define COMPONENT_TIME_WINDOW_A
static int _powercap_read(hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
#define COMPONENT_MAX_POWER_A
static int _powercap_init_component(int cidx)
static int _powercap_ntv_code_to_name(unsigned int EventCode, char *name, int len)
static int _powercap_reset(hwd_context_t *ctx, hwd_control_state_t *ctl)
#define HANDLE_STRING_ERROR
#define PAPI_NATIVE_AND_MASK
Return codes and api definitions.
#define SUBDBG(format, args...)
papi_mdi_t _papi_hwi_system_info
char units[MAX_EVENTS][BUFSIZ]
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]
char units[PAPI_MIN_STR_LEN]
char symbol[PAPI_HUGE_STR_LEN]
char long_descr[PAPI_HUGE_STR_LEN]
long long start_value[POWERCAP_MAX_COUNTERS]
_powercap_control_state_t state
long long need_difference[POWERCAP_MAX_COUNTERS]
long long count[POWERCAP_MAX_COUNTERS]
long long which_counter[POWERCAP_MAX_COUNTERS]
char name[PAPI_MAX_STR_LEN]
char description[PAPI_MAX_STR_LEN]
_powercap_register_t resources
char units[PAPI_MIN_STR_LEN]
_powercap_register_t ra_bits
PAPI_component_info_t cmp_info