gem5 v24.0.0.0
Loading...
Searching...
No Matches
mem_pool.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "sim/mem_pool.hh"
33
34#include "base/addr_range.hh"
35#include "base/logging.hh"
36
37namespace gem5
38{
39
41 : pageShift(page_shift), startPageNum(ptr >> page_shift),
42 freePageNum(ptr >> page_shift),
43 _totalPages((limit - ptr) >> page_shift)
44{
46}
47
50{
51 return startPageNum;
52}
53
56{
57 return freePageNum;
58}
59
60void
62{
63 freePageNum = value;
64}
65
66Addr
68{
69 return freePageNum << pageShift;
70}
71
74{
75 return _totalPages;
76}
77
83
86{
87 return _totalPages - allocatedPages();
88}
89
90Addr
92{
93 return startPage() << pageShift;
94}
95
96Addr
98{
99 return allocatedPages() << pageShift;
100}
101
102Addr
104{
105 return freePages() << pageShift;
106}
107
108Addr
110{
111 return totalPages() << pageShift;
112}
113
114Addr
116{
117 Addr return_addr = freePageAddr();
118 freePageNum += npages;
119
120 fatal_if(freePages() <= 0,
121 "Out of memory, please increase size of physical memory.");
122
123 return return_addr;
124}
125
126void
128{
129 paramOut(cp, "page_shift", pageShift);
130 paramOut(cp, "start_page", startPageNum);
131 paramOut(cp, "free_page_num", freePageNum);
132 paramOut(cp, "total_pages", _totalPages);
133}
134
135void
137{
138 paramIn(cp, "page_shift", pageShift);
139 paramIn(cp, "start_page", startPageNum);
140 paramIn(cp, "free_page_num", freePageNum);
141 paramIn(cp, "total_pages", _totalPages);
142}
143
144void
146{
147 for (const auto &mem : memories)
148 pools.emplace_back(pageShift, mem.start(), mem.end());
149}
150
151Addr
152MemPools::allocPhysPages(int npages, int pool_id)
153{
154 return pools[pool_id].allocate(npages);
155}
156
157Addr
158MemPools::memSize(int pool_id) const
159{
160 return pools[pool_id].totalBytes();
161}
162
163Addr
164MemPools::freeMemSize(int pool_id) const
165{
166 return pools[pool_id].freeBytes();
167}
168
169void
171{
172 ScopedCheckpointSection sec(cp, "mempools");
173 int num_pools = pools.size();
174 SERIALIZE_SCALAR(num_pools);
175
176 for (int i = 0; i < num_pools; i++)
177 pools[i].serializeSection(cp, csprintf("pool%d", i));
178}
179
180void
182{
183 // Delete previous mem_pools
184 pools.clear();
185
186 ScopedCheckpointSection sec(cp, "mempools");
187 int num_pools = 0;
188 UNSERIALIZE_SCALAR(num_pools);
189
190 for (int i = 0; i < num_pools; i++) {
191 MemPool pool;
192 pool.unserializeSection(cp, csprintf("pool%d", i));
193 pools.push_back(pool);
194 }
195}
196
197} // namespace gem5
Class for handling allocation of physical pages in SE mode.
Definition mem_pool.hh:46
Addr totalBytes() const
Definition mem_pool.cc:109
Addr startAddr() const
Definition mem_pool.cc:91
void setFreePage(Counter value)
Definition mem_pool.cc:61
Counter totalPages() const
Definition mem_pool.cc:73
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition mem_pool.cc:127
Addr freePageAddr() const
Definition mem_pool.cc:67
Counter _totalPages
The size of the pool, in number of pages.
Definition mem_pool.hh:57
Counter allocatedPages() const
Definition mem_pool.cc:79
Counter startPageNum
Start page of pool.
Definition mem_pool.hh:51
Addr allocatedBytes() const
Definition mem_pool.cc:97
Counter startPage() const
Definition mem_pool.cc:49
Addr allocate(Addr npages)
Definition mem_pool.cc:115
Addr freeBytes() const
Definition mem_pool.cc:103
Counter freePage() const
Definition mem_pool.cc:55
Counter freePages() const
Definition mem_pool.cc:85
Counter freePageNum
Page number of free memory.
Definition mem_pool.hh:54
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition mem_pool.cc:136
Addr allocPhysPages(int npages, int pool_id=0)
Allocate npages contiguous unused physical pages.
Definition mem_pool.cc:152
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition mem_pool.cc:170
void populate(const AddrRangeList &memories)
Definition mem_pool.cc:145
Addr freeMemSize(int pool_id=0) const
Amount of physical memory that is still free in a pool.
Definition mem_pool.cc:164
std::vector< MemPool > pools
Definition mem_pool.hh:91
Addr memSize(int pool_id=0) const
Amount of physical memory that exists in a pool.
Definition mem_pool.cc:158
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition mem_pool.cc:181
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:317
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition serialize.cc:74
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition serialize.cc:81
Bitfield< 7 > i
Definition misc_types.hh:67
BitfieldType< SegDescriptorLimit > limit
Definition misc.hh:959
double Counter
All counters are of 64-bit values.
Definition types.hh:46
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition types.cc:72
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
bool_vector8 mem[]
Definition reset_stim.h:43

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0