Of course,
I'm testing the code on an Intel(R) Core(TM)2 CPU T5500 @ 1.66GHz using Linux 2.6.32-25 (Ubuntu 10.4).
Technical spec can be found on
http://ark.intel.com/Product.aspx?id=29758.
Finally, here's my code:
High Level
==========
- Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<papi.h>
#define NEvents 3
long long counters[NEvents];
int events[] = { PAPI_L1_DCA, PAPI_L1_DCH, PAPI_L1_DCM };
void main(){
//papi initialization
if (PAPI_VER_CURRENT != PAPI_library_init(PAPI_VER_CURRENT)){
printf("Error in papi version");
exit(-1);
}
PAPI_start_counters(events, NEvents);
if (PAPI_OK != PAPI_read_counters(counters, NEvents))
printf("Problem reading counters");
PAPI_stop_counters(counters, NEvents);
printf ("L1 data cache access: %lld\t L1 data cache hits: %lli\t : L1 data cache misses: %lld\n", counters[0], counters[1], counters[2]);
}
Low level
========
- Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<papi.h>
#define NEvents 3
long long counters[NEvents];
int events[] = { PAPI_L1_DCA, PAPI_L1_DCH, PAPI_L1_DCM };
const PAPI_hw_info_t *hwinfo = NULL;
int EventSet = PAPI_NULL;
int retval = 0;
void initPapi(){
/**
* 1. Init PAPI
*/
if( (retval = PAPI_library_init( PAPI_VER_CURRENT) ) != PAPI_VER_CURRENT){
printf("Error in papi version\n");
exit(-1);
}
if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL ) {
printf("Error PAPI_get_hardware_info\n");
exit(-1);
}
if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ){
printf("Error PAPI_create_eventset %d\n", retval );
exit(-1);
}
}
void startPapi(){
/**
*2.starting PAPI
*/
if ( PAPI_add_events( EventSet, events, NEvents ) != PAPI_OK )
printf("Error PAPI_add_event \n" );
if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
printf("Error PAPI_start %d\n", retval );
}
void endPapi(){
/**
* 3. Stop and destroy PAPI
*/
if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
printf( "Error PAPI_stop %d\n", retval );
if( ( retval = PAPI_cleanup_eventset(EventSet) ) != PAPI_OK )
printf("Error PAPI_cleanup_eventset %d\n", retval);
if ( ( retval = PAPI_destroy_eventset( &EventSet ) ) != PAPI_OK )
printf("Error PAPI_destroy_eventset %d\n", retval );
}
void main(){
initPapi();
startPapi();
if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
printf("Error PAPI_reset %d\n", retval );
if ( ( retval = PAPI_read( EventSet, counters ) ) != PAPI_OK )
printf("Error PAPI_read %d\n", retval );
endPapi();
printf ("L1 data cache access: %lld\t L1 data cache hits: %lli\t : L1 data cache misses: %lld\n", counters[0], counters[1], counters[2]);
}
Finally, some executions of the codes show the following results:
High Level ----
L1 data cache access: 1015 L1 data cache hits: 996 : L1 data cache misses: 19
L1 data cache access: 1005 L1 data cache hits: 988 : L1 data cache misses: 17
L1 data cache access: 1019 L1 data cache hits: 1001 : L1 data cache misses: 18
Low Level ----
L1 data cache access: 885 L1 data cache hits: 874 : L1 data cache misses: 11
L1 data cache access: 869 L1 data cache hits: 860 : L1 data cache misses: 9
L1 data cache access: 892 L1 data cache hits: 882 : L1 data cache misses: 10
Thanks.