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

A component for Myricom MX (Myrinet Express) More...

Include dependency graph for linux-mx.c:

Go to the source code of this file.

Data Structures

struct  MX_register_t
 
struct  MX_native_event_entry_t
 
struct  MX_reg_alloc_t
 
struct  MX_control_state_t
 
struct  MX_context_t
 

Macros

#define MX_MAX_COUNTERS   100
 
#define MX_MAX_COUNTER_TERMS   MX_MAX_COUNTERS
 
#define LINELEN   128
 

Functions

static int read_mx_counters (long long *counters)
 
int _mx_init_component (int cidx)
 
int _mx_init_thread (hwd_context_t *ctx)
 
int _mx_shutdown_component (void)
 
int _mx_shutdown_thread (hwd_context_t *ctx)
 
int _mx_init_control_state (hwd_control_state_t *ctl)
 
int _mx_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int _mx_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _mx_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _mx_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
int _mx_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int _mx_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long long *from)
 
int _mx_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int _mx_set_domain (hwd_control_state_t *cntrl, int domain)
 
int _mx_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int _mx_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int _mx_ntv_enum_events (unsigned int *EventCode, int modifier)
 

Variables

MX_native_event_entry_t mx_native_table []
 
static int num_events =0
 
papi_vector_t _mx_vector
 
static char mx_counters_exe [BUFSIZ]
 

Macro Definition Documentation

#define LINELEN   128

Definition at line 20 of file linux-mx.c.

#define MX_MAX_COUNTER_TERMS   MX_MAX_COUNTERS

Definition at line 18 of file linux-mx.c.

#define MX_MAX_COUNTERS   100

Definition at line 17 of file linux-mx.c.

Function Documentation

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

Definition at line 415 of file linux-mx.c.

416 {
417  ( void ) ctx; /*unused */
418  ( void ) code; /*unused */
419  ( void ) option; /*unused */
420 
421  return PAPI_OK;
422 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _mx_init_component ( int  cidx)

Definition at line 223 of file linux-mx.c.

224 {
225 
226  FILE *fff;
227  char test_string[BUFSIZ];
228 
229  /* detect if MX available */
230 
231  strncpy(mx_counters_exe,"mx_counters 2> /dev/null",BUFSIZ);
232  fff=popen(mx_counters_exe,"r");
233  /* popen only returns NULL if "sh" fails, not the actual command */
234  if (fgets(test_string,BUFSIZ,fff)==NULL) {
235  pclose(fff);
236  strncpy(mx_counters_exe,"./components/mx/utils/fake_mx_counters 2> /dev/null",BUFSIZ);
237  fff=popen(mx_counters_exe,"r");
238  if (fgets(test_string,BUFSIZ,fff)==NULL) {
239  pclose(fff);
240  /* neither real nor fake found */
242  "No MX utilities found",PAPI_MAX_STR_LEN);
243  return PAPI_ECMP;
244  }
245  }
246  pclose(fff);
247 
250 
251  /* Export the component id */
253 
254 
255  return PAPI_OK;
256 }
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static char mx_counters_exe[BUFSIZ]
Definition: linux-mx.c:164
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
FILE * fff[MAX_EVENTS]
papi_vector_t _mx_vector
Definition: linux-mx.c:162
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:633
static int cidx
Definition: event_info.c:40
#define PAPI_ECMP
Definition: papi.h:254
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int _mx_init_control_state ( hwd_control_state_t ctl)

Definition at line 290 of file linux-mx.c.

291 {
292  ( void ) ctl; /*unused */
293 
294  return PAPI_OK;
295 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _mx_init_thread ( hwd_context_t ctx)

Definition at line 263 of file linux-mx.c.

264 {
265  ( void ) ctx; /*unused */
266  return PAPI_OK;
267 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _mx_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 463 of file linux-mx.c.

464 {
465  int event=EventCode;
466 
467  if (event >=0 && event < num_events) {
468  strncpy( name, mx_native_table[event].description, len );
469  return PAPI_OK;
470  }
471  return PAPI_ENOEVNT;
472 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
MX_native_event_entry_t mx_native_table[]
Definition: linux-mx.c:58
char * name
Definition: iozone.c:23648
int _mx_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 448 of file linux-mx.c.

449 {
450 
451  int event=EventCode;
452 
453  if (event >=0 && event < num_events) {
454  strncpy( name, mx_native_table[event].name, len );
455  return PAPI_OK;
456  }
457  return PAPI_ENOEVNT;
458 
459 
460 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
MX_native_event_entry_t mx_native_table[]
Definition: linux-mx.c:58
char * name
Definition: iozone.c:23648
int _mx_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

Definition at line 477 of file linux-mx.c.

478 {
479 
480  if ( modifier == PAPI_ENUM_FIRST ) {
481  if (num_events==0) return PAPI_ENOEVNT;
482  *EventCode = 0;
483  return PAPI_OK;
484  }
485 
486  if ( modifier == PAPI_ENUM_EVENTS ) {
487  int index = *EventCode;
488 
489  if ( mx_native_table[index + 1].resources.selector ) {
490  *EventCode = *EventCode + 1;
491  return PAPI_OK;
492  } else {
493  return PAPI_ENOEVNT;
494  }
495  }
496 
497  return PAPI_EINVAL;
498 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
MX_native_event_entry_t mx_native_table[]
Definition: linux-mx.c:58
int _mx_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

Definition at line 365 of file linux-mx.c.

367 {
368  ( void ) ctx; /*unused */
369  ( void ) flags; /*unused */
370  int i;
371  long long mx_counters[MX_MAX_COUNTERS];
372 
373  MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
374 
375  read_mx_counters( mx_counters );
376 
377  for ( i = 0; i < mx_ctl->num_events; i++ ) {
378  mx_ctl->current_count[i]=
379  mx_counters[mx_ctl->which_counter[i]];
380  mx_ctl->difference[i] = mx_ctl->current_count[i]-
381  mx_ctl->start_count[i];
382  }
383  *events = mx_ctl->difference;
384 
385  return PAPI_OK;
386 }
long long start_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:45
long long flags
Definition: iozone.c:12330
long long current_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:46
static int read_mx_counters(long long *counters)
Definition: linux-mx.c:167
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]
int i
Definition: fileop.c:140
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
int which_counter[MX_MAX_COUNTERS]
Definition: linux-mx.c:48
long long difference[MX_MAX_COUNTERS]
Definition: linux-mx.c:47

Here is the call graph for this function:

int _mx_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 390 of file linux-mx.c.

391 {
392  _mx_start( ctx, ctrl );
393  return PAPI_OK;
394 }
return PAPI_OK
Definition: linux-nvml.c:458
int _mx_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
Definition: linux-mx.c:321

Here is the call graph for this function:

int _mx_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

Definition at line 435 of file linux-mx.c.

436 {
437  ( void ) cntrl; /*unused */
438  if ( PAPI_DOM_ALL != domain ) {
439  return PAPI_EINVAL;
440  }
441 
442  return PAPI_OK;
443 }
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
int _mx_shutdown_component ( void  )

Definition at line 271 of file linux-mx.c.

272 {
273  return PAPI_OK;
274 }
return PAPI_OK
Definition: linux-nvml.c:458
int _mx_shutdown_thread ( hwd_context_t ctx)

Definition at line 277 of file linux-mx.c.

278 {
279  ( void ) ctx; /*unused */
280  return PAPI_OK;
281 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _mx_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 321 of file linux-mx.c.

322 {
323 
324  long long mx_counters[MX_MAX_COUNTERS];
325 
326  ( void ) ctx; /*unused */
327 
328  MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
329  int i;
330 
331  read_mx_counters( mx_counters );
332 
333  // for(i=0;i<MX_MAX_COUNTERS;i++) printf("%d %lld\n",i,mx_counters[i]);
334 
335  for(i=0;i<mx_ctl->num_events;i++) {
336  mx_ctl->current_count[i]=
337  mx_counters[mx_ctl->which_counter[i]];
338  mx_ctl->start_count[i]=mx_ctl->current_count[i];
339  }
340 
341  return PAPI_OK;
342 }
long long start_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:45
long long current_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:46
static int read_mx_counters(long long *counters)
Definition: linux-mx.c:167
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
int which_counter[MX_MAX_COUNTERS]
Definition: linux-mx.c:48

Here is the call graph for this function:

Here is the caller graph for this function:

int _mx_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 346 of file linux-mx.c.

347 {
348  ( void ) ctx; /*unused */
349 
350  long long mx_counters[MX_MAX_COUNTERS];
351  MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
352  int i;
353 
354  read_mx_counters( mx_counters );
355 
356  for(i=0;i<mx_ctl->num_events;i++) {
357  mx_ctl->current_count[i]=
358  mx_counters[mx_ctl->which_counter[i]];
359  }
360 
361  return PAPI_OK;
362 }
long long current_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:46
static int read_mx_counters(long long *counters)
Definition: linux-mx.c:167
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
int which_counter[MX_MAX_COUNTERS]
Definition: linux-mx.c:48

Here is the call graph for this function:

int _mx_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 298 of file linux-mx.c.

300 {
301  ( void ) ctx; /*unused */
302  int i, index;
303 
304  MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
305 
306  for(i=0; i<count; i++ ) {
307  index = native[i].ni_event;
308  mx_ctl->which_counter[i]=index;
309  // printf("Mapping event# %d to HW counter %d (count=%d)\n",
310  // i,index,count);
311  native[i].ni_position = i;
312  }
313 
314  mx_ctl->num_events=count;
315 
316  return PAPI_OK;
317 }
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
int which_counter[MX_MAX_COUNTERS]
Definition: linux-mx.c:48
int _mx_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long from 
)

Definition at line 397 of file linux-mx.c.

398 {
399  ( void ) ctx; /*unused */
400  ( void ) ctrl; /*unused */
401  ( void ) from; /*unused */
402 
403  return PAPI_OK;
404 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
static int read_mx_counters ( long long counters)
static

Definition at line 167 of file linux-mx.c.

168 {
169  FILE *fp;
170  char line[LINELEN];
171  int i, linenum;
172 
173  /* Open a pipe to the mx_counters executable */
174 
175  fp = popen( mx_counters_exe, "r" );
176  if ( !fp ) {
177  perror( "popen" );
178  return PAPI_ECMP;
179  }
180 
181 
182  /* A line of output looks something similar to: */
183  /* " Lanai uptime (seconds): 766268 (0xbb13c)" */
184 
185  /* This code may fail if number of ports on card > 1 */
186 
187  linenum = 0;
188  while ( fgets( line, LINELEN, fp ) ) {
189  // printf("%s",line);
190  for(i=0; line[i]!= '\0' && i<LINELEN-1;i++) {
191 
192  /* skip to colon */
193  if (line[i]==':') {
194 
195  /* read in value */
196  if (line[i+1]!='\0') {
197  // printf("Line %d trying %s",linenum,&line[i+1]);
198  sscanf(&line[i+1],"%lld",&counters[linenum]);
199  linenum++;
200  break;
201  }
202  }
203  }
204  if (linenum>=MX_MAX_COUNTERS) break;
205  }
206 
207  pclose( fp );
208 
209  return PAPI_OK;
210 }
return PAPI_OK
Definition: linux-nvml.c:458
static char mx_counters_exe[BUFSIZ]
Definition: linux-mx.c:164
#define LINELEN
Definition: linux-mx.c:20
int i
Definition: fileop.c:140
static FILE * fp
#define PAPI_ECMP
Definition: papi.h:254
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _mx_vector

Definition at line 162 of file linux-mx.c.

char mx_counters_exe[BUFSIZ]
static

Definition at line 164 of file linux-mx.c.

MX_native_event_entry_t mx_native_table[]

Definition at line 58 of file linux-mx.c.

int num_events =0
static

Definition at line 161 of file linux-mx.c.