PAPI  5.3.0.0
papi_hl.c File Reference

This file contains the 'high level' interface to PAPI. BASIC is a high level language. ;-) More...

Include dependency graph for papi_hl.c:

Go to the source code of this file.

Data Structures

struct  HighLevelInfo

Defines

#define HL_STOP   0
#define HL_START   1
#define HL_FLIP   2
#define HL_FLOP   3
#define HL_IPC   4
#define HL_EPC   5
#define HL_READ   6
#define HL_ACCUM   7

Functions

int _hl_rate_calls (float *real_time, float *proc_time, int *events, long long *values, long long *ins, float *rate, int mode)
void _internal_cleanup_hl_info (HighLevelInfo *state)
int _internal_check_state (HighLevelInfo **state)
int _internal_start_hl_counters (HighLevelInfo *state)
int _internal_hl_read_cnts (long long *values, int array_len, int flag)
int PAPI_flips (float *rtime, float *ptime, long long *flpins, float *mflips)
int PAPI_flops (float *rtime, float *ptime, long long *flpops, float *mflops)
int PAPI_ipc (float *rtime, float *ptime, long long *ins, float *ipc)
int PAPI_epc (int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc)
int PAPI_num_counters (void)
int PAPI_start_counters (int *events, int array_len)
int PAPI_read_counters (long long *values, int array_len)
int PAPI_accum_counters (long long *values, int array_len)
int PAPI_stop_counters (long long *values, int array_len)
void _papi_hwi_shutdown_highlevel ()

Detailed Description

Author:
Philip Mucci mucci@cs.utk.edu
Kevin London london@cs.utk.edu
dan terpstra terpstra@cs.utk.edu

Definition in file papi_hl.c.


Define Documentation

#define HL_ACCUM   7

Definition at line 33 of file papi_hl.c.

#define HL_EPC   5

Definition at line 31 of file papi_hl.c.

#define HL_FLIP   2

Definition at line 28 of file papi_hl.c.

#define HL_FLOP   3

Definition at line 29 of file papi_hl.c.

#define HL_IPC   4

Definition at line 30 of file papi_hl.c.

#define HL_READ   6

Definition at line 32 of file papi_hl.c.

#define HL_START   1

Definition at line 27 of file papi_hl.c.

#define HL_STOP   0

Definition at line 26 of file papi_hl.c.


Function Documentation

int _hl_rate_calls ( float *  real_time,
float *  proc_time,
int *  events,
long long *  values,
long long *  ins,
float *  rate,
int  mode 
)

Definition at line 405 of file papi_hl.c.

{
    long long rt, pt; // current elapsed real and process times in usec
    int num_events = 2;
    int retval = 0;
    HighLevelInfo *state = NULL;

    if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) {
        return ( retval );
    }
    
    if ( state->running != HL_STOP && state->running != mode ) {
        return PAPI_EINVAL;
    }

    if ( state->running == HL_STOP ) {
    
        switch (mode) {
            case HL_FLOP:
            case HL_FLIP:
                num_events = 1;
                break;
            case HL_IPC:
                break;
            case HL_EPC:
                if ( events[2] != 0 ) num_events = 3;
                break;
            default:
                return PAPI_EINVAL;
        }
        if (( retval = PAPI_add_events( state->EventSet, events, num_events )) != PAPI_OK ) {
            _internal_cleanup_hl_info( state );
            PAPI_cleanup_eventset( state->EventSet );
            return retval;
        }

        state->total_ins = 0;
        state->initial_real_time = state->last_real_time = PAPI_get_real_usec( );
        state->initial_proc_time = state->last_proc_time = PAPI_get_virt_usec( );

        if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
            return retval;
        }
        
        /* Initialize the interface */
        state->running = mode;
        *real_time  = 0.0;
        *proc_time  = 0.0;
        *rate       = 0.0;

    } else {
        if ( ( retval = PAPI_stop( state->EventSet, values ) ) != PAPI_OK ) {
            state->running = HL_STOP;
            return retval;
        }

        /* Read elapsed real and process times  */
        rt = PAPI_get_real_usec();
        pt = PAPI_get_virt_usec();

        /* Convert to seconds with multiplication because it is much faster */
        *real_time = ((float)( rt - state->initial_real_time )) * .000001;
        *proc_time = ((float)( pt - state->initial_proc_time )) * .000001;

        state->total_ins += values[0];

        switch (mode) {
            case HL_FLOP:
            case HL_FLIP:
                /* Calculate MFLOP and MFLIP rates */
                if ( pt > 0 ) {
                     *rate = (float)values[0] / (pt - state->last_proc_time);
                } else *rate = 0;
                break;
            case HL_IPC:
            case HL_EPC:
                /* Calculate IPC */
                if (values[1]!=0) {
                    *rate = (float) ((float)values[0] / (float) ( values[1]));
                }
                break;
            default:
                return PAPI_EINVAL;
        }
        state->last_real_time = rt;
        state->last_proc_time = pt;
    
        if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
            state->running = HL_STOP;
            return retval;
        }
    }
    *ins = state->total_ins;
    return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _internal_check_state ( HighLevelInfo **  outgoing)

