|
|
dfaf77 |
diff -up papi-5.2.0/src/papi_internal.c.postfix papi-5.2.0/src/papi_internal.c
|
|
|
dfaf77 |
--- papi-5.2.0/src/papi_internal.c.postfix 2016-07-25 14:25:09.331487358 -0400
|
|
|
dfaf77 |
+++ papi-5.2.0/src/papi_internal.c 2016-07-25 14:27:17.271715363 -0400
|
|
|
dfaf77 |
@@ -32,6 +32,7 @@
|
|
|
dfaf77 |
#include <errno.h>
|
|
|
dfaf77 |
#include <string.h>
|
|
|
dfaf77 |
#include <ctype.h>
|
|
|
dfaf77 |
+#include <assert.h>
|
|
|
dfaf77 |
|
|
|
dfaf77 |
#include "papi.h"
|
|
|
dfaf77 |
#include "papi_internal.h"
|
|
|
dfaf77 |
@@ -1840,89 +1841,90 @@ handle_derived_add_ps( int *position, lo
|
|
|
dfaf77 |
/* this function implement postfix calculation, it reads in a string where I use:
|
|
|
dfaf77 |
| as delimiter
|
|
|
dfaf77 |
N2 indicate No. 2 native event in the derived preset
|
|
|
dfaf77 |
- +, -, *, /, % as operator
|
|
|
dfaf77 |
+ +, -, *, / as operator
|
|
|
dfaf77 |
# as MHZ(million hz) got from _papi_hwi_system_info.hw_info.cpu_max_mhz*1000000.0
|
|
|
dfaf77 |
|
|
|
dfaf77 |
Haihang (you@cs.utk.edu)
|
|
|
dfaf77 |
*/
|
|
|
dfaf77 |
-static long long
|
|
|
dfaf77 |
-_papi_hwi_postfix_calc( EventInfo_t * evi, long long *hw_counter )
|
|
|
dfaf77 |
-{
|
|
|
dfaf77 |
- char *point = evi->ops, operand[16];
|
|
|
dfaf77 |
- double stack[PAPI_EVENTS_IN_DERIVED_EVENT];
|
|
|
dfaf77 |
- int i, top = 0;
|
|
|
dfaf77 |
-
|
|
|
dfaf77 |
- memset(&stack,0,PAPI_EVENTS_IN_DERIVED_EVENT*sizeof(double));
|
|
|
dfaf77 |
-
|
|
|
dfaf77 |
- while ( *point != '\0' ) {
|
|
|
dfaf77 |
- if ( *point == 'N' ) { /* to get count for each native event */
|
|
|
dfaf77 |
- i = 0;
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- operand[i] = *point;
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- i++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- operand[i] = '\0';
|
|
|
dfaf77 |
- stack[top] = ( double ) hw_counter[evi->pos[atoi( operand )]];
|
|
|
dfaf77 |
- top++;
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( *point == '#' ) { /* to get mhz, ignore the rest char's */
|
|
|
dfaf77 |
- stack[top] = _papi_hwi_system_info.hw_info.cpu_max_mhz * 1000000.0;
|
|
|
dfaf77 |
- top++;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( isdigit( *point ) ) { /* to get integer, I suppose only integer will be used,
|
|
|
dfaf77 |
- no error check here, please only use integer */
|
|
|
dfaf77 |
- i = 0;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- operand[i] = *point;
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- i++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- operand[i] = '\0';
|
|
|
dfaf77 |
- stack[top] = atoi( operand );
|
|
|
dfaf77 |
- top++;
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( *point == '+' ) { /* + calculation */
|
|
|
dfaf77 |
- stack[top - 2] += stack[top - 1];
|
|
|
dfaf77 |
- top--;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( *point == '-' ) { /* - calculation */
|
|
|
dfaf77 |
- stack[top - 2] -= stack[top - 1];
|
|
|
dfaf77 |
- top--;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( *point == '*' ) { /* * calculation */
|
|
|
dfaf77 |
- stack[top - 2] *= stack[top - 1];
|
|
|
dfaf77 |
- top--;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else if ( *point == '/' ) { /* / calculation */
|
|
|
dfaf77 |
- stack[top - 2] /= stack[top - 1];
|
|
|
dfaf77 |
- top--;
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } else { /* do nothing */
|
|
|
dfaf77 |
- do {
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- } while ( *point != '|' );
|
|
|
dfaf77 |
- point++;
|
|
|
dfaf77 |
- }
|
|
|
dfaf77 |
- }
|
|
|
dfaf77 |
- return ( long long ) stack[0];
|
|
|
dfaf77 |
-}
|
|
|
dfaf77 |
+ static long long
|
|
|
dfaf77 |
+ _papi_hwi_postfix_calc( EventInfo_t * evi, long long *hw_counter )
|
|
|
dfaf77 |
+ {
|
|
|
dfaf77 |
+ char *point = evi->ops, operand[16];
|
|
|
dfaf77 |
+ double stack[PAPI_EVENTS_IN_DERIVED_EVENT];
|
|
|
dfaf77 |
+ int i, val, top = 0;
|
|
|
dfaf77 |
+
|
|
|
dfaf77 |
+ INTDBG("ENTER: evi: %p, evi->ops: %p (%s), evi->pos[0]: %d, evi->pos[1]: %d, hw_counter: %p (%lld %lld)\n",
|
|
|
dfaf77 |
+ evi, evi->ops, evi->ops, evi->pos[0], evi->pos[1], hw_counter, hw_counter[0], hw_counter[1]);
|
|
|
dfaf77 |
+
|
|
|
dfaf77 |
+ memset(&stack,0,PAPI_EVENTS_IN_DERIVED_EVENT*sizeof(double));
|
|
|
dfaf77 |
+
|
|
|
dfaf77 |
+ while ( *point != '\0' ) {
|
|
|
dfaf77 |
+ if ( *point == '|' ) { /* consume '|' characters */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ } else if ( *point == 'N' ) { /* to get count for each native event */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ i = 0;
|
|
|
dfaf77 |
+ while ( isdigit(*point) ) {
|
|
|
dfaf77 |
+ assert(i<16);
|
|
|
dfaf77 |
+ operand[i] = *point;
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ i++;
|
|
|
dfaf77 |
+ }
|
|
|
dfaf77 |
+ assert(0
|
|
|
dfaf77 |
+ operand[i] = '\0';
|
|
|
dfaf77 |
+ val = atoi( operand );
|
|
|
dfaf77 |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
dfaf77 |
+ assert( 0 <= val && val < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
dfaf77 |
+ stack[top] = ( double ) hw_counter[evi->pos[val]];
|
|
|
dfaf77 |
+ top++;
|
|
|
dfaf77 |
+ } else if ( *point == '#' ) { /* to get mhz */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
dfaf77 |
+ stack[top] = _papi_hwi_system_info.hw_info.cpu_max_mhz * 1000000.0;
|
|
|
dfaf77 |
+ top++;
|
|
|
dfaf77 |
+ } else if ( isdigit( *point ) ) {
|
|
|
dfaf77 |
+ i = 0;
|
|
|
dfaf77 |
+ while ( isdigit(*point) ) {
|
|
|
dfaf77 |
+ assert(i<16);
|
|
|
dfaf77 |
+ operand[i] = *point;
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ i++;
|
|
|
dfaf77 |
+ }
|
|
|
dfaf77 |
+ assert(0
|
|
|
dfaf77 |
+ operand[i] = '\0';
|
|
|
dfaf77 |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
dfaf77 |
+ stack[top] = atoi( operand );
|
|
|
dfaf77 |
+ top++;
|
|
|
dfaf77 |
+ } else if ( *point == '+' ) { /* + calculation */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ assert(top >= 2);
|
|
|
dfaf77 |
+ stack[top - 2] += stack[top - 1];
|
|
|
dfaf77 |
+ top--;
|
|
|
dfaf77 |
+ } else if ( *point == '-' ) { /* - calculation */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ assert(top >= 2);
|
|
|
dfaf77 |
+ stack[top - 2] -= stack[top - 1];
|
|
|
dfaf77 |
+ top--;
|
|
|
dfaf77 |
+ } else if ( *point == '*' ) { /* * calculation */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ assert(top >= 2);
|
|
|
dfaf77 |
+ stack[top - 2] *= stack[top - 1];
|
|
|
dfaf77 |
+ top--;
|
|
|
dfaf77 |
+ } else if ( *point == '/' ) { /* / calculation */
|
|
|
dfaf77 |
+ point++;
|
|
|
dfaf77 |
+ assert(top >= 2);
|
|
|
dfaf77 |
+ /* FIXME should handle runtime divide by zero */
|
|
|
dfaf77 |
+ stack[top - 2] /= stack[top - 1];
|
|
|
dfaf77 |
+ top--;
|
|
|
dfaf77 |
+ } else { /* flag an error parsing the preset */
|
|
|
dfaf77 |
+ PAPIERROR( "BUG! Unable to parse \"%s\"", evi->ops );
|
|
|
dfaf77 |
+ return ( long long ) stack[0];
|
|
|
dfaf77 |
+ }
|
|
|
dfaf77 |
+ }
|
|
|
dfaf77 |
+ assert(top == 1);
|
|
|
dfaf77 |
+ INTDBG("EXIT: stack[0]: %lld\n", (long long)stack[0]);
|
|
|
dfaf77 |
+ return ( long long ) stack[0];
|
|
|
dfaf77 |
+ }
|
|
|
dfaf77 |
|
|
|
dfaf77 |
static long long
|
|
|
dfaf77 |
handle_derived( EventInfo_t * evi, long long *from )
|