mem_footprint.hh revision 11803
111803Srjthakur@google.com/* 211803Srjthakur@google.com * Copyright (c) 2016 Google Inc. 311803Srjthakur@google.com * All rights reserved. 411803Srjthakur@google.com * 511803Srjthakur@google.com * The license below extends only to copyright in the software and 611803Srjthakur@google.com * shall not be construed as granting a license to any other 711803Srjthakur@google.com * intellectual property including but not limited to intellectual 811803Srjthakur@google.com * property relating to a hardware implementation of the 911803Srjthakur@google.com * functionality of the software licensed hereunder. You may use the 1011803Srjthakur@google.com * software subject to the license terms below provided that you 1111803Srjthakur@google.com * ensure that this notice is replicated unmodified and in its 1211803Srjthakur@google.com * entirety in all distributions of the software, modified or 1311803Srjthakur@google.com * unmodified, in source code or in binary form. 1411803Srjthakur@google.com * 1511803Srjthakur@google.com * Redistribution and use in source and binary forms, with or without 1611803Srjthakur@google.com * modification, are permitted provided that the following conditions are 1711803Srjthakur@google.com * met: redistributions of source code must retain the above copyright 1811803Srjthakur@google.com * notice, this list of conditions and the following disclaimer; 1911803Srjthakur@google.com * redistributions in binary form must reproduce the above copyright 2011803Srjthakur@google.com * notice, this list of conditions and the following disclaimer in the 2111803Srjthakur@google.com * documentation and/or other materials provided with the distribution; 2211803Srjthakur@google.com * neither the name of the copyright holders nor the names of its 2311803Srjthakur@google.com * contributors may be used to endorse or promote products derived from 2411803Srjthakur@google.com * this software without specific prior written permission. 2511803Srjthakur@google.com * 2611803Srjthakur@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2711803Srjthakur@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2811803Srjthakur@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2911803Srjthakur@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3011803Srjthakur@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3111803Srjthakur@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3211803Srjthakur@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3311803Srjthakur@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3411803Srjthakur@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3511803Srjthakur@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3611803Srjthakur@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3711803Srjthakur@google.com * 3811803Srjthakur@google.com * Authors: Rahul Thakur 3911803Srjthakur@google.com */ 4011803Srjthakur@google.com 4111803Srjthakur@google.com#ifndef __MEM_PROBES_MEM_FOOTPRINT_HH__ 4211803Srjthakur@google.com#define __MEM_PROBES_MEM_FOOTPRINT_HH__ 4311803Srjthakur@google.com 4411803Srjthakur@google.com#include <unordered_map> 4511803Srjthakur@google.com 4611803Srjthakur@google.com#include "base/callback.hh" 4711803Srjthakur@google.com#include "mem/packet.hh" 4811803Srjthakur@google.com#include "mem/probes/base.hh" 4911803Srjthakur@google.com#include "sim/stats.hh" 5011803Srjthakur@google.com#include "sim/system.hh" 5111803Srjthakur@google.com 5211803Srjthakur@google.comstruct MemFootprintProbeParams; 5311803Srjthakur@google.com 5411803Srjthakur@google.com/// Probe to track footprint of accessed memory 5511803Srjthakur@google.com/// Two granularity of footprint measurement i.e. cache line and page 5611803Srjthakur@google.comclass MemFootprintProbe : public BaseMemProbe 5711803Srjthakur@google.com{ 5811803Srjthakur@google.com public: 5911803Srjthakur@google.com typedef std::unordered_set<Addr> AddrSet; 6011803Srjthakur@google.com 6111803Srjthakur@google.com MemFootprintProbe(MemFootprintProbeParams *p); 6211803Srjthakur@google.com void regStats() override; 6311803Srjthakur@google.com // Fix footprint tracking state on stat reset 6411803Srjthakur@google.com void statReset(); 6511803Srjthakur@google.com 6611803Srjthakur@google.com protected: 6711803Srjthakur@google.com /// Cache Line size for footprint measurement (log2) 6811803Srjthakur@google.com const uint8_t cacheLineSizeLg2; 6911803Srjthakur@google.com /// Page size for footprint measurement (log2) 7011803Srjthakur@google.com const uint8_t pageSizeLg2; 7111803Srjthakur@google.com const uint64_t totalCacheLinesInMem; 7211803Srjthakur@google.com const uint64_t totalPagesInMem; 7311803Srjthakur@google.com 7411803Srjthakur@google.com void insertAddr(Addr addr, AddrSet *set, uint64_t limit); 7511803Srjthakur@google.com void handleRequest(const ProbePoints::PacketInfo &pkt_info) override; 7611803Srjthakur@google.com 7711803Srjthakur@google.com /// Footprint at cache line size granularity 7811803Srjthakur@google.com Stats::Scalar fpCacheLine; 7911803Srjthakur@google.com /// Footprint at cache line size granularity, since simulation begin 8011803Srjthakur@google.com Stats::Scalar fpCacheLineTotal; 8111803Srjthakur@google.com /// Footprint at page granularity 8211803Srjthakur@google.com Stats::Scalar fpPage; 8311803Srjthakur@google.com /// Footprint at page granularity, since simulation begin 8411803Srjthakur@google.com Stats::Scalar fpPageTotal; 8511803Srjthakur@google.com 8611803Srjthakur@google.com // Addr set to track unique cache lines accessed 8711803Srjthakur@google.com AddrSet cacheLines; 8811803Srjthakur@google.com // Addr set to track unique cache lines accessed since simulation begin 8911803Srjthakur@google.com AddrSet cacheLinesAll; 9011803Srjthakur@google.com // Addr set to track unique pages accessed 9111803Srjthakur@google.com AddrSet pages; 9211803Srjthakur@google.com // Addr set to track unique pages accessed since simulation begin 9311803Srjthakur@google.com AddrSet pagesAll; 9411803Srjthakur@google.com System *system; 9511803Srjthakur@google.com}; 9611803Srjthakur@google.com 9711803Srjthakur@google.com#endif //__MEM_PROBES_MEM_FOOTPRINT_HH__ 98