PAPI  5.0.1.0
multiplex1.c File Reference
Include dependency graph for multiplex1.c:

Go to the source code of this file.

Defines

#define TOTAL_EVENTS   6
#define CPP_TEST_FAIL(string, retval)   test_fail(__FILE__, __LINE__, string, retval)

Functions

void init_papi (int *out_events, int *len)
int case1 ()
int case2 ()
int case3 ()
int case4 ()
int case5 ()
int main (int argc, char **argv)

Variables

int solaris_preset_PAPI_events [6]
int power6_preset_PAPI_events [6]
int preset_PAPI_events [6]
static int PAPI_events [6] = { 0, }
static int PAPI_events_len = 0

Define Documentation

#define CPP_TEST_FAIL (   string,
  retval 
)    test_fail(__FILE__, __LINE__, string, retval)

Definition at line 30 of file multiplex1.c.

#define TOTAL_EVENTS   6

Definition at line 16 of file multiplex1.c.


Function Documentation

int case1 ( void  )

Definition at line 90 of file multiplex1.c.

{
    int retval, i, EventSet = PAPI_NULL;
    long long values[2];

    PAPI_events_len = 2;
    init_papi( PAPI_events, &PAPI_events_len );

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_create_eventset", retval );

    for ( i = 0; i < PAPI_events_len; i++ ) {
        char out[PAPI_MAX_STR_LEN];

        retval = PAPI_add_event( EventSet, PAPI_events[i] );
        if ( retval != PAPI_OK )
            CPP_TEST_FAIL( "PAPI_add_event", retval );
        PAPI_event_code_to_name( PAPI_events[i], out );
        if ( !TESTS_QUIET )
            printf( "Added %s\n", out );
    }

    do_stuff(  );

    if ( PAPI_start( EventSet ) != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_start", retval );

    do_stuff(  );

    retval = PAPI_stop( EventSet, values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_stop", retval );

    if ( !TESTS_QUIET ) {
        test_print_event_header( "case1:", EventSet );
        printf( TAB2, "case1:", values[0], values[1] );
    }
    retval = PAPI_cleanup_eventset( EventSet ); /* JT */
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );

    PAPI_shutdown(  );
    return ( SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int case2 ( void  )

Definition at line 139 of file multiplex1.c.

{
    int retval, i, EventSet = PAPI_NULL;
    long long values[2];

    PAPI_events_len = 2;
    init_papi( PAPI_events, &PAPI_events_len );

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_create_eventset", retval );

    /* In Component PAPI, EventSets must be assigned a component index
       before you can fiddle with their internals.
       0 is always the cpu component */
    retval = PAPI_assign_eventset_component( EventSet, 0 );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval );

    retval = PAPI_set_multiplex( EventSet );
        if ( retval == PAPI_ENOSUPP) {
       test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
    }   
    else if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_set_multiplex", retval );

    for ( i = 0; i < PAPI_events_len; i++ ) {
        char out[PAPI_MAX_STR_LEN];

        retval = PAPI_add_event( EventSet, PAPI_events[i] );
        if ( retval != PAPI_OK )
            CPP_TEST_FAIL( "PAPI_add_event", retval );
        PAPI_event_code_to_name( PAPI_events[i], out );
        if ( !TESTS_QUIET )
            printf( "Added %s\n", out );
    }

    do_stuff(  );

    if ( PAPI_start( EventSet ) != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_start", retval );

    do_stuff(  );

    retval = PAPI_stop( EventSet, values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_stop", retval );

    if ( !TESTS_QUIET ) {
        test_print_event_header( "case2:", EventSet );
        printf( TAB2, "case2:", values[0], values[1] );
    }

    retval = PAPI_cleanup_eventset( EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );

    PAPI_shutdown(  );
    return ( SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int case3 ( void  )

Definition at line 203 of file multiplex1.c.

{
    int retval, i, EventSet = PAPI_NULL;
    long long values[2];

    PAPI_events_len = 2;
    init_papi( PAPI_events, &PAPI_events_len );

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_create_eventset", retval );

    for ( i = 0; i < PAPI_events_len; i++ ) {
        char out[PAPI_MAX_STR_LEN];

        retval = PAPI_add_event( EventSet, PAPI_events[i] );
        if ( retval != PAPI_OK )
            CPP_TEST_FAIL( "PAPI_add_event", retval );
        PAPI_event_code_to_name( PAPI_events[i], out );
        if ( !TESTS_QUIET )
            printf( "Added %s\n", out );
    }

    retval = PAPI_set_multiplex( EventSet );
        if ( retval == PAPI_ENOSUPP) {
       test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
    } else if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_set_multiplex", retval );

    do_stuff(  );

    if ( PAPI_start( EventSet ) != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_start", retval );

    do_stuff(  );

    retval = PAPI_stop( EventSet, values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_stop", retval );

    if ( !TESTS_QUIET ) {
        test_print_event_header( "case3:", EventSet );
        printf( TAB2, "case3:", values[0], values[1] );
    }

    retval = PAPI_cleanup_eventset( EventSet ); /* JT */
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );

    PAPI_shutdown(  );
    return ( SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int case4 ( void  )

Definition at line 262 of file multiplex1.c.

{
    int retval, i, EventSet = PAPI_NULL;
    long long values[4];
    char out[PAPI_MAX_STR_LEN];

    PAPI_events_len = 2;
    init_papi( PAPI_events, &PAPI_events_len );

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_create_eventset", retval );

    i = 0;
    retval = PAPI_add_event( EventSet, PAPI_events[i] );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_add_event", retval );
    PAPI_event_code_to_name( PAPI_events[i], out );
    printf( "Added %s\n", out );

    retval = PAPI_set_multiplex( EventSet );
        if ( retval == PAPI_ENOSUPP) {
       test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
    }   
    else if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_set_multiplex", retval );

    i = 1;
    retval = PAPI_add_event( EventSet, PAPI_events[i] );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_add_event", retval );
    PAPI_event_code_to_name( PAPI_events[i], out );
    printf( "Added %s\n", out );

    do_stuff(  );

    if ( PAPI_start( EventSet ) != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_start", retval );

    do_stuff(  );

    retval = PAPI_stop( EventSet, values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_stop", retval );

    if ( !TESTS_QUIET ) {
        test_print_event_header( "case4:", EventSet );
        printf( TAB2, "case4:", values[0], values[1] );
    }

    retval = PAPI_cleanup_eventset( EventSet ); /* JT */
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );

    PAPI_shutdown(  );
    return ( SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int case5 ( )

Definition at line 324 of file multiplex1.c.

{
  int retval, i, j, EventSet = PAPI_NULL;
    long long start_values[4] = { 0,0,0,0 }, values[4] = {0,0,0,0};
    char out[PAPI_MAX_STR_LEN];

    PAPI_events_len = 2;
    init_papi( PAPI_events, &PAPI_events_len );

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_create_eventset", retval );

    /* In Component PAPI, EventSets must be assigned a component index
       before you can fiddle with their internals.
       0 is always the cpu component */

    retval = PAPI_assign_eventset_component( EventSet, 0 );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval );
    
    retval = PAPI_set_multiplex( EventSet );
        if ( retval == PAPI_ENOSUPP) {
       test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
    }   
    else if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_set_multiplex", retval );

    /* Add 2 events... */

    i = 0;
    retval = PAPI_add_event( EventSet, PAPI_events[i] );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_add_event", retval );
    PAPI_event_code_to_name( PAPI_events[i], out );
    printf( "Added %s\n", out );
    i++;
    retval = PAPI_add_event( EventSet, PAPI_events[i] );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_add_event", retval );
    PAPI_event_code_to_name( PAPI_events[i], out );
    printf( "Added %s\n", out );
    i++;

    do_stuff(  );

    retval = PAPI_start( EventSet );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_start", retval );
    
    retval = PAPI_read( EventSet, start_values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_read", retval );

    do_stuff(  );

    retval = PAPI_stop( EventSet, values );
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_stop", retval );

    for (j=0;j<i;j++)
      {
          printf("read @start counter[%d]: %lld\n", j, start_values[j]);
          printf("read @stop  counter[%d]: %lld\n", j, values[j]);
          printf("difference  counter[%d]: %lld\n ", j, values[j]-start_values[j]);
          if (values[j]-start_values[j] < 0LL)
        CPP_TEST_FAIL( "Difference in start and stop resulted in negative value!", 0 );
      }

    retval = PAPI_cleanup_eventset( EventSet ); /* JT */
    if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );

    PAPI_shutdown(  );
    return ( SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void init_papi ( int *  out_events,
int *  len 
)

Definition at line 33 of file multiplex1.c.

{
    int retval;
    int i, real_len = 0;
    int *in_events = preset_PAPI_events;
    const PAPI_hw_info_t *hw_info;

    /* Initialize the library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
        CPP_TEST_FAIL( "PAPI_library_init", retval );

    hw_info = PAPI_get_hardware_info(  );
    if ( hw_info == NULL )
        test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

    if ( strstr( hw_info->model_string, "UltraSPARC" ) ) {
        in_events = solaris_preset_PAPI_events;
    }

    if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
        in_events = power6_preset_PAPI_events;
        retval = PAPI_set_domain( PAPI_DOM_ALL );
        if ( retval != PAPI_OK )
            CPP_TEST_FAIL( "PAPI_set_domain", retval );
    }

    retval = PAPI_multiplex_init(  );
        if ( retval == PAPI_ENOSUPP) {
       test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
    }
    else if ( retval != PAPI_OK )
        CPP_TEST_FAIL( "PAPI_multiplex_init", retval );

    for ( i = 0; in_events[i] != 0; i++ ) {
        char out[PAPI_MAX_STR_LEN];
        /* query and set up the right instruction to monitor */
        retval = PAPI_query_event( in_events[i] );
        if ( retval == PAPI_OK ) {
            out_events[real_len++] = in_events[i];
            PAPI_event_code_to_name( in_events[i], out );
            if ( real_len == *len )
                break;
        } else {
            PAPI_event_code_to_name( in_events[i], out );
            if ( !TESTS_QUIET )
                printf( "%s does not exist\n", out );
        }
    }
    if ( real_len < 1 )
        CPP_TEST_FAIL( "No counters available", 0 );
    *len = real_len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 402 of file multiplex1.c.

{

    tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */

    printf
        ( "case1: Does PAPI_multiplex_init() not break regular operation?\n" );
    case1(  );

    printf( "\ncase2: Does setmpx/add work?\n" );
    case2(  );

    printf( "\ncase3: Does add/setmpx work?\n" );
    case3(  );

    printf( "\ncase4: Does add/setmpx/add work?\n" );
    case4(  );
    
    printf( "\ncase5: Does setmpx/add/add/start/read work?\n" );
    case5(  );

    test_pass( __FILE__, NULL, 0 );
    exit( 0 );
}

Here is the call graph for this function:


Variable Documentation

int PAPI_events[6] = { 0, } [static]

Definition at line 27 of file multiplex1.c.

int PAPI_events_len = 0 [static]

Definition at line 28 of file multiplex1.c.

Initial value:

Definition at line 21 of file multiplex1.c.

Initial value:

Definition at line 24 of file multiplex1.c.

Initial value:

Definition at line 18 of file multiplex1.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines