int _papi_hwi_cleanup_all_presets(void) { int preset_index; for (preset_index = 0; preset_index < PAPI_MAX_PRESET_EVENTS; preset_index++) { /* There's currently a debate over the use of papi_xxx memory functions. One camp says they should always be used; the other says they're only for debug. Meanwhile, our code had better not rely on their function... */ #ifndef PAPI_NO_MEMORY_MANAGEMENT /* free the names and descriptions only if they were malloc'd by PAPI * Generally, this info is statically allocated at compile time. * However, it is possible to override existing info, or append new * info to the table. In these cases, papi_valid_free can prevent * pointers from being stranded. */ #ifdef PAPI_MOD_EVENTS /* this can only happen if events are modifiable */ if (papi_valid_free(_papi_hwi_presets.info[preset_index].symbol)) _papi_hwi_presets.info[preset_index].symbol = NULL; if (papi_valid_free(_papi_hwi_presets.info[preset_index].long_descr)) _papi_hwi_presets.info[preset_index].long_descr = NULL; if (papi_valid_free(_papi_hwi_presets.info[preset_index].short_descr)) _papi_hwi_presets.info[preset_index].short_descr = NULL; #endif #endif /* free the data and or note string if they exist */ if (_papi_hwi_presets.data[preset_index] != NULL) { papi_free(_papi_hwi_presets.data[preset_index]); _papi_hwi_presets.data[preset_index] = NULL; } if (_papi_hwi_presets.dev_note[preset_index] != NULL) { papi_free(_papi_hwi_presets.dev_note[preset_index]); _papi_hwi_presets.dev_note[preset_index] = NULL; } } /* xxxx right now presets are only cpu, component 0 */ _papi_hwd[0]->cmp_info.num_preset_events = 0; return (PAPI_OK); }
/* The function below, _xml_start(), is a hook into expat's XML * parser. _xml_start() defines how the parser handles the * opening tags in PAPI's XML file. This function can be understood * more easily if you follow along with its logic while looking at * papi_events.xml. The location variable is a global telling us * where we are in the XML file. Have we found our architecture's * events yet? Are we looking at an event definition?...etc. */ static void _xml_start( void *data, const char *el, const char **attr ) { int native_encoding; if ( location == SPARSE_BEGIN && !strcmp( "papistdevents", el ) ) { location = SPARSE_EVENT_SEARCH; } else if ( location == SPARSE_EVENT_SEARCH && !strcmp( "papievent", el ) ) { _papi_hwi_presets[sparse_index].info.symbol = papi_strdup( attr[1] ); // strcpy(_papi_hwi_presets.info[sparse_index].symbol, attr[1]); location = SPARSE_EVENT; } else if ( location == SPARSE_EVENT && !strcmp( "desc", el ) ) { location = SPARSE_DESC; } else if ( location == ARCH_SEARCH && !strcmp( "availevents", el ) && !strcmp( xml_arch, attr[1] ) ) { location = DENSE_EVENT_SEARCH; } else if ( location == DENSE_EVENT_SEARCH && !strcmp( "papievent", el ) ) { if ( !strcmp( "PAPI_NULL", attr[1] ) ) { location = FINISHED; return; } else if ( PAPI_event_name_to_code( ( char * ) attr[1], &sparse_index ) != PAPI_OK ) { PAPIERROR( "Improper Preset name given in XML file for %s.", attr[1] ); error = 1; } sparse_index &= PAPI_PRESET_AND_MASK; /* allocate and initialize data space for this event */ papi_valid_free( _papi_hwi_presets[sparse_index].data ); _papi_hwi_presets[sparse_index].data = papi_malloc( sizeof ( hwi_preset_data_t ) ); native_index = 0; _papi_hwi_presets[sparse_index].data->native[native_index] = PAPI_NULL; _papi_hwi_presets[sparse_index].data->operation[0] = '\0'; if ( attr[2] ) { /* derived event */ _papi_hwi_presets[sparse_index].data->derived = _papi_hwi_derived_type( ( char * ) attr[3] ); /* where does DERIVED POSTSCRIPT get encoded?? */ if ( _papi_hwi_presets[sparse_index].data->derived == -1 ) { PAPIERROR( "No derived type match for %s in Preset XML file.", attr[3] ); error = 1; } if ( attr[5] ) { _papi_hwi_presets[sparse_index].count = atoi( attr[5] ); } else { PAPIERROR( "No count given for %s in Preset XML file.", attr[1] ); error = 1; } } else { _papi_hwi_presets[sparse_index].data->derived = NOT_DERIVED; _papi_hwi_presets[sparse_index].count = 1; } location = DENSE_NATIVE_SEARCH; } else if ( location == DENSE_NATIVE_SEARCH && !strcmp( "native", el ) ) { location = DENSE_NATIVE_DESC; } else if ( location == DENSE_NATIVE_DESC && !strcmp( "event", el ) ) { if ( _papi_hwi_native_name_to_code( attr[1], &native_encoding ) != PAPI_OK ) { printf( "Improper Native name given in XML file for %s\n", attr[1] ); PAPIERROR( "Improper Native name given in XML file for %s\n", attr[1] ); error = 1; } _papi_hwi_presets[sparse_index].data->native[native_index] = native_encoding; native_index++; _papi_hwi_presets[sparse_index].data->native[native_index] = PAPI_NULL; } else if ( location && location != ARCH_SEARCH && location != FINISHED ) { PAPIERROR( "Poorly-formed Preset XML document." ); error = 1; } }