PAPI 7.1.0.0
Loading...
Searching...
No Matches
cycles_validation.c
Go to the documentation of this file.
1/* cycles_validation.c */
2
3/* This is based on the old zero.c test */
4
5/* It fails on some platforms due to differences in */
6/* PAPI_TOT_CYCLES / real_cycles / virt_cycles */
7
8#include <stdio.h>
9#include <stdlib.h>
10
11#include "papi.h"
12#include "papi_test.h"
13
14#include "testcode.h"
15
16#define MAX_CYCLE_ERROR 30
17
18#define NUM_EVENTS 2
19
20#define NUM_LOOPS 200
21
22int
23main( int argc, char **argv )
24{
25 int retval, tmp, result, i;
26 int EventSet1 = PAPI_NULL;
27 long long values[NUM_EVENTS];
28 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
29 double cycles_error;
30 int quiet=0;
31
32 /* Set TESTS_QUIET variable */
33 quiet=tests_quiet( argc, argv );
34
35 /* Init the PAPI library */
37 if ( retval != PAPI_VER_CURRENT ) {
38 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
39 }
40
41 /* Initialize the EventSet */
43 if (retval!=PAPI_OK) {
44 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
45 }
46
47 /* Add PAPI_TOT_CYC */
49 if (retval!=PAPI_OK) {
50 if (!quiet) printf("Trouble adding PAPI_TOT_CYC\n");
51 test_skip( __FILE__, __LINE__, "adding PAPI_TOT_CYC", retval );
52 }
53
54 /* Add PAPI_TOT_INS */
56 if (retval!=PAPI_OK) {
57 test_fail( __FILE__, __LINE__, "adding PAPI_TOT_INS", retval );
58 }
59
60 /* warm up the processor to pull it out of idle state */
61 for(i=0;i<100;i++) {
63 }
64
66 if (!quiet) printf("Instructions testcode not available\n");
67 test_skip( __FILE__, __LINE__, "No instructions code", retval );
68 }
69
70 /* Gather before stats */
73 elapsed_virt_us = PAPI_get_virt_usec( );
74 elapsed_virt_cyc = PAPI_get_virt_cyc( );
75
76 /* Start PAPI */
78 if ( retval != PAPI_OK ) {
79 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
80 }
81
82 /* our work code */
83 for(i=0;i<NUM_LOOPS;i++) {
85 }
86
87 /* Stop PAPI */
89 if ( retval != PAPI_OK ) {
90 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
91 }
92
93 /* Calculate total values */
94 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
95 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
98
99 /* Shutdown the EventSet */
100 retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_CYC" );
101 if (retval!=PAPI_OK) {
102 test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
103 }
104
105 retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_INS" );
106 if (retval!=PAPI_OK) {
107 test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
108 }
109
111 if (retval!=PAPI_OK) {
112 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
113 }
114
115 /* Print the results */
116 if ( !quiet ) {
117 printf( "Test case 0: start, stop.\n" );
118 printf( "-----------------------------------------------\n" );
119 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
120 printf( "Default domain is: %d (%s)\n", tmp,
122 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
123 printf( "Default granularity is: %d (%s)\n", tmp,
125 printf( "Using %d iterations 1 million instructions\n", NUM_LOOPS );
126 printf( "-------------------------------------------------------------------------\n" );
127
128 printf( "Test type : \t 1\n" );
129
130 /* cycles is first, other event second */
131 printf( "%-12s %12lld\n", "PAPI_TOT_CYC : \t", values[0] );
132 printf( "%-12s %12lld\n", "PAPI_TOT_INS : \t", values[1] );
133
134 printf( "%-12s %12lld\n", "Real usec : \t", elapsed_us );
135 printf( "%-12s %12lld\n", "Real cycles : \t", elapsed_cyc );
136 printf( "%-12s %12lld\n", "Virt usec : \t", elapsed_virt_us );
137 printf( "%-12s %12lld\n", "Virt cycles : \t", elapsed_virt_cyc );
138
139 printf( "-------------------------------------------------------------------------\n" );
140
141 printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" );
142 printf( "NOTE: Not true if dynamic frequency scaling or turbo boost is enabled.\n" );
143 printf( "Verification: PAPI_TOT_INS should be roughly %d\n", NUM_LOOPS*1000000 );
144 }
145
146 /* Check that TOT_CYC and real_cycles roughly match */
147 cycles_error=100.0*((double)values[0] - (double)elapsed_cyc)/((double)elapsed_cyc);
148 if ((cycles_error > MAX_CYCLE_ERROR) || (cycles_error < -MAX_CYCLE_ERROR)) {
149 if (!quiet) printf("PAPI_TOT_CYC Error of %.2f%%\n",cycles_error);
150 test_warn( __FILE__, __LINE__, "Cycles validation", 0 );
151 }
152
153 /* Check that TOT_INS is reasonable */
154 if (llabs(values[1] - (1000000*NUM_LOOPS)) > (1000000*NUM_LOOPS)) {
155 printf("%s Error of %.2f%%\n", "PAPI_TOT_INS", (100.0 * (double)(values[1] - (1000000*NUM_LOOPS)))/(1000000*NUM_LOOPS));
156 test_fail( __FILE__, __LINE__, "Instruction validation", 0 );
157 }
158
159 test_pass( __FILE__ );
160
161 return 0;
162}
volatile int result
double tmp
int i
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Get PAPI library or event set options.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
get virtual time counter value in clock cycles
get virtual time counter values in microseconds
initialize the PAPI library.
removes a named hardware event from a PAPI event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define MAX_CYCLE_ERROR
#define NUM_LOOPS
#define NUM_EVENTS
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int instructions_million(void)
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int EventSet1
Definition: zero_fork.c:47
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53