PAPI  5.7.0.0
cycles_validation.c File Reference
Include dependency graph for cycles_validation.c:

Go to the source code of this file.

Macros

#define MAX_CYCLE_ERROR   30
 
#define NUM_EVENTS   2
 
#define NUM_LOOPS   200
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_CYCLE_ERROR

#define MAX_CYCLE_ERROR   30

Definition at line 16 of file cycles_validation.c.

◆ NUM_EVENTS

#define NUM_EVENTS   2

Definition at line 18 of file cycles_validation.c.

◆ NUM_LOOPS

#define NUM_LOOPS   200

Definition at line 20 of file cycles_validation.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file cycles_validation.c.

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 */
48  retval=PAPI_add_named_event(EventSet1,"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 */
55  retval=PAPI_add_named_event(EventSet1,"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++) {
62  result=instructions_million();
63  }
64 
65  if (result==CODE_UNIMPLEMENTED) {
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 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6300
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:524
double tmp
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
long long elapsed_cyc
Definition: zero_fork.c:50
#define NUM_EVENTS
#define PAPI_NULL
Definition: fpapi.h:13
#define NUM_LOOPS
int instructions_million(void)
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define PAPI_DEFGRN
Definition: fpapi.h:51
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
#define PAPI_DEFDOM
Definition: fpapi.h:49
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_remove_named_event(int EventSet, const char *EventName)
Definition: papi.c:1961
#define MAX_CYCLE_ERROR
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
long long elapsed_us
Definition: zero_fork.c:50
int EventSet1
Definition: zero_fork.c:47
int i
Definition: fileop.c:140
Here is the call graph for this function: