gem5  v22.1.0.0
mem_footprint.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Google Inc.
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and
6  * shall not be construed as granting a license to any other
7  * intellectual property including but not limited to intellectual
8  * property relating to a hardware implementation of the
9  * functionality of the software licensed hereunder. You may use the
10  * software subject to the license terms below provided that you
11  * ensure that this notice is replicated unmodified and in its
12  * entirety in all distributions of the software, modified or
13  * unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
40 
41 #include "base/intmath.hh"
42 #include "params/MemFootprintProbe.hh"
43 
44 namespace gem5
45 {
46 
47 MemFootprintProbe::MemFootprintProbe(const MemFootprintProbeParams &p)
48  : BaseMemProbe(p),
49  cacheLineSizeLg2(floorLog2(p.system->cacheLineSize())),
50  pageSizeLg2(floorLog2(p.page_size)),
51  totalCacheLinesInMem(p.system->memSize() / p.system->cacheLineSize()),
52  totalPagesInMem(p.system->memSize() / p.page_size),
53  cacheLines(),
54  cacheLinesAll(),
55  pages(),
56  pagesAll(),
57  system(p.system),
58  stats(this)
59 {
61  "MemFootprintProbe expects cache line size is power of 2.");
62  fatal_if(!isPowerOf2(p.page_size),
63  "MemFootprintProbe expects page size parameter is power of 2");
64 }
65 
67  MemFootprintProbe *parent)
68  : statistics::Group(parent),
69  ADD_STAT(cacheLine, statistics::units::Count::get(),
70  "Memory footprint at cache line granularity"),
71  ADD_STAT(cacheLineTotal, statistics::units::Count::get(),
72  "Total memory footprint at cache line granularity since "
73  "simulation begin"),
74  ADD_STAT(page, statistics::units::Count::get(),
75  "Memory footprint at page granularity"),
76  ADD_STAT(pageTotal, statistics::units::Count::get(),
77  "Total memory footprint at page granularity since simulation "
78  "begin")
79 {
80  using namespace statistics;
81  // clang-format off
86  // clang-format on
87  registerResetCallback([parent]() { parent->statReset(); });
88 }
89 
90 void
92 {
93  set->insert(addr);
94  assert(set->size() <= limit);
95 }
96 
97 void
99 {
100  if (!pi.cmd.isRequest() || !system->isMemAddr(pi.addr))
101  return;
102 
103  const Addr cl_addr = (pi.addr >> cacheLineSizeLg2) << cacheLineSizeLg2;
104  const Addr page_addr = (pi.addr >> pageSizeLg2) << pageSizeLg2;
107  insertAddr(page_addr, &pages, totalPagesInMem);
108  insertAddr(page_addr, &pagesAll, totalPagesInMem);
109 
110  assert(cacheLines.size() <= cacheLinesAll.size());
111  assert(pages.size() <= pagesAll.size());
112 
113  stats.cacheLine = cacheLines.size() << cacheLineSizeLg2;
114  stats.cacheLineTotal = cacheLinesAll.size() << cacheLineSizeLg2;
115  stats.page = pages.size() << pageSizeLg2;
116  stats.pageTotal = pagesAll.size() << pageSizeLg2;
117 }
118 
119 void
121 {
122  cacheLines.clear();
123  pages.clear();
124 }
125 
126 } // namespace gem5
Base class for memory system probes accepting Packet instances.
Definition: base.hh:65
bool isRequest() const
Definition: packet.hh:229
Probe to track footprint of accessed memory Two granularity of footprint measurement i....
const uint64_t totalCacheLinesInMem
const uint8_t pageSizeLg2
Page size for footprint measurement (log2)
void handleRequest(const probing::PacketInfo &pkt_info) override
Callback to analyse intercepted Packets.
const uint64_t totalPagesInMem
const uint8_t cacheLineSizeLg2
Cache Line size for footprint measurement (log2)
std::unordered_set< Addr > AddrSet
void insertAddr(Addr addr, AddrSet *set, uint64_t limit)
MemFootprintProbe(const MemFootprintProbeParams &p)
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:311
bool isMemAddr(Addr addr) const
Check if a physical address is within a range of a memory that is part of the global address map.
Definition: system.cc:288
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:358
Statistics container.
Definition: group.hh:94
std::vector< Info * > stats
Definition: group.hh:221
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
#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
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 15 > system
Definition: misc.hh:1004
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:931
Bitfield< 3 > addr
Definition: types.hh:84
const FlagsType nonan
Don't print if this is NAN.
Definition: info.hh:70
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:68
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:278
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
statistics::Scalar cacheLineTotal
Footprint at cache line size granularity, since simulation begin.
statistics::Scalar pageTotal
Footprint at page granularity, since simulation begin.
statistics::Scalar page
Footprint at page granularity.
MemFootprintProbeStats(MemFootprintProbe *parent)
statistics::Scalar cacheLine
Footprint at cache line size granularity.
A struct to hold on to the essential fields from a packet, so that the packet and underlying request ...
Definition: mem.hh:59

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1