PAPI 7.1.0.0
Loading...
Searching...
No Matches
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)
 
static int _mx_init_component (int cidx)
 
static int _mx_init_thread (hwd_context_t *ctx)
 
static int _mx_shutdown_component (void)
 
static int _mx_shutdown_thread (hwd_context_t *ctx)
 
static int _mx_init_control_state (hwd_control_state_t *ctl)
 
static int _mx_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _mx_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _mx_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _mx_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
static int _mx_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
static int _mx_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _mx_set_domain (hwd_control_state_t *cntrl, int domain)
 
static int _mx_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _mx_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static int _mx_ntv_enum_events (unsigned int *EventCode, int modifier)
 

Variables

static const 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

◆ LINELEN

#define LINELEN   128

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

◆ MX_MAX_COUNTER_TERMS

#define MX_MAX_COUNTER_TERMS   MX_MAX_COUNTERS

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

◆ MX_MAX_COUNTERS

#define MX_MAX_COUNTERS   100

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

Function Documentation

◆ _mx_ctl()

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

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

448{
449 ( void ) ctx; /*unused */
450 ( void ) code; /*unused */
451 ( void ) option; /*unused */
452
453 return PAPI_OK;
454}
#define PAPI_OK
Definition: f90papi.h:73

◆ _mx_init_component()

static int _mx_init_component ( int  cidx)
static

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

224{
225 int retval = PAPI_OK;
226 FILE *fff;
227 char *path;
228 int checklen, len, pathlen;
229
230 /* detect if MX available */
231
232 path = getenv("PATH");
233 pathlen = strlen(path);
234 while(pathlen > 0) {
235 len = strcspn(path, ":");
236 if (len < BUFSIZ) {
237 strncpy(mx_counters_exe, path, len);
238 } else {
239 fff = NULL;
240 break;
241 }
242 mx_counters_exe[len] = '\0';
243 checklen = len + strlen("/mx_counters");
244 if (checklen < BUFSIZ) {
245 strcat(mx_counters_exe, "/mx_counters");
246 } else {
247 fff = NULL;
248 break;
249 }
250 fff = fopen(mx_counters_exe, "r");
251 if (fff != NULL) {
252 checklen = checklen + strlen(" 2> /dev/null");
253 if (checklen < BUFSIZ) {
254 strcat(mx_counters_exe, " 2> /dev/null");
255 break;
256 } else {
257 fclose(fff);
258 fff = NULL;
259 break;
260 }
261 }
262 pathlen = pathlen - len - 1;
263 if (pathlen > 0) {
264 path = path + len + 1;
265 }
266 }
267 if (fff == NULL) {
268 /* mx_counters not found */
270 "No MX utilities found",PAPI_MAX_STR_LEN);
272 goto fn_fail;
273 }
274 fclose(fff);
275
278
279 /* Export the component id */
281
282 fn_exit:
283 _papi_hwd[cidx]->cmp_info.disabled = retval;
284 return retval;
285 fn_fail:
286 goto fn_exit;
287}
struct papi_vectors * _papi_hwd[]
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
FILE * fff[MAX_EVENTS]
static int num_events
Definition: linux-mx.c:161
papi_vector_t _mx_vector
Definition: linux-mx.c:162
static char mx_counters_exe[BUFSIZ]
Definition: linux-mx.c:164
#define MX_MAX_COUNTERS
Definition: linux-mx.c:17
int fclose(FILE *__stream)
static int cidx
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ _mx_init_control_state()

static int _mx_init_control_state ( hwd_control_state_t ctl)
static

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

322{
323 ( void ) ctl; /*unused */
324
325 return PAPI_OK;
326}

◆ _mx_init_thread()

static int _mx_init_thread ( hwd_context_t ctx)
static

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

295{
296 ( void ) ctx; /*unused */
297 return PAPI_OK;
298}

◆ _mx_ntv_code_to_descr()

static int _mx_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)
static

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

496{
497 int event=EventCode;
498
499 if (event >=0 && event < num_events) {
500 strncpy( name, mx_native_table[event].description, len );
501 return PAPI_OK;
502 }
503 return PAPI_ENOEVNT;
504}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
static const MX_native_event_entry_t mx_native_table[]
Definition: linux-mx.c:58
const char * name
Definition: rocs.c:225

◆ _mx_ntv_code_to_name()

static int _mx_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

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

481{
482
483 int event=EventCode;
484
485 if (event >=0 && event < num_events) {
486 strncpy( name, mx_native_table[event].name, len );
487 return PAPI_OK;
488 }
489 return PAPI_ENOEVNT;
490
491
492}

◆ _mx_ntv_enum_events()

static int _mx_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)
static

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

510{
511
512 if ( modifier == PAPI_ENUM_FIRST ) {
513 if (num_events==0) return PAPI_ENOEVNT;
514 *EventCode = 0;
515 return PAPI_OK;
516 }
517
518 if ( modifier == PAPI_ENUM_EVENTS ) {
519 int index = *EventCode;
520
521 if ( mx_native_table[index + 1].resources.selector ) {
522 *EventCode = *EventCode + 1;
523 return PAPI_OK;
524 } else {
525 return PAPI_ENOEVNT;
526 }
527 }
528
529 return PAPI_EINVAL;
530}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _mx_read()

static int _mx_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)
static

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

398{
399 ( void ) ctx; /*unused */
400 ( void ) flags; /*unused */
401 int i;
402 long long mx_counters[MX_MAX_COUNTERS];
403
404 MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
405
406 read_mx_counters( mx_counters );
407
408 for ( i = 0; i < mx_ctl->num_events; i++ ) {
409 mx_ctl->current_count[i]=
410 mx_counters[mx_ctl->which_counter[i]];
411 mx_ctl->difference[i] = mx_ctl->current_count[i]-
412 mx_ctl->start_count[i];
413 }
414 *events = mx_ctl->difference;
415
416 return PAPI_OK;
417}
int i
char events[MAX_EVENTS][BUFSIZ]
static int read_mx_counters(long long *counters)
Definition: linux-mx.c:167
long long difference[MX_MAX_COUNTERS]
Definition: linux-mx.c:47
int which_counter[MX_MAX_COUNTERS]
Definition: linux-mx.c:48
long long current_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:46
long long start_count[MX_MAX_COUNTERS]
Definition: linux-mx.c:45
Here is the call graph for this function:

◆ _mx_reset()

static int _mx_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)
static

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

422{
423 _mx_start( ctx, ctrl );
424 return PAPI_OK;
425}
static int _mx_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
Definition: linux-mx.c:352
Here is the call graph for this function:

◆ _mx_set_domain()

static int _mx_set_domain ( hwd_control_state_t cntrl,
int  domain 
)
static

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

468{
469 ( void ) cntrl; /*unused */
470 if ( PAPI_DOM_ALL != domain ) {
471 return PAPI_EINVAL;
472 }
473
474 return PAPI_OK;
475}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _mx_shutdown_component()

static int _mx_shutdown_component ( void  )
static

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

303{
304 return PAPI_OK;
305}

◆ _mx_shutdown_thread()

static int _mx_shutdown_thread ( hwd_context_t ctx)
static

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

309{
310 ( void ) ctx; /*unused */
311 return PAPI_OK;
312}

◆ _mx_start()

static int _mx_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

353{
354
355 long long mx_counters[MX_MAX_COUNTERS];
356
357 ( void ) ctx; /*unused */
358
359 MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
360 int i;
361
362 read_mx_counters( mx_counters );
363
364 // for(i=0;i<MX_MAX_COUNTERS;i++) printf("%d %lld\n",i,mx_counters[i]);
365
366 for(i=0;i<mx_ctl->num_events;i++) {
367 mx_ctl->current_count[i]=
368 mx_counters[mx_ctl->which_counter[i]];
369 mx_ctl->start_count[i]=mx_ctl->current_count[i];
370 }
371
372 return PAPI_OK;
373}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _mx_stop()

static int _mx_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

378{
379 ( void ) ctx; /*unused */
380
381 long long mx_counters[MX_MAX_COUNTERS];
382 MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
383 int i;
384
385 read_mx_counters( mx_counters );
386
387 for(i=0;i<mx_ctl->num_events;i++) {
388 mx_ctl->current_count[i]=
389 mx_counters[mx_ctl->which_counter[i]];
390 }
391
392 return PAPI_OK;
393}
Here is the call graph for this function:

◆ _mx_update_control_state()

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

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

331{
332 ( void ) ctx; /*unused */
333 int i, index;
334
335 MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
336
337 for(i=0; i<count; i++ ) {
338 index = native[i].ni_event;
339 mx_ctl->which_counter[i]=index;
340 // printf("Mapping event# %d to HW counter %d (count=%d)\n",
341 // i,index,count);
342 native[i].ni_position = i;
343 }
344
345 mx_ctl->num_events=count;
346
347 return PAPI_OK;
348}
static long count
static int native

◆ read_mx_counters()

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}
#define LINELEN
Definition: linux-mx.c:20
static FILE * fp
Here is the caller graph for this function:

Variable Documentation

◆ _mx_vector

papi_vector_t _mx_vector

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

◆ mx_counters_exe

char mx_counters_exe[BUFSIZ]
static

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

◆ mx_native_table

const MX_native_event_entry_t mx_native_table[]
static

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

◆ num_events

int num_events =0
static

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