PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
papi_preset.c File Reference
Include dependency graph for papi_preset.c:

Go to the source code of this file.

Macros

#define PAPI_EVENT_FILE   "papi_events.csv"
 

Functions

int _papi_hwi_setup_all_presets (hwi_search_t *findem, int cidx)
 
int _papi_hwi_cleanup_all_presets (void)
 
static char * trim_string (char *in)
 
static char * trim_note (char *in)
 
static int find_preset_code (char *tmp, int *code)
 
static FILE * open_event_table (char *name)
 
static int get_event_line (char *line, FILE *table, char **tmp_perfmon_events_table)
 
int _papi_load_preset_table (char *pmu_str, int pmu_type, int cidx)
 

Variables

static char * papi_events_table = NULL
 

Macro Definition Documentation

#define PAPI_EVENT_FILE   "papi_events.csv"

Definition at line 144 of file papi_preset.c.

Function Documentation

int _papi_hwi_cleanup_all_presets ( void  )

Definition at line 107 of file papi_preset.c.

108 {
109  int preset_index,cidx;
110  unsigned int j;
111 
112  for ( preset_index = 0; preset_index < PAPI_MAX_PRESET_EVENTS;
113  preset_index++ ) {
114  if ( _papi_hwi_presets[preset_index].postfix != NULL ) {
115  free( _papi_hwi_presets[preset_index].postfix );
116  _papi_hwi_presets[preset_index].postfix = NULL;
117  }
118  if ( _papi_hwi_presets[preset_index].note != NULL ) {
119  free( _papi_hwi_presets[preset_index].note );
120  _papi_hwi_presets[preset_index].note = NULL;
121  }
122  for(j=0; j<_papi_hwi_presets[preset_index].count;j++) {
123  free(_papi_hwi_presets[preset_index].name[j]);
124  }
125  }
126 
127  for(cidx=0;cidx<papi_num_components;cidx++) {
128  _papi_hwd[cidx]->cmp_info.num_preset_events = 0;
129  }
130 
131 #if defined(ITANIUM2) || defined(ITANIUM3)
132  /* NOTE: This memory may need to be freed for BG/P builds as well */
133  if ( preset_search_map != NULL ) {
135  preset_search_map = NULL;
136  }
137 #endif
138 
139  return PAPI_OK;
140 }
#define papi_free(a)
Definition: papi_memory.h:35
return PAPI_OK
Definition: linux-nvml.c:458
free(dummyfile[xx])
static int cidx
Definition: event_info.c:40
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
hwi_search_t * preset_search_map
#define PAPI_MAX_PRESET_EVENTS
Definition: fpapi.h:16
int papi_num_components
char * name
Definition: iozone.c:23648
struct papi_vectors * _papi_hwd[]
long j
Definition: iozone.c:19135
unsigned int count
Definition: papi_preset.h:29
char * postfix
Definition: papi_preset.h:31

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_setup_all_presets ( hwi_search_t findem,
int  cidx 
)

Definition at line 37 of file papi_preset.c.

