gem5 v24.0.0.0
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}
68
69void
77
79{
80 // free up all the directory entries
81 for (uint64_t i = 0; i < m_num_entries; i++) {
82 if (m_entries[i] != NULL) {
83 delete m_entries[i];
84 }
85 }
86 delete [] m_entries;
87}
88
89bool
91{
92 for (const auto& r: addrRanges) {
93 if (r.contains(address)) {
94 return true;
95 }
96 }
97 return false;
98}
99
100uint64_t
102{
103 uint64_t ret = 0;
104 for (const auto& r: addrRanges) {
105 if (r.contains(address)) {
106 ret += r.getOffset(address);
107 break;
108 }
109 ret += r.size();
110 }
111 return ret >> RubySystem::getBlockSizeBits();
112}
113
116{
117 assert(isPresent(address));
118 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
119
120 uint64_t idx = mapAddressToLocalIdx(address);
121 assert(idx < m_num_entries);
122 return m_entries[idx];
123}
124
127{
128 assert(isPresent(address));
129 uint64_t idx;
130 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
131
132 idx = mapAddressToLocalIdx(address);
133 assert(idx < m_num_entries);
134 assert(m_entries[idx] == NULL);
135 entry->changePermission(AccessPermission_Read_Only);
136 m_entries[idx] = entry;
137
138 return entry;
139}
140
141void
143{
144 assert(isPresent(address));
145 uint64_t idx;
146 DPRINTF(RubyCache, "Removing entry for address: %#x\n", address);
147
148 idx = mapAddressToLocalIdx(address);
149 assert(idx < m_num_entries);
150 assert(m_entries[idx] != NULL);
151 delete m_entries[idx];
152 m_entries[idx] = NULL;
153}
154
155void
156DirectoryMemory::print(std::ostream& out) const
157{
158}
159
160void
161DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
162 DPRINTF(RubyStats, "Recorded statistic: %s\n",
163 DirectoryRequestType_to_string(requestType));
164}
165
166} // namespace ruby
167} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Abstract superclass for simulation objects.
void changePermission(AccessPermission new_perm)
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 uint32_t getBlockSizeBytes()
Definition RubySystem.hh:72
static uint32_t getBlockSizeBits()
Definition RubySystem.hh:73
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 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0