PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-infiniband.c File Reference

This file has the source code for a component that enables PAPI-C to access the infiniband performance monitor through the Linux sysfs interface. This code will dynamically create a native events table for all the events that can be accesed through the sysfs interface. The counters exported by this component cannot be reset programatically. More...

Include dependency graph for linux-infiniband.c:

Go to the source code of this file.

Data Structures

struct  infiniband_register_t
 
struct  ib_device_t
 
struct  ib_counter_t
 
struct  infiniband_native_event_entry_t
 
struct  infiniband_control_state_t
 
struct  infiniband_context_t
 

Macros

#define INFINIBAND_MAX_COUNTERS   128
 

Functions

static char * make_ib_event_description (const char *input_str, int extended)
 
static ib_device_tadd_ib_device (const char *name, int port)
 
static ib_counter_tadd_ib_counter (const char *name, const char *file_name, int extended, ib_device_t *device)
 
static int find_ib_device_events (ib_device_t *dev, int extended)
 
static int find_ib_devices ()
 
static long long read_ib_counter_value (int index)
 
static void deallocate_infiniband_resources ()
 
static int _infiniband_init_thread (hwd_context_t *ctx)
 
static int _infiniband_init_component (int cidx)
 
static int _infiniband_init_control_state (hwd_control_state_t *ctl)
 
static int _infiniband_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _infiniband_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _infiniband_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long_long **events, int flags)
 
static int _infiniband_shutdown_component (void)
 
static int _infiniband_shutdown_thread (hwd_context_t *ctx)
 
static int _infiniband_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _infiniband_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _infiniband_set_domain (hwd_control_state_t *ctl, int domain)
 
static int _infiniband_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _infiniband_ntv_enum_events (unsigned int *EventCode, int modifier)
 
static int _infiniband_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _infiniband_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static int _infiniband_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 

Variables

static const char * ib_dir_path = "/sys/class/infiniband"
 
static
infiniband_native_event_entry_t
infiniband_native_events = 0
 
static int num_events = 0
 
papi_vector_t _infiniband_vector
 
static ib_device_troot_device = 0
 
static ib_counter_troot_counter = 0
 

Detailed Description

Author
Heike Jagode jagod.nosp@m.e@ic.nosp@m.l.utk.nosp@m..edu
Gabriel Marin gmari.nosp@m.n@ee.nosp@m.cs.ut.nosp@m.k.ed.nosp@m.u

Infiniband component

Definition in file linux-infiniband.c.

Macro Definition Documentation

#define INFINIBAND_MAX_COUNTERS   128

Definition at line 44 of file linux-infiniband.c.

Function Documentation

static int _infiniband_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)
static

Definition at line 626 of file linux-infiniband.c.

627 {
628  ( void ) ctx;
629  ( void ) code;
630  ( void ) option;
631  return PAPI_OK;
632 }
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
static int _infiniband_init_component ( int  cidx)
static

Definition at line 482 of file linux-infiniband.c.

483 {
484  /* discover Infiniband devices and available events */
485  int result = find_ib_devices();
486 
487  if (result != PAPI_OK) // we couldn't initialize the component
488  {
489  // deallocate any eventually allocated memory
491  }
492 
494 
497 
498 
499  /* Export the component id */
501 
502  return (result);
503 }
static void deallocate_infiniband_resources()
static int num_events
return PAPI_OK
Definition: linux-nvml.c:497
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static int cidx
static int find_ib_devices()
papi_vector_t _infiniband_vector

Here is the call graph for this function:

static int _infiniband_init_control_state ( hwd_control_state_t ctl)
static

Definition at line 511 of file linux-infiniband.c.

512 {
514  int i;
515 
516  for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
517  control->being_measured[i] = 0;
518  }
519 
520  return PAPI_OK;
521 }
return PAPI_OK
Definition: linux-nvml.c:497
int i
Definition: fileop.c:140
int being_measured[INFINIBAND_MAX_COUNTERS]
#define INFINIBAND_MAX_COUNTERS
static int _infiniband_init_thread ( hwd_context_t ctx)
static

Definition at line 470 of file linux-infiniband.c.

471 {
472  (void) ctx;
473  return PAPI_OK;
474 }
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
static int _infiniband_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 756 of file linux-infiniband.c.

757 {
758  int index = EventCode;
759 
760  if (index>=0 && index<num_events) {
761  strncpy(name, infiniband_native_events[index].description, len);
762  }
763  return PAPI_OK;
764 }
static infiniband_native_event_entry_t * infiniband_native_events
static int num_events
return PAPI_OK
Definition: linux-nvml.c:497
char * name
Definition: iozone.c:23648
static int _infiniband_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

Definition at line 767 of file linux-infiniband.c.

768 {
769  int index = EventCode;
770 
771  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
772 
773  if (infiniband_native_events[index].name)
774  {
775  unsigned int len = strlen(infiniband_native_events[index].name);
776  if (len > sizeof(info->symbol)-1) len = sizeof(info->symbol)-1;
777  strncpy(info->symbol, infiniband_native_events[index].name, len);
778  info->symbol[len] = '\0';
779  }
780  if (infiniband_native_events[index].description)
781  {
782  unsigned int len = strlen(infiniband_native_events[index].description);
783  if (len > sizeof(info->long_descr)-1) len = sizeof(info->long_descr)-1;
784  strncpy(info->long_descr, infiniband_native_events[index].description, len);
785  info->long_descr[len] = '\0';
786  }
787 
788  strncpy(info->units, "\0", 1);
789  /* infiniband_native_events[index].units, sizeof(info->units)); */
790 
791 /* info->data_type = infiniband_native_events[index].return_type;
792  */
793  return PAPI_OK;
794 }
#define PAPI_ENOEVNT
Definition: papi.h:260
static infiniband_native_event_entry_t * infiniband_native_events
char * name
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
return PAPI_OK
Definition: linux-nvml.c:497
char * description
char * name
Definition: iozone.c:23648
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:975
static int _infiniband_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 741 of file linux-infiniband.c.

742 {
743  int index = EventCode;
744 
745  if (index>=0 && index<num_events) {
746  strncpy( name, infiniband_native_events[index].name, len );
747  }
748 
749  return PAPI_OK;
750 }
static infiniband_native_event_entry_t * infiniband_native_events
static int num_events
return PAPI_OK
Definition: linux-nvml.c:497
char * name
Definition: iozone.c:23648
static int _infiniband_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)
static

Definition at line 709 of file linux-infiniband.c.

710 {
711  switch (modifier) {
712  case PAPI_ENUM_FIRST:
713  if (num_events == 0)
714  return (PAPI_ENOEVNT);
715 
716  *EventCode = 0;
717  return PAPI_OK;
718 
719  case PAPI_ENUM_EVENTS:
720  {
721  int index = *EventCode & PAPI_NATIVE_AND_MASK;
722 
723  if (index < num_events - 1) {
724  *EventCode = *EventCode + 1;
725  return PAPI_OK;
726  } else
727  return PAPI_ENOEVNT;
728 
729  break;
730  }
731  default:
732  return PAPI_EINVAL;
733  }
734  return PAPI_EINVAL;
735 }
#define PAPI_ENOEVNT
Definition: papi.h:260
static int num_events
return PAPI_OK
Definition: linux-nvml.c:497
return PAPI_EINVAL
Definition: linux-nvml.c:436
#define PAPI_NATIVE_AND_MASK
static int _infiniband_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long_long **  events,
int  flags 
)
static

Definition at line 589 of file linux-infiniband.c.

591 {
592  ( void ) flags;
593 
594  _infiniband_stop(ctx, ctl); /* we cannot actually stop the counters */
595  /* Pass back a pointer to our results */
596  *events = ((infiniband_control_state_t*) ctl)->counts;
597 
598  return PAPI_OK;
599 }
long long flags
Definition: iozone.c:12330
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]
static int _infiniband_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)

