PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_l2_dcw.c File Reference
Include dependency graph for papi_l2_dcw.c:

Go to the source code of this file.

Macros

#define NUM_RUNS   100
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NUM_RUNS

#define NUM_RUNS   100

Definition at line 18 of file papi_l2_dcw.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file papi_l2_dcw.c.

20 {
21
22 int i;
23 int eventset=PAPI_NULL;
24 int num_runs=NUM_RUNS;
25 long long high,low,average,expected;
26 long long count,total;
27
28 int retval;
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;
34 double *array;
35 double aSumm = 0.0;
36
37 quiet=tests_quiet(argc,argv);
38
39 if (!quiet) {
40 printf("Testing the PAPI_L2_DCW event\n");
41 }
42
43 /* Init the PAPI library */
45 if (retval != PAPI_VER_CURRENT) {
46 test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);
47 }
48
50 if (retval!=PAPI_OK) {
51 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
52 }
53
54 retval=PAPI_add_named_event(eventset,"PAPI_L2_DCW");
55 if (retval!=PAPI_OK) {
56 test_skip( __FILE__, __LINE__, "adding PAPI_L2_DCW", retval );
57 }
58
59 l1_size=get_cachesize(L1D_CACHE);
60 l1_linesize=get_linesize(L1D_CACHE);
61 l2_size=get_cachesize(L2_CACHE);
62 l2_linesize=get_linesize(L2_CACHE);
63 l2_entries=get_entries(L2_CACHE);
64
65 if (!quiet) {
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
74 if (!quiet) {
75 printf("\tAllocating %zu bytes of memory (%d doubles)\n",
76 arraysize*sizeof(double),arraysize);
77 }
78
79 array=calloc(arraysize,sizeof(double));
80 if (array==NULL) {
81 test_fail(__FILE__,__LINE__,"Can't allocate memory",0);
82 }
83
84 /******************/
85 /* Testing Writes */
86 /******************/
87
88 if (!quiet) {
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
97 PAPI_reset(eventset);
98 PAPI_start(eventset);
99
100 cache_write_test(array,arraysize);
101
102 retval=PAPI_stop(eventset,&count);
103
104 if (retval!=PAPI_OK) {
105 test_fail( __FILE__, __LINE__,
106 "reading PAPI_L2_DCW", retval );
107 }
108
109 if (count>high) high=count;
110 if ((low==0) || (count<low)) low=count;
111 total+=count;
112 }
113
114 average=(total/num_runs);
115
116 expected=arraysize/(l1_linesize/sizeof(double));
117
118 if (!quiet) {
119 printf("\tShould be roughly "
120 "arraysize/L1_linesize/double_size (%d/%d/%zu): "
121 "%lld\n\n",
122 arraysize,l1_linesize,sizeof(double),
123 expected);
124 }
125
126 error=display_error(average,high,low,expected,quiet);
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
133 if (low<expected/10) {
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 /* Testing Reads */
142 /******************/
143
144 if (!quiet) {
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
153 PAPI_reset(eventset);
154 PAPI_start(eventset);
155
156 aSumm+=cache_read_test(array,arraysize);
157
158 retval=PAPI_stop(eventset,&count);
159
160 if (retval!=PAPI_OK) {
161 test_fail( __FILE__, __LINE__,
162 "reading PAPI_L2_DCW", retval );
163 }
164
165 if (count>high) high=count;
166 if ((low==0) || (count<low)) low=count;
167 total+=count;
168 }
169
170 average=(total/num_runs);
171
172 expected=(arraysize/(l1_linesize/sizeof(double)))/10;
173
174 if (!quiet) {
175 printf("\tShould be very low as we are measuring writes\n");
176 }
177
178 if (!quiet) {
179 printf("Average writes: %lld\n",average);
180 }
181
182
183
184 if (average>expected) {
185 if (!quiet) printf("ERROR: Write count unexpectedly high\n");
186 errors++;
187 }
188
189 if (!quiet) {
190 printf("\n");
191 }
192
193 /* FIXME: warn for now, as fail on broadwell and more recent */
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
202 test_pass(__FILE__);
203
204 return 0;
205}
int i
long long get_cachesize(int type)
Definition: cache_helper.c:78
long long get_linesize(int type)
Definition: cache_helper.c:110
long long get_entries(int type)
Definition: cache_helper.c:94
#define L2_CACHE
Definition: cache_helper.h:3
#define L1D_CACHE
Definition: cache_helper.h:2
int cache_write_test(double *array, int size)
Definition: cache_testcode.c:6
double cache_read_test(double *array, int size)
static long count
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)
Definition: display_error.c:7
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
#define NUM_RUNS
Definition: papi_l2_dcw.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
static int total
Definition: rapl_overflow.c:9
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: