PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cost.c File Reference
Include dependency graph for cost.c:

Go to the source code of this file.

Functions

int find_derived (int i, char *type)
 
int find_derived_add (int i)
 
int find_derived_postfix (int i)
 
static void print_help (void)
 
static void print_stats (int i, long long min, long long max, double average, double std)
 
static void print_std_dev (int *s)
 
static void print_dist (long long min, long long max, int bins, int *d)
 
static void do_output (int test_type, long long *array, int bins, int show_std_dev, int show_dist)
 
int main (int argc, char **argv)
 

Function Documentation

static void do_output ( int  test_type,
long long array,
int  bins,
int  show_std_dev,
int  show_dist 
)
static

Definition at line 144 of file cost.c.

146 {
147  int s[10];
148  long long min, max;
149  double average, std;
150 
151  std = do_stats( array, &min, &max, &average );
152 
153  print_stats( test_type, min, max, average, std );
154 
155  if ( show_std_dev ) {
156  do_std_dev( array, s, std, average );
157  print_std_dev( s );
158  }
159 
160  if ( show_dist ) {
161  int *d;
162  d = calloc( bins , sizeof ( int ) );
163  do_dist( array, min, max, bins, d );
164  print_dist( min, max, bins, d );
165  free( d );
166  }
167 }
off64_t max
Definition: libasync.c:331
static void print_stats(int i, long long min, long long max, double average, double std)
Definition: cost.c:94
double do_stats(long long *array, long long *min, long long *max, double *average)
Definition: cost_utils.c:7
static void print_dist(long long min, long long max, int bins, int *d)
Definition: cost.c:123
free(dummyfile[xx])
s
Definition: iozone.c:20289
#define min(x, y)
Definition: darwin-common.h:4
void do_dist(long long *a, long long min, long long max, int bins, int *d)
Definition: cost_utils.c:51
static void print_std_dev(int *s)
Definition: cost.c:108
void do_std_dev(long long *a, int *s, double std, double ave)
Definition: cost_utils.c:32

Here is the call graph for this function:

Here is the caller graph for this function:

int find_derived ( int  i,
char *  type 
)

Definition at line 37 of file cost.c.

38 {
39  PAPI_event_info_t info;
40 
42 
43  do {
44  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
45  if ( strcmp( info.derived, type) == 0 )
46  return i;
47  }
48  } while ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );
49 
50  return PAPI_NULL;
51 }
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1143
return PAPI_OK
Definition: linux-nvml.c:458
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:841
int i
Definition: fileop.c:140
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:990

Here is the call graph for this function:

Here is the caller graph for this function:

int find_derived_add ( int  i)

Definition at line 55 of file cost.c.

56 {
57  int ret;
58 
59  if ( (ret = find_derived( i, "DERIVED_ADD")) != PAPI_NULL)
60  return ret;
61 
62 
63  return find_derived( i, "DERIVED_SUB");
64 }
#define PAPI_NULL
Definition: fpapi.h:13
int find_derived(int i, char *type)
Definition: cost.c:37
long long ret
Definition: iozone.c:1346
int i
Definition: fileop.c:140

Here is the call graph for this function:

Here is the caller graph for this function:

int find_derived_postfix ( int  i)

Definition at line 67 of file cost.c.

68 {
69  return ( find_derived ( i, "DERIVED_POSTFIX" ) );
70 }
int find_derived(int i, char *type)
Definition: cost.c:37
int i
Definition: fileop.c:140

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 171 of file cost.c.