Here is the call graph for this function:

static int _infiniband_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 697 of file linux-infiniband.c.

698 {
699  (void) ctx;
700  (void) ctl;
701  return PAPI_OK;
702 }
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
static int _infiniband_set_domain ( hwd_control_state_t ctl,
int  domain 
)
static

Definition at line 672 of file linux-infiniband.c.

673 {
674  int found = 0;
675  (void) ctl;
676 
677  if (PAPI_DOM_USER & domain)
678  found = 1;
679 
680  if (PAPI_DOM_KERNEL & domain)
681  found = 1;
682 
683  if (PAPI_DOM_OTHER & domain)
684  found = 1;
685 
686  if (!found)
687  return (PAPI_EINVAL);
688 
689  return (PAPI_OK);
690 }
#define PAPI_DOM_KERNEL
Definition: papi.h:300
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_DOM_USER
Definition: papi.h:298
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:436
long long found
Definition: libasync.c:735
#define PAPI_DOM_OTHER
Definition: papi.h:301
static int _infiniband_shutdown_component ( void  )
static

Definition at line 603 of file linux-infiniband.c.

604 {
605  /* Cleanup resources used by this component before leaving */
607 
608  return PAPI_OK;
609 }
static void deallocate_infiniband_resources()
return PAPI_OK
Definition: linux-nvml.c:497

Here is the call graph for this function:

static int _infiniband_shutdown_thread ( hwd_context_t ctx)
static

Definition at line 612 of file linux-infiniband.c.

613 {
614  ( void ) ctx;
615 
616  return PAPI_OK;
617 }
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
static int _infiniband_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 527 of file linux-infiniband.c.

528 {
529  infiniband_context_t* context = (infiniband_context_t*) ctx;
531  long long now = PAPI_get_real_usec();
532  int i;
533 
534  for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
535  if (control->being_measured[i] && control->need_difference[i]) {
536  context->start_value[i] = read_ib_counter_value(i);
537  }
538  }
539  control->lastupdate = now;
540 
541  return PAPI_OK;
542 }
static long long read_ib_counter_value(int index)
return PAPI_OK
Definition: linux-nvml.c:497
int i
Definition: fileop.c:140
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
int being_measured[INFINIBAND_MAX_COUNTERS]
int need_difference[INFINIBAND_MAX_COUNTERS]
long long start_value[INFINIBAND_MAX_COUNTERS]
#define INFINIBAND_MAX_COUNTERS

Here is the call graph for this function:

static int _infiniband_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 549 of file linux-infiniband.c.

550 {
551  infiniband_context_t* context = (infiniband_context_t*) ctx;
553  long long now = PAPI_get_real_usec();
554  int i;
555  long long temp;
556 
557  for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
558  if (control->being_measured[i])
559  {
560  temp = read_ib_counter_value(i);
561  if (context->start_value[i] && control->need_difference[i]) {
562  /* Must subtract values, but check for wraparound.
563  * We cannot even detect all wraparound cases. Using the short,
564  * auto-resetting IB counters is error prone.
565  */
566  if (temp < context->start_value[i]) {
567  SUBDBG("Wraparound!\nstart:\t%#016x\ttemp:\t%#016x",
568  (unsigned)context->start_value[i], (unsigned)temp);
569  /* The counters auto-reset. I cannot even adjust them to
570  * account for a simple wraparound.
571  * Just use the current reading of the counter, which is useless.
572  */
573  } else
574  temp -= context->start_value[i];
575  }
576  control->counts[i] = temp;
577  }
578  }
579  control->lastupdate = now;
580 
581  return PAPI_OK;
582 }
static long long read_ib_counter_value(int index)
return PAPI_OK
Definition: linux-nvml.c:497
int i
Definition: fileop.c:140
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
long long counts[INFINIBAND_MAX_COUNTERS]
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
int temp
Definition: iozone.c:22158
int being_measured[INFINIBAND_MAX_COUNTERS]
int need_difference[INFINIBAND_MAX_COUNTERS]
long long start_value[INFINIBAND_MAX_COUNTERS]
#define INFINIBAND_MAX_COUNTERS

