gem5  v20.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 MemFootprintProbe::MemFootprintProbe(MemFootprintProbeParams *p)
45  : BaseMemProbe(p),
46  cacheLineSizeLg2(floorLog2(p->system->cacheLineSize())),
47  pageSizeLg2(floorLog2(p->page_size)),
48  totalCacheLinesInMem(p->system->memSize() / p->system->cacheLineSize()),
49  totalPagesInMem(p->system->memSize() / p->page_size),
50  cacheLines(),
51  cacheLinesAll(),
52  pages(),
53  pagesAll(),
54  system(p->system)
55 {
57  "MemFootprintProbe expects cache line size is power of 2.");
58  fatal_if(!isPowerOf2(p->page_size),
59  "MemFootprintProbe expects page size parameter is power of 2");
60 }
61 
62 void
64 {
66 
67  using namespace Stats;
68  // clang-format off
69  fpCacheLine.name(name() + ".cacheline")
70  .desc("Memory footprint at cache line granularity")
71  .flags(nozero | nonan);
72  fpCacheLineTotal.name(name() + ".cacheline_total")
73  .desc("Total memory footprint at cache line granularity since "
74  "simulation begin")
75  .flags(nozero | nonan);
76  fpPage.name(name() + ".page")
77  .desc("Memory footprint at page granularity")
78  .flags(nozero | nonan);
79  fpPageTotal.name(name() + ".page_total")
80  .desc("Total memory footprint at page granularity since simulation "
81  "begin")
82  .flags(nozero | nonan);
83  // clang-format on
84 
85  registerResetCallback([this]() { statReset(); });
86 }
87 
88 void
90 {
91  set->insert(addr);
92  assert(set->size() <= limit);
93 }
94 
95 void
97 {
98  if (!pi.cmd.isRequest() || !system->isMemAddr(pi.addr))
99  return;
100 
101  const Addr cl_addr = (pi.addr >> cacheLineSizeLg2) << cacheLineSizeLg2;
102  const Addr page_addr = (pi.addr >> pageSizeLg2) << pageSizeLg2;
105  insertAddr(page_addr, &pages, totalPagesInMem);
106  insertAddr(page_addr, &pagesAll, totalPagesInMem);
107 
108  assert(cacheLines.size() <= cacheLinesAll.size());
109  assert(pages.size() <= pagesAll.size());
110 
113  fpPage = pages.size() << pageSizeLg2;
114  fpPageTotal = pagesAll.size() << pageSizeLg2;
115 }
116 
117 void
119 {
120  cacheLines.clear();
121  pages.clear();
122 }
123 
125 MemFootprintProbeParams::create()
126 {
127  return new MemFootprintProbe(this);
128 }
MemFootprintProbe::cacheLineSizeLg2
const uint8_t cacheLineSizeLg2
Cache Line size for footprint measurement (log2)
Definition: mem_footprint.hh:66
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
MemFootprintProbe::pagesAll
AddrSet pagesAll
Definition: mem_footprint.hh:91
MemFootprintProbe::system
System * system
Definition: mem_footprint.hh:92
MemFootprintProbe
Probe to track footprint of accessed memory Two granularity of footprint measurement i....
Definition: mem_footprint.hh:54
ProbePoints::PacketInfo::addr
Addr addr
Definition: mem.hh:55
MemFootprintProbe::fpPage
Stats::Scalar fpPage
Footprint at page granularity.
Definition: mem_footprint.hh:80
MemFootprintProbe::fpCacheLine
Stats::Scalar fpCacheLine
Footprint at cache line size granularity.
Definition: mem_footprint.hh:76
MemFootprintProbe::MemFootprintProbe
MemFootprintProbe(MemFootprintProbeParams *p)
Definition: mem_footprint.cc:44
floorLog2
std::enable_if< std::is_integral< T >::value, int >::type floorLog2(T x)
Definition: intmath.hh:63
MemFootprintProbe::pageSizeLg2
const uint8_t pageSizeLg2
Page size for footprint measurement (log2)
Definition: mem_footprint.hh:68
MemFootprintProbe::handleRequest
void handleRequest(const ProbePoints::PacketInfo &pkt_info) override
Callback to analyse intercepted Packets.
Definition: mem_footprint.cc:96
MemFootprintProbe::cacheLinesAll
AddrSet cacheLinesAll
Definition: mem_footprint.hh:87
MemFootprintProbe::insertAddr
void insertAddr(Addr addr, AddrSet *set, uint64_t limit)
Definition: mem_footprint.cc:89
Stats::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:331
MemFootprintProbe::fpPageTotal
Stats::Scalar fpPageTotal
Footprint at page granularity, since simulation begin.
Definition: mem_footprint.hh:82
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
MemFootprintProbe::AddrSet
std::unordered_set< Addr > AddrSet
Definition: mem_footprint.hh:57
Stats::registerResetCallback
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:537
MemCmd::isRequest
bool isRequest() const
Definition: packet.hh:202
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
mem_footprint.hh
Stats::DataWrap::name
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:274
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
MemFootprintProbe::pages
AddrSet pages
Definition: mem_footprint.hh:89
MemFootprintProbe::cacheLines
AddrSet cacheLines
Definition: mem_footprint.hh:85
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
MemFootprintProbe::totalCacheLinesInMem
const uint64_t totalCacheLinesInMem
Definition: mem_footprint.hh:69
ProbePoints::PacketInfo::cmd
MemCmd cmd
Definition: mem.hh:54
MemFootprintProbe::statReset
void statReset()
Definition: mem_footprint.cc:118
addr
ip6_addr_t addr
Definition: inet.hh:423
MemFootprintProbe::regStats
void regStats() override
Callback to set stat parameters.
Definition: mem_footprint.cc:63
X86ISA::limit
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:924
Stats
Definition: statistics.cc:61
MemFootprintProbe::fpCacheLineTotal
Stats::Scalar fpCacheLineTotal
Footprint at cache line size granularity, since simulation begin.
Definition: mem_footprint.hh:78
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
intmath.hh
System::cacheLineSize
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:307
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:219
Stats::DataWrap::desc
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:307
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
ProbePoints::PacketInfo
A struct to hold on to the essential fields from a packet, so that the packet and underlying request ...
Definition: mem.hh:53
System::isMemAddr
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:417
MemFootprintProbe::totalPagesInMem
const uint64_t totalPagesInMem
Definition: mem_footprint.hh:70
Stats::nonan
const FlagsType nonan
Don't print if this is NAN.
Definition: info.hh:59
BaseMemProbe
Base class for memory system probes accepting Packet instances.
Definition: base.hh:61

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17