int GPTLevent_code_to_name (const int code, char *name) { int ret; /* return code */ int n; /* loop over derived entries */ /* ** First check derived events */ for (n = 0; n < nderivedentries; ++n) { if (code == derivedtable[n].counter) { strcpy (name, derivedtable[n].namestr); return 0; } } /* ** Next check PAPI events--note that PAPI must be initialized before the ** code_to_name function can be invoked. */ if ((ret = GPTL_PAPIlibraryinit ()) < 0) return GPTLerror ("GPTL_event_code_to_name: GPTL_PAPIlibraryinit failure\n"); if (PAPI_event_code_to_name (code, name) != PAPI_OK) return GPTLerror ("GPTL_event_code_to_name: PAPI_event_code_to_name failure\n"); return 0; }
/* ** GPTLevent_name_to_code: convert a string to a PAPI code ** or derived event code. ** ** Input arguments: ** arg: string to convert ** ** Output arguments: ** code: PAPI or GPTL derived code ** ** Return value: 0 (success) or GPTLerror (failure) */ int GPTLevent_name_to_code (const char *name, int *code) { int ret; /* return code */ int n; /* loop over derived entries */ static const char *thisfunc = "GPTLevent_name_to_code"; /* First check derived events */ for (n = 0; n < nderivedentries; ++n) { if (STRMATCH (name, derivedtable[n].namestr)) { *code = derivedtable[n].counter; return 0; } } /* ** Next check PAPI events--note that PAPI must be initialized before the ** name_to_code function can be invoked. */ if ((ret = GPTL_PAPIlibraryinit ()) < 0) return GPTLerror ("%s: GPTL_PAPIlibraryinit failure\n", thisfunc); if ((PAPI_event_name_to_code ((char *) name, code)) != PAPI_OK) return GPTLerror ("%s: PAPI_event_name_to_code failure\n", thisfunc); return 0; }
int GPTL_PAPIinitialize (const int maxthreads, /* number of threads */ const bool verbose_flag, /* output verbosity */ int *nevents_out, /* nevents needed by gptl.c */ Entry *pr_event_out) /* events needed by gptl.c */ { int ret; /* return code */ int n; /* loop index */ int t; /* thread index */ verbose = verbose_flag; if (maxthreads < 1) return GPTLerror ("GPTL_PAPIinitialize: maxthreads = %d\n", maxthreads); /* Ensure that PAPI_library_init has already been called */ if ((ret = GPTL_PAPIlibraryinit ()) < 0) return GPTLerror ("GPTL_PAPIinitialize: GPTL_PAPIlibraryinit failure\n"); /* PAPI_thread_init needs to be called if threading enabled */ #if ( defined THREADED_OMP ) if (PAPI_thread_init ((unsigned long (*)(void)) (omp_get_thread_num)) != PAPI_OK) return GPTLerror ("GPTL_PAPIinitialize: PAPI_thread_init failure\n"); #elif ( defined THREADED_PTHREADS ) if (PAPI_thread_init ((unsigned long (*)(void)) (pthread_self)) != PAPI_OK) return GPTLerror ("GPTL_PAPIinitialize: PAPI_thread_init failure\n"); #endif /* allocate and initialize static local space */ EventSet = (int *) GPTLallocate (maxthreads * sizeof (int)); papicounters = (long_long **) GPTLallocate (maxthreads * sizeof (long_long *)); for (t = 0; t < maxthreads; t++) { EventSet[t] = PAPI_NULL; papicounters[t] = (long_long *) GPTLallocate (MAX_AUX * sizeof (long_long)); } *nevents_out = nevents; for (n = 0; n < nevents; ++n) { pr_event_out[n].counter = pr_event[n].event.counter; pr_event_out[n].namestr = pr_event[n].event.namestr; pr_event_out[n].str8 = pr_event[n].event.str8; pr_event_out[n].str16 = pr_event[n].event.str16; pr_event_out[n].longstr = pr_event[n].event.longstr; } return 0; }
int GPTL_PAPIget_eventvalue (const char *eventname, const Papistats *aux, double *value) { int n; /* loop index through enabled events */ int numidx; /* numerator index into papicounters */ int denomidx; /* denominator index into papicounters */ for (n = 0; n < nevents; ++n) { if (STRMATCH (eventname, pr_event[n].event.namestr)) { numidx = pr_event[n].numidx; if (pr_event[n].denomidx > -1) { /* derived event */ denomidx = pr_event[n].denomidx; if (aux->accum[denomidx] > 0) /* protect against divide by zero */ *value = (double) aux->accum[numidx] / (double) aux->accum[denomidx]; else *value = 0.; } else { /* Raw PAPI event */ *value = (double) aux->accum[numidx]; } break; } } if (n == nevents) return GPTLerror ("GPTL_PAPIget_eventvalue: event %s not enabled\n", eventname); return 0; }
int gptlevent_code_to_name (int *code, char *str, int nc) { int i; if (nc < PAPI_MAX_STR_LEN) return GPTLerror ("gptl_event_code_to_name: output name must hold at least %d characters\n", PAPI_MAX_STR_LEN); if (GPTLevent_code_to_name (*code, str) == 0) { for (i = strlen(str); i < nc; ++i) str[i] = ' '; } else { return GPTLerror (""); } return 0; }
int gptlpr_summary_file (int *fcomm, char *file, int nc1) { char *locfile; int c; int ret; #ifdef HAVE_MPI MPI_Comm ccomm; #ifdef HAVE_COMM_F2C ccomm = MPI_Comm_f2c (*fcomm); #else /* Punt and try just casting the Fortran communicator */ ccomm = (MPI_Comm) *fcomm; #endif #else int ccomm = 0; #endif if ( ! (locfile = (char *) malloc (nc1+1))) return GPTLerror ("gptlpr_summary_file: malloc error\n"); //pw snprintf (locfile, nc1+1, "%s", file); for (c = 0; c < nc1; c++) { locfile[c] = file[c]; } locfile[c] = '\0'; ret = GPTLpr_summary_file (ccomm, locfile); free (locfile); return ret; }
int GPTL_PAPIstop (const int t, /* thread number */ Papistats *aux) /* struct containing PAPI stats */ { int ret; /* return code from PAPI lib calls */ int n; /* loop index */ long_long delta; /* change in counters from previous read */ /* If no events are to be counted just return */ if (npapievents == 0) return 0; /* Read the counters */ if ((ret = PAPI_read (EventSet[t], papicounters[t])) != PAPI_OK) return GPTLerror ("GPTL_PAPIstop: %s\n", PAPI_strerror (ret)); /* ** Accumulate the difference since timer start in aux. ** Negative accumulation can happen when multiplexing is enabled, so don't ** set count to BADCOUNT in that case. */ for (n = 0; n < npapievents; n++) { #ifdef DEBUG printf ("GPTL_PAPIstop: event %d counter value is %ld\n", n, (long) papicounters[t][n]); #endif delta = papicounters[t][n] - aux->last[n]; if ( ! is_multiplexed && delta < 0) aux->accum[n] = BADCOUNT; else aux->accum[n] += delta; } return 0; }
int GPTL_PAPIstart (const int t, /* thread number */ Papistats *aux) /* struct containing PAPI stats */ { int ret; /* return code from PAPI lib calls */ int n; /* loop index */ /* If no events are to be counted just return */ if (npapievents == 0) return 0; /* Read the counters */ if ((ret = PAPI_read (EventSet[t], papicounters[t])) != PAPI_OK) return GPTLerror ("GPTL_PAPIstart: %s\n", PAPI_strerror (ret)); /* ** Store the counter values. When GPTL_PAPIstop is called, the counters ** will again be read, and differenced with the values saved here. */ for (n = 0; n < npapievents; n++) aux->last[n] = papicounters[t][n]; return 0; }
int getderivedidx (int dcounter) { int n; for (n = 0; n < nderivedentries; ++n) { if (derivedtable[n].counter == dcounter) return n; } return GPTLerror ("getderivedidx: failed to find derived counter %d\n", dcounter); }
int gptlpr_summary_file (char *outfile, int nc1) { char *locfile; int ret; if ( ! (locfile = (char *) malloc (nc1+1))) return GPTLerror ("gptlpr_summary_file: malloc error\n"); snprintf (locfile, nc1+1, "%s", outfile); ret = GPTLpr_summary_file (locfile); free (locfile); return ret; }
/* ** GPTL_PAPIlibraryinit: Call PAPI_library_init if necessary ** ** Return value: 0 (success) or GPTLerror (failure) */ int GPTL_PAPIlibraryinit () { int ret; static const char *thisfunc = "GPTL_PAPIlibraryinit"; if ((ret = PAPI_is_initialized ()) == PAPI_NOT_INITED) { if ((ret = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { fprintf (stderr, "%s: ret=%d PAPI_VER_CURRENT=%d\n", thisfunc, ret, (int) PAPI_VER_CURRENT); return GPTLerror ("%s: PAPI_library_init failure:%s\n", thisfunc, PAPI_strerror (ret)); } } return 0; }
int GPTL_PAPIlibraryinit () { int ret; if ((ret = PAPI_is_initialized ()) == PAPI_NOT_INITED) { if ((ret = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { fprintf (stderr, "GPTL_PAPIlibraryinit: ret=%d PAPI_VER_CURRENT=%d\n", ret, (int) PAPI_VER_CURRENT); return GPTLerror ("GPTL_PAPIlibraryinit: PAPI_library_init failure:%s\n", PAPI_strerror (ret)); } } return 0; }
int gptlpr_file (char *file, int nc1) { char *locfile; int c; int ret; if ( ! (locfile = (char *) malloc (nc1+1))) return GPTLerror ("gptlpr_file: malloc error\n"); //pw snprintf (locfile, nc1+1, "%s", file); for (c = 0; c < nc1; c++) { locfile[c] = file[c]; } locfile[c] = '\0'; ret = GPTLpr_file (locfile); free (locfile); return ret; }
int gptlpr_summary_file (int *fcomm, char *outfile, int nc1) { MPI_Comm ccomm; char *locfile; int ret; if ( ! (locfile = (char *) malloc (nc1+1))) return GPTLerror ("gptlpr_summary_file: malloc error\n"); snprintf (locfile, nc1+1, "%s", outfile); #ifdef HAVE_COMM_F2C ccomm = MPI_Comm_f2c (*fcomm); #else /* Punt and try just casting the Fortran communicator */ ccomm = (MPI_Comm) *fcomm; #endif ret = GPTLpr_summary_file (ccomm, locfile); free (locfile); return ret; }
int gptlbarrier (void) { return GPTLerror ("gptlbarrier: Need to build GPTL with #define HAVE_MPI to enable this routine\n"); }
int GPTLcreate_and_start_events (const int t) /* thread number */ { int ret; /* return code */ int n; /* loop index over events */ char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ /* Create the event set */ if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: thread %d failure creating eventset: %s\n", t, PAPI_strerror (ret)); if (verbose) printf ("GPTLcreate_and_start_events: successfully created eventset for thread %d\n", t); /* Add requested events to the event set */ for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { if (verbose) { fprintf (stderr, "%s\n", PAPI_strerror (ret)); ret = PAPI_event_code_to_name (papieventlist[n], eventname); fprintf (stderr, "GPTLcreate_and_start_events: failure adding event:%s\n", eventname); } if (enable_multiplexing) { if (verbose) printf ("Trying multiplexing...\n"); is_multiplexed = true; break; } else return GPTLerror ("enable_multiplexing is false: giving up\n"); } } if (is_multiplexed) { /* Cleanup the eventset for multiplexing */ if ((ret = PAPI_cleanup_eventset (EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: %s\n", PAPI_strerror (ret)); if ((ret = PAPI_destroy_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: %s\n", PAPI_strerror (ret)); if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: failure creating eventset: %s\n", PAPI_strerror (ret)); if ((ret = PAPI_multiplex_init ()) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: failure from PAPI_multiplex_init%s\n", PAPI_strerror (ret)); if ((ret = PAPI_set_multiplex (EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: failure from PAPI_set_multiplex: %s\n", PAPI_strerror (ret)); for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { ret = PAPI_event_code_to_name (papieventlist[n], eventname); return GPTLerror ("GPTLcreate_and_start_events: failure adding event:%s\n" " Error was: %s\n", eventname, PAPI_strerror (ret)); } } } /* Start the event set. It will only be read from now on--never stopped */ if ((ret = PAPI_start (EventSet[t])) != PAPI_OK) return GPTLerror ("GPTLcreate_and_start_events: failed to start event set: %s\n", PAPI_strerror (ret)); return 0; }
/* ** GPTLcreate_and_start_events: Create and start the PAPI eventset. ** Threaded routine to create the "event set" (PAPI terminology) and start ** the counters. This is only done once, and is called from get_thread_num ** for the first time for the thread. ** ** Input args: ** t: thread number ** ** Return value: 0 (success) or GPTLerror (failure) */ int GPTLcreate_and_start_events (const int t) /* thread number */ { int ret; /* return code */ int n; /* loop index over events */ char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ static const char *thisfunc = "GPTLcreate_and_start_events"; /* ** Set the domain to count all contexts. Only needs to be set once for all threads */ if ((ret = PAPI_set_domain (PAPI_DOM_ALL)) != PAPI_OK) return GPTLerror ("%s: thread %d failure setting PAPI domain: %s\n", thisfunc, t, PAPI_strerror (ret)); /* Create the event set */ if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: thread %d failure creating eventset: %s\n", thisfunc, t, PAPI_strerror (ret)); if (verbose) printf ("%s: successfully created eventset for thread %d\n", thisfunc, t); /* Add requested events to the event set */ for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { if (verbose) { fprintf (stderr, "%s\n", PAPI_strerror (ret)); ret = PAPI_event_code_to_name (papieventlist[n], eventname); fprintf (stderr, "%s: failure adding event:%s\n", thisfunc, eventname); } if (enable_multiplexing) { if (verbose) printf ("Trying multiplexing...\n"); is_multiplexed = true; break; } else return GPTLerror ("enable_multiplexing is false: giving up\n"); } } if (is_multiplexed) { /* Cleanup the eventset for multiplexing */ if ((ret = PAPI_cleanup_eventset (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_destroy_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failure creating eventset: %s\n", thisfunc, PAPI_strerror (ret)); /* ** Assign EventSet to component 0 (cpu). This step is MANDATORY in recent PAPI releases ** in order to enable event multiplexing */ if ((ret = PAPI_assign_eventset_component (EventSet[t], 0)) != PAPI_OK) return GPTLerror ("%s: thread %d failure in PAPI_assign_eventset_component: %s\n", thisfunc, t, PAPI_strerror (ret)); if ((ret = PAPI_multiplex_init ()) != PAPI_OK) return GPTLerror ("%s: failure from PAPI_multiplex_init%s\n", thisfunc, PAPI_strerror (ret)); if ((ret = PAPI_set_multiplex (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failure from PAPI_set_multiplex: %s\n", thisfunc, PAPI_strerror (ret)); for (n = 0; n < npapievents; n++) { if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) { ret = PAPI_event_code_to_name (papieventlist[n], eventname); return GPTLerror ("%s: failure adding event:%s Error was: %s\n", thisfunc, eventname, PAPI_strerror (ret)); } } } /* Start the event set. It will only be read from now on--never stopped */ if ((ret = PAPI_start (EventSet[t])) != PAPI_OK) return GPTLerror ("%s: failed to start event set: %s\n", thisfunc, PAPI_strerror (ret)); return 0; }
int GPTL_PAPIsetoption (const int counter, /* PAPI counter (or option) */ const int val) /* true or false for enable or disable */ { int n; /* loop index */ int ret; /* return code */ int numidx; /* numerator index */ int idx; /* derived counter index */ char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */ /* ** First, check for option which is not an actual counter */ switch (counter) { case GPTLverbose: /* don't printf here--that'd duplicate what's in gptl.c */ verbose = (bool) val; return 0; case GPTLmultiplex: enable_multiplexing = (bool) val; if (verbose) printf ("GPTL_PAPIsetoption: boolean enable_multiplexing = %d\n", val); return 0; case GPTLnarrowprint: narrowprint = (bool) val; if (verbose) printf ("GPTL_PAPIsetoption: boolean narrowprint = %d\n", val); return 0; case GPTLpersec: persec = (bool) val; if (verbose) printf ("GPTL_PAPIsetoption: boolean persec = %d\n", val); return 0; default: break; } /* ** If val is false, return an error if the event has already been enabled. ** Otherwise just warn that attempting to disable a PAPI-based event ** that has already been enabled doesn't work--for now it's just a no-op */ if (! val) { if (already_enabled (counter)) return GPTLerror ("GPTL_PAPIsetoption: already enabled counter %d cannot be disabled\n", counter); else if (verbose) printf ("GPTL_PAPIsetoption: 'disable' %d currently is just a no-op\n", counter); return 0; } /* If the event has already been enabled for printing, exit */ if (already_enabled (counter)) return GPTLerror ("GPTL_PAPIsetoption: counter %d has already been enabled\n", counter); /* ** Initialize PAPI if it hasn't already been done. ** From here on down we can assume the intent is to enable (not disable) an option */ if (GPTL_PAPIlibraryinit () < 0) return GPTLerror ("GPTL_PAPIsetoption: PAPI library init error\n"); /* Ensure max nevents won't be exceeded */ if (nevents+1 > MAX_AUX) return GPTLerror ("GPTL_PAPIsetoption: %d is too many events. Can be increased in private.h\n", nevents+1); /* Check derived events */ switch (counter) { case GPTL_IPC: if ( ! canenable2 (PAPI_TOT_INS, PAPI_TOT_CYC)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_IPC unavailable\n"); idx = getderivedidx (GPTL_IPC); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_TOT_INS); pr_event[nevents].denomidx = enable (PAPI_TOT_CYC); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_TOT_INS / PAPI_TOT_CYC\n", pr_event[nevents].event.namestr); ++nevents; return 0; case GPTL_CI: idx = getderivedidx (GPTL_CI); if (canenable2 (PAPI_FP_OPS, PAPI_LST_INS)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_FP_OPS); pr_event[nevents].denomidx = enable (PAPI_LST_INS); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_FP_OPS / PAPI_LST_INS\n", pr_event[nevents].event.namestr); } else if (canenable2 (PAPI_FP_OPS, PAPI_L1_DCA)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_FP_OPS); pr_event[nevents].denomidx = enable (PAPI_L1_DCA); #ifdef DEBUG printf ("GPTL_PAPIsetoption: pr_event %d is derived and will be PAPI event %d / %d\n", nevents, pr_event[nevents].numidx, pr_event[nevents].denomidx); #endif if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_FP_OPS / PAPI_L1_DCA\n", pr_event[nevents].event.namestr); } else { return GPTLerror ("GPTL_PAPIsetoption: GPTL_CI unavailable\n"); } ++nevents; return 0; case GPTL_FPC: if ( ! canenable2 (PAPI_FP_OPS, PAPI_TOT_CYC)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_FPC unavailable\n"); idx = getderivedidx (GPTL_FPC); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_FP_OPS); pr_event[nevents].denomidx = enable (PAPI_TOT_CYC); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_FP_OPS / PAPI_TOT_CYC\n", pr_event[nevents].event.namestr); ++nevents; return 0; case GPTL_FPI: if ( ! canenable2 (PAPI_FP_OPS, PAPI_TOT_INS)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_FPI unavailable\n"); idx = getderivedidx (GPTL_FPI); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_FP_OPS); pr_event[nevents].denomidx = enable (PAPI_TOT_INS); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_FP_OPS / PAPI_TOT_INS\n", pr_event[nevents].event.namestr); ++nevents; return 0; case GPTL_LSTPI: idx = getderivedidx (GPTL_LSTPI); if (canenable2 (PAPI_LST_INS, PAPI_TOT_INS)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_LST_INS); pr_event[nevents].denomidx = enable (PAPI_TOT_INS); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_LST_INS / PAPI_TOT_INS\n", pr_event[nevents].event.namestr); } else if (canenable2 (PAPI_L1_DCA, PAPI_TOT_INS)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L1_DCA); pr_event[nevents].denomidx = enable (PAPI_TOT_INS); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L1_DCA / PAPI_TOT_INS\n", pr_event[nevents].event.namestr); } else { return GPTLerror ("GPTL_PAPIsetoption: GPTL_LSTPI unavailable\n"); } ++nevents; return 0; case GPTL_DCMRT: if ( ! canenable2 (PAPI_L1_DCM, PAPI_L1_DCA)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_DCMRT unavailable\n"); idx = getderivedidx (GPTL_DCMRT); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L1_DCM); pr_event[nevents].denomidx = enable (PAPI_L1_DCA); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L1_DCM / PAPI_L1_DCA\n", pr_event[nevents].event.namestr); ++nevents; return 0; case GPTL_LSTPDCM: idx = getderivedidx (GPTL_LSTPDCM); if (canenable2 (PAPI_LST_INS, PAPI_L1_DCM)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_LST_INS); pr_event[nevents].denomidx = enable (PAPI_L1_DCM); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_LST_INS / PAPI_L1_DCM\n", pr_event[nevents].event.namestr); } else if (canenable2 (PAPI_L1_DCA, PAPI_L1_DCM)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L1_DCA); pr_event[nevents].denomidx = enable (PAPI_L1_DCM); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L1_DCA / PAPI_L1_DCM\n", pr_event[nevents].event.namestr); } else { return GPTLerror ("GPTL_PAPIsetoption: GPTL_LSTPDCM unavailable\n"); } ++nevents; return 0; /* ** For L2 counts, use TC* instead of DC* to avoid PAPI derived events */ case GPTL_L2MRT: if ( ! canenable2 (PAPI_L2_TCM, PAPI_L2_TCA)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_L2MRT unavailable\n"); idx = getderivedidx (GPTL_L2MRT); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L2_TCM); pr_event[nevents].denomidx = enable (PAPI_L2_TCA); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L2_TCM / PAPI_L2_TCA\n", pr_event[nevents].event.namestr); ++nevents; return 0; case GPTL_LSTPL2M: idx = getderivedidx (GPTL_LSTPL2M); if (canenable2 (PAPI_LST_INS, PAPI_L2_TCM)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_LST_INS); pr_event[nevents].denomidx = enable (PAPI_L2_TCM); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_LST_INS / PAPI_L2_TCM\n", pr_event[nevents].event.namestr); } else if (canenable2 (PAPI_L1_DCA, PAPI_L2_TCM)) { pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L1_DCA); pr_event[nevents].denomidx = enable (PAPI_L2_TCM); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L1_DCA / PAPI_L2_TCM\n", pr_event[nevents].event.namestr); } else { return GPTLerror ("GPTL_PAPIsetoption: GPTL_LSTPL2M unavailable\n"); } ++nevents; return 0; case GPTL_L3MRT: if ( ! canenable2 (PAPI_L3_TCM, PAPI_L3_TCR)) return GPTLerror ("GPTL_PAPIsetoption: GPTL_L3MRT unavailable\n"); idx = getderivedidx (GPTL_L3MRT); pr_event[nevents].event = derivedtable[idx]; pr_event[nevents].numidx = enable (PAPI_L3_TCM); pr_event[nevents].denomidx = enable (PAPI_L3_TCR); if (verbose) printf ("GPTL_PAPIsetoption: enabling derived event %s = PAPI_L3_TCM / PAPI_L3_TCR\n", pr_event[nevents].event.namestr); ++nevents; return 0; default: break; } /* Check PAPI presets */ for (n = 0; n < npapientries; n++) { if (counter == papitable[n].counter) { if ((numidx = papievent_is_enabled (counter)) >= 0) { pr_event[nevents].event = papitable[n]; pr_event[nevents].numidx = numidx; pr_event[nevents].denomidx = -1; /* flag says not derived (no denominator) */ } else if (canenable (counter)) { pr_event[nevents].event = papitable[n]; pr_event[nevents].numidx = enable (counter); pr_event[nevents].denomidx = -1; /* flag says not derived (no denominator) */ } else { return GPTLerror ("GPTL_PAPIsetoption: Can't enable event \n", papitable[n].longstr); } if (verbose) printf ("GPTL_PAPIsetoption: enabling PAPI preset event %s\n", pr_event[nevents].event.namestr); ++nevents; return 0; } } /* ** Check native events last: If PAPI_event_code_to_name fails, give up */ if ((ret = PAPI_event_code_to_name (counter, eventname)) != PAPI_OK) return GPTLerror ("GPTL_PAPIsetoption: name not found for counter %d: PAPI_strerror: %s\n", counter, PAPI_strerror (ret)); /* ** A table with predefined names of various lengths does not exist for ** native events. Just truncate eventname. */ if ((numidx = papievent_is_enabled (counter)) >= 0) { pr_event[nevents].event.counter = counter; pr_event[nevents].event.namestr = (char *) GPTLallocate (12+1); strncpy (pr_event[nevents].event.namestr, eventname, 12); pr_event[nevents].event.namestr[12] = '\0'; pr_event[nevents].event.str16 = (char *) GPTLallocate (16+1); strncpy (pr_event[nevents].event.str16, eventname, 16); pr_event[nevents].event.str16[16] = '\0'; pr_event[nevents].event.longstr = (char *) GPTLallocate (PAPI_MAX_STR_LEN); strncpy (pr_event[nevents].event.longstr, eventname, PAPI_MAX_STR_LEN); pr_event[nevents].numidx = numidx; pr_event[nevents].denomidx = -1; /* flag says not derived (no denominator) */ } else if (canenable (counter)) { pr_event[nevents].event.counter = counter; pr_event[nevents].event.namestr = (char *) GPTLallocate (12+1); strncpy (pr_event[nevents].event.namestr, eventname, 12); pr_event[nevents].event.namestr[12] = '\0'; pr_event[nevents].event.str16 = (char *) GPTLallocate (16+1); strncpy (pr_event[nevents].event.str16, eventname, 16); pr_event[nevents].event.str16[16] = '\0'; pr_event[nevents].event.longstr = (char *) GPTLallocate (PAPI_MAX_STR_LEN); strncpy (pr_event[nevents].event.longstr, eventname, PAPI_MAX_STR_LEN); pr_event[nevents].numidx = enable (counter); pr_event[nevents].denomidx = -1; /* flag says not derived (no denominator) */ } else { return GPTLerror ("GPTL_PAPIsetoption: Can't enable event %s\n", eventname); } if (verbose) printf ("GPTL_PAPIsetoption: enabling native event %s\n", pr_event[nevents].event.longstr); ++nevents; return 0; }
int GPTLevent_code_to_name (int code, char *name) { return GPTLerror ("GPTLevent_code_to_name: PAPI not enabled\n"); }
int GPTLevent_name_to_code (const char *name, int *code) { return GPTLerror ("GPTLevent_name_to_code: PAPI not enabled\n"); }
int GPTL_PAPIlibraryinit () { return GPTLerror ("GPTL_PAPIlibraryinit: PAPI not enabled\n"); }