gem5  v22.0.0.2
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 
37 namespace gem5
38 {
39 
40 MemPool::MemPool(Addr page_shift, Addr ptr, Addr limit)
41  : pageShift(page_shift), startPageNum(ptr >> page_shift),
42  freePageNum(ptr >> page_shift),
43  _totalPages((limit - ptr) >> page_shift)
44 {
46 }
47 
48 Counter
50 {
51  return startPageNum;
52 }
53 
54 Counter
56 {
57  return freePageNum;
58 }
59 
60 void
62 {
63  freePageNum = value;
64 }
65 
66 Addr
68 {
69  return freePageNum << pageShift;
70 }
71 
72 Counter
74 {
75  return _totalPages;
76 }
77 
78 Counter
80 {
81  return freePageNum - startPageNum;
82 }
83 
84 Counter
86 {
87  return _totalPages - allocatedPages();
88 }
89 
90 Addr
92 {
93  return startPage() << pageShift;
94 }
95 
96 Addr
98 {
99  return allocatedPages() << pageShift;
100 }
101 
102 Addr
104 {
105  return freePages() << pageShift;
106 }
107 
108 Addr
110 {
111  return totalPages() << pageShift;
112 }
113 
114 Addr
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 
126 void
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 
135 void
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 
144 void
146 {
147  for (const auto &mem : memories)
148  pools.emplace_back(pageShift, mem.start(), mem.end());
149 }
150 
151 Addr
152 MemPools::allocPhysPages(int npages, int pool_id)
153 {
154  return pools[pool_id].allocate(npages);
155 }
156 
157 Addr
158 MemPools::memSize(int pool_id) const
159 {
160  return pools[pool_id].totalBytes();
161 }
162 
163 Addr
164 MemPools::freeMemSize(int pool_id) const
165 {
166  return pools[pool_id].freeBytes();
167 }
168 
169 void
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 
180 void
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
gem5::MemPool::freeBytes
Addr freeBytes() const
Definition: mem_pool.cc:103
gem5::MemPools::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_pool.cc:181
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
gem5::MemPool::freePages
Counter freePages() const
Definition: mem_pool.cc:85
gem5::MemPools::pageShift
Addr pageShift
Definition: mem_pool.hh:89
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:74
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::X86ISA::limit
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:924
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::MemPool::startPageNum
Counter startPageNum
Start page of pool.
Definition: mem_pool.hh:51
gem5::MemPools::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_pool.cc:170
gem5::MemPool
Class for handling allocation of physical pages in SE mode.
Definition: mem_pool.hh:45
gem5::MemPools::populate
void populate(const AddrRangeList &memories)
Definition: mem_pool.cc:145
gem5::MemPool::startAddr
Addr startAddr() const
Definition: mem_pool.cc:91
gem5::MemPool::totalPages
Counter totalPages() const
Definition: mem_pool.cc:73
gem5::MemPool::setFreePage
void setFreePage(Counter value)
Definition: mem_pool.cc:61
gem5::Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:81
gem5::MemPool::allocate
Addr allocate(Addr npages)
Definition: mem_pool.cc:115
gem5::MemPools::allocPhysPages
Addr allocPhysPages(int npages, int pool_id=0)
Allocate npages contiguous unused physical pages.
Definition: mem_pool.cc:152
gem5::MemPool::freePage
Counter freePage() const
Definition: mem_pool.cc:55
gem5::MemPools::memSize
Addr memSize(int pool_id=0) const
Amount of physical memory that exists in a pool.
Definition: mem_pool.cc:158
gem5::MemPool::totalBytes
Addr totalBytes() const
Definition: mem_pool.cc:109
gem5::MemPool::allocatedPages
Counter allocatedPages() const
Definition: mem_pool.cc:79
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::MemPool::allocatedBytes
Addr allocatedBytes() const
Definition: mem_pool.cc:97
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
gem5::MemPool::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_pool.cc:127
addr_range.hh
gem5::MemPool::freePageAddr
Addr freePageAddr() const
Definition: mem_pool.cc:67
mem_pool.hh
gem5::paramOut
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition: types.cc:40
gem5::MemPool::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_pool.cc:136
gem5::paramIn
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition: types.cc:72
gem5::statistics::Counter
double Counter
All counters are of 64-bit values.
Definition: types.hh:47
logging.hh
gem5::MemPool::startPage
Counter startPage() const
Definition: mem_pool.cc:49
gem5::MemPools::freeMemSize
Addr freeMemSize(int pool_id=0) const
Amount of physical memory that is still free in a pool.
Definition: mem_pool.cc:164
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
mem
bool_vector8 mem[]
Definition: reset_stim.h:43
gem5::MemPool::freePageNum
Counter freePageNum
Page number of free memory.
Definition: mem_pool.hh:54
gem5_assert
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition: logging.hh:318
std::list< AddrRange >
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:226
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::Serializable::ScopedCheckpointSection
Definition: serialize.hh:172
gem5::MemPool::_totalPages
Counter _totalPages
The size of the pool, in number of pages.
Definition: mem_pool.hh:57
gem5::MemPools::pools
std::vector< MemPool > pools
Definition: mem_pool.hh:91
gem5::MemPool::MemPool
MemPool()
Definition: mem_pool.hh:59
gem5::MemPool::pageShift
Addr pageShift
Definition: mem_pool.hh:48

Generated on Thu Jul 28 2022 13:32:36 for gem5 by doxygen 1.8.17