46 int i, pnum, did_something = 0;
47 unsigned int preset_index, j, k;
53 if ( findem != NULL ) {
55 ( findem[pnum].event_code != 0 ); pnum++ ) {
74 INTDBG(
"Counting number of terms for preset index %d, "
75 "search map index %d.\n", preset_index, pnum );
88 INTDBG(
"This preset has %d terms.\n", j );
108 _papi_hwd[
cidx]->cmp_info.num_preset_events += did_something;
116 int preset_index,
cidx;
138#if defined(ITANIUM2) || defined(ITANIUM3)
151#define PAPI_EVENT_FILE "papi_events.csv"
164 len = (
int ) strlen( in );
170 if ( isblank( in[
i] ) ) {
181 if ( isblank(
start[
i] ) )
200 char *note,
start, end;
203 if ( note != NULL ) {
204 len = (
int ) strlen( note );
206 if ( ispunct( *note ) ) {
209 if ( (
start == end )
210 || ( (
start ==
'(' ) && ( end ==
')' ) )
211 || ( (
start ==
'<' ) && ( end ==
'>' ) )
212 || ( (
start ==
'{' ) && ( end ==
'}' ) )
213 || ( (
start ==
'[' ) && ( end ==
']' ) ) ) {
214 note[len - 1] =
'\0';
226 SUBDBG(
"ENTER: array: %p, size: %d, tmp: %s\n",
array, size,
tmp);
228 for (
i = 0;
i < size;
i++) {
229 if (
array[
i].symbol == NULL) {
234 if (strcasecmp(
tmp,
array[
i].symbol) == 0) {
239 SUBDBG(
"EXIT: PAPI_EINVAL\n");
251 table = fopen(
name,
"r" );
252 if ( table == NULL ) {
253 SUBDBG(
"Open %s failed, trying ./%s.\n",
256 table = fopen(
name,
"r" );
258 if ( table == NULL ) {
259 SUBDBG(
"Open ./%s failed, trying ../%s.\n",
262 table = fopen(
name,
"r" );
278 if ( fgets( line, LINE_MAX, table ) == NULL)
281 i = (
int ) strlen( line );
284 if ( line[
i-1] ==
'\n' )
289 **tmp_perfmon_events_table && **tmp_perfmon_events_table !=
'\n';
290 i++, ( *tmp_perfmon_events_table )++ )
291 line[
i] = **tmp_perfmon_events_table;
294 if ( **tmp_perfmon_events_table && **tmp_perfmon_events_table ==
'\n' ) {
295 ( *tmp_perfmon_events_table )++;
305 INTDBG(
"ENTER: *formula: %s, old_index: %d, new_index: %d\n", *formula?*formula:
"NULL", old_index, new_index);
310 char *tok_save_ptr=NULL;
313 if (*formula == NULL) {
314 INTDBG(
"EXIT: Null pointer to formula passed in\n");
319 newFormula =
papi_calloc(strlen(*formula) + 20, 1);
322 newFormula[0] =
'\0';
323 subtoken = strtok_r(*formula,
"|", &tok_save_ptr);
324 while ( subtoken != NULL) {
328 if ((subtoken[0] ==
'N') && (isdigit(subtoken[1]))) {
329 cur_index = atoi(&subtoken[1]);
331 if (cur_index == old_index) {
332 sprintf (
work,
"N%d", new_index);
333 strcat (newFormula,
work);
334 }
else if (cur_index > old_index) {
336 sprintf (
work,
"N%d", cur_index-1);
337 strcat (newFormula,
work);
340 strcat(newFormula, subtoken);
344 strcat(newFormula, subtoken);
346 strcat (newFormula,
"|");
347 subtoken = strtok_r(NULL,
"|", &tok_save_ptr);
350 *formula = newFormula;
352 INTDBG(
"EXIT: newFormula: %s\n", newFormula);
364 INTDBG(
"ENTER: results: %p, depends_on: %p, addition %d\n", results, depends_on, addition);
367 int second_event = 0;
373 if (results->
postfix != NULL) {
376 strncat(newFormula, results->
postfix,
sizeof(newFormula)-1);
377 newFormula[
sizeof(newFormula)-1] =
'\0';
387 if (depends_on->
postfix == NULL) {
388 INTDBG(
"Event %s is of type DERIVED_POSTFIX but is missing operation string\n", depends_on->
symbol);
401 for (
i=depends_on->
count-1 ;
i>=0 ;
i--) {
407 strncat(newFormula, temp,
sizeof(newFormula)-1);
408 newFormula[
sizeof(newFormula)-1] =
'\0';
417 strcat(newFormula,
work);
425 strcat(newFormula,
work);
433 strcat(newFormula,
work);
438 INTDBG(
"Event %s depends on event %s which has an unsupported derived type of %d\n", results->
symbol, depends_on->
symbol, depends_on->
derived_int);
446 strcat(newFormula,
"+|");
448 strcat(newFormula,
"-|");
457 INTDBG(
"EXIT: newFormula: %s\n", newFormula);
465 INTDBG(
"ENTER: original: %p, *original: %s, insertion: %s, replaces: %d, start_index: %d\n", original, *original, insertion, replaces, start_index);
472 char *tok_save_ptr=NULL;
478 if (*original != NULL) {
479 orig_len = strlen(*original);
481 if (insertion != NULL) {
482 ins_len = strlen(insertion);
484 newFormula =
papi_calloc (orig_len + ins_len + 40, 1);
487 if (insertion == NULL) {
490 if (workPtr[0] ==
'|') {
491 strcpy(newFormula, &workPtr[1]);
493 strcpy(newFormula, workPtr);
497 *original = newFormula;
498 INTDBG(
"EXIT: newFormula: %s\n", *original);
508 subtoken = strtok_r(workPtr,
"|", &tok_save_ptr);
509 while ( subtoken != NULL) {
511 if ((subtoken[0] ==
'N') && (isdigit(subtoken[1]))) {
513 int val = atoi(&subtoken[1]);
516 sprintf (workBuf,
"N%d", val);
518 strcpy(workBuf, subtoken);
520 strcat (newInsertion, workBuf);
521 strcat (newInsertion,
"|");
522 subtoken = strtok_r(NULL,
"|", &tok_save_ptr);
526 INTDBG(
"newInsertion: %s\n", newInsertion);
530 if (*original == NULL) {
532 INTDBG(
"EXIT: newFormula: %s\n", newInsertion);
539 if ((replaces < 0)) {
542 INTDBG(
"EXIT: Invalid value for token in original formula to be replaced\n");
552 subtoken = strtok_r(workPtr,
"|", &tok_save_ptr);
553 while ( subtoken != NULL) {
556 strcpy(workBuf, subtoken);
557 if ((subtoken[0] ==
'N') && (isdigit(subtoken[1]))) {
558 int val = atoi(&subtoken[1]);
559 if (val > replaces) {
560 val += insert_events-1;
562 sprintf (workBuf,
"N%d", val);
566 strcat (newOriginal, workBuf);
567 strcat (newOriginal,
"|");
568 subtoken = strtok_r(NULL,
"|", &tok_save_ptr);
572 INTDBG(
"newOriginal: %s\n", newOriginal);
575 newFormula[0] =
'\0';
576 workPtr = newOriginal;
577 subtoken = strtok_r(workPtr,
"|", &tok_save_ptr);
578 while ( subtoken != NULL) {
581 if ((subtoken[0] ==
'N') && (isdigit(subtoken[1])) && (replaces == atoi(&subtoken[1]))) {
583 strcat(newFormula, newInsertion);
586 strcat(newFormula, subtoken);
587 strcat(newFormula,
"|");
589 subtoken = strtok_r(NULL,
"|", &tok_save_ptr);
596 *original = newFormula;
597 INTDBG(
"EXIT: newFormula: %s\n", newFormula);
619 INTDBG(
"ENTER: target: %p (%s), results: %p, search: %p, search_size: %d, token_index: %d\n", target, target, results, search, search_size, token_index);
625 for (j=0; j < search_size; j++) {
627 if (search[j].symbol == NULL) {
628 INTDBG(
"EXIT: returned: 0\n");
633 if ( strcasecmp( target, search[j].symbol) != 0 ) {
637 INTDBG(
"Found a match\n");
642 switch (derived_type) {
660 INTDBG(
"Derived type: %d, not currently handled\n", derived_type);
666 for ( k = 0; k < (
int)search[j].
count; k++ ) {
669 for (
i=0 ;
i < results->
count ;
i++) {
670 if (results->
code[
i] == search[j].
code[k]) {
671 INTDBG(
"event: %s, code: %#x, already in results at index: %d\n", search[j].
name[k], search[j].code[k],
i);
683 if (search[j].
name[k]) {
695 INTDBG(
"EXIT: returned: 1\n");
699 INTDBG(
"EXIT: returned: 0\n");
706 INTDBG(
"ENTER: target: %p (%s), results: %p\n", target, target, results);
711 INTDBG(
"EXIT: returned: 0, call to convert name to event code failed with ret: %d\n", ret);
716 if ( results->
code[results->
count] == 0 ) {
717 INTDBG(
"EXIT: returned: 0, event code not found\n");
724 INTDBG(
"EXIT: returned: 0, new event not associated with component 0 (current limitation with derived events)\n");
729 INTDBG(
"\tFound a native event %s\n", target);
732 INTDBG(
"EXIT: returned: 1\n");
740 INTDBG(
"ENTER: event_name: %p (%s), derived_type: %d, results: %p, token_index: %d\n",
event_name,
event_name, derived_type, results, token_index);
744 INTDBG(
"EXIT: found preset event\n");
750 INTDBG(
"EXIT: found user event\n");
756 INTDBG(
"EXIT: found native event\n");
760 INTDBG(
"EXIT: event not found\n");
765#if defined(STATIC_PAPI_EVENTS_TABLE)
772 SUBDBG(
"ENTER: pmu_str: %s, pmu_type: %d, cidx: %d\n", pmu_str, pmu_type,
cidx);
817 INTDBG(
"stack overflow converting algebraic expression (%d,%c)\n",
stacktop,symbol );
828 INTDBG(
"stack underflow converting algebraic expression\n" );
840 INTDBG(
"ENTER: in: %s, size: %zu\n", infix, strlen(infix));
857 for( index=0; index<strlen(infix); index++ ) {
858 token = infix[index];
859 INTDBG(
"INTDBG: in: %s, length: %zu, index: %d token %c\n", infix, strlen( infix ), index, token);
865 if (postfix[postfixlen-1]!=
'|') postfix[postfixlen++] =
'|';
867 postfix[postfixlen++] =
pop();
868 postfix[postfixlen++] =
'|';
878 if (postfix[postfixlen-1]!=
'|') postfix[postfixlen++] =
'|';
880 postfix[postfixlen++] =
pop();
881 postfix[postfixlen++] =
'|';
886 postfix[postfixlen++] = token;
892 if (postfix[postfixlen-1]!=
'|') postfix[postfixlen++] =
'|';
894 postfix[postfixlen++] =
pop();
895 postfix[postfixlen++] =
'|';
897 postfix[postfixlen++] =
'\0';
900 INTDBG(
"EXIT: postfix: %s, size: %zu\n", postfix, strlen(postfix));
948 SUBDBG(
"ENTER: pmu_str: %s, pmu_type: %d, cidx: %d, preset_flag: %d\n", pmu_str, pmu_type,
cidx, preset_flag);
952 char name[PATH_MAX] =
"builtin papi_events_table";
953 char *event_file_path=NULL;
954 char *event_table_ptr=NULL;
955 int event_type_bits = 0;
957 char *tok_save_ptr=NULL;
958 FILE *event_file = NULL;
968 int found_events = 0;
976 if ((tmpn = getenv(
"PAPI_CSV_EVENT_FILE")) && (strlen(tmpn) > 0)) {
977 event_file_path = tmpn;
987 event_file_path = path;
997 if ((event_file_path = getenv(
"PAPI_USER_EVENTS_FILE" )) == NULL ) {
998 SUBDBG(
"EXIT: User event definition file not provided.\n");
1009 if (event_file_path != NULL) {
1012 SUBDBG(
"EXIT: Event file open failed.\n");
1015 strncpy(
name, event_file_path,
sizeof(
name)-1);
1017 }
else if (event_table_ptr == NULL) {
1019 SUBDBG(
"EXIT: Both event_file_path and event_table_ptr are NULL.\n");
1026 if (*pmu_str !=
',')
1040 t =
trim_string(strtok_r(line,
",", &tok_save_ptr));
1043 if ((t == NULL) || (strlen(t) == 0))
1051 if (strcasecmp(t,
"CPU") == 0) {
1053 SUBDBG(
"Ending event scanning at line %d of %s.\n", line_no,
name);
1058 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1059 if ((t == NULL) || (strlen(t) == 0)) {
1060 PAPIERROR(
"Expected name after CPU token at line %d of %s -- ignoring", line_no,
name);
1064 if (strcasecmp(t, pmu_name) == 0) {
1067 SUBDBG(
"Process events for PMU %s found at line %d of %s.\n", t, line_no,
name);
1069 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1070 if ((t == NULL) || (strlen(t) == 0)) {
1071 SUBDBG(
"No additional qualifier found, matching on string.\n");
1073 }
else if ((sscanf(t,
"%d", &
type) == 1) && (
type == pmu_type)) {
1074 SUBDBG(
"Found CPU %s type %d at line %d of %s.\n", pmu_name,
type, line_no,
name);
1077 SUBDBG(
"Additional qualifier match failed %d vs %d.\n", pmu_type,
type);
1083 if ((strcasecmp(t,
"PRESET") == 0) || (strcasecmp(t,
"EVENT") == 0)) {
1089 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1091 if ((t == NULL) || (strlen(t) == 0)) {
1092 PAPIERROR(
"Expected name after PRESET token at line %d of %s -- ignoring", line_no,
name);
1096 SUBDBG(
"Examining event %s\n", t);
1100 PAPIERROR(
"No room left for event %s -- ignoring", t);
1105 preset = res_idx | event_type_bits;
1110 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1111 if ((t == NULL) || (strlen(t) == 0)) {
1113 if (results[res_idx].symbol != NULL){
1115 results[res_idx].
symbol = NULL;
1117 PAPIERROR(
"Expected derived type after PRESET token at line %d of %s -- ignoring", line_no,
name);
1123 if (results[res_idx].symbol != NULL){
1125 results[res_idx].
symbol = NULL;
1127 PAPIERROR(
"Invalid derived name %s after PRESET token at line %d of %s -- ignoring", t, line_no,
name);
1135 SUBDBG(
"Adding event: %s, code: %#x, derived: %d results[%d]: %p.\n", t,
preset, derived, res_idx, &results[res_idx]);
1143 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1144 if ((t == NULL) || (strlen(t) == 0)) {
1146 if (results[res_idx].symbol != NULL){
1148 results[res_idx].
symbol = NULL;
1150 PAPIERROR(
"Expected Operation string after derived type DERIVED_POSTFIX or DERIVED_INFIX at line %d of %s -- ignoring", line_no,
name);
1156 SUBDBG(
"Converting InFix operations %s\n", t);
1161 SUBDBG(
"Saving PostFix operations %s\n", t);
1168 results[res_idx].
count = 0;
1170 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1171 if ((t == NULL) || (strlen(t) == 0))
1173 if (strcasecmp(t,
"NOTE") == 0)
1175 if (strcasecmp(t,
"LDESC") == 0)
1177 if (strcasecmp(t,
"SDESC") == 0)
1180 SUBDBG(
"Adding term (%d) %s to derived event %#x, current native event count: %d.\n",
i, t,
preset, results[res_idx].
count);
1189 if (
is_event(t, results[res_idx].derived_int, &results[res_idx],
i) == 0) {
1191 PAPIERROR(
"Missing event %s, used in derived event %s", t, results[res_idx].symbol);
1203 if (invalid_event) {
1207 for (j = 0; j < results[res_idx].
count; j++){
1208 if (results[res_idx].
name[j] != NULL){
1210 results[res_idx].
name[j] = NULL;
1215 if(results[res_idx].symbol != NULL){
1217 results[res_idx].
symbol = NULL;
1230 if(results[res_idx].symbol != NULL){
1232 results[res_idx].
symbol = NULL;
1235 PAPIERROR(
"Expected PFM event after DERIVED token at line %d of %s -- ignoring", line_no,
name);
1240 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1244 if ( t!= NULL && strlen(t) > 0 ) {
1250 t =
trim_note(strtok_r(NULL,
",", &tok_save_ptr));
1251 if ( t== NULL || strlen(t) == 0 ) {
1257 if (strcasecmp(fptr,
"SDESC") == 0) {
1260 if (strcasecmp(fptr,
"LDESC") == 0) {
1263 if (strcasecmp(fptr,
"NOTE") == 0) {
1267 SUBDBG(
"Found %s (%s) on line %d\n", fptr, t, line_no);
1271 t =
trim_string(strtok_r(NULL,
",", &tok_save_ptr));
1272 if ( t== NULL || strlen(t) == 0 ) {
1275 }
while (t != NULL);
1281 PAPIERROR(
"Unrecognized token %s at line %d of %s -- ignoring", t, line_no,
name);
1288 SUBDBG(
"EXIT: Done processing derived event file.\n");
1303#define BUFFSIZE 8192
1304#define SPARSE_BEGIN 0
1305#define SPARSE_EVENT_SEARCH 1
1306#define SPARSE_EVENT 2
1307#define SPARSE_DESC 3
1308#define ARCH_SEARCH 4
1309#define DENSE_EVENT_SEARCH 5
1310#define DENSE_NATIVE_SEARCH 6
1311#define DENSE_NATIVE_DESC 7
1314char buffer[BUFFSIZE], *xml_arch;
1315int location = SPARSE_BEGIN, sparse_index = 0, native_index, error = 0;
1326_xml_start(
void *data,
const char *el,
const char **attr )
1328 int native_encoding;
1330 if (
location == SPARSE_BEGIN && !strcmp(
"papistdevents", el ) ) {
1332 }
else if (
location == SPARSE_EVENT_SEARCH && !strcmp(
"papievent", el ) ) {
1336 }
else if (
location == SPARSE_EVENT && !strcmp(
"desc", el ) ) {
1338 }
else if (
location == ARCH_SEARCH && !strcmp(
"availevents", el ) &&
1339 !strcmp( xml_arch, attr[1] ) ) {
1341 }
else if (
location == DENSE_EVENT_SEARCH && !strcmp(
"papievent", el ) ) {
1342 if ( !strcmp(
"PAPI_NULL", attr[1] ) ) {
1347 PAPIERROR(
"Improper Preset name given in XML file for %s.",
1367 PAPIERROR(
"No derived type match for %s in Preset XML file.",
1375 PAPIERROR(
"No count given for %s in Preset XML file.",
1384 }
else if (
location == DENSE_NATIVE_SEARCH && !strcmp(
"native", el ) ) {
1386 }
else if (
location == DENSE_NATIVE_DESC && !strcmp(
"event", el ) ) {
1389 printf(
"Improper Native name given in XML file for %s\n",
1391 PAPIERROR(
"Improper Native name given in XML file for %s",
1400 PAPIERROR(
"Poorly-formed Preset XML document." );
1410_xml_end(
void *data,
const char *el )
1414 if (
location == SPARSE_EVENT_SEARCH && !strcmp(
"papistdevents", el ) ) {
1421 }
else if (
location == DENSE_NATIVE_DESC && !strcmp(
"native", el ) ) {
1423 }
else if (
location == DENSE_EVENT_SEARCH && !strcmp(
"availevents", el ) ) {
1434_xml_content(
void *data,
const char *el,
const int len )
1440 for (
i = 0;
i < len;
i++ )
1455 FILE *
fp = fopen(
"./papi_events.xml",
"r" );
1456 XML_Parser p = XML_ParserCreate( NULL );
1459 PAPIERROR(
"Couldn't allocate memory for XML parser." );
1463 XML_SetElementHandler( p, _xml_start, _xml_end );
1464 XML_SetCharacterDataHandler( p, _xml_content );
1466 PAPIERROR(
"Error opening Preset XML file." );
1475 void *buffer = XML_GetBuffer( p, BUFFSIZE );
1477 if ( buffer == NULL ) {
1478 PAPIERROR(
"Couldn't allocate memory for XML buffer." );
1482 len =
fread( buffer, 1, BUFFSIZE,
fp );
1483 if ( ferror(
fp ) ) {
1489 if ( !XML_ParseBuffer( p, len, len == 0 ) ) {
1490 PAPIERROR(
"Parse error at line %d:\n%s",
1491 XML_GetCurrentLineNumber( p ),
1492 XML_ErrorString( XML_GetErrorCode( p ) ) );
1501 XML_ParserFree( p );
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Convert a name to a numeric hardware event code.
struct papi_vectors * _papi_hwd[]
char event_name[2][PAPI_MAX_STR_LEN]
#define PAPI_HUGE_STR_LEN
static struct timeval start
#define PAPI_MAX_USER_EVENTS
#define PAPI_PRESET_AND_MASK
#define PAPI_MAX_PRESET_EVENTS
Return codes and api definitions.
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
#define INTDBG(format, args...)
#define SUBDBG(format, args...)
int fclose(FILE *__stream)
void PAPIERROR(char *format,...)
int _papi_hwi_derived_type(char *tmp, int *code)
int _papi_hwi_native_name_to_code(const char *in, int *out)
int _papi_hwi_component_index(int event_code)
void _papi_hwi_set_papi_event_code(unsigned int event_code, int update_flag)
#define PAPI_EVENTS_IN_DERIVED_EVENT
static double array[ARRAYSIZE]
#define papi_valid_free(a)
#define papi_calloc(a, b)
static int push(char symbol)
static int check_native_events(char *target, hwi_presets_t *results)
static void ops_string_merge(char **original, char *insertion, int replaces, int start_index)
static void update_ops_string(char **formula, int old_index, int new_index)
int _papi_hwi_cleanup_all_presets(void)
static char stack[2 *PAPI_HUGE_STR_LEN]
static int is_event(char *event_name, int derived_type, hwi_presets_t *results, int token_index)
static char * papi_events_table
static char * infix_to_postfix(char *infix)
int _papi_hwi_setup_all_presets(hwi_search_t *findem, int cidx)
static int get_event_line(char *line, FILE *table, char **tmp_perfmon_events_table)
static void ops_string_append(hwi_presets_t *results, hwi_presets_t *depends_on, int addition)
int _papi_load_preset_table(char *pmu_str, int pmu_type, int cidx)
hwi_presets_t user_defined_events[]
static int check_derived_events(char *target, int derived_type, hwi_presets_t *results, hwi_presets_t *search, int search_size, int token_index)
static int papi_load_derived_events(char *pmu_str, int pmu_type, int cidx, int preset_flag)
static int priority(char symbol)
int user_defined_events_count
static char * trim_string(char *in)
static char * trim_note(char *in)
static int find_event_index(hwi_presets_t *array, int size, char *tmp)
static FILE * open_event_table(char *name)
int _xml_papi_hwi_setup_all_presets(char *arch)
static void work(int EventSet, int sleep_test, int quiet)
hwi_search_t * preset_search_map
static const int event_count[]
unsigned int code[PAPI_MAX_INFO_TERMS]
char * name[PAPI_MAX_INFO_TERMS]
int native[PAPI_EVENTS_IN_DERIVED_EVENT]
static int get_events(ntv_event_t *events, int num_events)