172 {
173  int i, retval, EventSet = PAPI_NULL;
174  int retval_start,retval_stop;
175  int bins = 100;
176  int show_dist = 0, show_std_dev = 0;
177  long long totcyc, values[2];
178  long long *array;
179  int event;
180  PAPI_event_info_t info;
181 
182 
183  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
184 
185  for ( i = 1; i < argc; i++ ) {
186  if ( !strcmp( argv[i], "-b" ) ) {
187  i++;
188  if ( i >= argc || (bins = atoi( argv[i] ) > 0 ) ) {
189  printf( "-b requires a positive bin count!\n" );
190  exit( 1 );
191  }
192  }
193  else if ( !strcmp( argv[i], "-d" ) )
194  show_dist = 1;
195  else if ( !strcmp( argv[i], "-h" ) ) {
196  print_help( );
197  exit( 1 );
198  }
199  else if ( !strcmp( argv[i], "-s" ) )
200  show_std_dev = 1;
201  else if ( !strcmp( argv[i], "-t" ) ) {
202  i++;
203  if ( i >= argc || (num_iters = ( int ) atol( argv[i] ) > 0) ) {
204  printf( "-t requires a positive threshold value!\n" );
205  exit( 1 );
206  }
207  }
208  else {
209  /* If not a valid option, print out some help information */
210  print_help( );
211  exit( 1 );
212  }
213  }
214 
215  printf( "Cost of execution for PAPI start/stop, read and accum.\n" );
216  printf( "This test takes a while. Please be patient...\n" );
217 
218  if ( ( retval =
220  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
221  if ( ( retval = PAPI_set_debug( PAPI_VERB_ECONT ) ) != PAPI_OK )
222  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
223  if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK )
224  test_fail( __FILE__, __LINE__, "PAPI_query_event", retval );
225  if ( ( retval = PAPI_query_event( PAPI_TOT_INS ) ) != PAPI_OK )
226  test_fail( __FILE__, __LINE__, "PAPI_query_event", retval );
227  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
228  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
229 
230  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
231  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
232 
233  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_INS ) ) != PAPI_OK )
234  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_IIS ) ) != PAPI_OK )
235  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
236 
237  /* Make sure no errors and warm up */
238 
239  totcyc = PAPI_get_real_cyc( );
240  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
241  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
242  if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
243  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
244 
245  array =
246  ( long long * ) malloc( ( size_t ) num_iters * sizeof ( long long ) );
247  if ( array == NULL )
248  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
249 
250  /* Determine clock latency */
251 
252  printf( "\nPerforming loop latency test...\n" );
253 
254  for ( i = 0; i < num_iters; i++ ) {
255  totcyc = PAPI_get_real_cyc( );
256  totcyc = PAPI_get_real_cyc( ) - totcyc;
257  array[i] = totcyc;
258  }
259 
260  do_output( 0, array, bins, show_std_dev, show_dist );
261 
262  /* Start the start/stop eval */
263 
264  printf( "\nPerforming start/stop test...\n" );
265 
266  for ( i = 0; i < num_iters; i++ ) {
267  totcyc = PAPI_get_real_cyc( );
268  retval_start=PAPI_start( EventSet );
269  retval_stop=PAPI_stop( EventSet, values );
270  totcyc = PAPI_get_real_cyc( ) - totcyc;
271  array[i] = totcyc;
272  if (retval_start || retval_stop) {
273  test_fail( __FILE__, __LINE__, "PAPI start/stop", retval_start );
274  }
275  }
276 
277  do_output( 1, array, bins, show_std_dev, show_dist );
278 
279  /* Start the read eval */
280  printf( "\nPerforming read test...\n" );
281 
282  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
283  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
284  PAPI_read( EventSet, values );
285 
286  for ( i = 0; i < num_iters; i++ ) {
287  totcyc = PAPI_get_real_cyc( );
288  PAPI_read( EventSet, values );
289  totcyc = PAPI_get_real_cyc( ) - totcyc;
290  array[i] = totcyc;
291  }
292  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
293  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
294 
295  do_output( 2, array, bins, show_std_dev, show_dist );
296 
297  /* Start the read with timestamp eval */
298  printf( "\nPerforming read with timestamp test...\n" );
299 
300  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
301  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
302  PAPI_read_ts( EventSet, values, &totcyc );
303 
304  for ( i = 0; i < num_iters; i++ ) {
305  PAPI_read_ts( EventSet, values, &array[i] );
306  }
307  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
308  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
309 
310  /* post-process the timing array */
311  for ( i = num_iters - 1; i > 0; i-- ) {
312  array[i] -= array[i - 1];
313  }
314  array[0] -= totcyc;
315 
316  do_output( 3, array, bins, show_std_dev, show_dist );
317 
318  /* Start the accum eval */
319  printf( "\nPerforming accum test...\n" );
320 
321  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
322  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
323  PAPI_accum( EventSet, values );
324 
325  for ( i = 0; i < num_iters; i++ ) {
326  totcyc = PAPI_get_real_cyc( );
327  PAPI_accum( EventSet, values );
328  totcyc = PAPI_get_real_cyc( ) - totcyc;
329  array[i] = totcyc;
330  }
331  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
332  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
333 
334  do_output( 4, array, bins, show_std_dev, show_dist );
335 
336  /* Start the reset eval */
337  printf( "\nPerforming reset test...\n" );
338 
339  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
340  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
341 
342  for ( i = 0; i < num_iters; i++ ) {
343  totcyc = PAPI_get_real_cyc( );
344  PAPI_reset( EventSet );
345  totcyc = PAPI_get_real_cyc( ) - totcyc;
346  array[i] = totcyc;
347  }
348  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
349  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
350 
351  do_output( 5, array, bins, show_std_dev, show_dist );
352 
353  /* Derived event test */
354  PAPI_cleanup_eventset( EventSet );
355 
356  event = 0 | PAPI_PRESET_MASK;
357 
358  if ( ( event = find_derived_postfix( event ) ) != PAPI_NULL ) {
359  if ( (retval = PAPI_add_event( EventSet, event) ) != PAPI_OK )
360  test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);
361 
362  PAPI_get_event_info(event, &info);
363  printf( "\nPerforming DERIVED_POSTFIX PAPI_read(%d counters) test...", info.count );
364 
365  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
366  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
367  PAPI_read( EventSet, values );
368 
369  for ( i = 0; i < num_iters; i++ ) {
370  totcyc = PAPI_get_real_cyc( );
371  PAPI_read( EventSet, values );
372  totcyc = PAPI_get_real_cyc( ) - totcyc;
373  array[i] = totcyc;
374  }
375  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
376  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
377 
378  do_output( 6, array, bins, show_std_dev, show_dist );
379 
380  } else {
381  printf("\tI was unable to find a DERIVED_POSTFIX preset event to "
382  "test on this architecture, skipping.\n");
383  }
384 
385  if ( ( event = find_derived_add( event ) ) != PAPI_NULL ) {
386  if ( (retval = PAPI_add_event( EventSet, event) ) != PAPI_OK )
387  test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);
388 
389  PAPI_get_event_info(event, &info);
390  printf( "\nPerforming DERIVED_[ADD|SUB] PAPI_read(%d counters) test...", info.count );
391 
392  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
393  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
394  PAPI_read( EventSet, values );
395 
396  for ( i = 0; i < num_iters; i++ ) {
397  totcyc = PAPI_get_real_cyc( );
398  PAPI_read( EventSet, values );
399  totcyc = PAPI_get_real_cyc( ) - totcyc;
400  array[i] = totcyc;
401  }
402  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
403  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
404 
405  do_output( 7, array, bins, show_std_dev, show_dist );
406  } else {
407  printf("\tI was unable to find a suitable DERIVED_[ADD|SUB] event to test, skipping.\n");
408  }
409 
410  free( array );
411  test_pass( __FILE__, NULL, 0 );
412  exit( 1 );
413 }
int atoi()
unsigned int count
Definition: papi.h:982
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
int PAPI_reset(int EventSet)
Definition: papi.c:2370
#define PAPI_NULL
Definition: fpapi.h:13
volatile int num_iters
static void do_output(int test_type, long long *array, int bins, int show_std_dev, int show_dist)
Definition: cost.c:144
#define PAPI_TOT_INS
Definition: fpapi.h:185
static void print_help(void)
Definition: cost.c:73
#define PAPI_VERB_ECONT
Definition: fpapi.h:39
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PAPI_PRESET_MASK
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:841
char ** argv
Definition: iozone.c:1610
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2653
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int find_derived_postfix(int i)
Definition: cost.c:67
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
Definition: fpapi.h:194
free(dummyfile[xx])
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int find_derived_add(int i)
Definition: cost.c:55
int PAPI_query_event(int EventCode)
Definition: papi.c:695
int EventSet
#define PAPI_TOT_IIS
Definition: fpapi.h:184
int PAPI_read_ts(int EventSet, long long *values, long long *cycles)
Definition: papi.c:2557
long long PAPI_get_real_cyc(void)
Definition: papi.c:6078
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2469
int PAPI_start(int EventSet)
Definition: papi.c:2019
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
void exit()
int PAPI_set_debug(int level)
Definition: papi.c:3027

Here is the call graph for this function:

static void print_dist ( long long  min,
long long  max,
int  bins,
int d 
)
static

Definition at line 123 of file cost.c.

124 {
125  int i, j;
126  int step = ( int ) ( max - min ) / bins;
127 
128  printf( "\nCost distribution profile\n\n" );
129  for ( i = 0; i < bins; i++ ) {
130  printf( "%8d:", ( int ) min + ( step * i ) );
131  if ( d[i] > 100 ) {
132  printf
133  ( "**************************** %d counts ****************************",
134  d[i] );
135  } else {
136  for ( j = 0; j < d[i]; j++ )
137  printf( "*" );
138  }
139  printf( "\n" );
140  }
141 }
off64_t max
Definition: libasync.c:331
#define printf
Definition: papi_test.h:125
int i
Definition: fileop.c:140
#define min(x, y)
Definition: darwin-common.h:4
int
Definition: iozone.c:18528
long j
Definition: iozone.c:19135

Here is the caller graph for this function:

static void print_help ( void  )
static

Definition at line 73 of file cost.c.

74 {
75  printf( "This is the PAPI cost program.\n" );
76  printf
77  ( "It computes min / max / mean / std. deviation for PAPI start/stop pairs; for PAPI reads, and for PAPI_accums. Usage:\n\n" );
78  printf( " cost [options] [parameters]\n" );
79  printf( " cost TESTS_QUIET\n\n" );
80  printf( "Options:\n\n" );
81  printf
82  ( " -b BINS set the number of bins for the graphical distribution of costs. Default: 100\n" );
83  printf( " -d show a graphical distribution of costs\n" );
84  printf( " -h print this help message\n" );
85  printf
86  ( " -s show number of iterations above the first 10 std deviations\n" );
87  printf
88  ( " -t THRESHOLD set the threshold for the number of iterations. Default: 100,000\n" );
89  printf( "\n" );
90 }
#define printf
Definition: papi_test.h:125

Here is the caller graph for this function:

static void print_stats ( int  i,
long long  min,
long long  max,
double  average,
double  std 
)
static

Definition at line 94 of file cost.c.

95 {
96  char *test[] = { "loop latency", "PAPI_start/stop (2 counters)",
97  "PAPI_read (2 counters)", "PAPI_read_ts (2 counters)",
98  "PAPI_accum (2 counters)", "PAPI_reset (2 counters)",
99  "PAPI_read (1 derived_postfix counter)"," PAPI_read (1 derived_[add|sub] counter)"
100  };
101  printf( "\nTotal cost for %s over %d iterations\n", test[i], num_iters );
102  printf
103  ( "min cycles : %lld\nmax cycles : %lld\nmean cycles : %lf\nstd deviation: %lf\n ",
104  min, max, average, std );
105 }
off64_t max
Definition: libasync.c:331
volatile int num_iters
#define printf
Definition: papi_test.h:125
int i
Definition: fileop.c:140
#define min(x, y)
Definition: darwin-common.h:4
char * test
Definition: iozone.c:23679

Here is the caller graph for this function:

static void print_std_dev ( int s)
static

Definition at line 108 of file cost.c.

109 {
110  int i;
111 
112  printf( "\n" );
113  printf
114  ( " --------# Standard Deviations Above the Mean--------\n" );
115  printf
116  ( "0-------1-------2-------3-------4-------5-------6-------7-------8-------9-----10\n" );
117  for ( i = 0; i < 10; i++ )
118  printf( " %d\t", s[i] );
119  printf( "\n\n" );
120 }
#define printf
Definition: papi_test.h:125
int i
Definition: fileop.c:140
s
Definition: iozone.c:20289

Here is the caller graph for this function: