PAPI  5.7.0.0
linux-infiniband_umad.c File Reference

This file has the source code for a component that enables PAPI-C to access hardware monitoring counters for InfiniBand devices through the. More...

Include dependency graph for linux-infiniband_umad.c:

Go to the source code of this file.

Macros

#define infiniband_native_table   subscriptions
 
#define InitStruct(var, type)   type var; memset(&var, 0, sizeof(type))
 

Functions

static counter_infoaddCounter (const char *name, const char *desc, const char *unit)
 
static void addIBPort (const char *ca_name, umad_port_t *port)
 
static int init_ib_port (ib_port *portdata)
 
static int read_ib_counter ()
 
void host_read_values (long long *data)
 
static counter_infocounterFromName (const char *cntr)
 
static uint64_t host_subscribe (const char *cntr)
 
static string_listhost_listCounter (int num_counters1)
 
static void host_finalize ()
 
static void host_deleteStringList (string_list *to_delete)
 
int INFINIBAND_init_thread (hwd_context_t *ctx)
 
int INFINIBAND_init_component (int cidx)
 
static int linkInfinibandLibraries ()
 
int INFINIBAND_init_control_state (hwd_control_state_t *ctrl)
 
int INFINIBAND_start (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int INFINIBAND_stop (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int INFINIBAND_read (hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long **events, int flags)
 
int INFINIBAND_shutdown_thread (hwd_context_t *ctx)
 
int INFINIBAND_shutdown_component (void)
 
int INFINIBAND_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int INFINIBAND_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int INFINIBAND_set_domain (hwd_control_state_t *cntrl, int domain)
 
int INFINIBAND_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int INFINIBAND_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int INFINIBAND_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int INFINIBAND_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int INFINIBAND_ntv_code_to_bits (unsigned int EventCode, hwd_register_t *bits)
 

Variables

void(* _dl_non_dynamic_init )(void)
 
papi_vector_t _infiniband_umad_vector
 

Detailed Description

Author
Heike Jagode (in collaboration with Michael Kluge, TU Dresden) jagod.nosp@m.e@ee.nosp@m.cs.ut.nosp@m.k.ed.nosp@m.u
Tony Castaldo; minor changes; the infiniband_umad.h differs on the declaration of umad_get_ca(), and demands a const char* instead of a char*. Corrected the prototypes below.

InfiniBand component

Tested version of OFED: 1.4

OFED library. Since a new interface was introduced with OFED version 1.4 (released Dec 2008), the current InfiniBand component does not support OFED versions < 1.4.

Definition in file linux-infiniband_umad.c.

Macro Definition Documentation

◆ infiniband_native_table

#define infiniband_native_table   subscriptions

◆ InitStruct

#define InitStruct (   var,
  type 
)    type var; memset(&var, 0, sizeof(type))

Function Documentation

◆ addCounter()

static counter_info* addCounter ( const char *  name,
const char *  desc,
const char *  unit 
)
static

add a counter to the list of available counters

Parameters
namethe short name of the counter
desca longer description
unitthe unit for this counter

Definition at line 157 of file linux-infiniband_umad.c.

158 {
159  counter_info *cntr, *last;
160 
161  cntr = ( counter_info * ) malloc( sizeof ( counter_info ) );
162  if ( cntr == NULL ) {
163  fprintf( stderr, "can not allocate memory for new counter\n" );
164  exit( 1 );
165  }
166  cntr->name = strdup( name );
167  cntr->description = strdup( desc );
168  cntr->unit = strdup( unit );
169  cntr->value = 0;
170  cntr->next = NULL;
171 
172  if ( root_counter == NULL ) {
173  root_counter = cntr;
174  } else {
175  last = root_counter;
176  while ( last->next != NULL )
177  last = last->next;
178  last->next = cntr;
179  }
180 
181  return cntr;
182 }
static const char * name
Definition: fork_overflow.c:31
struct counter_info_struct * next
struct temp_event * next
static struct temp_event * last
static ib_counter_t * root_counter
void exit()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addIBPort()

static void addIBPort ( const char *  ca_name,
umad_port_t *  port 
)
static

add one IB port to the list of available ports and add the counters related to this port to the global counter list

Definition at line 190 of file linux-infiniband_umad.c.

191 {
192  ib_port *nwif, *last;
193  char counter_name[512];
194 
195  nwif = ( ib_port * ) malloc( sizeof ( ib_port ) );
196 
197  if ( nwif == NULL ) {
198  fprintf( stderr, "can not allocate memory for IB port description\n" );
199  exit( 1 );
200  }
201 
202  sprintf( counter_name, "%s_%d", ca_name, port->portnum );
203  nwif->name = strdup( counter_name );
204 
205  sprintf( counter_name, "%s_%d_recv", ca_name, port->portnum );
206  nwif->recv_cntr =
207  addCounter( counter_name, "bytes received on this IB port", "bytes" );
208 
209  sprintf( counter_name, "%s_%d_send", ca_name, port->portnum );
210  nwif->send_cntr =
211  addCounter( counter_name, "bytes written to this IB port", "bytes" );
212 
213  nwif->port_rate = port->rate;
214  nwif->is_initialized = 0;
215  nwif->port_number = port->portnum;
216  nwif->next = NULL;
217 
218  num_counters += 2;
219 
220  if ( root_ib_port == NULL ) {
221  root_ib_port = nwif;
222  } else {
223  last = root_ib_port;
224  while ( last->next != NULL )
225  last = last->next;
226  last->next = nwif;
227  }
228 }
counter_info * send_cntr
counter_info * recv_cntr
struct temp_event * next
struct ib_port_struct * next
static counter_info * addCounter(const char *name, const char *desc, const char *unit)
static struct temp_event * last
void exit()
Here is the call graph for this function:

◆ counterFromName()

static counter_info* counterFromName ( const char *  cntr)
static

find the pointer for a counter_info structure based on the counter name

Definition at line 357 of file linux-infiniband_umad.c.

358 {
359  int loop = 0;
360  char tmp[512];
361  counter_info *local_cntr = root_counter;
362 
363  while ( local_cntr != NULL ) {
364  if ( strcmp( cntr, local_cntr->name ) == 0 )
365  return local_cntr;
366 
367  local_cntr = local_cntr->next;
368  loop++;
369  }
370 
371  gethostname( tmp, 512 );
372  fprintf( stderr, "can not find host counter: %s on %s\n", cntr, tmp );
373  fprintf( stderr, "we only have: " );
374  local_cntr = root_counter;
375 
376  while ( local_cntr != NULL ) {
377  fprintf( stderr, "'%s' ", local_cntr->name );
378  local_cntr = local_cntr->next;
379  loop++;
380  }
381 
382  fprintf( stderr, "\n" );
383  exit( 1 );
384  /* never reached */
385  return 0;
386 }
struct counter_info_struct * next
double loop(long n)
Definition: kufrin.c:26
double tmp
static ib_counter_t * root_counter
void exit()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_deleteStringList()

static void host_deleteStringList ( string_list to_delete)
static

delete a list of strings

Definition at line 525 of file linux-infiniband_umad.c.

526 {
527  int loop;
528 
529  if ( to_delete->data != NULL ) {
530  for ( loop = 0; loop < to_delete->count; loop++ )
531  free( to_delete->data[loop] );
532 
533  free( to_delete->data );
534  }
535 
536  free( to_delete );
537 }
double loop(long n)
Definition: kufrin.c:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_finalize()

static void host_finalize ( void  )
static

finalizes the library

Definition at line 485 of file linux-infiniband_umad.c.

486 {
487  counter_info *cntr, *next;
488 
489  if ( is_finalized )
490  return;
491 
492  cntr = root_counter;
493 
494  while ( cntr != NULL ) {
495  next = cntr->next;
496  free( cntr->name );
497  free( cntr->description );
498  free( cntr->unit );
499  free( cntr );
500  cntr = next;
501  }
502 
503  root_counter = NULL;
504 
505  ib_port *nwif, *last;
506  last = root_ib_port;
507  while ( last != NULL ) { // While we have ports;
508  nwif = last; // Copy the pointer.
509  last = last->next; // update the loop pointer now.
510  if (nwif->name) free(nwif->name); // Free any name malloc.
511 
512  free(nwif); // free the chain link itself.
513  }
514 
515  root_ib_port = NULL; // All done with this.
516 
517  is_finalized = 1;
518 } // end host_finalize()
struct counter_info_struct * next
struct temp_event * next
static struct temp_event * last
static ib_counter_t * root_counter
Here is the caller graph for this function:

◆ host_listCounter()

static string_list* host_listCounter ( int  num_counters1)
static

return a newly allocated list of strings containing all counter names

Definition at line 452 of file linux-infiniband_umad.c.

453 {
454  string_list *list;
455  counter_info *cntr = root_counter;
456 
457  list = malloc( sizeof ( string_list ) );
458  if ( list == NULL ) {
459  fprintf( stderr, "unable to allocate memory for new string_list" );
460  exit( 1 );
461  }
462  list->count = 0;
463  list->data = ( char ** ) malloc( num_counters1 * sizeof ( char * ) );
464 
465  if ( list->data == NULL ) {
466  fprintf( stderr,
467  "unable to allocate memory for %d pointers in a new string_list\n",
468  num_counters1 );
469  exit( 1 );
470  }
471 
472  while ( cntr != NULL ) {
473  list->data[list->count++] = strdup( cntr->name );
474  cntr = cntr->next;
475  }
476 
477  return list;
478 }
struct counter_info_struct * next
static ib_counter_t * root_counter
void exit()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_read_values()

void host_read_values ( long long *  data)

Definition at line 338 of file linux-infiniband_umad.c.

339 {
340  int loop;
341 
342  read_ib_counter( );
343 
344  for ( loop = 0; loop < INFINIBAND_MAX_COUNTERS; loop++ ) {
345  if ( subscriptions[loop] == NULL )
346  break;
347 
348  data[loop] = subscriptions[loop]->value;
349  }
350 }
double loop(long n)
Definition: kufrin.c:26
static int read_ib_counter()
#define INFINIBAND_MAX_COUNTERS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_subscribe()

static uint64_t host_subscribe ( const char *  cntr)
static

allow external code to subscribe to a counter based on the counter name

Definition at line 393 of file linux-infiniband_umad.c.

394 {
395  int loop;
396  int len;
397  char tmp_name[512];
398  ib_port *aktp;
399 
400  counter_info *counter = counterFromName( cntr );
401 
402  for ( loop = 0; loop < INFINIBAND_MAX_COUNTERS; loop++ ) {
403  if ( subscriptions[loop] == NULL ) {
404  subscriptions[loop] = counter;
405  counter->idx = loop;
406 
407  /* we have an IB counter if the name ends with _send or _recv and
408  the prefix before that is in the ib_port list */
409  if ( ( len = strlen( cntr ) ) > 5 ) {
410  if ( strcmp( &cntr[len - 5], "_recv" ) == 0 ||
411  strcmp( &cntr[len - 5], "_send" ) == 0 ) {
412  /* look through all IB_counters */
413  strncpy( tmp_name, cntr, len - 5 );
414  tmp_name[len - 5] = 0;
415  aktp = root_ib_port;
416  // printf("looking for IB port '%s'\n", tmp_name);
417  while ( aktp != NULL ) {
418  if ( strcmp( aktp->name, tmp_name ) == 0 ) {
419  if ( !aktp->is_initialized ) {
420  init_ib_port( aktp );
421  active_ib_port = aktp;
422  }
423  return loop + 1;
424  }
425  /* name does not match, if this counter is
426  initialized, we can't have two active IB ports */
427  if ( aktp->is_initialized ) {
428 #if 0 /* not necessary with OFED version >= 1.4 */
429  fprintf( stderr,
430  "unable to activate IB port monitoring for more than one port\n" );
431  exit( 1 );
432 #endif
433  }
434  aktp = aktp->next;
435  }
436  }
437  }
438  return loop + 1;
439  }
440  }
441  fprintf( stderr, "please subscribe only once to each counter\n" );
442  exit( 1 );
443  /* never reached */
444  return 0;
445 }
double loop(long n)
Definition: kufrin.c:26
static counter_info * counterFromName(const char *cntr)
struct ib_port_struct * next
static int init_ib_port(ib_port *portdata)
void exit()
#define INFINIBAND_MAX_COUNTERS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ INFINIBAND_ctl()

int INFINIBAND_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

Definition at line 803 of file linux-infiniband_umad.c.

804 {
805  ( void ) ctx;
806  ( void ) code;
807  ( void ) option;
808  return ( PAPI_OK );
809 }
#define PAPI_OK
Definition: fpapi.h:105

◆ INFINIBAND_init_component()

int INFINIBAND_init_component ( int  cidx)

Definition at line 585 of file linux-infiniband_umad.c.

586 {
587  SUBDBG ("Entry: cidx: %d\n", cidx);
588  int i;
589 
590  /* link in all the infiniband libraries and resolve the symbols we need to use */
591  if (linkInfinibandLibraries() != PAPI_OK) {
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");
594  return (PAPI_ENOSUPP);
595  }
596 
597  /* make sure that the infiniband library finds the kernel module loaded. */
598  if ( (*umad_initPtr)( ) < 0 ) {
599  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Call to initialize umad library failed.",PAPI_MAX_STR_LEN);
600  return ( PAPI_ENOSUPP );
601  }
602 
603  for ( i = 0; i < INFINIBAND_MAX_COUNTERS; i++ ) {
604  _papi_hwd_infiniband_register_start[i] = -1;
605  _papi_hwd_infiniband_register[i] = -1;
606  }
607 
608  /* Export the component id */
610 
611  return ( PAPI_OK );
612 }
#define PAPI_OK
Definition: fpapi.h:105
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
#define PAPI_ENOSUPP
Definition: fpapi.h:123
static int linkInfinibandLibraries()
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static int cidx
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
papi_vector_t _infiniband_umad_vector
#define INFINIBAND_MAX_COUNTERS
int i
Definition: fileop.c:140
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function:

◆ INFINIBAND_init_control_state()

int INFINIBAND_init_control_state ( hwd_control_state_t ctrl)

Definition at line 703 of file linux-infiniband_umad.c.

704 {
705  ( void ) ctrl;
706  return PAPI_OK;
707 }
#define PAPI_OK
Definition: fpapi.h:105

◆ INFINIBAND_init_thread()

int INFINIBAND_init_thread ( hwd_context_t ctx)

Definition at line 548 of file linux-infiniband_umad.c.

549 {
550  string_list *counter_list = NULL;
551  int i;
552  int loop;
553 
554  /* initialize portid struct of type ib_portid_t to 0 */
555  InitStruct( portid, ib_portid_t );
556 
557  if ( is_initialized )
558  return PAPI_OK;
559 
560  is_initialized = 1;
561 
562  init_ib_counter( );
563 
564  for ( loop = 0; loop < INFINIBAND_MAX_COUNTERS; loop++ )
565  subscriptions[loop] = NULL;
566 
567  counter_list = host_listCounter( num_counters );
568 
569  for ( i = 0; i < counter_list->count; i++ )
570  host_subscribe( counter_list->data[i] );
571 
572  ( ( INFINIBAND_context_t * ) ctx )->state.ncounter = counter_list->count;
573 
574  host_deleteStringList( counter_list );
575 
576  return PAPI_OK;
577 }
#define PAPI_OK
Definition: fpapi.h:105
static string_list * host_listCounter(int num_counters1)
static void init_ib_counter()
static void host_deleteStringList(string_list *to_delete)
double loop(long n)
Definition: kufrin.c:26
static int is_initialized
#define InitStruct(var, type)
static uint64_t host_subscribe(const char *cntr)
#define INFINIBAND_MAX_COUNTERS
int i
Definition: fileop.c:140
Here is the call graph for this function:

◆ INFINIBAND_ntv_code_to_bits()

int INFINIBAND_ntv_code_to_bits ( unsigned int  EventCode,
hwd_register_t bits 
)

Definition at line 913 of file linux-infiniband_umad.c.

914 {
915  memcpy( ( INFINIBAND_register_t * ) bits,
916  infiniband_native_table[EventCode],
917  sizeof ( INFINIBAND_register_t ) );
918 
919  return PAPI_OK;
920 }
#define PAPI_OK
Definition: fpapi.h:105
#define infiniband_native_table

◆ INFINIBAND_ntv_code_to_descr()

int INFINIBAND_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 901 of file linux-infiniband_umad.c.

902 {
903  strncpy( name, infiniband_native_table[EventCode]->description, len );
904 
905  return PAPI_OK;
906 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
#define infiniband_native_table

◆ INFINIBAND_ntv_code_to_name()

int INFINIBAND_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 889 of file linux-infiniband_umad.c.

890 {
891  strncpy( name, infiniband_native_table[EventCode]->name, len );
892 
893  return PAPI_OK;
894 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
#define infiniband_native_table

◆ INFINIBAND_ntv_enum_events()

int INFINIBAND_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Definition at line 865 of file linux-infiniband_umad.c.

866 {
867  if ( modifier == PAPI_ENUM_FIRST ) {
868  *EventCode = 0;
869  return PAPI_OK;
870  }
871 
872  if ( modifier == PAPI_ENUM_EVENTS ) {
873  int index = *EventCode;
874 
875  if ( infiniband_native_table[index + 1] ) {
876  *EventCode = *EventCode + 1;
877  return ( PAPI_OK );
878  } else
879  return ( PAPI_ENOEVNT );
880  } else
881  return ( PAPI_EINVAL );
882 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define infiniband_native_table
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ INFINIBAND_read()

int INFINIBAND_read ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long_long **  events,
int  flags 
)

Definition at line 753 of file linux-infiniband_umad.c.

755 {
756  int i;
757  ( void ) flags;
758 
759  host_read_values( _papi_hwd_infiniband_register );
760 
761  for ( i = 0; i < ( ( INFINIBAND_context_t * ) ctx )->state.ncounter; i++ ) {
762  ( ( INFINIBAND_control_state_t * ) ctrl )->counts[i] =
763  _papi_hwd_infiniband_register[i] -
764  _papi_hwd_infiniband_register_start[i];
765  }
766 
767  *events = ( ( INFINIBAND_control_state_t * ) ctrl )->counts;
768  return ( PAPI_OK );
769 }
#define PAPI_OK
Definition: fpapi.h:105
char events[MAX_EVENTS][BUFSIZ]
void host_read_values(long long *data)
int i
Definition: fileop.c:140
Here is the call graph for this function:

◆ INFINIBAND_reset()

int INFINIBAND_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 854 of file linux-infiniband_umad.c.

855 {
856  INFINIBAND_start( ctx, ctrl );
857  return ( PAPI_OK );
858 }
#define PAPI_OK
Definition: fpapi.h:105
int INFINIBAND_start(hwd_context_t *ctx, hwd_control_state_t *ctrl)
Here is the call graph for this function:

◆ INFINIBAND_set_domain()

int INFINIBAND_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

Definition at line 840 of file linux-infiniband_umad.c.

841 {
842  (void) cntrl;
843  if ( PAPI_DOM_ALL != domain )
844  return ( PAPI_EINVAL );
845 
846  return ( PAPI_OK );
847 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define PAPI_DOM_ALL
Definition: fpapi.h:25

◆ INFINIBAND_shutdown_component()

int INFINIBAND_shutdown_component ( void  )

Definition at line 788 of file linux-infiniband_umad.c.

789 {
790  // close the dynamic libraries needed by this component (opened in the init substrate call)
791  dlclose(dl1);
792  dlclose(dl2);
793 
794  return ( PAPI_OK );
795 } // end Shutdown component.
#define PAPI_OK
Definition: fpapi.h:105
static void * dl1
Definition: linux-cuda.c:110
static void * dl2
Definition: linux-cuda.c:111

◆ INFINIBAND_shutdown_thread()

int INFINIBAND_shutdown_thread ( hwd_context_t ctx)

Definition at line 776 of file linux-infiniband_umad.c.

777 {
778  ( void ) ctx;
779  host_finalize( );
780  return ( PAPI_OK );
781 }
#define PAPI_OK
Definition: fpapi.h:105
static void host_finalize()
Here is the call graph for this function:

◆ INFINIBAND_start()

int INFINIBAND_start ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 714 of file linux-infiniband_umad.c.

715 {
716  ( void ) ctx;
717  ( void ) ctrl;
718 
719  host_read_values( _papi_hwd_infiniband_register_start );
720 
721  memcpy( _papi_hwd_infiniband_register, _papi_hwd_infiniband_register_start,
722  INFINIBAND_MAX_COUNTERS * sizeof ( long long ) );
723 
724  return ( PAPI_OK );
725 }
#define PAPI_OK
Definition: fpapi.h:105
void host_read_values(long long *data)
#define INFINIBAND_MAX_COUNTERS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ INFINIBAND_stop()

int INFINIBAND_stop ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 732 of file linux-infiniband_umad.c.

733 {
734  int i;
735  ( void ) ctx;
736 
737  host_read_values( _papi_hwd_infiniband_register );
738 
739  for ( i = 0; i < ( ( INFINIBAND_context_t * ) ctx )->state.ncounter; i++ ) {
740  ( ( INFINIBAND_control_state_t * ) ctrl )->counts[i] =
741  _papi_hwd_infiniband_register[i] -
742  _papi_hwd_infiniband_register_start[i];
743  }
744 
745  return ( PAPI_OK );
746 }
#define PAPI_OK
Definition: fpapi.h:105
void host_read_values(long long *data)
int i
Definition: fileop.c:140
Here is the call graph for this function:

◆ INFINIBAND_update_control_state()

int INFINIBAND_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 819 of file linux-infiniband_umad.c.

822 {
823  ( void ) ptr;
824  ( void ) ctx;
825  int i, index;
826 
827  for ( i = 0; i < count; i++ ) {
828  index = native[i].ni_event;
829  native[i].ni_position = index;
830  }
831 
832  return ( PAPI_OK );
833 }
#define PAPI_OK
Definition: fpapi.h:105
static int native
static long count
int i
Definition: fileop.c:140

◆ init_ib_port()

static int init_ib_port ( ib_port portdata)
static

initialize one IB port so that we are able to read values from it

Definition at line 235 of file linux-infiniband_umad.c.

236 {
237  int mgmt_classes[4] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS,
238  IB_PERFORMANCE_CLASS
239  };
240  char *ca = 0;
241  static uint8_t pc[1024];
242  int mask = 0xFFFF;
243 
244  srcport = (*mad_rpc_open_portPtr)( ca, portdata->port_number, mgmt_classes, 4 );
245  if ( !srcport ) {
246  fprintf( stderr, "Failed to open '%s' port '%d'\n", ca,
247  portdata->port_number );
248  exit( 1 );
249  }
250 
251  if ( (*ib_resolve_self_viaPtr)( &portid, &ibportnum, 0, srcport ) < 0 ) {
252  fprintf( stderr, "can't resolve self port\n" );
253  exit( 1 );
254  }
255 
256  /* PerfMgt ClassPortInfo is a required attribute */
257  /* might be redundant, could be left out for fast implementation */
258  if ( !(*pma_query_viaPtr) ( pc, &portid, ibportnum, ib_timeout, CLASS_PORT_INFO, srcport ) ) {
259  fprintf( stderr, "classportinfo query\n" );
260  exit( 1 );
261  }
262 
263  if ( !(*performance_reset_viaPtr) ( pc, &portid, ibportnum, mask, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
264  fprintf( stderr, "perf reset\n" );
265  exit( 1 );
266  }
267 
268  /* read the initial values */
269  (*mad_decode_fieldPtr)( pc, IB_PC_XMT_BYTES_F, &portdata->last_send_val );
270  portdata->sum_send_val = 0;
271  (*mad_decode_fieldPtr)( pc, IB_PC_RCV_BYTES_F, &portdata->last_recv_val );
272  portdata->sum_recv_val = 0;
273 
274  portdata->is_initialized = 1;
275 
276  return 0;
277 }
uint32_t last_recv_val
uint32_t last_send_val
uint64_t sum_send_val
void exit()
uint64_t sum_recv_val
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linkInfinibandLibraries()

static int linkInfinibandLibraries ( )
static

Definition at line 622 of file linux-infiniband_umad.c.

623 {
624  /* Attempt to guess if we were statically linked to libc, if so bail */
625  if ( _dl_non_dynamic_init != NULL ) {
626  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "The Infiniband component does not support statically linking of libc.", PAPI_MAX_STR_LEN);
627  return PAPI_ENOSUPP;
628  }
629 
630  /* Need to link in the Infiniband libraries, if not found disable the component */
631  dl1 = dlopen("libibumad.so", RTLD_NOW | RTLD_GLOBAL);
632  if (!dl1)
633  {
634  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband library libibumad.so not found.",PAPI_MAX_STR_LEN);
635  return ( PAPI_ENOSUPP );
636  }
637  umad_initPtr = dlsym(dl1, "umad_init");
638  if (dlerror() != NULL)
639  {
640  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function umad_init not found.",PAPI_MAX_STR_LEN);
641  return ( PAPI_ENOSUPP );
642  }
643  umad_get_cas_namesPtr = dlsym(dl1, "umad_get_cas_names");
644  if (dlerror() != NULL)
645  {
646  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function umad_get_cas_names not found.",PAPI_MAX_STR_LEN);
647  return ( PAPI_ENOSUPP );
648  }
649  umad_get_caPtr = dlsym(dl1, "umad_get_ca");
650  if (dlerror() != NULL)
651  {
652  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function umad_get_ca not found.",PAPI_MAX_STR_LEN);
653  return ( PAPI_ENOSUPP );
654  }
655 
656  /* Need to link in the Infiniband libraries, if not found disable the component */
657  dl2 = dlopen("libibmad.so", RTLD_NOW | RTLD_GLOBAL);
658  if (!dl2)
659  {
660  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband library libibmad.so not found.",PAPI_MAX_STR_LEN);
661  return ( PAPI_ENOSUPP );
662  }
663  mad_decode_fieldPtr = dlsym(dl2, "mad_decode_field");
664  if (dlerror() != NULL)
665  {
666  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function mad_decode_field not found.",PAPI_MAX_STR_LEN);
667  return ( PAPI_ENOSUPP );
668  }
669  mad_rpc_open_portPtr = dlsym(dl2, "mad_rpc_open_port");
670  if (dlerror() != NULL)
671  {
672  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function mad_rpc_open_port not found.",PAPI_MAX_STR_LEN);
673  return ( PAPI_ENOSUPP );
674  }
675  ib_resolve_self_viaPtr = dlsym(dl2, "ib_resolve_self_via");
676  if (dlerror() != NULL)
677  {
678  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function ib_resolve_self_via not found.",PAPI_MAX_STR_LEN);
679  return ( PAPI_ENOSUPP );
680  }
681  performance_reset_viaPtr = dlsym(dl2, "performance_reset_via");
682  if (dlerror() != NULL)
683  {
684  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function performance_reset_via not found.",PAPI_MAX_STR_LEN);
685  return ( PAPI_ENOSUPP );
686  }
687  pma_query_viaPtr = dlsym(dl2, "pma_query_via");
688  if (dlerror() != NULL)
689  {
690  strncpy(_infiniband_umad_vector.cmp_info.disabled_reason, "Infiniband function pma_query_via not found.",PAPI_MAX_STR_LEN);
691  return ( PAPI_ENOSUPP );
692  }
693 
694  return ( PAPI_OK );
695 }
#define PAPI_OK
Definition: fpapi.h:105
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
#define PAPI_ENOSUPP
Definition: fpapi.h:123
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static void * dl1
Definition: linux-cuda.c:110
static void * dl2
Definition: linux-cuda.c:111
void(* _dl_non_dynamic_init)(void)
papi_vector_t _infiniband_umad_vector
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the caller graph for this function:

◆ read_ib_counter()

static int read_ib_counter ( )
static

read and reset IB counters (reset on demand)

Definition at line 284 of file linux-infiniband_umad.c.

285 {
286  uint32_t send_val;
287  uint32_t recv_val;
288  uint8_t pc[1024];
289  /* 32 bit counter FFFFFFFF */
290  uint32_t max_val = 4294967295;
291  /* if it is bigger than this -> reset */
292  uint32_t reset_limit = max_val * 0.7;
293  int mask = 0xFFFF;
294 
295  if ( active_ib_port == NULL )
296  return 0;
297 
298  /* reading cost ~70 mirco secs */
299  if ( !(*pma_query_viaPtr) ( pc, &portid, ibportnum, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
300  fprintf( stderr, "perfquery\n" );
301  exit( 1 );
302  }
303 
304  (*mad_decode_fieldPtr)( pc, IB_PC_XMT_BYTES_F, &send_val );
305  (*mad_decode_fieldPtr)( pc, IB_PC_RCV_BYTES_F, &recv_val );
306 
307  /* multiply the numbers read by 4 as the IB port counters are not
308  counting bytes. they always count 32dwords. see man page of
309  perfquery for details
310  internally a uint64_t ia used to sum up the values */
311  active_ib_port->sum_send_val +=
312  ( send_val - active_ib_port->last_send_val ) * 4;
313  active_ib_port->sum_recv_val +=
314  ( recv_val - active_ib_port->last_recv_val ) * 4;
315 
316  active_ib_port->send_cntr->value = active_ib_port->sum_send_val;
317  active_ib_port->recv_cntr->value = active_ib_port->sum_recv_val;
318 
319  if ( send_val > reset_limit || recv_val > reset_limit ) {
320  /* reset cost ~70 mirco secs */
321  if ( !(*performance_reset_viaPtr) ( pc, &portid, ibportnum, mask, ib_timeout, IB_GSI_PORT_COUNTERS, srcport ) ) {
322  fprintf( stderr, "perf reset\n" );
323  exit( 1 );
324  }
325 
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 );
328  } else {
329  active_ib_port->last_send_val = send_val;
330  active_ib_port->last_recv_val = recv_val;
331  }
332 
333  return 0;
334 }
void exit()
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _dl_non_dynamic_init

void(* _dl_non_dynamic_init) (void)

use libumad to discover IB ports

Definition at line 36 of file linux-infiniband_umad.c.

114 {
115  char names[20][UMAD_CA_NAME_LEN];
116  int n, i;
117  char *ca_name;
118  umad_ca_t ca;
119  int r;
120  int portnum;
121 
122 // if ( umad_init( ) < 0 ) {
123 // fprintf( stderr, "can't init UMAD library\n" );
124 // exit( 1 );
125 // }
126 
127  if ( ( n = (*umad_get_cas_namesPtr)( ( void * ) names, UMAD_CA_NAME_LEN ) ) < 0 ) {
128  fprintf( stderr, "can't list IB device names\n" );
129  exit( 1 );
130  }
131 
132  for ( i = 0; i < n; i++ ) {
133  ca_name = names[i];
134 
135  if ( ( r = (*umad_get_caPtr)( ca_name, &ca ) ) < 0 ) {
136  fprintf( stderr, "can't read ca from IB device\n" );
137  exit( 1 );
138  }
139 
140  if ( !ca.node_type )
141  continue;
142 
143  /* port numbers are '1' based in OFED */
144  for ( portnum = 1; portnum <= ca.numports; portnum++ )
145  addIBPort( ca.ca_name, ca.ports[portnum] );
146  }
147 }
static void addIBPort(const char *ca_name, umad_port_t *port)
const char * names[NUM_EVENTS]
void exit()
int i
Definition: fileop.c:140

◆ _infiniband_umad_vector

papi_vector_t _infiniband_umad_vector

Definition at line 926 of file linux-infiniband_umad.c.