PAPI  5.7.0.0
papi_l1_dca.c
Go to the documentation of this file.
1 /* This code attempts to test the L1 Data Cache Accesses */
2 /* performance counter PAPI_L1_DCA */
3 
4 /* by Vince Weaver, <vincent.weaver@maine.edu> */
5 
6 /* Note on AMD fam15h we get 3x expected on writes? */
7 
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 
13 #include "papi.h"
14 #include "papi_test.h"
15 
16 #include "testcode.h"
17 #include "display_error.h"
18 
19 #define NUM_RUNS 100
20 
21 #define ARRAYSIZE 65536
22 
23 static double array[ARRAYSIZE];
24 
25 int main(int argc, char **argv) {
26 
27  int i;
28  int quiet;
29  int eventset=PAPI_NULL;
30 
31  int errors=0;
32  int retval;
33  int num_runs=NUM_RUNS;
34  long long high,low,average,expected=ARRAYSIZE;
35  long long count,total;
36  double aSumm = 0.0;
37  double error;
38 
39  quiet=tests_quiet(argc,argv);
40 
41  if (!quiet) {
42  printf("Testing the PAPI_L1_DCA event\n");
43  }
44 
45  /* Init the PAPI library */
47  if (retval != PAPI_VER_CURRENT) {
48  test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);
49  }
50 
51  retval=PAPI_create_eventset(&eventset);
52  if (retval!=PAPI_OK) {
53  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
54  }
55 
56  retval=PAPI_add_named_event(eventset,"PAPI_L1_DCA");
57  if (retval!=PAPI_OK) {
58  test_skip( __FILE__, __LINE__, "adding PAPI_L1_DCA", retval );
59  }
60 
61 
62  /*******************************************************************/
63  /* Test if the C compiler uses a sane number of data cache acceess */
64  /* This tests writes to memory. */
65  /*******************************************************************/
66 
67  if (!quiet) {
68  printf("Write Test: Initializing an array of %d doubles:\n",
69  ARRAYSIZE);
70  }
71 
72  high=0; low=0; total=0;
73 
74  for(i=0;i<num_runs;i++) {
75 
76  PAPI_reset(eventset);
77  PAPI_start(eventset);
78 
80 
81  retval=PAPI_stop(eventset,&count);
82 
83  if (retval!=PAPI_OK) {
84  test_fail( __FILE__, __LINE__,
85  "reading PAPI_L1_DCA", retval );
86  }
87 
88  if (count>high) high=count;
89  if ((low==0) || (count<low)) low=count;
90  total+=count;
91  }
92 
93  average=(total/num_runs);
94 
95  error=display_error(average,high,low,expected,quiet);
96 
97  if ((error > 1.0) || (error<-1.0)) {
98  if (!quiet) printf("Instruction count off by more than 1%%\n");
99  errors++;
100  }
101 
102  if (!quiet) printf("\n");
103 
104 
105  /*******************************************************************/
106  /* Test if the C compiler uses a sane number of data cache acceess */
107  /* This tests writes to memory. */
108  /*******************************************************************/
109 
110  if (!quiet) {
111  printf("Read Test: Summing an array of %d doubles:\n",
112  ARRAYSIZE);
113  }
114 
115  high=0; low=0; total=0;
116 
117  for(i=0;i<num_runs;i++) {
118 
119  PAPI_reset(eventset);
120  PAPI_start(eventset);
121 
122 
124 
125  retval=PAPI_stop(eventset,&count);
126 
127  if (retval!=PAPI_OK) {
128  test_fail( __FILE__, __LINE__,
129  "reading PAPI_L1_DCA", retval );
130  }
131 
132  if (count>high) high=count;
133  if ((low==0) || (count<low)) low=count;
134  total+=count;
135  }
136 
137  if (!quiet) {
138  printf("\tRead test sim= %lf\n",aSumm);
139  }
140 
141  average=(total/num_runs);
142 
143  error=display_error(average,high,low,expected,quiet);
144 
145  if ((error > 1.0) || (error<-1.0)) {
146  if (!quiet) printf("Instruction count off by more than 1%%\n");
147  errors++;
148  }
149 
150  if (!quiet) {
151  printf("\n");
152  }
153 
154  if (errors) {
155  test_fail( __FILE__, __LINE__, "Error too high", 1 );
156  }
157 
158  test_pass(__FILE__);
159 
160  return 0;
161 }
#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
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
Definition: papi.c:2459
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
#define NUM_RUNS
Definition: papi_l1_dca.c:19
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
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
int quiet
Definition: rapl_overflow.c:18
int cache_write_test(double *array, int size)
Definition: cache_testcode.c:6
#define PAPI_NULL
Definition: fpapi.h:13
int main(int argc, char **argv)
Definition: papi_l1_dca.c:25
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
static int total
Definition: rapl_overflow.c:9
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 ARRAYSIZE
Definition: papi_l1_dca.c:21
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long count
int i
Definition: fileop.c:140
double cache_read_test(double *array, int size)