-
Notifications
You must be signed in to change notification settings - Fork 2
/
plru_test.cpp
executable file
·122 lines (106 loc) · 2.97 KB
/
plru_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdlib.h>
#include "SACache.h"
#include "GenericCache.h"
#include "CacheMemory.h"
#include "RP_PLRU.h"
int main()
{
unsigned P = 1;
srand(time(0));
//test hits for exact set fit
for (unsigned way_bits = 1; way_bits < 6; way_bits++)
{
unsigned ways = 1 << way_bits;
CacheConfig config = {way_bits, way_bits, 1, 0};
RP_PLRU policy(config);
RMapper R(config, P);
GenericCache cache(config, policy, R, P);
//preload set
for (unsigned i = 0; i < ways; i++)
{
size_t addr = i;
cache.access({addr, 0, false, false});
}
//test it (not expecting a surprise here)
for (unsigned i = 0; i < 5; i++)
{
for (unsigned j = 0; j < ways; j++)
{
size_t addr = j;
if (!cache.access({addr, 0, false, false}).hit)
{
printf("unexpected miss, ways: %u, addr: %lx, loop: %u\n", ways, addr, i);
return -1;
}
}
}
}
//test missing for overfull set
for (unsigned way_bits = 1; way_bits < 6; way_bits++)
{
unsigned ways = 1 << way_bits;
CacheConfig config = {way_bits, way_bits, 1, 0};
RP_PLRU policy(config);
RMapper R(config, P);
GenericCache cache(config, policy, R, P);
//SACache cache(config, RP_PLRU);
//preload set first, because empty init order != plru order
for (unsigned i = 0; i < ways; i++)
{
size_t addr = i+ways;
cache.access({addr, 0, false, false});
}
for (unsigned i = 0; i < 100; i++)
{
for (unsigned j = 0; j < ways+1; j++)
{
size_t addr = j;
if (cache.access({addr, 0, false, false}).hit)
{
printf("unexpected hit, ways: %u, addr: %lx, loop: %u\n", ways, addr, i);
return -1;
}
}
}
}
//test early eviction of non-oldest address
for (unsigned way_bits = 2; way_bits < 6; way_bits++)
{
unsigned ways = 1 << way_bits;
CacheConfig config = {way_bits, way_bits, 1, 0};
RP_PLRU policy(config);
RMapper R(config, P);
//GenericCache cache(config, policy, R, P);
SACache cache(config, policy);
//preload set first, because empty init order != plru order
for (unsigned i = 0; i < ways; i++)
{
size_t addr = i;
cache.access({addr, 0, false, false});
}
for (unsigned i = 0; i < 100; i++)
{
size_t addr_start = rand();
//define set order
for (unsigned j = 1; j < ways+1; j++)
{
size_t addr = addr_start+j;
cache.access({addr, 0, false, false});
}
//prime set to evict non-oldest
for (unsigned j = ways/2; j >0; j/=2)
{
size_t addr = addr_start+j;
cache.access({addr, 0, false, false});
}
//replace non-oldest
cache.access({addr_start-1, 0, false, false});
if (cache.access({addr_start+ways, 0, false, false}).hit)
{
printf("unexpected hit on non-oldest, ways: %u, addr: %lx, loop: %u\n", ways, addr_start+ways, i);
return -1;
}
}
}
return 0;
}