ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TLB.h
Go to the documentation of this file.
1
56#ifndef ETISS_INCLUDE_MM_TLB_H_
57#define ETISS_INCLUDE_MM_TLB_H_
58
59#include <map>
60
61#include "etiss/mm/PTE.h"
62
63namespace etiss
64{
65namespace mm
66{
67
68template <uint32_t EntryNum>
69class TLB
70{
71
72 typedef std::map<uint64_t, PTE> TLBMap;
73
74 public:
75 explicit TLB() : is_full_(false)
76 {
77
78 if (unlikely(0 == EntryNum))
80 else
81 max_entry_ = EntryNum;
82 }
83
89 {
90 if (unlikely(is_full_))
91 return TLBISFULL;
92 else if (tlb_map_.find(vfn) != tlb_map_.end())
93 return PTEOVERLAP;
94
95 tlb_map_[vfn] = std::move(PTE(pte_val));
96
97 if (EntryNum == ++current_entry_num_)
98 is_full_ = true;
99 return NOERROR;
100 }
101
106 uint32_t AddPTE(uint64_t vfn, const PTE &pte_entry)
107 {
108 if (unlikely(is_full_))
109 return TLBISFULL;
110 else if (tlb_map_.find(vfn) != tlb_map_.end())
111 return PTEOVERLAP;
112
113 tlb_map_[vfn] = std::move(PTE(pte_entry));
114
115 if (EntryNum == ++current_entry_num_)
116 is_full_ = true;
117 return NOERROR;
118 }
119
125 {
126 TLBMap::iterator itr = tlb_map_.find(vfn);
127 // Debug
128 // std::cout << "vfn in TLB: 0x" << std::hex << vfn << std::endl;
129 if (itr == tlb_map_.end())
130 return TLBMISS;
131 *pte_buf = itr->second;
132 return NOERROR;
133 }
134
138 inline void Flush()
139 {
140 tlb_map_.clear();
142 if (is_full_)
143 is_full_ = false;
144 }
145
151 {
152 TLBMap::iterator itr = tlb_map_.find(vfn);
153 if (unlikely(itr == tlb_map_.end()))
154 return PTENOTEXISTED;
155 itr->second.Update(pte_val);
156 return NOERROR;
157 }
158
164 {
165 TLBMap::iterator itr = tlb_map_.find(vfn);
166 if (unlikely(itr == tlb_map_.end()))
167 return PTENOTEXISTED;
168 tlb_map_.erase(itr);
170 is_full_ = false;
171 return NOERROR;
172 }
173
174 inline bool IsFull() const { return is_full_; }
175
181 {
182 TLBMap::iterator itr = tlb_map_.find(vfn);
183 if (unlikely(itr == tlb_map_.end()))
184 {
185 etiss::log(etiss::ERROR, "No Virtual Memory Address (VMA) mapping existed");
186 return;
187 }
188 std::cout << "Virtual Frame Number (VFN) : 0x" << std::hex << vfn << std::endl;
189 itr->second.Dump();
190 std::cout << "---------------------------" << std::endl;
191 return;
192 }
193
198 void Dump()
199 {
200 using std::cout;
201 using std::endl;
202 TLBMap::const_iterator itr = tlb_map_.begin();
203 std::cout << "----------TLB Details---------" << std::endl;
204 cout << "TLB is full : " << std::boolalpha << is_full_ << endl;
205 cout << "Total entry number in TLB : " << (infinite_tlb_entries_ ? "infinite" : std::to_string(max_entry_))
206 << endl;
207 cout << "TLB current entry number : " << current_entry_num_ << endl;
208 for (; itr != tlb_map_.end(); ++itr)
209 DumpEntry(itr->first);
210 return;
211 }
212
213 private:
215
220};
221
222} // namespace mm
223} // namespace etiss
224
225#endif
static __inline__ uint32_t
Definition arm_cde.h:25
static __inline__ uint64_t
Definition arm_cde.h:31
#define unlikely(x)
Definition types.h:74
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition PTE.h:69
void DumpEntry(uint64_t vfn)
Dump the PTE details according to the given VPN.
Definition TLB.h:180
uint32_t max_entry_
Definition TLB.h:216
void Dump()
Dump all PTEs in TLB and TLB details.
Definition TLB.h:198
uint32_t AddPTE(uint64_t vfn, const PTE &pte_entry)
Add an PTE entry in TLB from the given PTE.
Definition TLB.h:106
bool is_full_
Definition TLB.h:218
uint32_t AddPTE(uint64_t vfn, uint64_t pte_val)
Add an PTE entry in TLB with a pte value.
Definition TLB.h:88
std::map< uint64_t, PTE > TLBMap
Definition TLB.h:72
bool infinite_tlb_entries_
Definition TLB.h:219
uint32_t Lookup(uint64_t vfn, PTE *pte_buf)
Look up the TLB for the given given virtual page number.
Definition TLB.h:124
uint32_t UpdatePTE(uint64_t vfn, uint64_t pte_val)
Update the PTE entry.
Definition TLB.h:150
uint32_t current_entry_num_
Definition TLB.h:217
uint32_t EvictPTE(uint64_t vfn)
Evict the PTE entry.
Definition TLB.h:163
TLBMap tlb_map_
Definition TLB.h:214
bool IsFull() const
Definition TLB.h:174
void Flush()
Flush the TLB.
Definition TLB.h:138
MM_EXPORT const int32_t PTENOTEXISTED
MM_EXPORT const int32_t TLBISFULL
MM_EXPORT const int32_t TLBMISS
MM_EXPORT const int32_t NOERROR
MM_EXPORT const int32_t PTEOVERLAP
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
@ ERROR
Definition Misc.h:127
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:125
#define false
Definition stdbool.h:17