54 int __attribute__((weak)) umad_get_cas_names (
char [][UMAD_CA_NAME_LEN],
int );
55 int __attribute__((weak)) umad_get_ca (
const char *, umad_ca_t * );
56 void __attribute__((weak)) mad_decode_field (
unsigned char *,
enum MAD_FIELDS,
void *);
57 struct ibmad_port *
__attribute__((weak)) mad_rpc_open_port (
char *,
int,
int *,
int );
58 int __attribute__((weak)) ib_resolve_self_via ( ib_portid_t *,
int *, ibmad_gid_t *,
const struct ibmad_port * );
59 uint8_t *
__attribute__((weak)) performance_reset_via (
void *, ib_portid_t *,
int,
unsigned,
unsigned,
unsigned,
const struct ibmad_port * );
60 uint8_t *
__attribute__((weak)) pma_query_via (
void *, ib_portid_t *,
int,
unsigned,
unsigned,
const struct ibmad_port * );
62 int (*umad_initPtr) ( void );
63 int (*umad_get_cas_namesPtr) (
char [][UMAD_CA_NAME_LEN], int );
64 int (*umad_get_caPtr) (
const char *, umad_ca_t * );
65 void (*mad_decode_fieldPtr) (
unsigned char *,
enum MAD_FIELDS,
void * );
66 struct ibmad_port * (*mad_rpc_open_portPtr) (
char *, int,
int *, int );
67 int (*ib_resolve_self_viaPtr) (ib_portid_t *,
int *, ibmad_gid_t *,
const struct ibmad_port * );
68 uint8_t * (*performance_reset_viaPtr) (
void *, ib_portid_t *, int, unsigned, unsigned, unsigned,
const struct ibmad_port * );
69 uint8_t * (*pma_query_viaPtr) (
void *, ib_portid_t *, int, unsigned, unsigned,
const struct ibmad_port * );
72 static void*
dl1 = NULL;
73 static void*
dl2 = NULL;
81 struct ibmad_port *srcport;
82 static ib_portid_t portid;
83 static int ib_timeout = 0;
84 static int ibportnum = 0;
88 static int num_counters = 0;
89 static int is_finalized = 0;
94 static ib_port *root_ib_port = NULL;
95 static ib_port *active_ib_port = NULL;
97 #define infiniband_native_table subscriptions 99 #define InitStruct(var, type) type var; memset(&var, 0, sizeof(type)) 115 char names[20][UMAD_CA_NAME_LEN];
127 if ( ( n = (*umad_get_cas_namesPtr)( (
void * )
names, UMAD_CA_NAME_LEN ) ) < 0 ) {
128 fprintf( stderr,
"can't list IB device names\n" );
132 for (
i = 0;
i < n;
i++ ) {
135 if ( ( r = (*umad_get_caPtr)( ca_name, &ca ) ) < 0 ) {
136 fprintf( stderr,
"can't read ca from IB device\n" );
144 for ( portnum = 1; portnum <= ca.numports; portnum++ )
145 addIBPort( ca.ca_name, ca.ports[portnum] );
162 if ( cntr == NULL ) {
163 fprintf( stderr,
"can not allocate memory for new counter\n" );
168 cntr->
unit = strdup( unit );
193 char counter_name[512];
197 if ( nwif == NULL ) {
198 fprintf( stderr,
"can not allocate memory for IB port description\n" );
202 sprintf( counter_name,
"%s_%d", ca_name, port->portnum );
203 nwif->
name = strdup( counter_name );
205 sprintf( counter_name,
"%s_%d_recv", ca_name, port->portnum );
207 addCounter( counter_name,
"bytes received on this IB port",
"bytes" );
209 sprintf( counter_name,
"%s_%d_send", ca_name, port->portnum );
211 addCounter( counter_name,
"bytes written to this IB port",
"bytes" );
220 if ( root_ib_port == NULL ) {
237 int mgmt_classes[4] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS,
241 static uint8_t pc[1024];
244 srcport = (*mad_rpc_open_portPtr)( ca, portdata->
port_number, mgmt_classes, 4 );
246 fprintf( stderr,
"Failed to open '%s' port '%d'\n", ca,
251 if ( (*ib_resolve_self_viaPtr)( &portid, &ibportnum, 0, srcport ) < 0 ) {
252 fprintf( stderr,
"can't resolve self port\n" );
258 if ( !(*pma_query_viaPtr) ( pc, &portid, ibportnum, ib_timeout, CLASS_PORT_INFO, srcport ) ) {
259 fprintf( stderr,
"classportinfo query\n" );
263 if ( !(*performance_reset_viaPtr) ( pc, &portid, ibportnum, mask, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
264 fprintf( stderr,
"perf reset\n" );
269 (*mad_decode_fieldPtr)( pc, IB_PC_XMT_BYTES_F, &portdata->
last_send_val );
271 (*mad_decode_fieldPtr)( pc, IB_PC_RCV_BYTES_F, &portdata->
last_recv_val );
290 uint32_t max_val = 4294967295;
292 uint32_t reset_limit = max_val * 0.7;
295 if ( active_ib_port == NULL )
299 if ( !(*pma_query_viaPtr) ( pc, &portid, ibportnum, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
300 fprintf( stderr,
"perfquery\n" );
304 (*mad_decode_fieldPtr)( pc, IB_PC_XMT_BYTES_F, &send_val );
305 (*mad_decode_fieldPtr)( pc, IB_PC_RCV_BYTES_F, &recv_val );
319 if ( send_val > reset_limit || recv_val > reset_limit ) {
321 if ( !(*performance_reset_viaPtr) ( pc, &portid, ibportnum, mask, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
322 fprintf( stderr,
"perf reset\n" );
326 (*mad_decode_fieldPtr)( pc, IB_PC_XMT_BYTES_F, &active_ib_port->
last_send_val );
327 (*mad_decode_fieldPtr)( pc, IB_PC_RCV_BYTES_F, &active_ib_port->
last_recv_val );
345 if ( subscriptions[
loop] == NULL )
363 while ( local_cntr != NULL ) {
364 if ( strcmp( cntr, local_cntr->
name ) == 0 )
367 local_cntr = local_cntr->
next;
371 gethostname(
tmp, 512 );
372 fprintf( stderr,
"can not find host counter: %s on %s\n", cntr,
tmp );
373 fprintf( stderr,
"we only have: " );
376 while ( local_cntr != NULL ) {
377 fprintf( stderr,
"'%s' ", local_cntr->
name );
378 local_cntr = local_cntr->
next;
382 fprintf( stderr,
"\n" );
403 if ( subscriptions[
loop] == NULL ) {
404 subscriptions[
loop] = counter;
409 if ( ( len = strlen( cntr ) ) > 5 ) {
410 if ( strcmp( &cntr[len - 5],
"_recv" ) == 0 ||
411 strcmp( &cntr[len - 5],
"_send" ) == 0 ) {
413 strncpy( tmp_name, cntr, len - 5 );
414 tmp_name[len - 5] = 0;
417 while ( aktp != NULL ) {
418 if ( strcmp( aktp->
name, tmp_name ) == 0 ) {
421 active_ib_port = aktp;
430 "unable to activate IB port monitoring for more than one port\n" );
441 fprintf( stderr,
"please subscribe only once to each counter\n" );
458 if ( list == NULL ) {
459 fprintf( stderr,
"unable to allocate memory for new string_list" );
463 list->
data = (
char ** ) malloc( num_counters1 *
sizeof (
char * ) );
465 if ( list->
data == NULL ) {
467 "unable to allocate memory for %d pointers in a new string_list\n",
472 while ( cntr != NULL ) {
494 while ( cntr != NULL ) {
507 while (
last != NULL ) {
529 if ( to_delete->
data != NULL ) {
533 free( to_delete->
data );
565 subscriptions[
loop] = NULL;
569 for (
i = 0;
i < counter_list->
count;
i++ )
592 SUBDBG (
"Dynamic link of Infiniband libraries failed, component will be disabled.\n");
593 SUBDBG (
"See disable reason in papi_component_avail output for more details.\n");
598 if ( (*umad_initPtr)( ) < 0 ) {
604 _papi_hwd_infiniband_register_start[
i] = -1;
605 _papi_hwd_infiniband_register[
i] = -1;
631 dl1 = dlopen(
"libibumad.so", RTLD_NOW | RTLD_GLOBAL);
637 umad_initPtr = dlsym(
dl1,
"umad_init");
638 if (dlerror() != NULL)
643 umad_get_cas_namesPtr = dlsym(
dl1,
"umad_get_cas_names");
644 if (dlerror() != NULL)
649 umad_get_caPtr = dlsym(
dl1,
"umad_get_ca");
650 if (dlerror() != NULL)
657 dl2 = dlopen(
"libibmad.so", RTLD_NOW | RTLD_GLOBAL);
663 mad_decode_fieldPtr = dlsym(
dl2,
"mad_decode_field");
664 if (dlerror() != NULL)
669 mad_rpc_open_portPtr = dlsym(
dl2,
"mad_rpc_open_port");
670 if (dlerror() != NULL)
675 ib_resolve_self_viaPtr = dlsym(
dl2,
"ib_resolve_self_via");
676 if (dlerror() != NULL)
681 performance_reset_viaPtr = dlsym(
dl2,
"performance_reset_via");
682 if (dlerror() != NULL)
687 pma_query_viaPtr = dlsym(
dl2,
"pma_query_via");
688 if (dlerror() != NULL)
721 memcpy( _papi_hwd_infiniband_register, _papi_hwd_infiniband_register_start,
741 _papi_hwd_infiniband_register[
i] -
742 _papi_hwd_infiniband_register_start[
i];
763 _papi_hwd_infiniband_register[
i] -
764 _papi_hwd_infiniband_register_start[
i];
873 int index = *EventCode;
876 *EventCode = *EventCode + 1;
929 .
name =
"infiniband_umad",
930 .short_name=
"infiniband_umad",
932 .description =
"Infiniband statistics (for OFED versions < 1.4)",
942 .fast_real_timer = 0,
943 .fast_virtual_timer = 0,
945 .attach_must_ptrace = 0,
static string_list * host_listCounter(int num_counters1)
char disabled_reason[PAPI_MAX_STR_LEN]
static void init_ib_counter()
struct counter_info_struct * next
int INFINIBAND_set_domain(hwd_control_state_t *cntrl, int domain)
int INFINIBAND_shutdown_thread(hwd_context_t *ctx)
static int linkInfinibandLibraries()
counter_info INFINIBAND_register_t
int INFINIBAND_ntv_code_to_name(unsigned int EventCode, char *name, int len)
This file has the source code for a component that enables PAPI-C to access hardware monitoring count...
static void host_deleteStringList(string_list *to_delete)
PAPI_component_info_t cmp_info
Return codes and api definitions.
char events[MAX_EVENTS][BUFSIZ]
int INFINIBAND_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
int INFINIBAND_read(hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long **events, int flags)
static int read_ib_counter()
int INFINIBAND_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
int INFINIBAND_start(hwd_context_t *ctx, hwd_control_state_t *ctrl)
int INFINIBAND_init_component(int cidx)
static counter_info * counterFromName(const char *cntr)
void host_read_values(long long *data)
int INFINIBAND_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
__attribute__((constructor))
void(* _dl_non_dynamic_init)(void)
#define SUBDBG(format, args...)
struct ib_port_struct * next
int INFINIBAND_stop(hwd_context_t *ctx, hwd_control_state_t *ctrl)
#define infiniband_native_table
static counter_info * addCounter(const char *name, const char *desc, const char *unit)
char name[PAPI_MAX_STR_LEN]
static struct temp_event * last
static int is_initialized
int INFINIBAND_ntv_code_to_bits(unsigned int EventCode, hwd_register_t *bits)
int INFINIBAND_init_thread(hwd_context_t *ctx)
int INFINIBAND_reset(hwd_context_t *ctx, hwd_control_state_t *ctrl)
#define InitStruct(var, type)
static void addIBPort(const char *ca_name, umad_port_t *port)
int INFINIBAND_shutdown_component(void)
static ib_counter_t * root_counter
int INFINIBAND_ntv_enum_events(unsigned int *EventCode, int modifier)
static uint64_t host_subscribe(const char *cntr)
int INFINIBAND_init_control_state(hwd_control_state_t *ctrl)
static int init_ib_port(ib_port *portdata)
papi_vector_t _infiniband_umad_vector
const char * names[NUM_EVENTS]
#define INFINIBAND_MAX_COUNTERS
static void host_finalize()