gem5  v20.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 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 =
59  indexingPolicy->getPossibleEntries(addr);
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 =
84  indexingPolicy->getPossibleEntries(addr);
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 =
98  indexingPolicy->getPossibleEntries(addr);
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__
std::vector
STL vector class.
Definition: stl.hh:37
BaseReplacementPolicy::instantiateEntry
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
AssociativeSet::findEntry
Entry * findEntry(Addr addr, bool is_secure) const
Find an entry within the set.
Definition: associative_set_impl.hh:55
AssociativeSet::entries
std::vector< Entry > entries
Vector containing the entries of the container.
Definition: associative_set.hh:134
AssociativeSet::accessEntry
void accessEntry(Entry *entry)
Do an access to the entry, this is required to update the replacement information data.
Definition: associative_set_impl.hh:73
BaseReplacementPolicy
A common base class of cache replacement policy objects.
Definition: base.hh:46
AssociativeSet::getPossibleEntries
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...
Definition: associative_set_impl.hh:95
BaseIndexingPolicy::setEntry
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition: base.cc:78
AssociativeSet::insertEntry
void insertEntry(Addr addr, bool is_secure, Entry *entry)
Indicate that an entry has just been inserted.
Definition: associative_set_impl.hh:110
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
AssociativeSet::findVictim
Entry * findVictim(Addr addr)
Find a victim to be replaced.
Definition: associative_set_impl.hh:80
AssociativeSet::numEntries
const int numEntries
Total number of entries, entries are organized in sets of the provided associativity.
Definition: associative_set.hh:128
AssociativeSet::invalidate
void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
Definition: associative_set_impl.hh:120
addr
ip6_addr_t addr
Definition: inet.hh:423
BaseIndexingPolicy
A common base class for indexing table locations.
Definition: base.hh:63
AssociativeSet::indexingPolicy
BaseIndexingPolicy *const indexingPolicy
Pointer to the indexing policy.
Definition: associative_set.hh:130
AssociativeSet::replacementPolicy
BaseReplacementPolicy *const replacementPolicy
Pointer to the replacement policy.
Definition: associative_set.hh:132
associative_set.hh
intmath.hh
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
AssociativeSet::AssociativeSet
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy, BaseReplacementPolicy *rpl_policy, Entry const &init_value=Entry())
Public constructor.
Definition: associative_set_impl.hh:36
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17