20 {
21
27
29 int l1_size,l2_size,l1_linesize,l2_linesize,l2_entries;
30 int arraysize;
31 int quiet,errors=0,warnings=0;
32
33 double error;
35 double aSumm = 0.0;
36
38
40 printf("Testing the PAPI_L2_DCW event\n");
41 }
42
43
47 }
48
52 }
53
57 }
58
64
66 printf("\tDetected %dk L1 DCache, %dB linesize\n",
67 l1_size/1024,l1_linesize);
68 printf("\tDetected %dk L2 DCache, %dB linesize, %d entries\n",
69 l2_size/1024,l2_linesize,l2_entries);
70 }
71
72 arraysize=l2_size/sizeof(double);
73
75 printf("\tAllocating %zu bytes of memory (%d doubles)\n",
76 arraysize*sizeof(double),arraysize);
77 }
78
79 array=calloc(arraysize,
sizeof(
double));
81 test_fail(__FILE__,__LINE__,
"Can't allocate memory",0);
82 }
83
84
85
86
87
89 printf("\nWrite Test: Initializing an array of %d doubles:\n",
90 arraysize);
91 }
92
93 high=0; low=0;
total=0;
94
95 for(
i=0;
i<num_runs;
i++) {
96
99
101
103
106 "reading PAPI_L2_DCW",
retval );
107 }
108
112 }
113
114 average=(
total/num_runs);
115
116 expected=arraysize/(l1_linesize/
sizeof(double));
117
119 printf("\tShould be roughly "
120 "arraysize/L1_linesize/double_size (%d/%d/%zu): "
121 "%lld\n\n",
122 arraysize,l1_linesize,sizeof(double),
124 }
125
127
128 if ((error > 10.0) || (error<-10.0)) {
129 if (!
quiet) printf(
"Instruction count off by more than 1%%\n");
130 errors++;
131 }
132
134 if (!
quiet) printf(
"WARNING: Average OK but low value seems suspicious\n");
135 warnings++;
136 }
137
138 if (!
quiet) printf(
"\n");
139
140
141
142
143
145 printf("\nRead Test: Summing an array of %d doubles:\n",
146 arraysize);
147 }
148
149 high=0; low=0;
total=0;
150
151 for(
i=0;
i<num_runs;
i++) {
152
155
157
159
162 "reading PAPI_L2_DCW",
retval );
163 }
164
168 }
169
170 average=(
total/num_runs);
171
172 expected=(arraysize/(l1_linesize/
sizeof(double)))/10;
173
175 printf("\tShould be very low as we are measuring writes\n");
176 }
177
179 printf("Average writes: %lld\n",average);
180 }
181
182
183
185 if (!
quiet) printf(
"ERROR: Write count unexpectedly high\n");
186 errors++;
187 }
188
190 printf("\n");
191 }
192
193
194 if (errors) {
195 test_warn( __FILE__, __LINE__,
"Error too high", 1 );
196 }
197
198 if (warnings) {
199 test_warn(__FILE__, __LINE__,
"Average results OK but some measurements low",1);
200 }
201
203
204 return 0;
205}
long long get_cachesize(int type)
long long get_linesize(int type)
long long get_entries(int type)
int cache_write_test(double *array, int size)
double cache_read_test(double *array, int size)
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
double display_error(long long average, long long high, long long low, long long expected, int quiet)
static double array[ARRAYSIZE]
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_pass(const char *filename)
void test_warn(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)