gem5 v24.1.0.1
Loading...
Searching...
No Matches
DirectoryMemory.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017,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 * Copyright (c) 2017 Google Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
43
44#include "base/addr_range.hh"
45#include "base/intmath.hh"
46#include "debug/RubyCache.hh"
47#include "debug/RubyStats.hh"
50#include "sim/system.hh"
51
52namespace gem5
53{
54
55namespace ruby
56{
57
59 : SimObject(p), addrRanges(p.addr_ranges.begin(), p.addr_ranges.end())
60{
61 m_size_bytes = 0;
62 for (const auto &r: addrRanges) {
63 m_size_bytes += r.size();
64 }
66 m_num_entries = 0;
67 m_block_size = p.block_size;
68 m_ruby_system = p.ruby_system;
69}
70
71void
79
81{
82 // free up all the directory entries
83 for (uint64_t i = 0; i < m_num_entries; i++) {
84 if (m_entries[i] != NULL) {
85 delete m_entries[i];
86 }
87 }
88 delete [] m_entries;
89}
90
91bool
93{
94 for (const auto& r: addrRanges) {
95 if (r.contains(address)) {
96 return true;
97 }
98 }
99 return false;
100}
101
102uint64_t
104{
105 uint64_t ret = 0;
106 for (const auto& r: addrRanges) {
107 if (r.contains(address)) {
108 ret += r.getOffset(address);
109 break;
110 }
111 ret += r.size();
112 }
113 return ret >> (floorLog2(m_block_size));
114}
115
118{
119 assert(isPresent(address));
120 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
121
122 uint64_t idx = mapAddressToLocalIdx(address);
123 assert(idx < m_num_entries);
124 return m_entries[idx];
125}
126
129{
130 assert(isPresent(address));
131 uint64_t idx;
132 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
133
134 idx = mapAddressToLocalIdx(address);
135 assert(idx < m_num_entries);
136 assert(m_entries[idx] == NULL);
137 entry->changePermission(AccessPermission_Read_Only);
140 m_entries[idx] = entry;
141
142 return entry;
143}
144
145void
147{
148 assert(isPresent(address));
149 uint64_t idx;
150 DPRINTF(RubyCache, "Removing entry for address: %#x\n", address);
151
152 idx = mapAddressToLocalIdx(address);
153 assert(idx < m_num_entries);
154 assert(m_entries[idx] != NULL);
155 delete m_entries[idx];
156 m_entries[idx] = NULL;
157}
158
159void
160DirectoryMemory::print(std::ostream& out) const
161{
162}
163
164void
165DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
166 DPRINTF(RubyStats, "Recorded statistic: %s\n",
167 DirectoryRequestType_to_string(requestType));
168}
169
170} // namespace ruby
171} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Abstract superclass for simulation objects.
virtual void setRubySystem(RubySystem *rs)
void changePermission(AccessPermission new_perm)
virtual void initBlockSize(int block_size)
AbstractCacheEntry ** m_entries
const AddrRangeList addrRanges
The address range for which the directory responds.
void print(std::ostream &out) const
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
RubyDirectoryMemoryParams Params
AbstractCacheEntry * lookup(Addr address)
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
uint64_t mapAddressToLocalIdx(Addr address)
Return the index in the directory based on an address.
void recordRequestType(DirectoryRequestType requestType)
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
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

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