gem5  v20.0.0.2
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 
29 #ifndef __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
30 #define __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
31 
32 #include "base/intmath.hh"
34 
35 template<class Entry>
36 AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
37  BaseIndexingPolicy *idx_policy, BaseReplacementPolicy *rpl_policy,
38  Entry const &init_value)
39  : associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
40  replacementPolicy(rpl_policy), entries(numEntries, init_value)
41 {
42  fatal_if(!isPowerOf2(num_entries), "The number of entries of an "
43  "AssociativeSet<> must be a power of 2");
44  fatal_if(!isPowerOf2(assoc), "The associativity of an AssociativeSet<> "
45  "must be a power of 2");
46  for (unsigned int entry_idx = 0; entry_idx < numEntries; entry_idx += 1) {
47  Entry* entry = &entries[entry_idx];
48  indexingPolicy->setEntry(entry, entry_idx);
49  entry->replacementData = replacementPolicy->instantiateEntry();
50  }
51 }
52 
53 template<class Entry>
54 Entry*
56 {
57  Addr tag = indexingPolicy->extractTag(addr);
58  const std::vector<ReplaceableEntry*> selected_entries =
60 
61  for (const auto& location : selected_entries) {
62  Entry* entry = static_cast<Entry *>(location);
63  if ((entry->getTag() == tag) && entry->isValid() &&
64  entry->isSecure() == is_secure) {
65  return entry;
66  }
67  }
68  return nullptr;
69 }
70 
71 template<class Entry>
72 void
74 {
75  replacementPolicy->touch(entry->replacementData);
76 }
77 
78 template<class Entry>
79 Entry*
81 {
82  // Get possible entries to be victimized
83  const std::vector<ReplaceableEntry*> selected_entries =
85  Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
86  selected_entries));
87  // There is only one eviction for this replacement
88  invalidate(victim);
89  return victim;
90 }
91 
92 
93 template<class Entry>
96 {
97  std::vector<ReplaceableEntry *> selected_entries =
99  std::vector<Entry *> entries(selected_entries.size(), nullptr);
100 
101  unsigned int idx = 0;
102  for (auto &entry : selected_entries) {
103  entries[idx++] = static_cast<Entry *>(entry);
104  }
105  return entries;
106 }
107 
108 template<class Entry>
109 void
110 AssociativeSet<Entry>::insertEntry(Addr addr, bool is_secure, Entry* entry)
111 {
112  entry->setValid();
113  entry->setTag(indexingPolicy->extractTag(addr));
114  entry->setSecure(is_secure);
115  replacementPolicy->reset(entry->replacementData);
116 }
117 
118 template<class Entry>
119 void
121 {
122  entry->invalidate();
123  replacementPolicy->invalidate(entry->replacementData);
124 }
125 
126 #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:330
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:46
STL vector class.
Definition: stl.hh:37
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:96
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:90
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:199
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
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:78
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:63
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 Mon Jun 8 2020 15:45:11 for gem5 by doxygen 1.8.13