38 {
39  int i, pnum, did_something = 0;
40  unsigned int preset_index, j, k;
41 
42  /* dense array of events is terminated with a 0 preset.
43  don't do anything if NULL pointer. This allows just notes to be loaded.
44  It's also good defensive programming.
45  */
46  if ( findem != NULL ) {
47  for ( pnum = 0; ( pnum < PAPI_MAX_PRESET_EVENTS ) &&
48  ( findem[pnum].event_code != 0 ); pnum++ ) {
49  /* find the index for the event to be initialized */
50  preset_index = ( findem[pnum].event_code & PAPI_PRESET_AND_MASK );
51  /* count and set the number of native terms in this event,
52  these items are contiguous.
53 
54  PAPI_EVENTS_IN_DERIVED_EVENT is arbitrarily defined in the high
55  level to be a reasonable number of terms to use in a derived
56  event linear expression, currently 8.
57 
58  This wastes space for components with less than 8 counters,
59  but keeps the framework independent of the components.
60 
61  The 'native' field below is an arbitrary opaque identifier
62  that points to information on an actual native event.
63  It is not an event code itself (whatever that might mean).
64  By definition, this value can never == PAPI_NULL.
65  - dkt */
66 
67  INTDBG( "Counting number of terms for preset index %d, "
68  "search map index %d.\n", preset_index, pnum );
69  i = 0;
70  j = 0;
71  while ( i < PAPI_EVENTS_IN_DERIVED_EVENT ) {
72  if ( findem[pnum].native[i] != PAPI_NULL ) {
73  j++;
74  }
75  else if ( j ) {
76  break;
77  }
78  i++;
79  }
80 
81  INTDBG( "This preset has %d terms.\n", j );
82  _papi_hwi_presets[preset_index].count = j;
83 
84  _papi_hwi_presets[preset_index].derived_int = findem[pnum].derived;
85  for(k=0;k<j;k++) {
86  _papi_hwi_presets[preset_index].code[k] =
87  findem[pnum].native[k];
88  }
89  /* preset code list must be PAPI_NULL terminated */
91  _papi_hwi_presets[preset_index].code[k] = PAPI_NULL;
92  }
93 
94  _papi_hwi_presets[preset_index].postfix=
95  strdup(findem[pnum].operation);
96 
97  did_something++;
98  }
99  }
100 
101  _papi_hwd[cidx]->cmp_info.num_preset_events += did_something;
102 
103  return ( did_something ? PAPI_OK : PAPI_ENOEVNT );
104 }
#define PAPI_EVENTS_IN_DERIVED_EVENT
Definition: genpapifdef.c:39
#define PAPI_NULL
Definition: fpapi.h:13
unsigned int event_code
Definition: papi_preset.h:14
#define PAPI_ENOEVNT
Definition: fpapi.h:112
return PAPI_OK
Definition: linux-nvml.c:458
#define INTDBG(format, args...)
Definition: papi_debug.h:65
int i
Definition: fileop.c:140
static int cidx
Definition: event_info.c:40
int k
Definition: iozone.c:19136
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
static int native
Definition: event_info.c:39
int native[PAPI_EVENTS_IN_DERIVED_EVENT]
Definition: papi_preset.h:16
#define PAPI_MAX_PRESET_EVENTS
Definition: fpapi.h:16
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi_preset.h:32
#define PAPI_PRESET_AND_MASK
struct papi_vectors * _papi_hwd[]
long j
Definition: iozone.c:19135
unsigned int count
Definition: papi_preset.h:29
char * postfix
Definition: papi_preset.h:31

Here is the caller graph for this function:

int _papi_load_preset_table ( char *  pmu_str,
int  pmu_type,
int  cidx 
)

Definition at line 299 of file papi_preset.c.

300 {
301 
302  (void) cidx; /* We'll use this later */
303 
304  char pmu_name[PAPI_MIN_STR_LEN];
305  char line[LINE_MAX];
306  char name[PATH_MAX] = "builtin papi_events_table";
307  char *tmp_papi_events_table = NULL;
308  char *tmpn;
309  FILE *table;
310  int ret;
311  unsigned int event_idx;
312  int invalid_event;
313  int line_no = 1, derived = 0, insert = 0, preset = 0;
314  int get_presets = 0; /* only get PRESETS after CPU is identified */
315  int found_presets = 0; /* only terminate search after PRESETS are found */
316  /* this allows support for synonyms for CPU names*/
317 
318  SUBDBG("ENTER\n");
319 
320  /* copy the pmu identifier, stripping commas if found */
321  tmpn = pmu_name;
322  while ( *pmu_str ) {
323  if ( *pmu_str != ',' ) *tmpn++ = *pmu_str;
324  pmu_str++;
325  }
326  *tmpn = '\0';
327 
328  /* try the environment variable first */
329  if ( ( tmpn = getenv( "PAPI_CSV_EVENT_FILE" ) ) &&
330  ( strlen( tmpn ) != 0 ) ) {
331  sprintf( name, "%s", tmpn );
332  table = fopen( name, "r" );
333  }
334  /* if no valid environment variable, look for built-in table */
335  else if ( papi_events_table ) {
336  tmp_papi_events_table = papi_events_table;
337  table = NULL;
338  }
339  /* if no env var and no built-in, search for default file */
340  else {
341 #ifdef PAPI_DATADIR
342  sprintf( name, "%s/%s", PAPI_DATADIR, PAPI_EVENT_FILE );
343 #else
344  sprintf( name, "%s", PAPI_EVENT_FILE );
345 #endif
346  table = open_event_table( name );
347  }
348 
349  /* if no valid file or built-in table, bail */
350  if ( table == NULL && tmp_papi_events_table == NULL ) {
351  PAPIERROR( "fopen(%s): %s, please set the PAPI_CSV_EVENT_FILE "
352  "env. variable", name, strerror( errno ) );
353  return PAPI_ESYS;
354  }
355 
356  /* at this point either a valid file pointer or built-in table pointer */
357  while ( get_event_line( line, table, &tmp_papi_events_table ) ) {
358  char *t;
359  int i;
360 
361  t = trim_string( strtok( line, "," ) );
362 
363  /* Skip blank lines */
364  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) continue;
365 
366  /* Skip comments */
367  if ( t[0] == '#' ) {
368  goto nextline;
369  }
370 
371  if ( strcasecmp( t, "CPU" ) == 0 ) {
372 
373  if ( get_presets != 0 && found_presets != 0 ) {
374  SUBDBG( "Ending preset scanning at line %d of %s.\n",
375  line_no, name );
376 
377  get_presets=0; found_presets=0;
378 
379  }
380 
381  t = trim_string( strtok( NULL, "," ) );
382  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
383  PAPIERROR( "Expected name after CPU token at line %d of %s "
384  "-- ignoring", line_no, name );
385  goto nextline;
386  }
387 
388  SUBDBG( "Examining CPU (%s) vs. (%s)\n", t, pmu_name );
389 
390  if ( strcasecmp( t, pmu_name ) == 0 ) {
391  int type;
392 
393  SUBDBG( "Found CPU %s at line %d of %s.\n", t, line_no, name );
394 
395  t = trim_string( strtok( NULL, "," ) );
396  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
397  SUBDBG("No additional qualifier found, matching on string.\n");
398 
399  get_presets = 1;
400  } else if ( ( sscanf( t,"%d",&type )==1) && (type==pmu_type) ) {
401  SUBDBG( "Found CPU %s type %d at line %d of %s.\n",
402  pmu_name, type, line_no, name );
403  get_presets = 1;
404  } else {
405  SUBDBG( "Additional qualifier match failed %d vs %d.\n",
406  pmu_type, type );
407 
408  }
409  }
410  } else if ( strcasecmp( t, "PRESET" ) == 0 ) {
411 
412  if ( get_presets == 0 ) goto nextline;
413 
414  found_presets = 1;
415  t = trim_string( strtok( NULL, "," ) );
416 
417  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
418 
419  PAPIERROR( "Expected name after PRESET token at line %d of %s "
420  "-- ignoring", line_no, name );
421  goto nextline;
422  }
423 
424  SUBDBG( "Examining preset %s\n", t );
425 
426  if ( find_preset_code( t, &preset ) != PAPI_OK ) {
427  PAPIERROR ( "Invalid preset name %s after PRESET token "
428  "at line %d of %s -- ignoring",
429  t, line_no, name );
430  goto nextline;
431  }
432 
433  SUBDBG( "Found %#08x for %s\n", preset, t );
434 
435  t = trim_string( strtok( NULL, "," ) );
436  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
437  PAPIERROR( "Expected derived type after PRESET token at "
438  "line %d of %s -- ignoring", line_no, name );
439  goto nextline;
440  }
441 
442  if ( _papi_hwi_derived_type( t, &derived ) != PAPI_OK ) {
443  PAPIERROR( "Invalid derived name %s after PRESET token at "
444  "line %d of %s -- ignoring",
445  t, line_no, name );
446  goto nextline;
447  }
448 
449  /****************************************/
450  /* Have a preset, let's start assigning */
451  /****************************************/
452 
453  SUBDBG( "Found %d for %s\n", derived, t );
454  SUBDBG( "Adding %#x,%d to preset search table.\n",
455  preset, derived );
456 
458 
459  /* _papi_hwi_presets[insert].event_code = preset; */
460  _papi_hwi_presets[insert].derived_int = derived;
461 
462  /* Derived support starts here */
463  /* Special handling for postfix */
464  if ( derived == DERIVED_POSTFIX ) {
465  t = trim_string( strtok( NULL, "," ) );
466  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
467  PAPIERROR( "Expected Operation string after derived type "
468  "DERIVED_POSTFIX at line %d of %s -- ignoring",
469  line_no, name );
470  goto nextline;
471  }
472 
473  SUBDBG( "Saving PostFix operations %s\n", t );
474 
475  _papi_hwi_presets[insert].postfix=strdup(t);
476  }
477 
478  /* All derived terms collected here */
479  i = 0;
480  invalid_event=0;
481  do {
482  t = trim_string( strtok( NULL, "," ) );
483  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) break;
484  if ( strcasecmp( t, "NOTE" ) == 0 ) break;
485  _papi_hwi_presets[insert].name[i]=strdup(t);
486 
487  SUBDBG( "Adding term (%d) %s to preset event %#x.\n",
488  i, t, preset );
489 
490  SUBDBG("Looking up: %s\n",t);
491 
492  ret=_papi_hwd[cidx]->ntv_name_to_code(t, &event_idx);
493 
494  if (ret==PAPI_OK) {
495  _papi_hwi_presets[insert].code[i]=
497  SUBDBG("Found: %s %#x c%d e%d\n",t,
498  _papi_hwi_presets[insert].code[i],
499  cidx,event_idx);
500  }
501  else {
502  PAPIERROR("papi_preset: Error finding event %s",t);
503  invalid_event=1;
504  }
505 
506  } while ( ++i < PAPI_EVENTS_IN_DERIVED_EVENT );
507 
508  /* preset code list must be PAPI_NULL terminated */
510  _papi_hwi_presets[insert].code[i] = PAPI_NULL;
511  }
512 
513  if (invalid_event) {
514  /* We signify a valid preset if count > 0 */
515  _papi_hwi_presets[insert].count=0;
516  } else {
517  _papi_hwi_presets[insert].count=i;
518  }
519 
520  /* End of derived support */
521 
522  if ( i == 0 ) {
523  PAPIERROR( "Expected PFM event after DERIVED token at "
524  "line %d of %s -- ignoring", line_no, name );
525  goto nextline;
526  }
527  if ( i == PAPI_EVENTS_IN_DERIVED_EVENT ) {
528  t = trim_string( strtok( NULL, "," ) );
529  }
530 
531  /* Handle optional NOTEs */
532  if ( t && ( strcasecmp( t, "NOTE" ) == 0 ) ) {
533  SUBDBG( "%s found on line %d\n", t, line_no );
534 
535  /* read the rest of the line */
536  t = trim_note( strtok( NULL, "" ) );
537 
538  if ( ( t == NULL ) || ( strlen( t ) == 0 ) ) {
539  PAPIERROR( "Expected Note string at line %d of %s\n",
540  line_no, name );
541  }
542  else {
543  _papi_hwi_presets[insert].note = strdup( t );
544  SUBDBG( "NOTE: --%s-- found on line %d\n", t, line_no );
545  }
546  }
547  _papi_hwd[cidx]->cmp_info.num_preset_events++;
548 
549  } else {
550  PAPIERROR( "Unrecognized token %s at line %d of %s -- ignoring",
551  t, line_no, name );
552  goto nextline;
553  }
554 nextline:
555  line_no++;
556  }
557 
558  if ( table ) {
559  fclose( table );
560  }
561 
562  SUBDBG("Done parsing preset table\n");
563 
564  return PAPI_OK;
565 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int errno
char * getenv()
#define PAPI_EVENTS_IN_DERIVED_EVENT
Definition: genpapifdef.c:39
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
static char * trim_note(char *in)
Definition: papi_preset.c:190
int _papi_hwi_derived_type(char *tmp, int *code)
return PAPI_OK
Definition: linux-nvml.c:458
static int preset
Definition: event_info.c:38
fclose(thread_wqfd)
void
Definition: iozone.c:18627
static char * papi_events_table
Definition: papi_preset.c:295
long long ret
Definition: iozone.c:1346
t
Definition: iozone.c:23562
static int find_preset_code(char *tmp, int *code)
Definition: papi_preset.c:218
int i
Definition: fileop.c:140
static int cidx
Definition: event_info.c:40
#define PAPI_EVENT_FILE
Definition: papi_preset.c:144
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
void PAPIERROR(char *format,...)
#define PAPI_ESYS
Definition: fpapi.h:108
static int get_event_line(char *line, FILE *table, char **tmp_perfmon_events_table)
Definition: papi_preset.c:262
static FILE * open_event_table(char *name)
Definition: papi_preset.c:235
int _papi_hwi_native_to_eventcode(int cidx, int event_code)
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
#define PATH_MAX
Definition: fileop.c:68
char * name
Definition: iozone.c:23648
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi_preset.h:32
char * name[PAPI_MAX_INFO_TERMS]
Definition: papi_preset.h:33
static char * trim_string(char *in)
Definition: papi_preset.c:150
#define PAPI_PRESET_AND_MASK
struct papi_vectors * _papi_hwd[]
#define DERIVED_POSTFIX
Definition: papi_internal.h:75
unsigned int count
Definition: papi_preset.h:29
char * postfix
Definition: papi_preset.h:31

