ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
TLB.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
18#ifndef ETISS_INCLUDE_MM_TLB_H_
19#define ETISS_INCLUDE_MM_TLB_H_
20
21#include <map>
22
24#include "etiss/mm/PTE.h"
25
26namespace etiss
27{
28namespace mm
29{
30
31template <uint32_t EntryNum>
32class TLB
33{
34
35 typedef std::map<uint64_t, PTE> TLBMap;
36
37 public:
38 explicit TLB() : is_full_(false)
39 {
40
41 if (unlikely(0 == EntryNum))
43 else
44 max_entry_ = EntryNum;
45 }
46
52 {
53 if (unlikely(is_full_))
54 return TLBISFULL;
55 else if (tlb_map_.find(vfn) != tlb_map_.end())
56 return PTEOVERLAP;
57
58 tlb_map_[vfn] = PTE(pte_val);
59
60 if (EntryNum == ++current_entry_num_)
61 is_full_ = true;
62 return NOERROR;
63 }
64
69 uint32_t AddPTE(uint64_t vfn, const PTE &pte_entry)
70 {
71 if (unlikely(is_full_))
72 return TLBISFULL;
73 else if (tlb_map_.find(vfn) != tlb_map_.end())
74 return PTEOVERLAP;
75
76 tlb_map_[vfn] = PTE(pte_entry);
77
78 if (EntryNum == ++current_entry_num_)
79 is_full_ = true;
80 return NOERROR;
81 }
82
87 uint32_t Lookup(uint64_t vfn, PTE *pte_buf)
88 {
89 TLBMap::iterator itr = tlb_map_.find(vfn);
90 // Debug
91 // std::cout << "vfn in TLB: 0x" << std::hex << vfn << std::endl;
92 if (itr == tlb_map_.end())
93 return TLBMISS;
94 *pte_buf = itr->second;
95 return NOERROR;
96 }
97
101 inline void Flush()
102 {
103 tlb_map_.clear();
105 if (is_full_)
106 is_full_ = false;
107 }
108
114 {
115 TLBMap::iterator itr = tlb_map_.find(vfn);
116 if (unlikely(itr == tlb_map_.end()))
117 return PTENOTEXISTED;
118 itr->second.Update(pte_val);
119 return NOERROR;
120 }
121
127 {
128 TLBMap::iterator itr = tlb_map_.find(vfn);
129 if (unlikely(itr == tlb_map_.end()))
130 return PTENOTEXISTED;
131 tlb_map_.erase(itr);
133 is_full_ = false;
134 return NOERROR;
135 }
136
137 inline bool IsFull() const { return is_full_; }
138
144 {
145 TLBMap::iterator itr = tlb_map_.find(vfn);
146 if (unlikely(itr == tlb_map_.end()))
147 {
148 etiss::log(etiss::ERROR, "No Virtual Memory Address (VMA) mapping existed");
149 return;
150 }
151 std::cout << "Virtual Frame Number (VFN) : 0x" << std::hex << vfn << std::endl;
152 itr->second.Dump();
153 std::cout << "---------------------------" << std::endl;
154 return;
155 }
156
161 void Dump()
162 {
163 using std::cout;
164 using std::endl;
165 TLBMap::const_iterator itr = tlb_map_.begin();
166 std::cout << "----------TLB Details---------" << std::endl;
167 cout << "TLB is full : " << std::boolalpha << is_full_ << endl;
168 cout << "Total entry number in TLB : " << (infinite_tlb_entries_ ? "infinite" : std::to_string(max_entry_))
169 << endl;
170 cout << "TLB current entry number : " << current_entry_num_ << endl;
171 for (; itr != tlb_map_.end(); ++itr)
172 DumpEntry(itr->first);
173 return;
174 }
175
176 private:
178
183};
184
185} // namespace mm
186} // namespace etiss
187
188#endif
Internal fault inside MMU and.
static __inline__ uint32_t
Definition arm_cde.h:25
static __inline__ uint64_t
Definition arm_cde.h:31
#define unlikely(x)
Definition types.h:36
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition PTE.h:31
void DumpEntry(uint64_t vfn)
Dump the PTE details according to the given VPN.
Definition TLB.h:143
uint32_t max_entry_
Definition TLB.h:179
void Dump()
Dump all PTEs in TLB and TLB details.
Definition TLB.h:161
uint32_t AddPTE(uint64_t vfn, const PTE &pte_entry)
Add an PTE entry in TLB from the given PTE.
Definition TLB.h:69
bool is_full_
Definition TLB.h:181
uint32_t AddPTE(uint64_t vfn, uint64_t pte_val)
Add an PTE entry in TLB with a pte value.
Definition TLB.h:51
std::map< uint64_t, PTE > TLBMap
Definition TLB.h:35
bool infinite_tlb_entries_
Definition TLB.h:182
uint32_t Lookup(uint64_t vfn, PTE *pte_buf)
Look up the TLB for the given given virtual page number.
Definition TLB.h:87
uint32_t UpdatePTE(uint64_t vfn, uint64_t pte_val)
Update the PTE entry.
Definition TLB.h:113
uint32_t current_entry_num_
Definition TLB.h:180
uint32_t EvictPTE(uint64_t vfn)
Evict the PTE entry.
Definition TLB.h:126
TLBMap tlb_map_
Definition TLB.h:177
bool IsFull() const
Definition TLB.h:137
void Flush()
Flush the TLB.
Definition TLB.h:101
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
forwards: include/jit/*
Definition Benchmark.h:17
@ ERROR
Definition Misc.h:85
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
#define false
Definition stdbool.h:17