19 #include <sys/types.h> 29 typedef struct _powercap_register {
33 typedef struct _powercap_native_event_entry {
45 typedef struct _powercap_reg_alloc {
56 #define PKG_MAX_ENERGY_RANGE 1 57 #define PKG_MAX_POWER_A 2 58 #define PKG_POWER_LIMIT_A 3 59 #define PKG_TIME_WINDOW_A 4 60 #define PKG_MAX_POWER_B 5 61 #define PKG_POWER_LIMIT_B 6 62 #define PKG_TIME_WINDOW_B 7 66 #define PKG_NUM_EVENTS 10 68 static 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"};
69 static 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"};
70 static 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};
74 #define COMPONENT_ENERGY 10 75 #define COMPONENT_MAX_ENERGY_RANGE 11 76 #define COMPONENT_MAX_POWER_A 12 77 #define COMPONENT_POWER_LIMIT_A 13 78 #define COMPONENT_TIME_WINDOW_A 14 79 #define COMPONENT_ENABLED 15 80 #define COMPONENT_NAME 16 82 #define COMPONENT_NUM_EVENTS 7 85 static 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"};
88 #define POWERCAP_MAX_COUNTERS (2 * (PKG_NUM_EVENTS + (3 * COMPONENT_NUM_EVENTS))) 94 typedef struct _powercap_control_state {
101 typedef struct _powercap_context {
115 char *
retval = strncpy( dst, src, size );
116 if ( size>0 ) dst[size-1] =
'\0';
133 perror(
"Error in pwrite(): ");
155 int num_sockets = -1;
156 int s = -1, e = -1,
c = -1;
158 char events_dir[128];
159 char event_path[128];
177 for(
s = 0;
s < num_sockets;
s++) {
180 snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d/",
s);
183 events = opendir(events_dir);
186 if (
events == NULL) {
continue; }
193 snprintf(event_path,
sizeof(event_path),
"%s%s", events_dir,
pkg_sys_names[e]);
195 if (access(event_path, F_OK) == -1) {
continue; }
218 snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d:%d/",
s,
c);
219 while((
events = opendir(events_dir)) != NULL) {
229 if (access(event_path, F_OK) == -1) {
continue; }
254 snprintf(events_dir,
sizeof(events_dir),
"/sys/class/powercap/intel-rapl:%d:%d/",
s,
c);
323 long long **
events,
int flags )
325 SUBDBG(
"Enter _powercap_read\n");
331 long long start_val = 0;
332 long long curr_val = 0;
339 SUBDBG(
"%d, start value: %lld, current value %lld\n",
c, start_val, curr_val);
347 if(start_val > curr_val) {
348 SUBDBG(
"Wraparound!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
349 curr_val += (0x100000000 - start_val);
352 else if (start_val < curr_val) {
353 SUBDBG(
"Normal subtraction!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
354 curr_val -= start_val;
356 SUBDBG(
"Final value: %lld\n", curr_val);
360 control->
count[
c]=curr_val;
405 SUBDBG(
"Enter: ctx: %p\n", ctx );
457 switch ( modifier ) {
464 *EventCode = *EventCode + 1;
493 int index = EventCode;
503 int index = EventCode;
520 .short_name =
"powercap",
521 .description =
"Linux powercap energy measurements",
static char write_buff[PAPI_MAX_STR_LEN]
static char * pkg_event_names[PKG_NUM_EVENTS]
char disabled_reason[PAPI_MAX_STR_LEN]
#define COMPONENT_MAX_POWER_A
char units[PAPI_MIN_STR_LEN]
#define COMPONENT_TIME_WINDOW_A
static int _powercap_shutdown_thread(hwd_context_t *ctx)
#define COMPONENT_ENABLED
static int _powercap_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
static int _powercap_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
static int component_events[COMPONENT_NUM_EVENTS]
static int event_fds[POWERCAP_MAX_COUNTERS]
static char read_buff[PAPI_MAX_STR_LEN]
static mode_t component_sys_flags[COMPONENT_NUM_EVENTS]
long long start_value[POWERCAP_MAX_COUNTERS]
char long_descr[PAPI_HUGE_STR_LEN]
#define PKG_TIME_WINDOW_A
long long which_counter[POWERCAP_MAX_COUNTERS]
char units[MAX_EVENTS][BUFSIZ]
char name[PAPI_MAX_STR_LEN]
PAPI_component_info_t cmp_info
static int _powercap_init_control_state(hwd_control_state_t *ctl)
#define COMPONENT_POWER_LIMIT_A
static int write_powercap_value(int index, long long value)
static int _powercap_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
Return codes and api definitions.
static char * _local_strlcpy(char *dst, const char *src, size_t size)
#define PKG_TIME_WINDOW_B
char events[MAX_EVENTS][BUFSIZ]
char units[PAPI_MIN_STR_LEN]
#define COMPONENT_MAX_ENERGY_RANGE
static int _powercap_shutdown_component(void)
char description[PAPI_MAX_STR_LEN]
static long long read_powercap_value(int index)
long long count[POWERCAP_MAX_COUNTERS]
int open(const char *pathname, int flags, mode_t mode)
_powercap_register_t ra_bits
static int _powercap_ntv_code_to_name(unsigned int EventCode, char *name, int len)
static int _powercap_read(hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
static char * component_sys_names[COMPONENT_NUM_EVENTS]
char symbol[PAPI_HUGE_STR_LEN]
_powercap_register_t resources
#define PKG_MAX_ENERGY_RANGE
#define PKG_POWER_LIMIT_A
static int _powercap_init_thread(hwd_context_t *ctx)
#define SUBDBG(format, args...)
static int pkg_events[PKG_NUM_EVENTS]
static char * component_event_names[COMPONENT_NUM_EVENTS]
static mode_t pkg_sys_flags[PKG_NUM_EVENTS]
char name[PAPI_MAX_STR_LEN]
static int _powercap_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
papi_mdi_t _papi_hwi_system_info
static int _powercap_ntv_code_to_info(unsigned int EventCode, PAPI_event_info_t *info)
#define PAPI_VENDOR_INTEL
static int _powercap_write(hwd_context_t *ctx, hwd_control_state_t *ctl, long long *values)
static int _powercap_set_domain(hwd_control_state_t *ctl, int domain)
#define PAPI_NATIVE_AND_MASK
papi_vector_t _powercap_vector
_powercap_control_state_t state
static int _powercap_ntv_enum_events(unsigned int *EventCode, int modifier)
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
static long long values[NUM_EVENTS]
#define COMPONENT_NUM_EVENTS
static int _powercap_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
static const PAPI_hw_info_t * hw_info
static int _powercap_reset(hwd_context_t *ctx, hwd_control_state_t *ctl)
static double b[MATRIX_SIZE][MATRIX_SIZE]
long long need_difference[POWERCAP_MAX_COUNTERS]
static char * pkg_sys_names[PKG_NUM_EVENTS]
#define POWERCAP_MAX_COUNTERS
static int _powercap_init_component(int cidx)
#define PKG_POWER_LIMIT_B