Here is the call graph for this function:

Here is the caller graph for this function:

static int find_preset_code ( char *  tmp,
int code 
)
inlinestatic

Definition at line 218 of file papi_preset.c.

219 {
220  int i = 0;
221 
222  while ( _papi_hwi_presets[i].symbol != NULL ) {
223  if ( strcasecmp( tmp, _papi_hwi_presets[i].symbol ) == 0 ) {
224  *code = ( int ) ( i | PAPI_PRESET_MASK );
225  return PAPI_OK;
226  }
227  i++;
228  }
229  return PAPI_EINVAL;
230 }
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_PRESET_MASK
return PAPI_EINVAL
Definition: linux-nvml.c:408
int i
Definition: fileop.c:140
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
int
Definition: iozone.c:18528
long long tmp
Definition: iozone.c:12031

Here is the caller graph for this function:

static int get_event_line ( char *  line,
FILE *  table,
char **  tmp_perfmon_events_table 
)
static

Definition at line 262 of file papi_preset.c.

263 {
264  int i;
265 
266  if ( table ) {
267  if ( fgets( line, LINE_MAX, table ) == NULL)
268  return 0;
269 
270  i = ( int ) strlen( line );
271  if (i == 0)
272  return 0;
273  if ( line[i-1] == '\n' )
274  line[i-1] = '\0';
275  return 1;
276  } else {
277  for ( i = 0;
278  **tmp_perfmon_events_table && **tmp_perfmon_events_table != '\n';
279  i++, ( *tmp_perfmon_events_table )++ )
280  line[i] = **tmp_perfmon_events_table;
281  if (i == 0)
282  return 0;
283  if ( **tmp_perfmon_events_table && **tmp_perfmon_events_table == '\n' ) {
284  ( *tmp_perfmon_events_table )++;
285  }
286  line[i] = '\0';
287  return 1;
288  }
289 }
int i
Definition: fileop.c:140
int
Definition: iozone.c:18528