Here is the call graph for this function:

Here is the caller graph for this function:

static int _infiniband_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)
static

Definition at line 636 of file linux-infiniband.c.

640 {
641  int i, index;
642  ( void ) ctx;
643 
645 
646  for (i=0 ; i<INFINIBAND_MAX_COUNTERS ; ++i) {
647  control->being_measured[i] = 0;
648  }
649 
650  for (i=0 ; i<count ; ++i) {
651  index = native[i].ni_event & PAPI_NATIVE_AND_MASK;
652  native[i].ni_position =
654  control->being_measured[index] = 1;
655  control->need_difference[index] = 1;
656  }
657  return PAPI_OK;
658 }
static infiniband_native_event_entry_t * infiniband_native_events
infiniband_register_t resources
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
#define PAPI_NATIVE_AND_MASK
int being_measured[INFINIBAND_MAX_COUNTERS]
int need_difference[INFINIBAND_MAX_COUNTERS]
#define INFINIBAND_MAX_COUNTERS
static ib_counter_t* add_ib_counter ( const char *  name,
const char *  file_name,
int  extended,
ib_device_t device 
)
static

Definition at line 176 of file linux-infiniband.c.

177 {
178  ib_counter_t *new_cnt = (ib_counter_t*) papi_calloc(sizeof(ib_counter_t), 1);
179  if (new_cnt == 0) {
180  PAPIERROR("cannot allocate memory for new IB counter structure");
181  return (0);
182  }
183 
184  new_cnt->ev_name = strdup(name);
185  new_cnt->ev_file_name = strdup(file_name);
186  new_cnt->extended = extended;
187  new_cnt->ev_device = device;
188  if (new_cnt->ev_name==0 || new_cnt->ev_file_name==0)
189  {
190  PAPIERROR("cannot allocate memory for counter internal fields");
191  papi_free(new_cnt);
192  return (0);
193  }
194 
195  // prepend the new counter to the counter list
196  new_cnt->next = root_counter;
197  root_counter = new_cnt;
198 
199  return (new_cnt);
200 }
#define papi_free(a)
Definition: papi_memory.h:35
void PAPIERROR(char *format,...)
struct _ib_counter_type * next
char * name
Definition: iozone.c:23648
static ib_counter_t * root_counter
ib_device_t * ev_device
#define papi_calloc(a, b)
Definition: papi_memory.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

static ib_device_t* add_ib_device ( const char *  name,
int  port 
)
static

Definition at line 151 of file linux-infiniband.c.

152 {
153  ib_device_t *new_dev = (ib_device_t*) papi_calloc(sizeof(ib_device_t), 1);
154  if (new_dev == 0) {
155  PAPIERROR("cannot allocate memory for new IB device structure");
156  return (0);
157  }
158 
159  new_dev->dev_name = strdup(name);
160  new_dev->dev_port = port;
161  if (new_dev->dev_name==0)
162  {
163  PAPIERROR("cannot allocate memory for device internal fields");
164  papi_free(new_dev);
165  return (0);
166  }
167 
168  // prepend the new device to the device list
169  new_dev->next = root_device;
170  root_device = new_dev;
171 
172  return (new_dev);
173 }
#define papi_free(a)
Definition: papi_memory.h:35
static ib_device_t * root_device
char * port
Definition: iozone.c:1620
void PAPIERROR(char *format,...)
char * name
Definition: iozone.c:23648
struct _ib_device_type * next
#define papi_calloc(a, b)
Definition: papi_memory.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

static void deallocate_infiniband_resources ( )
static

Definition at line 432 of file linux-infiniband.c.

