-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeadblock.hpp
More file actions
63 lines (55 loc) · 1.31 KB
/
Copy pathdeadblock.hpp
File metadata and controls
63 lines (55 loc) · 1.31 KB
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
#ifndef DEADBLOCK
#define DEADBLOCK
#include "LRU.hpp"
#include <map>
class DeadBlockLRUCache : public LRUCache
{
public:
static const unsigned int MaxMiss = 3;
std::map<ulong, ulong> accessCounter;
DeadBlockLRUCache(ulong cacheSize, ulong blockSize) : LRUCache(cacheSize, blockSize) {}
void onMiss(ulong address, cacheState state)
{
if (accessCounter.find(address) != accessCounter.end())
{
accessCounter[address]++;
if(accessCounter[address] == (MaxMiss+1))
return; //blocks is now dead
}
else
accessCounter[address] = 1;
LRUCache::onMiss(address, state);
}
void onHit(ulong address, cacheState state)
{
if (accessCounter.find(address) != accessCounter.end())
{
if (accessCounter[address] > 0)
accessCounter[address]--;
}
else
accessCounter[address] = 0;
LRUCache::onHit(address, state);
}
bool isDeadBlock(ulong address)
{
return accessCounter.find(address) != accessCounter.end() && accessCounter[address] > MaxMiss;
}
void read(ulong address)
{
//std::cout << "L3 read" << std::endl;
if (isDeadBlock(address))
upperCache->read(address);
else
LRUCache::read(address);
}
void write(ulong address)
{
//std::cout << "L3 write" << std::endl;
if (isDeadBlock(address))
upperCache->write(address);
else
LRUCache::write(address);
}
};
#endif