The Sparta Modeling Framework
Loading...
Searching...
No Matches
SimpleTLB.hpp
1
2#pragma once
3
5#include "sparta/utils/MathUtils.hpp"
6#include "cache/BasicCacheItem.hpp"
7#include "cache/SimpleCache2.hpp"
8#include "cache/ReplacementIF.hpp"
9
10namespace core_example
11{
12 class SimpleTLBEntry : public sparta::cache::BasicCacheItem
13 {
14 public:
15 SimpleTLBEntry() = delete;
16
17 SimpleTLBEntry(uint32_t page_size) :
18 page_size_(page_size),
19 valid_(false)
20 {
21
22 sparta_assert(sparta::utils::is_power_of_2(page_size),
23 "TLBEntry: Page size must be a power of 2. page_size=" << page_size);
24 }
25
26 // Copy constructor
27 SimpleTLBEntry(const SimpleTLBEntry & rhs) :
28 BasicCacheItem(rhs),
29 page_size_(rhs.page_size_),
30 valid_(rhs.valid_)
31 {
32 }
33
34 // Copy assignment operator
35 SimpleTLBEntry &operator=(const SimpleTLBEntry & rhs)
36 {
37 BasicCacheItem::operator=(rhs);
38 page_size_ = rhs.page_size_;
39 valid_ = rhs.valid_;
40
41 return *this;
42 }
43
44 virtual ~SimpleTLBEntry() {}
45
46 // Required by SimpleCache2
47 void reset(uint64_t addr)
48 {
49 setValid(true);
50 BasicCacheItem::setAddr(addr);
51 }
52
53 // Required by SimpleCache2
54 void setValid(bool v) { valid_ = v; }
55
56 // Required by BasicCacheSet
57 bool isValid() const { return valid_; }
58
59 // Required by SimpleCache2
60 void setModified(bool m) { (void) m; }
61
62 // Required by SimpleCache2
63 bool read(uint64_t offset, uint32_t size, uint32_t *buf) const
64 {
65 (void) offset;
66 (void) size;
67 (void) buf;
68 sparta_assert(false);
69 return true;
70 }
71
72 // Required by SimpleCache2
73 bool write(uint64_t offset, uint32_t size, uint32_t *buf) const
74 {
75 (void) offset;
76 (void) size;
77 (void) buf;
78 sparta_assert(false);
79 return true;
80 }
81
82 private:
83 uint32_t page_size_;
84 bool valid_;
85
86 }; // class SimpleTLBEntry
87
88 class SimpleTLB : public sparta::cache::SimpleCache2<SimpleTLBEntry>,
89 public sparta::Unit
90 {
91 public:
92 static constexpr const char* name = "tlb";
94 {
95 public:
98 {}
99 PARAMETER(uint64_t, tlb_page_size, 4096, "Page size in bytes (power of 2)")
100 PARAMETER(uint64_t, tlb_num_of_entries, 32, "L1 TLB # of entries (power of 2)")
101 PARAMETER(uint64_t, tlb_associativity, 32, "L1 TLB associativity (power of 2)")
102 };
103 using Handle = std::shared_ptr<SimpleTLB>;
104
106 sparta::cache::SimpleCache2<SimpleTLBEntry> ( (p->tlb_page_size * p->tlb_num_of_entries) >> 10,
107 p->tlb_page_size,
108 p->tlb_page_size,
109 SimpleTLBEntry(p->tlb_page_size),
110 sparta::cache::TreePLRUReplacement(p->tlb_associativity)),
111 sparta::Unit(node),
112 hits(&unit_stat_set_, "tlb_hits", "number of TLB hits", sparta::Counter::COUNT_NORMAL)
113 {}
114
115 void touch(const SimpleTLBEntry& entry)
116 {
117 debug_logger_ << "TLB HIT";
118 touchMRU(entry);
119 hits++;
120 }
121 private:
122 sparta::Counter hits;
123 }; // class SimpleTLB
124
125} // namespace core_example
126
#define PARAMETER(type, name, def, doc)
Parameter declaration.
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Represents a counter of type counter_type (uint64_t). 2 and greater than 0 with a ceiling specified....
Definition Counter.hpp:27
Generic container of Parameters.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
log::MessageSource debug_logger_
Default debug logger.
Definition Unit.hpp:167
Unit(TreeNode *rc, const std::string &name)
Construct unit with a ResouceContainer.
Definition Unit.hpp:54
sparta::StatisticSet unit_stat_set_
The Unit's statistic set.
Definition Unit.hpp:117
Macros for handling exponential backoff.