Here is the caller graph for this function:

static FILE* open_event_table ( char *  name)
static

Definition at line 235 of file papi_preset.c.

236 {
237  FILE *table;
238 
239  SUBDBG( "Opening %s\n", name );
240  table = fopen( name, "r" );
241  if ( table == NULL ) {
242  SUBDBG( "Open %s failed, trying ./%s.\n",
244  sprintf( name, "%s", PAPI_EVENT_FILE );
245  table = fopen( name, "r" );
246  }
247  if ( table == NULL ) {
248  SUBDBG( "Open ./%s failed, trying ../%s.\n",
250  sprintf( name, "../%s", PAPI_EVENT_FILE );
251  table = fopen( name, "r" );
252  }
253  if ( table ) {
254  SUBDBG( "Open %s succeeded.\n", name );
255  }
256  return table;
257 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define PAPI_EVENT_FILE
Definition: papi_preset.c:144
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
char * name
Definition: iozone.c:23648

Here is the call graph for this function:

Here is the caller graph for this function:

static char* trim_note ( char *  in)
inlinestatic

Definition at line 190 of file papi_preset.c.

191 {
192  int len;
193  char *note, start, end;
194 
195  note = trim_string( in );
196  if ( note != NULL ) {
197  len = ( int ) strlen( note );
198  if ( len > 0 ) {
199  if ( ispunct( *note ) ) {
200  start = *note;
201  end = note[len - 1];
202  if ( ( start == end )
203  || ( ( start == '(' ) && ( end == ')' ) )
204  || ( ( start == '<' ) && ( end == '>' ) )
205  || ( ( start == '{' ) && ( end == '}' ) )
206  || ( ( start == '[' ) && ( end == ']' ) ) ) {
207  note[len - 1] = '\0';
208  *note = '\0';
209  note++;
210  }
211  }
212  }
213  }
214  return note;
215 }
start
Definition: iozone.c:22736
int
Definition: iozone.c:18528
static char * trim_string(char *in)
Definition: papi_preset.c:150

Here is the call graph for this function:

Here is the caller graph for this function:

static char* trim_string ( char *  in)
inlinestatic

Definition at line 150 of file papi_preset.c.

151 {
152  int len, i = 0;
153  char *start = in;
154 
155  if ( in == NULL )
156  return ( in );
157  len = ( int ) strlen( in );
158  if ( len == 0 )
159  return ( in );
160 
161  /* Trim left */
162  while ( i < len ) {
163  if ( isblank( in[i] ) ) {
164  in[i] = '\0';
165  start++;
166  } else
167  break;
168  i++;
169  }
170 
171  /* Trim right */
172  i = ( int ) strlen( start ) - 1;
173  while ( i >= 0 ) {
174  if ( isblank( start[i] ) )
175  start[i] = '\0';
176  else
177  break;
178  i--;
179  }
180  return ( start );
181 }
start
Definition: iozone.c:22736
int i
Definition: fileop.c:140
int
Definition: iozone.c:18528

Here is the caller graph for this function:

Variable Documentation

char* papi_events_table = NULL
static

Definition at line 295 of file papi_preset.c.