433 {
434  int i;
435 
437  {
438  for (i=0 ; i<num_events ; ++i) {
441  if (infiniband_native_events[i].file_name)
442  free(infiniband_native_events[i].file_name);
443  if (infiniband_native_events[i].description)
444  papi_free(infiniband_native_events[i].description);
445  }
447  }
448 
450  while (iter != 0)
451  {
452  if (iter->dev_name)
453  free(iter->dev_name);
454 
455  ib_device_t *tmp = iter;
456  iter = iter->next;
457  papi_free(tmp);
458  }
459  root_device = 0;
460 }
static infiniband_native_event_entry_t * infiniband_native_events
#define papi_free(a)
Definition: papi_memory.h:35
static int num_events
static long iter[MAX_THREADS]
int i
Definition: fileop.c:140
static ib_device_t * root_device
free(dummyfile[xx])
char * name
Definition: iozone.c:23648
struct _ib_device_type * next
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

Here is the caller graph for this function:

static int find_ib_device_events ( ib_device_t dev,
int  extended 
)
static

Definition at line 204 of file linux-infiniband.c.

205 {
206  int nevents = 0;
207  DIR *cnt_dir = NULL;
208  char counters_path[128];
209 
210  if ( extended ) {
211  /* mofed driver version <4.0 */
212  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/counters%s",
213  ib_dir_path, dev->dev_name, dev->dev_port, (extended?"_ext":""));
214 
215  cnt_dir = opendir(counters_path);
216  if (cnt_dir == NULL) {
217  /* directory counters_ext in sysfs fs has changed to hw_counters */
218  /* in 4.0 version of mofed driver */
219  SUBDBG("cannot open counters directory `%s'\n", counters_path);
220 
221  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/%scounters",
222  ib_dir_path, dev->dev_name, dev->dev_port, "hw_");
223 
224  cnt_dir = opendir(counters_path);
225  }
226  }
227  else {
228  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/counters",
229  ib_dir_path, dev->dev_name, dev->dev_port);
230  cnt_dir = opendir(counters_path);
231  }
232 
233  if (cnt_dir == NULL) {
234  SUBDBG("cannot open counters directory `%s'\n", counters_path);
235  goto out;
236  }
237 
238  struct dirent *ev_ent;
239  /* iterate over all the events */
240  while ((ev_ent = readdir(cnt_dir)) != NULL) {
241  char *ev_name = ev_ent->d_name;
242  long long value = -1;
243  char event_path[160];
244  char counter_name[80];
245 
246  if (ev_name[0] == '.')
247  continue;
248 
249  /* Check that we can read an integer from the counter file */
250  snprintf(event_path, sizeof(event_path), "%s/%s", counters_path, ev_name);
251  if (pscanf(event_path, "%lld", &value) != 1) {
252  SUBDBG("cannot read value for event '%s'\n", ev_name);
253  continue;
254  }
255 
256  /* Create new counter */
257  snprintf(counter_name, sizeof(counter_name), "%s_%d%s:%s",
258  dev->dev_name, dev->dev_port, (extended?"_ext":""), ev_name);
259  if (add_ib_counter(counter_name, ev_name, extended, dev))
260  {
261  SUBDBG("Added new counter `%s'\n", counter_name);
262  nevents += 1;
263  }
264  }
265 
266  out:
267  if (cnt_dir != NULL)
268  closedir(cnt_dir);
269 
270  return (nevents);
271 }
static const char * ib_dir_path
void double value
Definition: iozone.c:18781
static ib_counter_t * add_ib_counter(const char *name, const char *file_name, int extended, ib_device_t *device)
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
goto out
Definition: pscanf.h:20

Here is the call graph for this function:

Here is the caller graph for this function:

static int find_ib_devices ( )
static

Definition at line 274 of file linux-infiniband.c.

