PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

#define NUM_EVENTS   2

Definition at line 19 of file zero.c.

#define NUM_LOOPS   200

Definition at line 21 of file zero.c.

Function Documentation

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 */
42  retval=PAPI_create_eventset(&EventSet1);
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 */
71  elapsed_us = PAPI_get_real_usec( );
72  elapsed_cyc = PAPI_get_real_cyc( );
73  elapsed_virt_us = PAPI_get_virt_usec( );
74  elapsed_virt_cyc = PAPI_get_virt_cyc( );
75 
76  /* Start PAPI */
77  retval = PAPI_start( EventSet1 );
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 */
88  retval = PAPI_stop( EventSet1, values );
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;
96  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
97  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_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 
110  retval=PAPI_destroy_eventset( &EventSet1 );
111  if (retval!=PAPI_OK) {
112  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
113  }
114 
115  /* Calculate Instructions per Cycle, avoiding division by zero */
116  if (values[0]!=0) {
117  ipc = (double)values[1]/(double)values[0];
118  }
119  else {
120  ipc=0.0;
121  }
122 
123  /* Print the results */
124  if ( !quiet ) {
125  printf( "Test case 0: start, stop.\n" );
126  printf( "-----------------------------------------------\n" );
127  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
128  printf( "Default domain is: %d (%s)\n", tmp,
129  stringify_all_domains( tmp ) );
130  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
131  printf( "Default granularity is: %d (%s)\n", tmp,
132  stringify_granularity( tmp ) );
133  printf( "Using %d iterations 1 million instructions\n", NUM_LOOPS );
134  printf( "-------------------------------------------------------------------------\n" );
135 
136  printf( "Test type : \t 1\n" );
137 
138  /* cycles is first, other event second */
139  printf( "%-12s %12lld\n", "PAPI_TOT_CYC : \t", values[0] );
140  printf( "%-12s %12lld\n", "PAPI_TOT_INS : \t", values[1] );
141  printf( "%-12s %12.2lf\n", "IPC : \t", ipc );
142 
143  printf( "%-12s %12lld\n", "Real usec : \t", elapsed_us );
144  printf( "%-12s %12lld\n", "Real cycles : \t", elapsed_cyc );
145  printf( "%-12s %12lld\n", "Virt usec : \t", elapsed_virt_us );
146  printf( "%-12s %12lld\n", "Virt cycles : \t", elapsed_virt_cyc );
147 
148  printf( "-------------------------------------------------------------------------\n" );
149 
150 
151  printf( "Verification: PAPI_TOT_INS should be roughly %d\n", NUM_LOOPS*1000000 );
152 
153  }
154 
155  /* Check that TOT_INS is reasonable */
156  if (abs(values[1] - (1000000*NUM_LOOPS)) > (1000000*NUM_LOOPS)) {
157  printf("%s Error of %.2f%%\n", "PAPI_TOT_INS", (100.0 * (double)(values[1] - (1000000*NUM_LOOPS)))/(1000000*NUM_LOOPS));
158  test_fail( __FILE__, __LINE__, "Instruction validation", 0 );
159  }
160 
161  /* Check that TOT_CYC is non-zero */
162  if(values[0]==0) {
163  printf("Cycles is zero\n");
164  test_fail( __FILE__, __LINE__, "Cycles validation", 0 );
165  }
166 
167  /* Unless you have an amazing processor, IPC should be < 100 */
168  if ((ipc <=0.01 ) || (ipc >=100.0)) {
169  printf("Unlikely IPC of %.2f%%\n", ipc);
170  test_fail( __FILE__, __LINE__, "IPC validation", 0 );
171  }
172 
173  test_pass( __FILE__ );
174 
175  return 0;
176 }
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_NULL
Definition: papi.h:292
return PAPI_OK
Definition: linux-nvml.c:497
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
#define NUM_EVENTS
Definition: zero.c:19
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
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_DEFGRN
Definition: papi.h:434
int instructions_million(void)
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
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
#define PAPI_DEFDOM
Definition: papi.h:432
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
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long elapsed_us
Definition: zero_fork.c:50
#define PAPI_VER_CURRENT
Definition: papi.h:225
int EventSet1
Definition: zero_fork.c:47

Here is the call graph for this function: