-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_cache.h
More file actions
178 lines (146 loc) · 7.43 KB
/
simple_cache.h
File metadata and controls
178 lines (146 loc) · 7.43 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef SIMPLE_CACHE_H
#define SIMPLE_CACHE_H
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// //
// This file is distributed as part of the Cache Replacement Championship //
// workshop held in conjunction with ISCA'2010. //
// //
// //
// Everyone is granted permission to copy, modify, and/or re-distribute //
// this software. //
// //
// Please contact Aamer Jaleel <ajaleel@gmail.com> should you have any //
// questions //
// //
////////////////////////////////////////////////////////////////////////////////
#include <cassert>
#include "asim-defs.h"
#include "replacement_state.h"
#include "simple_cache_defs.h"
class SIMPLE_CACHE
{
private:
// parameters
UINT32 numsets;
UINT32 assoc;
UINT32 threads;
UINT32 linesize;
UINT32 replPolicy;
UINT32 numBanks;
UINT32 numGlobalBanks;
UINT32 numSetsPerBank;
UINT32 numSetsPerGlobalBank;
bool usePrivateBanks;
int setHashing;
LINE_STATE **cache;
CACHE_REPLACEMENT_STATE *cacheReplState;
// statistics
COUNTER *lookups[ACCESS_MAX];
COUNTER *misses[ACCESS_MAX];
COUNTER *hits[ACCESS_MAX];
// Lookup Parameters
UINT32 lineShift;
UINT32 indexShift;
UINT32 bankShift;
UINT32 indexMask;
UINT32 bankMask;
UINT32 globalBankShift;
COUNTER mytimer;
string CacheName;
private:
// Copy operations are private and not implemented to prevent copying
SIMPLE_CACHE(const SIMPLE_CACHE &);
SIMPLE_CACHE &operator=(const SIMPLE_CACHE &);
public:
SIMPLE_CACHE(UINT32 _cacheSize, UINT32 _assoc, UINT32 _tpc, UINT32 _linesize = 64, UINT32 _pol = REPL_LRU, UINT32 _numGlobalBanks = 16, UINT32 _numBanks = 4, bool _usePrivateBanks = false);
// SIMPLE_CACHE( UINT32 _cacheSize, UINT32 _assoc, UINT32 _tpc, UINT32 _linesize=64, UINT32 _numBanks=4,
// UINT32 _pol=REPL_LRU, bool _usePrivateBanks=false, UINT32 _numGlobalBanks=16, int _setHashing=5,
// bool evict_miss=false);
~SIMPLE_CACHE();
void SetCacheName(string _name) { CacheName = _name; } //
void SetCacheGlobalBankNum(UINT32 _num) { numGlobalBanks = _num; }
// bool CacheInspect( UINT32 tid , Addr_t PC, Addr_t paddr, UINT32 accessType, UINT32 privateBankID=0 );
// bool LookupAndFillCache( UINT32 tid, Addr_t PC, Addr_t paddr, UINT32 accessType, bool fillOnMiss=1, bool updateReplacement=true, UINT32 privateBankID=0, UINT64 cycle=0);
bool LookupAndFillCache(UINT32 tid, Addr_t PC, Addr_t paddr, UINT32 accessType, bool fillOnMiss = 1, UINT32 privateBankID = 0);
INT32 CountPartialMatches(Addr_t paddr, Addr_t mask); // Calculates partial tag matches
LINE_STATE *LookupCache(Addr_t paddr, UINT32 accessType, bool updateReplacement = true, UINT32 privateBankID = 0); // hit/miss
void SetCacheSetHashing(int _num) { setHashing = _num; }
LINE_STATE *FindVictim(Addr_t paddr, INT32 &wayID, UINT32 privateBankID = 0); // Find line to replace
LINE_STATE *FindVictim_CheckValid(Addr_t paddr, INT32 &wayID, bool &isValid, UINT32 privateBankID = 0); // Find line to replace
LINE_STATE *GetVictimLine(Addr_t paddr, INT32 wayID); // Return victim line to replace
INT32 GetLRUBits(Addr_t paddr, UINT32 privateBankID);
void FillCache(Addr_t paddr, INT32 wayID, bool markDirty, bool updateReplacement = true, UINT32 privateBankID = 0, UINT64 cycle = 0); // Find line at way provided by FindVictim
void UpdateVictimReplacementState(Addr_t paddr, INT32 wayID, UINT32 privateBankID = 0); //Update replacement state for victim way given by FindVictim_CheckValid
void ClearLineReplacementMask(Addr_t paddr, INT32 wayID, UINT32 privateBankID = 0);
void EvictLine(Addr_t paddr, INT32 wayID, UINT32 privateBankID = 0);
/*
bool CacheInspect( UINT32 tid, Addr_t PC, Addr_t paddr, UINT32 accessType, UINT64 bankID, UINT32 privateBankID=0 );
bool LookupAndFillCache( UINT32 tid, Addr_t PC, Addr_t paddr, UINT32 accessType, UINT64 bankID=0, bool fillOnMiss=1, UINT32 privateBankID=0 );
INT32 CountPartialMatches(Addr_t paddr, UINT64 bankID, Addr_t mask ); // Calculates partial tag matches
LINE_STATE* LookupCache( Addr_t paddr, UINT32 accessType, UINT64 bankID = 0, UINT32 privateBankID=0 ); // hit/miss
void SetCacheSetHashing(int _num) { setHashing = _num; }
LINE_STATE* FindVictim( Addr_t paddr, INT32 &wayID, UINT64 bankID = 0, UINT32 privateBankID=0 ); // Find line to replace
void FillCache( Addr_t paddr, INT32 wayID, bool markDirty, UINT64 bankID, UINT32 privateBankID=0 ); // Find line at way provided by FindVictim
*/
UINT32 getBankID(Addr_t addr) { return (GetSetIndex(addr) / numSetsPerBank); };
UINT32 getBankIDInterleaved(Addr_t addr) { return (GetSetIndex(addr) % numBanks); };
UINT32 getBankIDRandomized(Addr_t addr);
UINT32 getNumBanks() { return numBanks; };
Addr_t GetLineAddr(Addr_t addr)
{
return ((addr >> lineShift) << lineShift);
}
Addr_t GetTag(Addr_t addr)
{
return ((addr >> lineShift) << lineShift); // Tag is the line address
}
UINT32 GetSetIndex(Addr_t addr, UINT32 privateBankID = 0);
UINT32 GetGlobalSetIndex(Addr_t addr, UINT64 bankID, UINT32 privateBankID = 0);
ostream &PrintStats(ostream &out);
UINT32 getNumValidLines();
UINT32 getNumDirtyLines();
void InvalidateAddr(Addr_t paddr, UINT32 privateBankID = 0);
// FIXME: check what is this initializing
void Initialize();
private:
INT32 LookupSet(UINT32 setIndex, Addr_t tag);
void InitCache();
void InitCacheReplacementState();
void DeleteCacheReplacementState();
void InitStats();
// FIXME: check why is this removed?
// INT32 LookupSet( UINT32 setIndex, Addr_t tag );
INT32 GetVictimInSet(UINT32 tid, UINT32 setIndex, Addr_t PC, Addr_t paddr, UINT32 accessType);
INT32 GetVictimInSet_CheckValid(UINT32 tid, UINT32 setIndex, Addr_t PC, Addr_t paddr, UINT32 accessType, bool &isValid);
bool ACCEL_L2_EVICT_ON_MISS_FIX;
public:
void setReplPolicy(int repl_policy)
{
replPolicy = repl_policy;
InitCacheReplacementState();
}
// Statistics related functions
COUNTER ThreadDemandLookupStats(UINT32 tid)
{
COUNTER stat = 0;
for (UINT32 a = 0; a <= ACCESS_STORE; a++)
stat += lookups[a][tid];
return stat;
}
COUNTER ThreadDemandMissStats(UINT32 tid)
{
COUNTER stat = 0;
for (UINT32 a = 0; a <= ACCESS_STORE; a++)
stat += misses[a][tid];
return stat;
}
COUNTER ThreadDemandHitStats(UINT32 tid)
{
COUNTER stat = 0;
for (UINT32 a = 0; a <= ACCESS_STORE; a++)
stat += hits[a][tid];
return stat;
}
};
#endif