275 {
276  DIR *ib_dir = NULL;
277  int result = PAPI_OK;
278  num_events = 0;
279 
280  ib_dir = opendir(ib_dir_path);
281  if (ib_dir == NULL) {
282  SUBDBG("cannot open `%s'\n", ib_dir_path);
284  "Infiniband sysfs interface not found", PAPI_MAX_STR_LEN);
285  result = PAPI_ENOSUPP;
286  goto out;
287  }
288 
289  struct dirent *hca_ent;
290  while ((hca_ent = readdir(ib_dir)) != NULL) {
291  char *hca = hca_ent->d_name;
292  char ports_path[80];
293  DIR *ports_dir = NULL;
294 
295  if (hca[0] == '.')
296  goto next_hca;
297 
298  snprintf(ports_path, sizeof(ports_path), "%s/%s/ports", ib_dir_path, hca);
299  ports_dir = opendir(ports_path);
300  if (ports_dir == NULL) {
301  SUBDBG("cannot open `%s'\n", ports_path);
302  goto next_hca;
303  }
304 
305  struct dirent *port_ent;
306  while ((port_ent = readdir(ports_dir)) != NULL) {
307  int port = atoi(port_ent->d_name);
308  if (port <= 0)
309  continue;
310 
311  /* Check that port is active. .../HCA/ports/PORT/state should read "4: ACTIVE." */
312  int state = -1;
313  char state_path[80];
314  snprintf(state_path, sizeof(state_path), "%s/%s/ports/%d/state", ib_dir_path, hca, port);
315  if (pscanf(state_path, "%d", &state) != 1) {
316  SUBDBG("cannot read state of IB HCA `%s' port %d\n", hca, port);
317  continue;
318  }
319 
320  if (state != 4) {
321  SUBDBG("skipping inactive IB HCA `%s', port %d, state %d\n", hca, port, state);
322  continue;
323  }
324 
325  /* Create dev name (HCA/PORT) and get stats for dev. */
326  SUBDBG("Found IB device `%s', port %d\n", hca, port);
327  ib_device_t *dev = add_ib_device(hca, port);
328  if (!dev)
329  continue;
330  // do we want to check for short counters only if no extended counters found?
331  num_events += find_ib_device_events(dev, 1); // check if we have extended (64bit) counters
332  num_events += find_ib_device_events(dev, 0); // check also for short counters
333  }
334 
335  next_hca:
336  if (ports_dir != NULL)
337  closedir(ports_dir);
338  }
339 
340  if (root_device == 0) // no active devices found
341  {
343  "No active Infiniband ports found", PAPI_MAX_STR_LEN);
344  result = PAPI_ENOIMPL;
345  } else if (num_events == 0)
346  {
348  "No supported Infiniband events found", PAPI_MAX_STR_LEN);
349  result = PAPI_ENOIMPL;
350  } else
351  {
352  // Events are stored in a linked list, in reverse order than how I found them
353  // Revert them again, so that they are in finding order, not that it matters.
354  int i = num_events - 1;
355  // now allocate memory to store the counters into the native table
359  while (iter != 0)
360  {
368 
369  ib_counter_t *tmp = iter;
370  iter = iter->next;
371  papi_free(tmp);
372  -- i;
373  }
374  root_counter = 0;
375  }
376 
377  out:
378  if (ib_dir != NULL)
379  closedir(ib_dir);
380 
381  return (result);
382 }
int atoi()
static infiniband_native_event_entry_t * infiniband_native_events
#define papi_free(a)
Definition: papi_memory.h:35
char * name
static int num_events
#define PAPI_ENOSUPP
Definition: papi.h:271
static const char * ib_dir_path
infiniband_register_t resources
return PAPI_OK
Definition: linux-nvml.c:497
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
char * description
ib_device_t * device
static int find_ib_device_events(ib_device_t *dev, int extended)
int extended
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:636
static long iter[MAX_THREADS]
int i
Definition: fileop.c:140
static ib_device_t * root_device
static char * make_ib_event_description(const char *input_str, int extended)
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
char * port
Definition: iozone.c:1620
char * file_name
#define PAPI_ENOIMPL
Definition: papi.h:272
struct _ib_counter_type * next
goto out
Definition: pscanf.h:20
static ib_counter_t * root_counter
child_idents[x-1] state
Definition: iozone.c:21341
static ib_device_t * add_ib_device(const char *name, int port)
ib_device_t * ev_device
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
long long tmp
Definition: iozone.c:12031
papi_vector_t _infiniband_vector
#define papi_calloc(a, b)
Definition: papi_memory.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

