gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PerfectCacheMemory.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
42#define __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
43
44#include <type_traits>
45#include <unordered_map>
46
47#include "base/compiler.hh"
49#include "mem/ruby/protocol/AccessPermission.hh"
51
52namespace gem5
53{
54
55namespace ruby
56{
57
58template<class ENTRY>
60{
61 PerfectCacheLineState() { m_permission = AccessPermission_NUM; }
62 AccessPermission m_permission;
63 ENTRY m_entry;
64};
65
66template<class ENTRY>
67inline std::ostream&
68operator<<(std::ostream& out, const PerfectCacheLineState<ENTRY>& obj)
69{
70 return out;
71}
72
73template<class ENTRY>
75{
76 public:
78
80
81 // tests to see if an address is present in the cache
82 bool isTagPresent(Addr address) const;
83
84 // Returns true if there is:
85 // a) a tag match on this address or there is
86 // b) an Invalid line in the same cache "way"
87 bool cacheAvail(Addr address) const;
88
89 // find an Invalid entry and sets the tag appropriate for the address
90 void allocate(Addr address);
91
92 void deallocate(Addr address);
93
94 // Returns with the physical address of the conflicting cache line
95 Addr cacheProbe(Addr newAddress) const;
96
97 // looks an address up in the cache
98 ENTRY* lookup(Addr address);
99 const ENTRY* lookup(Addr address) const;
100
101 // Get/Set permission of cache block
102 AccessPermission getPermission(Addr address) const;
103 void changePermission(Addr address, AccessPermission new_perm);
104
105 // Print cache contents
106 void print(std::ostream& out) const;
107
108 private:
109 // Private copy constructor and assignment operator
112
113 // Data Members (m_prefix)
114 std::unordered_map<Addr, PerfectCacheLineState<ENTRY> > m_map;
115
118
119 static constexpr bool entryRequiresRubySystem =
120 std::is_member_function_pointer_v<decltype(&ENTRY::setRubySystem)>;
121};
122
123template<class ENTRY>
124inline std::ostream&
125operator<<(std::ostream& out, const PerfectCacheMemory<ENTRY>& obj)
126{
127 obj.print(out);
128 out << std::flush;
129 return out;
130}
131
132template<class ENTRY>
133inline
137
138template<class ENTRY>
139inline
141{
142 m_ruby_system = rs;
143 m_block_size = rs->getBlockSizeBytes();
144}
145
146// tests to see if an address is present in the cache
147template<class ENTRY>
148inline bool
150{
151 return m_map.count(makeLineAddress(address, floorLog2(m_block_size))) > 0;
152}
153
154template<class ENTRY>
155inline bool
157{
158 return true;
159}
160
161// find an Invalid or already allocated entry and sets the tag
162// appropriate for the address
163template<class ENTRY>
164inline void
166{
168 line_state.m_permission = AccessPermission_Invalid;
169 line_state.m_entry = ENTRY();
170 if constexpr (entryRequiresRubySystem) {
171 line_state.m_entry.setRubySystem(m_ruby_system);
172 }
173 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
174 m_map.emplace(line_addr, line_state);
175}
176
177// deallocate entry
178template<class ENTRY>
179inline void
181{
182 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
183 [[maybe_unused]] auto num_erased = m_map.erase(line_addr);
184 assert(num_erased == 1);
185}
186
187// Returns with the physical address of the conflicting cache line
188template<class ENTRY>
189inline Addr
191{
192 panic("cacheProbe called in perfect cache");
193 return newAddress;
194}
195
196// looks an address up in the cache
197template<class ENTRY>
198inline ENTRY*
200{
201 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
202 return &m_map[line_addr].m_entry;
203}
204
205// looks an address up in the cache
206template<class ENTRY>
207inline const ENTRY*
209{
210 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
211 return &m_map[line_addr].m_entry;
212}
213
214template<class ENTRY>
215inline AccessPermission
217{
218 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
219 return m_map[line_addr].m_permission;
220}
221
222template<class ENTRY>
223inline void
225 AccessPermission new_perm)
226{
227 Addr line_addr = makeLineAddress(address, floorLog2(m_block_size));
228 PerfectCacheLineState<ENTRY>& line_state = m_map[line_addr];
229 line_state.m_permission = new_perm;
230}
231
232template<class ENTRY>
233inline void
234PerfectCacheMemory<ENTRY>::print(std::ostream& out) const
235{
236}
237
238} // namespace ruby
239} // namespace gem5
240
241#endif // __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
PerfectCacheMemory & operator=(const PerfectCacheMemory &obj)
bool isTagPresent(Addr address) const
bool cacheAvail(Addr address) const
Addr cacheProbe(Addr newAddress) const
static constexpr bool entryRequiresRubySystem
PerfectCacheMemory(const PerfectCacheMemory &obj)
std::unordered_map< Addr, PerfectCacheLineState< ENTRY > > m_map
AccessPermission getPermission(Addr address) const
void print(std::ostream &out) const
void changePermission(Addr address, AccessPermission new_perm)
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 9, 8 > rs
Addr makeLineAddress(Addr addr, int cacheLineBits)
Definition Address.cc:61
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
std::ostream & operator<<(std::ostream &os, const BaseSemihosting::InPlaceArg &ipa)

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8