gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
associative_set_impl.hh
Go to the documentation of this file.
1 
31 #ifndef __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
32 #define __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
33 
34 #include "base/intmath.hh"
36 
37 template<class Entry>
38 AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
39  BaseIndexingPolicy *idx_policy, BaseReplacementPolicy *rpl_policy,
40  Entry const &init_value)
41  : associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
42  replacementPolicy(rpl_policy), entries(numEntries, init_value)
43 {
44  fatal_if(!isPowerOf2(num_entries), "The number of entries of an "
45  "AssociativeSet<> must be a power of 2");
46  fatal_if(!isPowerOf2(assoc), "The associativity of an AssociativeSet<> "
47  "must be a power of 2");
48  for (unsigned int entry_idx = 0; entry_idx < numEntries; entry_idx += 1) {
49  Entry* entry = &entries[entry_idx];
50  indexingPolicy->setEntry(entry, entry_idx);
51  entry->replacementData = replacementPolicy->instantiateEntry();
52  }
53 }
54 
55 template<class Entry>
56 Entry*
58 {
59  Addr tag = indexingPolicy->extractTag(addr);
60  const std::vector<ReplaceableEntry*> selected_entries =
62 
63  for (const auto& location : selected_entries) {
64  Entry* entry = static_cast<Entry *>(location);
65  if ((entry->getTag() == tag) && entry->isValid() &&
66  entry->isSecure() == is_secure) {
67  return entry;
68  }
69  }
70  return nullptr;
71 }
72 
73 template<class Entry>
74 void
76 {
77  replacementPolicy->touch(entry->replacementData);
78 }
79 
80 template<class Entry>
81 Entry*
83 {
84  // Get possible entries to be victimized
85  const std::vector<ReplaceableEntry*> selected_entries =
87  Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
88  selected_entries));
89  // There is only one eviction for this replacement
90  invalidate(victim);
91  return victim;
92 }
93 
94 
95 template<class Entry>
98 {
99  std::vector<ReplaceableEntry *> selected_entries =
101  std::vector<Entry *> entries(selected_entries.size(), nullptr);
102 
103  unsigned int idx = 0;
104  for (auto &entry : selected_entries) {
105  entries[idx++] = static_cast<Entry *>(entry);
106  }
107  return entries;
108 }
109 
110 template<class Entry>
111 void
112 AssociativeSet<Entry>::insertEntry(Addr addr, bool is_secure, Entry* entry)
113 {
114  entry->setValid();
115  entry->setTag(indexingPolicy->extractTag(addr));
116  entry->setSecure(is_secure);
117  replacementPolicy->reset(entry->replacementData);
118 }
119 
120 template<class Entry>
121 void
123 {
124  entry->invalidate();
125  replacementPolicy->invalidate(entry->replacementData);
126 }
127 
128 #endif//__CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
Entry * findEntry(Addr addr, bool is_secure) const
Find an entry within the set.
BaseIndexingPolicy *const indexingPolicy
Pointer to the indexing policy.
void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
BaseReplacementPolicy *const replacementPolicy
Pointer to the replacement policy.
virtual std::vector< ReplaceableEntry * > getPossibleEntries(const Addr addr) const =0
Find all possible entries for insertion and replacement of an address.
virtual void touch(const std::shared_ptr< ReplacementData > &replacement_data) const =0
Update replacement data.
ip6_addr_t addr
Definition: inet.hh:335
std::vector< Entry > entries
Vector containing the entries of the container.
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
A common base class of cache replacement policy objects.
Definition: base.hh:48
STL vector class.
Definition: stl.hh:40
Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:99
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...
bool isPowerOf2(const T &n)
Definition: intmath.hh:146
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:203
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition: base.cc:81
virtual void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const =0
Invalidate replacement data to set it as the next probable victim.
virtual void reset(const std::shared_ptr< ReplacementData > &replacement_data) const =0
Reset replacement data.
void insertEntry(Addr addr, bool is_secure, Entry *entry)
Indicate that an entry has just been inserted.
A common base class for indexing table locations.
Definition: base.hh:66
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...
const int numEntries
Total number of entries, entries are organized in sets of the provided associativity.
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy, BaseReplacementPolicy *rpl_policy, Entry const &init_value=Entry())
Public constructor.

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13