gem5  v21.1.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  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "sim/mem_pool.hh"
35 
36 #include "sim/system.hh"
37 
38 namespace gem5
39 {
40 
42  : sys(system), freePageNum(ptr >> sys->getPageShift()),
43  _totalPages(limit >> sys->getPageShift())
44 {
45 }
46 
47 Counter
49 {
50  return freePageNum;
51 }
52 
53 void
55 {
56  freePageNum = value;
57 }
58 
59 Addr
61 {
62  return freePageNum << sys->getPageShift();
63 }
64 
65 Counter
67 {
68  return _totalPages;
69 }
70 
71 Counter
73 {
74  return freePageNum;
75 }
76 
77 Counter
79 {
80  return _totalPages - freePageNum;
81 }
82 
83 Addr
85 {
86  return allocatedPages() << sys->getPageShift();
87 }
88 
89 Addr
91 {
92  return freePages() << sys->getPageShift();
93 }
94 
95 Addr
97 {
98  return totalPages() << sys->getPageShift();
99 }
100 
101 Addr
103 {
104  Addr return_addr = freePageAddr();
105  freePageNum += npages;
106  Addr next_return_addr = freePageAddr();
107 
108  if (sys->m5opRange().valid() &&
109  next_return_addr >= sys->m5opRange().start()) {
110  warn("Reached m5ops MMIO region\n");
111  return_addr = sys->m5opRange().end();
112  freePageNum = (return_addr >> sys->getPageShift()) + npages;
113  }
114 
115  fatal_if((freePages() <= 0), "Out of memory, "
116  "please increase size of physical memory.");
117 
118  return return_addr;
119 }
120 
121 } // namespace gem5
gem5::MemPool::freeBytes
Addr freeBytes() const
Definition: mem_pool.cc:90
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:317
warn
#define warn(...)
Definition: logging.hh:245
gem5::MemPool::sys
System * sys
Definition: mem_pool.hh:48
system.hh
gem5::MemPool::freePages
Counter freePages() const
Definition: mem_pool.cc:78
gem5::X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:1003
gem5::X86ISA::limit
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:930
gem5::MemPool::totalPages
Counter totalPages() const
Definition: mem_pool.cc:66
gem5::MemPool::setFreePage
void setFreePage(Counter value)
Definition: mem_pool.cc:54
gem5::System
Definition: system.hh:77
gem5::MemPool::allocate
Addr allocate(Addr npages)
Definition: mem_pool.cc:102
gem5::System::getPageShift
Addr getPageShift() const
Get the number of bits worth of in-page address for the ISA.
Definition: system.hh:414
gem5::MemPool::freePage
Counter freePage() const
Definition: mem_pool.cc:48
gem5::MemPool::totalBytes
Addr totalBytes() const
Definition: mem_pool.cc:96
gem5::AddrRange::end
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:324
gem5::AddrRange::valid
bool valid() const
Determine if the range is valid.
Definition: addr_range.hh:310
gem5::MemPool::allocatedPages
Counter allocatedPages() const
Definition: mem_pool.cc:72
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:84
gem5::MemPool::freePageAddr
Addr freePageAddr() const
Definition: mem_pool.cc:60
mem_pool.hh
gem5::System::m5opRange
const AddrRange & m5opRange() const
Range used by memory-mapped m5 pseudo-ops if enabled.
Definition: system.hh:596
gem5::statistics::Counter
double Counter
All counters are of 64-bit values.
Definition: types.hh:47
gem5::MemPool::freePageNum
Counter freePageNum
Page number to free memory.
Definition: mem_pool.hh:51
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::MemPool::_totalPages
Counter _totalPages
The size of the pool, in number of pages.
Definition: mem_pool.hh:54
gem5::MemPool::MemPool
MemPool(System *system, Addr ptr, Addr limit)
Definition: mem_pool.cc:41

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17