gem5  v22.1.0.0
associative_set_impl.hh
Go to the documentation of this file.
1 
29 #ifndef __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
30 #define __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
31 
32 #include "base/intmath.hh"
34 
35 namespace gem5
36 {
37 
38 template<class Entry>
39 AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
40  BaseIndexingPolicy *idx_policy, replacement_policy::Base *rpl_policy,
41  Entry const &init_value)
42  : associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
43  replacementPolicy(rpl_policy), entries(numEntries, init_value)
44 {
45  fatal_if(!isPowerOf2(num_entries), "The number of entries of an "
46  "AssociativeSet<> must be a power of 2");
47  fatal_if(!isPowerOf2(assoc), "The associativity of an AssociativeSet<> "
48  "must be a power of 2");
49  for (unsigned int entry_idx = 0; entry_idx < numEntries; entry_idx += 1) {
50  Entry* entry = &entries[entry_idx];
51  indexingPolicy->setEntry(entry, entry_idx);
52  entry->replacementData = replacementPolicy->instantiateEntry();
53  }
54 }
55 
56 template<class Entry>
57 Entry*
59 {
60  Addr tag = indexingPolicy->extractTag(addr);
61  const std::vector<ReplaceableEntry*> selected_entries =
62  indexingPolicy->getPossibleEntries(addr);
63 
64  for (const auto& location : selected_entries) {
65  Entry* entry = static_cast<Entry *>(location);
66  if ((entry->getTag() == tag) && entry->isValid() &&
67  entry->isSecure() == is_secure) {
68  return entry;
69  }
70  }
71  return nullptr;
72 }
73 
74 template<class Entry>
75 void
77 {
78  replacementPolicy->touch(entry->replacementData);
79 }
80 
81 template<class Entry>
82 Entry*
84 {
85  // Get possible entries to be victimized
86  const std::vector<ReplaceableEntry*> selected_entries =
87  indexingPolicy->getPossibleEntries(addr);
88  Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
89  selected_entries));
90  // There is only one eviction for this replacement
91  invalidate(victim);
92  return victim;
93 }
94 
95 
96 template<class Entry>
99 {
100  std::vector<ReplaceableEntry *> selected_entries =
101  indexingPolicy->getPossibleEntries(addr);
102  std::vector<Entry *> entries(selected_entries.size(), nullptr);
103 
104  unsigned int idx = 0;
105  for (auto &entry : selected_entries) {
106  entries[idx++] = static_cast<Entry *>(entry);
107  }
108  return entries;
109 }
110 
111 template<class Entry>
112 void
114 {
115  entry->insert(indexingPolicy->extractTag(addr), is_secure);
116  replacementPolicy->reset(entry->replacementData);
117 }
118 
119 template<class Entry>
120 void
122 {
123  entry->invalidate();
124  replacementPolicy->invalidate(entry->replacementData);
125 }
126 
127 } // namespace gem5
128 
129 #endif//__CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
std::vector< Entry * > getPossibleEntries(const Addr addr) const
Find the set of entries that could be replaced given that we want to add a new entry with the provide...
BaseIndexingPolicy *const indexingPolicy
Pointer to the indexing policy.
replacement_policy::Base *const replacementPolicy
Pointer to the replacement policy.
std::vector< Entry > entries
Vector containing the entries of the container.
const int numEntries
Total number of entries, entries are organized in sets of the provided associativity.
void insertEntry(Addr addr, bool is_secure, Entry *entry)
Indicate that an entry has just been inserted.
Entry * findVictim(Addr addr)
Find a victim to be replaced.
void accessEntry(Entry *entry)
Do an access to the entry, this is required to update the replacement information data.
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy, replacement_policy::Base *rpl_policy, Entry const &init_val=Entry())
Public constructor.
void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
Entry * findEntry(Addr addr, bool is_secure) const
Find an entry within the set.
A common base class for indexing table locations.
Definition: base.hh:67
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition: base.cc:81
A common base class of cache replacement policy objects.
Definition: base.hh:56
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
STL vector class.
Definition: stl.hh:37
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1