static char* make_ib_event_description ( const char *  input_str,
int  extended 
)
static

Definition at line 125 of file linux-infiniband.c.

126 {
127  int i, len;
128  char *desc = 0;
129  if (! input_str)
130  return (0);
131 
132  desc = (char*) papi_calloc(PAPI_MAX_STR_LEN, 1);
133  if (desc == 0) {
134  PAPIERROR("cannot allocate memory for event description");
135  return (0);
136  }
137  len = strlen(input_str);
138 
139  snprintf(desc, PAPI_MAX_STR_LEN, "%s (%s).",
140  input_str, (extended ? "free-running 64bit counter" :
141  "overflowing, auto-resetting counter"));
142  desc[0] = toupper(desc[0]);
143  for (i=0 ; i<len ; ++i)
144  if (desc[i] == '_')
145  desc[i] = ' ';
146 
147  return (desc);
148 }
int i
Definition: fileop.c:140
void PAPIERROR(char *format,...)
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
#define papi_calloc(a, b)
Definition: papi_memory.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

static long long read_ib_counter_value ( int  index)
static

Definition at line 385 of file linux-infiniband.c.

386 {
387  char ev_file[128];
388  char counters_path[128];
389  DIR *cnt_dir = NULL;
390  long long value = 0ll;
392 
393  if ( iter->extended ) {
394  /* mofed driver version <4.0 */
395  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/counters%s",
396  ib_dir_path, iter->device->dev_name, iter->device->dev_port, "_ext");
397 
398  cnt_dir = opendir(counters_path);
399  if (cnt_dir == NULL) {
400  /* directory counters_ext in sysfs fs has changed to hw_counters */
401  /* in 4.0 version of mofed driver */
402  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/%scounters",
403  ib_dir_path, iter->device->dev_name, iter->device->dev_port, "hw_");
404 
405  cnt_dir = opendir(counters_path);
406  }
407  }
408  else {
409  snprintf(counters_path, sizeof(counters_path), "%s/%s/ports/%d/counters",
410  ib_dir_path, iter->device->dev_name, iter->device->dev_port );
411  cnt_dir = opendir(counters_path);
412  }
413 
414 
415  if (cnt_dir != NULL)
416  closedir(cnt_dir);
417 
418 
419  snprintf(ev_file, sizeof(ev_file), "%s/%s",
420  counters_path, iter->file_name);
421 
422  if (pscanf(ev_file, "%lld", &value) != 1) {
423  PAPIERROR("cannot read value for counter '%s'\n", iter->name);
424  } else
425  {
426  SUBDBG("Counter '%s': %lld\n", iter->name, value);
427  }
428  return (value);
429 }
static infiniband_native_event_entry_t * infiniband_native_events
char * name
static const char * ib_dir_path
ib_device_t * device
void double value
Definition: iozone.c:18781
int extended
static long iter[MAX_THREADS]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
void PAPIERROR(char *format,...)
char * file_name

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _infiniband_vector

Definition at line 115 of file linux-infiniband.c.

const char* ib_dir_path = "/sys/class/infiniband"
static

Definition at line 75 of file linux-infiniband.c.

infiniband_native_event_entry_t* infiniband_native_events = 0
static

Definition at line 110 of file linux-infiniband.c.

int num_events = 0
static

Definition at line 112 of file linux-infiniband.c.

ib_counter_t* root_counter = 0
static

Definition at line 122 of file linux-infiniband.c.

ib_device_t* root_device = 0
static

Definition at line 121 of file linux-infiniband.c.