41 #include <msr/msr_core.h> 42 #include <msr/msr_rapl.h> 43 #include <msr/msr_counters.h> 57 typedef struct _libmsr_register {
61 typedef struct _libmsr_native_event_entry {
71 typedef struct _libmsr_reg_alloc {
76 #define LIBMSR_MAX_COUNTERS 64 77 #define LIBMSR_MAX_PACKAGES 64 79 typedef struct _libmsr_control_state {
93 typedef struct _libmsr_context {
113 static int (*init_msr_ptr)();
114 static int (*finalize_msr_ptr)();
115 static int (*rapl_init_ptr)(
struct rapl_data ** rapl, uint64_t ** rapl_flags);
116 static int (*poll_rapl_data_ptr) ( );
117 static void (*set_pkg_rapl_limit_ptr) (
const int socket,
struct rapl_limit* limit1,
struct rapl_limit* limit2 );
118 static void (*get_pkg_rapl_limit_ptr) (
const int socket,
struct rapl_limit* limit1,
struct rapl_limit* limit2 );
119 static int (*core_config_ptr) (uint64_t * coresPerSocket, uint64_t * threadsPerCore, uint64_t * sysSockets,
int * HTenabled);
120 static int (*rapl_storage_ptr) (
struct rapl_data ** data, uint64_t ** flags);
121 static int (*get_rapl_power_info_ptr) (
const unsigned socket,
struct rapl_power_info *info);
124 static int libmsr_init_msr () {
return ((*init_msr_ptr)()); }
126 static int libmsr_rapl_init (
struct rapl_data ** rapl_data, uint64_t ** rapl_flags) {
return (*rapl_init_ptr)( rapl_data, rapl_flags ); }
128 static void libmsr_set_pkg_rapl_limit (
const int socket,
struct rapl_limit* limit1,
struct rapl_limit* limit2 ) {
return (*set_pkg_rapl_limit_ptr) ( socket, limit1, limit2 ); }
129 static void libmsr_get_pkg_rapl_limit (
const int socket,
struct rapl_limit* limit1,
struct rapl_limit* limit2 ) {
return (*get_pkg_rapl_limit_ptr) ( socket, limit1, limit2 ); }
130 static int libmsr_core_config(uint64_t * coresPerSocket, uint64_t * threadsPerCore, uint64_t * sysSockets,
int * HTenabled) {
return (*core_config_ptr) ( coresPerSocket, threadsPerCore, sysSockets, HTenabled ); }
131 static int libmsr_rapl_storage(
struct rapl_data ** data, uint64_t ** flags) {
return (*rapl_storage_ptr) (data, flags); }
132 static int libmsr_get_rapl_power_info(
const unsigned socket,
struct rapl_power_info *info) {
return (*get_rapl_power_info_ptr) ( socket, info); }
135 #define CHECK_DL_STATUS( err, str ) if( err ) { strncpy( _libmsr_vector.cmp_info.disabled_reason, str, PAPI_MAX_STR_LEN ); return ( PAPI_ENOSUPP ); } 142 dllib1 = dlopen(
"libmsr.so", RTLD_NOW | RTLD_GLOBAL);
144 init_msr_ptr = dlsym(
dllib1,
"init_msr" );
145 CHECK_DL_STATUS( dlerror()!=NULL ,
"libmsr function init_msr not found." );
146 finalize_msr_ptr = dlsym(
dllib1,
"finalize_msr" );
147 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function finalize_msr not found." );
148 rapl_init_ptr = dlsym(
dllib1,
"rapl_init" );
149 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function rapl_init not found." );
150 poll_rapl_data_ptr = dlsym(
dllib1,
"poll_rapl_data" );
151 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function poll_rapl_data not found." );
152 set_pkg_rapl_limit_ptr = dlsym(
dllib1,
"set_pkg_rapl_limit" );
153 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function set_pkg_rapl_limit not found." );
154 get_pkg_rapl_limit_ptr = dlsym(
dllib1,
"get_pkg_rapl_limit" );
155 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function get_pkg_rapl_limit not found." );
156 core_config_ptr = dlsym(
dllib1,
"core_config" );
157 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function core_config not found." );
158 rapl_storage_ptr = dlsym(
dllib1,
"rapl_storage" );
159 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function rapl_storage not found." );
160 get_rapl_power_info_ptr = dlsym(
dllib1,
"get_rapl_power_info" );
161 CHECK_DL_STATUS( dlerror()!=NULL,
"libmsr function get_rapl_power_info not found." );
172 char *
retval = strncpy( dst, src, size );
173 if ( size>0 ) dst[size-1] =
'\0';
180 uint64_t socket, numSockets;
181 struct rapl_power_info raplinfo;
182 struct rapl_limit socketlim, socketlim2;
184 SUBDBG(
"Enter: Resetting the sockets to defaults\n");
186 for (socket = 0; socket < numSockets; socket++) {
189 socketlim.watts = raplinfo.pkg_therm_power;
190 socketlim.seconds = 1;
192 socketlim2.watts = raplinfo.pkg_therm_power * 1.2;
193 socketlim2.seconds = 3;
194 SUBDBG(
"Resetting socket %ld to defaults (%f,%f) (%f,%f)\n", socket, socketlim.watts, socketlim.seconds, socketlim2.watts, socketlim2.seconds);
226 struct rapl_data * libmsr_rapl_data;
227 uint64_t * libmsr_rapl_flags;
228 uint64_t coresPerSocket, threadsPerCore, numSockets;
242 SUBDBG (
"Dynamic link of libmsr.so libraries failed, component will be disabled.\n");
243 SUBDBG (
"See disable reason in papi_component_avail output for more details.\n");
248 if ( libmsr_init_msr() != 0 ) {
250 SUBDBG(
"init_msr (libmsr) returned error. Possible problems accessing /dev/cpu/<n>/msr_safe or /dev/cpu/<n>/msr");
258 SUBDBG(
"Library libmsr could not initialize RAPL (libmsr/rapl_init failed)");
323 sprintf(
libmsr_native_events[
i].description,
"Number of Joules consumed by all cores and last level cache on package. Unit is Joules (double precision).");
332 sprintf(
libmsr_native_events[
i].description,
"Watts consumed by package. Unit is Watts (double precision).");
341 sprintf(
libmsr_native_events[
i].description,
"Time elapsed since last LIBMSR data reading from package. Unit is seconds (double precision).");
350 sprintf(
libmsr_native_events[
i].description,
"Number of Joules consumed by package since last LIBMSR data reading. Unit is Joules (double precision).");
359 sprintf(
libmsr_native_events[
i].description,
"Average power limit over PKG_TIME_WINDOW_POWER_LIMIT_1 for package. Read/Write. Unit is Watts (double precision).");
368 sprintf(
libmsr_native_events[
i].description,
"Time window used for averaging PACKAGE_POWER_LIMIT_1 for package. Read/Write. Unit is seconds (double precision).");
377 sprintf(
libmsr_native_events[
i].description,
"Average power limit over PKG_TIME_WINDOW_POWER_LIMIT_2 for package. Read/Write. Unit is Watts (double precision).");
386 sprintf(
libmsr_native_events[
i].description,
"Time window used for averaging PACKAGE_POWER_LIMIT_2 for package. Read/Write. Unit is seconds (double precision).");
418 SUBDBG(
"Enter: ctl: %p\n", ctl );
434 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
441 for( nn = 0; nn <
count; nn++ ) {
443 native[nn].ni_position = nn;
445 control->
count[nn] = 0;
456 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
471 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
476 union {
long long ll;
double dbl; } event_value_union;
477 struct rapl_limit limit1, limit2;
479 struct rapl_data * libmsr_rapl_data;
480 uint64_t * libmsr_rapl_flags;
491 SUBDBG(
"Calling poll_rapl_data to read state from all sockets\n");
501 SUBDBG(
"Go thru events, assign package data to events as needed\n");
505 event_value_union.ll = 0LL;
507 SUBDBG(
"nn %d ee %d pp %d eventtype %d\n", nn, ee, pp, eventtype);
510 event_value_union.dbl = libmsr_rapl_data->pkg_joules[pp];
513 event_value_union.dbl = libmsr_rapl_data->elapsed;
516 event_value_union.dbl = libmsr_rapl_data->pkg_delta_joules[pp];
519 event_value_union.dbl = libmsr_rapl_data->pkg_watts[pp];
522 limit1.bits = 0; limit1.watts = 0; limit1.seconds = 0;
524 event_value_union.dbl = limit1.watts;
527 limit1.bits = 0; limit1.watts = 0; limit1.seconds = 0;
529 event_value_union.dbl = limit1.seconds;
532 limit2.bits = 0; limit2.watts = 0; limit2.seconds = 0;
534 event_value_union.dbl = limit2.watts;
537 limit2.bits = 0; limit2.watts = 0; limit2.seconds = 0;
539 event_value_union.dbl = limit2.seconds;
542 SUBDBG(
"This LIBMSR event is unknown\n");
545 control->
count[nn] = event_value_union.ll;
569 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
575 union {
long long ll;
double dbl; } event_value_union;
576 union {
long long ll;
double dbl; } timewin_union;
577 struct rapl_limit limit1, limit2;
585 event_value_union.ll =
values[nn];
587 if ( event_value_union.ll ==
PAPI_NULL )
continue;
589 SUBDBG(
"nn %d ee %d pp %d eventtype %d\n", nn, ee, pp, eventtype);
599 if ( timewin_union.ll > 0 ) {
600 limit1.watts = event_value_union.dbl;
601 limit1.seconds = timewin_union.dbl;
607 SUBDBG(
"PACKAGE_POWER_LIMIT_1 needs PKG_TIME_WINDOW_POWER_LIMIT_1: Power cap not updated. ");
612 if ( timewin_union.ll > 0 ) {
613 limit2.watts = event_value_union.dbl;
614 limit2.seconds = timewin_union.dbl;
620 PAPIERROR(
"PACKAGE_POWER_LIMIT_1 needs PKG_TIME_WINDOW_POWER_LIMIT_1: Powercap not updated.");
628 SUBDBG(
"This LIBMSR information type is unknown\n");
638 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
649 SUBDBG(
"Enter: ctl: %p\n", ctx );
682 SUBDBG(
"Enter: ctx: %p\n", ctx );
703 SUBDBG(
"Enter: ctl: %p\n", ctl );
715 SUBDBG(
"Enter: ctl: %p, ctx: %p\n", ctl, ctx );
728 SUBDBG(
"Enter: EventCode: %d\n", *EventCode );
733 switch ( modifier ) {
741 *EventCode = *EventCode + 1;
761 SUBDBG(
"Enter: EventCode: %d\n", EventCode );
774 SUBDBG(
"Enter: EventCode: %d\n", EventCode );
775 int index = EventCode;
787 SUBDBG(
"Enter: EventCode: %d\n", EventCode );
788 int index = EventCode;
804 .short_name =
"libmsr",
805 .description =
"PAPI component for libmsr from LANL for power (RAPL) read/write",
static int libmsr_poll_rapl_data()
char disabled_reason[PAPI_MAX_STR_LEN]
int _libmsr_init_control_state(hwd_control_state_t *ctl)
static void libmsr_set_pkg_rapl_limit(const int socket, struct rapl_limit *limit1, struct rapl_limit *limit2)
int _libmsr_shutdown_component(void)
static char * _local_strlcpy(char *dst, const char *src, size_t size)
static int _local_linkDynamicLibraries()
char units[PAPI_MIN_STR_LEN]
static int libmsr_core_config(uint64_t *coresPerSocket, uint64_t *threadsPerCore, uint64_t *sysSockets, int *HTenabled)
static _libmsr_native_event_entry_t * libmsr_native_events
#define CHECK_DL_STATUS(err, str)
int _libmsr_init_component(int cidx)
_libmsr_register_t resources
int _libmsr_ntv_code_to_info(unsigned int EventCode, PAPI_event_info_t *info)
int _libmsr_ntv_code_to_name(unsigned int EventCode, char *name, int len)
char long_descr[PAPI_HUGE_STR_LEN]
static int libmsr_get_rapl_power_info(const unsigned socket, struct rapl_power_info *info)
_libmsr_register_t ra_bits
char units[MAX_EVENTS][BUFSIZ]
PAPI_component_info_t cmp_info
Return codes and api definitions.
char events[MAX_EVENTS][BUFSIZ]
static int libmsr_finalize_msr()
papi_vector_t _libmsr_vector
int _libmsr_init_thread(hwd_context_t *ctx)
_libmsr_control_state_t state
static long long _local_get_eventval_from_values(_libmsr_control_state_t *control, long long *invalues, int package_num, eventtype_enum eventtype, long long defaultval)
static int already_called_libmsr_rapl_initialized_global
#define LIBMSR_MAX_COUNTERS
#define LIBMSR_MAX_PACKAGES
int _libmsr_write(hwd_context_t *ctx, hwd_control_state_t *ctl, long long *values)
static void libmsr_get_pkg_rapl_limit(const int socket, struct rapl_limit *limit1, struct rapl_limit *limit2)
char symbol[PAPI_HUGE_STR_LEN]
int which_counter[LIBMSR_MAX_COUNTERS]
int _libmsr_shutdown_thread(hwd_context_t *ctx)
int _libmsr_reset(hwd_context_t *ctx, hwd_control_state_t *ctl)
__attribute__((constructor))
static int libmsr_rapl_storage(struct rapl_data **data, uint64_t **flags)
#define SUBDBG(format, args...)
int _libmsr_set_domain(hwd_control_state_t *ctl, int domain)
void PAPIERROR(char *format,...)
char name[PAPI_MAX_STR_LEN]
char name[PAPI_MAX_STR_LEN]
int _libmsr_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
int _libmsr_read(hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
int package_being_measured[LIBMSR_MAX_PACKAGES]
papi_mdi_t _papi_hwi_system_info
#define PAPI_VENDOR_INTEL
static int libmsr_rapl_init(struct rapl_data **rapl_data, uint64_t **rapl_flags)
static int num_events_global
int _libmsr_ntv_enum_events(unsigned int *EventCode, int modifier)
int _libmsr_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
#define PAPI_NATIVE_AND_MASK
int _libmsr_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
long long count[LIBMSR_MAX_COUNTERS]
int _libmsr_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
void _local_set_to_defaults()
char description[PAPI_MAX_STR_LEN]
static long long values[NUM_EVENTS]
void(* _dl_non_dynamic_init)(void)
static const PAPI_hw_info_t * hw_info
int _libmsr_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
char units[PAPI_MIN_STR_LEN]