This function is called to determine the state of the system. We may as well set the HighLevelInfo so you don't have to look it up again.

Definition at line 100 of file papi_hl.c.

{
    int retval;
    HighLevelInfo *state = NULL;

    /* Only allow one thread at a time in here */
    if ( init_level == PAPI_NOT_INITED ) {
        retval = PAPI_library_init( PAPI_VER_CURRENT );
        if ( retval != PAPI_VER_CURRENT ) {
            return ( retval );
        } else {
            _papi_hwi_lock( HIGHLEVEL_LOCK );
            init_level = PAPI_HIGH_LEVEL_INITED;
            _papi_hwi_unlock( HIGHLEVEL_LOCK );
        }
    }

    /*
     * Do we have the thread specific data setup yet?
     */
    if ( ( retval =
           PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void * ) &state ) )
         != PAPI_OK || state == NULL ) {
        state = ( HighLevelInfo * ) papi_malloc( sizeof ( HighLevelInfo ) );
        if ( state == NULL )
            return ( PAPI_ENOMEM );

        memset( state, 0, sizeof ( HighLevelInfo ) );
        state->EventSet = -1;

        if ( ( retval = PAPI_create_eventset( &state->EventSet ) ) != PAPI_OK )
            return ( retval );

        if ( ( retval =
               PAPI_set_thr_specific( PAPI_HIGH_LEVEL_TLS,
                                      state ) ) != PAPI_OK )
            return ( retval );
    }
    *outgoing = state;
    return ( PAPI_OK );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 152 of file papi_hl.c.

{
    state->num_evts = 0;
    state->running = HL_STOP;
    state->initial_real_time = -1;
    state->initial_proc_time = -1;
    state->total_ins = 0;
    return;
}

Here is the caller graph for this function:

int _internal_hl_read_cnts ( long long *  values,
int  array_len,
int  flag 
)

Definition at line 639 of file papi_hl.c.

{
    int retval;
    HighLevelInfo *state = NULL;

    if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK )
        return ( retval );

    if ( state->running != HL_START || array_len < state->num_evts )
        return ( PAPI_EINVAL );

    if ( flag == HL_ACCUM )
        return ( PAPI_accum( state->EventSet, values ) );
    else if ( flag == HL_READ ) {
        if ( ( retval = PAPI_read( state->EventSet, values ) ) != PAPI_OK )
            return ( retval );
        return ( PAPI_reset( state->EventSet ) );
    }

    /* Invalid flag passed in */
    return ( PAPI_EINVAL );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Make sure to allocate space for values

Definition at line 146 of file papi_hl.c.

{
    return ( PAPI_start( state->EventSet ) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 836 of file papi_hl.c.

{
    HighLevelInfo *state = NULL;

    if ( PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void * ) &state ) ==
         PAPI_OK ) {
        if ( state )
            papi_free( state );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines