I am testing a simple piece of code that just reads/write from random
positions in a large array of ints for benchmarking purposes. The
relevant part of the code is
// We use calloc now so we can read as well as write.
p = calloc(length, sizeof(int));
srand(time(NULL));
// We make a read and a write to each randomly chosen position in the array
for (i=0;i<length;i++) {
val = rand() % length;
temp += p[val];
p[val] = i;
}
I have run using
valgrind --tool=cachegrind ./swaptestrand2 2000000 (the number sets
the variable length)
I am mystified by the D1 cache miss lines. I get
D refs: 144,057,551 (94,023,790 rd + 50,033,761 wr)
D1 misses: 2,119,185 ( 1,993,960 rd + 125,225 wr)
L2d misses: 1,603,262 ( 1,478,051 rd + 125,211 wr)
D1 miss rate: 1.4% ( 2.1% + 0.2% )
L2d miss rate: 1.1% ( 1.5% + 0.2% )
The cachegrind.out file says
desc: D1 cache: 32768 B, 64 B, 8-way associative
This D1 miss rate seems rather low give the random nature of the
choice of array location. So I tried reducing the size of the D1 cache
with
valgrind --tool=cachegrind --D1=128,2,64 ./swaptestrand2 2000000
and now I get
D refs: 144,057,551 (94,023,790 rd + 50,033,761 wr)
D1 misses: 38,556,711 (24,424,753 rd + 14,131,958 wr)
L2d misses: 1,602,496 ( 1,477,285 rd + 125,211 wr)
D1 miss rate: 26.7% ( 25.9% + 28.2% )
L2d miss rate: 1.1% ( 1.5% + 0.2% )
I am mystified, how can the D1 miss rate possibly be so low? The
total size in bytes of the array is 8,000,000 bytes and the cache size
is 8,192 bytes!
Any help much appreciated.
Raphael
|