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

Defines

#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]

Detailed Description

Definition in file linux-mx.c.


Define 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

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

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

00417 {
00418     ( void ) ctx;            /*unused */
00419     ( void ) code;           /*unused */
00420     ( void ) option;         /*unused */
00421 
00422     return PAPI_OK;
00423 }

static int _mx_init_component ( int  cidx  )  [static]

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

00224 {
00225 
00226     FILE *fff;
00227     char test_string[BUFSIZ];
00228 
00229     /* detect if MX available */
00230 
00231     strncpy(mx_counters_exe,"mx_counters 2> /dev/null",BUFSIZ);
00232     fff=popen(mx_counters_exe,"r");
00233     /* popen only returns NULL if "sh" fails, not the actual command */
00234     if (fgets(test_string,BUFSIZ,fff)==NULL) {
00235        pclose(fff);
00236        strncpy(mx_counters_exe,"./components/mx/utils/fake_mx_counters 2> /dev/null",BUFSIZ);
00237        fff=popen(mx_counters_exe,"r");
00238        if (fgets(test_string,BUFSIZ,fff)==NULL) {
00239           pclose(fff);
00240           /* neither real nor fake found */
00241           strncpy(_mx_vector.cmp_info.disabled_reason,
00242               "No MX utilities found",PAPI_MAX_STR_LEN);
00243           return PAPI_ECMP;
00244        }
00245     }
00246     pclose(fff);
00247 
00248     num_events=MX_MAX_COUNTERS;
00249     _mx_vector.cmp_info.num_native_events=num_events;
00250 
00251     /* Export the component id */
00252     _mx_vector.cmp_info.CmpIdx = cidx;
00253 
00254 
00255     return PAPI_OK;
00256 }

static int _mx_init_control_state ( hwd_control_state_t ctl  )  [static]

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

00291 {
00292     ( void ) ctl;            /*unused */
00293 
00294     return PAPI_OK;
00295 }

static int _mx_init_thread ( hwd_context_t ctx  )  [static]

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

00264 {
00265     ( void ) ctx;            /*unused */
00266     return PAPI_OK;
00267 }

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

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

00465 {
00466     int event=EventCode;
00467 
00468     if (event >=0 && event < num_events) {
00469        strncpy( name, mx_native_table[event].description, len );
00470        return PAPI_OK;
00471     }
00472     return PAPI_ENOEVNT;
00473 }

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

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

00450 {
00451 
00452     int event=EventCode;
00453 
00454     if (event >=0 && event < num_events) {
00455       strncpy( name, mx_native_table[event].name, len );
00456       return PAPI_OK;
00457     }
00458     return PAPI_ENOEVNT;
00459 
00460 
00461 }

static int _mx_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
) [static]

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

00479 {
00480 
00481     if ( modifier == PAPI_ENUM_FIRST ) {
00482        if (num_events==0) return PAPI_ENOEVNT;
00483        *EventCode = 0;
00484        return PAPI_OK;
00485     }
00486 
00487     if ( modifier == PAPI_ENUM_EVENTS ) {
00488         int index = *EventCode;
00489 
00490         if ( mx_native_table[index + 1].resources.selector ) {
00491             *EventCode = *EventCode + 1;
00492             return PAPI_OK;
00493         } else {
00494             return PAPI_ENOEVNT;
00495         }
00496     }
00497         
00498         return PAPI_EINVAL;
00499 }

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

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

00367 {
00368     ( void ) ctx;            /*unused */
00369     ( void ) flags;          /*unused */
00370     int i;
00371         long long mx_counters[MX_MAX_COUNTERS];
00372 
00373     MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
00374 
00375     read_mx_counters( mx_counters );
00376 
00377     for ( i = 0; i < mx_ctl->num_events; i++ ) {
00378             mx_ctl->current_count[i]=
00379              mx_counters[mx_ctl->which_counter[i]];
00380         mx_ctl->difference[i] = mx_ctl->current_count[i]-
00381                                    mx_ctl->start_count[i];
00382     }
00383     *events = mx_ctl->difference;
00384 
00385     return PAPI_OK;
00386 }

Here is the call graph for this function:

static int _mx_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
) [static]

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

00391 {
00392     _mx_start( ctx, ctrl );
00393     return PAPI_OK;
00394 }

Here is the call graph for this function:

static int _mx_set_domain ( hwd_control_state_t cntrl,
int  domain 
) [static]

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

00437 {
00438     ( void ) cntrl;          /*unused */
00439     if ( PAPI_DOM_ALL != domain ) {
00440         return PAPI_EINVAL;
00441     }
00442 
00443     return PAPI_OK;
00444 }

static int _mx_shutdown_component ( void   )  [static]

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

00272 {
00273   return PAPI_OK;
00274 }

static int _mx_shutdown_thread ( hwd_context_t ctx  )  [static]

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

00278 {
00279     ( void ) ctx;            /*unused */
00280     return PAPI_OK;
00281 }

static int _mx_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

00322 {
00323 
00324         long long mx_counters[MX_MAX_COUNTERS];
00325 
00326     ( void ) ctx;            /*unused */
00327 
00328     MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
00329     int i;
00330 
00331     read_mx_counters( mx_counters );
00332 
00333     //  for(i=0;i<MX_MAX_COUNTERS;i++) printf("%d %lld\n",i,mx_counters[i]);
00334 
00335     for(i=0;i<mx_ctl->num_events;i++) {
00336            mx_ctl->current_count[i]=
00337              mx_counters[mx_ctl->which_counter[i]];
00338        mx_ctl->start_count[i]=mx_ctl->current_count[i];
00339     }
00340 
00341     return PAPI_OK;
00342 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int _mx_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

00347 {
00348     ( void ) ctx;            /*unused */
00349 
00350         long long mx_counters[MX_MAX_COUNTERS];
00351     MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
00352     int i;
00353 
00354     read_mx_counters( mx_counters );
00355 
00356     for(i=0;i<mx_ctl->num_events;i++) {
00357            mx_ctl->current_count[i]=
00358              mx_counters[mx_ctl->which_counter[i]];
00359     }
00360 
00361     return PAPI_OK;
00362 }

Here is the call graph for this function:

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

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

00300 {
00301     ( void ) ctx;            /*unused */
00302     int i, index;
00303     
00304     MX_control_state_t *mx_ctl = (MX_control_state_t *)ctl;
00305 
00306     for(i=0; i<count; i++ ) {
00307         index = native[i].ni_event;
00308         mx_ctl->which_counter[i]=index;
00309         //      printf("Mapping event# %d to HW counter %d (count=%d)\n",
00310         //     i,index,count); 
00311         native[i].ni_position = i;
00312     }
00313 
00314     mx_ctl->num_events=count;
00315 
00316     return PAPI_OK;
00317 }

static int read_mx_counters ( long long *  counters  )  [static]

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

00168 {
00169     FILE *fp;
00170     char line[LINELEN];
00171     int i, linenum;
00172 
00173     /* Open a pipe to the mx_counters executable */
00174 
00175     fp = popen( mx_counters_exe, "r" );
00176     if ( !fp ) {
00177        perror( "popen" );
00178        return PAPI_ECMP;
00179     }
00180 
00181 
00182     /* A line of output looks something similar to:       */
00183         /* "    Lanai uptime (seconds):     766268 (0xbb13c)" */
00184 
00185     /* This code may fail if number of ports on card > 1 */
00186 
00187     linenum = 0;
00188     while ( fgets( line, LINELEN, fp ) ) {
00189       //       printf("%s",line);
00190        for(i=0; line[i]!= '\0' && i<LINELEN-1;i++) {
00191 
00192           /* skip to colon */
00193           if (line[i]==':') {
00194 
00195              /* read in value */
00196              if (line[i+1]!='\0') {
00197            //       printf("Line %d trying %s",linenum,&line[i+1]);
00198                 sscanf(&line[i+1],"%lld",&counters[linenum]);
00199             linenum++;
00200             break;
00201          }
00202           }
00203        }
00204        if (linenum>=MX_MAX_COUNTERS) break;
00205     }
00206 
00207     pclose( fp );
00208 
00209     return PAPI_OK;
00210 }

Here is the caller graph for this function:


Variable Documentation

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

char mx_counters_exe[BUFSIZ] [static]

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

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

int num_events = 0 [static]

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


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1