|
Packit |
577717 |
/* This file attempts to test the PAPI_HW_INT */
|
|
Packit |
577717 |
/* performance counter (Total hardware interrupts). */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* This assumes that interrupts will be happening in the background */
|
|
Packit |
577717 |
/* Including a regular timer tick of HZ. This is not always true */
|
|
Packit |
577717 |
/* but should be roughly true on your typical Linux system. */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* by Vince Weaver, <vincent.weaver@maine.edu> */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
#include <sys/time.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <time.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "display_error.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int main(int argc, char **argv) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int quiet;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
long long count;
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int eventset=PAPI_NULL;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
struct timespec before,after;
|
|
Packit |
577717 |
unsigned long long seconds;
|
|
Packit |
577717 |
unsigned long long ns;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
quiet=tests_quiet(argc,argv);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Init the PAPI library */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
printf("\nTesting PAPI_HW_INT\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_create_eventset(&eventset);
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_add_named_event(eventset,"PAPI_HW_INT");
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
if (!quiet) printf("Could not add PAPI_HW_INT\n");
|
|
Packit |
577717 |
test_skip( __FILE__, __LINE__, "adding PAPI_HW_INT", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/********************************/
|
|
Packit |
577717 |
/* testing 3 seconds of runtime */
|
|
Packit |
577717 |
/********************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
printf("\nRunning for 3 seconds\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
clock_gettime(CLOCK_REALTIME,&before);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_reset(eventset);
|
|
Packit |
577717 |
PAPI_start(eventset);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
while(1) {
|
|
Packit |
577717 |
clock_gettime(CLOCK_REALTIME,&after);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
seconds=after.tv_sec - before.tv_sec;
|
|
Packit |
577717 |
ns = after.tv_nsec - before.tv_nsec;
|
|
Packit |
577717 |
ns = (seconds*1000000000ULL)+ns;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* be done if 3 billion nanoseconds has passed */
|
|
Packit |
577717 |
if (ns>3000000000ULL) break;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_stop(eventset,&count);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
printf("\tMeasured interrupts = %lld\n",count);
|
|
Packit |
577717 |
/* FIXME: find actua Hz on system */
|
|
Packit |
577717 |
/* Or even, read /proc/interrupts */
|
|
Packit |
577717 |
printf("\tAssuming HZ=250, expect roughly 750\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) printf("\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (count<10) {
|
|
Packit |
577717 |
if (!quiet) printf("Too few interrupts!\n");
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Too few interrupts!", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|