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

Go to the source code of this file.

Macros

#define NUM_EVENTS   2
 
#define NUM_LOOPS   200
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NUM_EVENTS

#define NUM_EVENTS   2

Definition at line 19 of file zero.c.

◆ NUM_LOOPS

#define NUM_LOOPS   200

Definition at line 21 of file zero.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file zero.c.

23  {
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 ipc;
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) {
51  printf("Trouble adding PAPI_TOT_CYC: %s\n",
53  }
54  test_skip( __FILE__, __LINE__, "adding PAPI_TOT_CYC", retval );
55  }
56 
57  /* Add PAPI_TOT_INS */
58  retval=PAPI_add_named_event(EventSet1,"PAPI_TOT_INS");
59  if (retval!=PAPI_OK) {
60  test_fail( __FILE__, __LINE__, "adding PAPI_TOT_INS", retval );
61  }
62 
63  /* warm up the processor to pull it out of idle state */
64  for(i=0;i<100;i++) {
65  result=instructions_million();
66  }
67 
68  if (result==CODE_UNIMPLEMENTED) {
69  if (!quiet) printf("Instructions testcode not available\n");
70  test_skip( __FILE__, __LINE__, "No instructions code", retval );
71  }
72 
73  /* Gather before stats */
76  elapsed_virt_us = PAPI_get_virt_usec( );
77  elapsed_virt_cyc = PAPI_get_virt_cyc( );
78 
79  /* Start PAPI */
81  if ( retval != PAPI_OK ) {
82  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
83  }
84 
85  /* our work code */
86  for(i=0;i<NUM_LOOPS;i++) {
88  }
89 
90  /* Stop PAPI */
92  if ( retval != PAPI_OK ) {
93  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
94  }
95 
96  /* Calculate total values */
97  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
98  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
101 
102  /* Shutdown the EventSet */
103  retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_CYC" );
104  if (retval!=PAPI_OK) {
105  test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
106  }
107 
108  retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_INS" );
109  if (retval!=PAPI_OK) {
110  test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
111  }
112 
114  if (retval!=PAPI_OK) {
115  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
116  }
117 
118  /* Calculate Instructions per Cycle, avoiding division by zero */
119  if (values[0]!=0) {
120  ipc = (double)values[1]/(double)values[0];
121  }
122  else {
123  ipc=0.0;
124  }
125 
126  /* Print the results */
127  if ( !quiet ) {
128  printf( "Test case 0: start, stop.\n" );
129  printf( "-----------------------------------------------\n" );
130  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
131  printf( "Default domain is: %d (%s)\n", tmp,
133  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
134  printf( "Default granularity is: %d (%s)\n", tmp,
136  printf( "Using %d iterations 1 million instructions\n", NUM_LOOPS );
137  printf( "-------------------------------------------------------------------------\n" );
138 
139  printf( "Test type : \t 1\n" );
140 
141  /* cycles is first, other event second */
142  printf( "%-12s %12lld\n", "PAPI_TOT_CYC : \t", values[0] );
143  printf( "%-12s %12lld\n", "PAPI_TOT_INS : \t", values[1] );
144  printf( "%-12s %12.2lf\n", "IPC : \t", ipc );
145 
146  printf( "%-12s %12lld\n", "Real usec : \t", elapsed_us );
147  printf( "%-12s %12lld\n", "Real cycles : \t", elapsed_cyc );
148  printf( "%-12s %12lld\n", "Virt usec : \t", elapsed_virt_us );
149  printf( "%-12s %12lld\n", "Virt cycles : \t", elapsed_virt_cyc );
150 
151  printf( "-------------------------------------------------------------------------\n" );
152 
153 
154  printf( "Verification: PAPI_TOT_INS should be roughly %d\n", NUM_LOOPS*1000000 );
155 
156  }
157 
158  /* Check that TOT_INS is reasonable */
159  if (llabs(values[1] - (1000000*NUM_LOOPS)) > (1000000*NUM_LOOPS)) {
160  printf("%s Error of %.2f%%\n", "PAPI_TOT_INS", (100.0 * (double)(values[1] - (1000000*NUM_LOOPS)))/(1000000*NUM_LOOPS));
161  test_fail( __FILE__, __LINE__, "Instruction validation", 0 );
162  }
163 
164  /* Check that TOT_CYC is non-zero */
165  if(values[0]==0) {
166  printf("Cycles is zero\n");
167  test_fail( __FILE__, __LINE__, "Cycles validation", 0 );
168  }
169 
170  /* Unless you have an amazing processor, IPC should be < 100 */
171  if ((ipc <=0.01 ) || (ipc >=100.0)) {
172  printf("Unlikely IPC of %.2f%%\n", ipc);
173  test_fail( __FILE__, __LINE__, "IPC validation", 0 );
174  }
175 
176  test_pass( __FILE__ );
177 
178  return 0;
179 }
#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
#define NUM_EVENTS
Definition: zero.c:19
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_LOOPS
Definition: zero.c:21
#define PAPI_NULL
Definition: fpapi.h:13
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
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
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
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: