stat_control.cc revision 9450
1695SN/A/* 29262Ssascha.bischoff@arm.com * Copyright (c) 2012 ARM Limited 39262Ssascha.bischoff@arm.com * All rights reserved 49262Ssascha.bischoff@arm.com * 59262Ssascha.bischoff@arm.com * The license below extends only to copyright in the software and shall 69262Ssascha.bischoff@arm.com * not be construed as granting a license to any other intellectual 79262Ssascha.bischoff@arm.com * property including but not limited to intellectual property relating 89262Ssascha.bischoff@arm.com * to a hardware implementation of the functionality of the software 99262Ssascha.bischoff@arm.com * licensed hereunder. You may use the software subject to the license 109262Ssascha.bischoff@arm.com * terms below provided that you ensure that this notice is replicated 119262Ssascha.bischoff@arm.com * unmodified and in its entirety in all distributions of the software, 129262Ssascha.bischoff@arm.com * modified or unmodified, in source code or in binary form. 139262Ssascha.bischoff@arm.com * 141762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 15695SN/A * All rights reserved. 16695SN/A * 17695SN/A * Redistribution and use in source and binary forms, with or without 18695SN/A * modification, are permitted provided that the following conditions are 19695SN/A * met: redistributions of source code must retain the above copyright 20695SN/A * notice, this list of conditions and the following disclaimer; 21695SN/A * redistributions in binary form must reproduce the above copyright 22695SN/A * notice, this list of conditions and the following disclaimer in the 23695SN/A * documentation and/or other materials provided with the distribution; 24695SN/A * neither the name of the copyright holders nor the names of its 25695SN/A * contributors may be used to endorse or promote products derived from 26695SN/A * this software without specific prior written permission. 27695SN/A * 28695SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29695SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30695SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31695SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32695SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33695SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34695SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35695SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36695SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37695SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38695SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 419262Ssascha.bischoff@arm.com * Sascha Bischoff 42695SN/A */ 43695SN/A 44695SN/A// This file will contain default statistics for the simulator that 45695SN/A// don't really belong to a specific simulator object 46695SN/A 47695SN/A#include <fstream> 48695SN/A#include <iostream> 49695SN/A#include <list> 50695SN/A 51695SN/A#include "base/callback.hh" 52695SN/A#include "base/hostinfo.hh" 53695SN/A#include "base/statistics.hh" 54695SN/A#include "base/time.hh" 557768SAli.Saidi@ARM.com#include "config/the_isa.hh" 567768SAli.Saidi@ARM.com#if THE_ISA == NO_ISA 577768SAli.Saidi@ARM.com#include "arch/noisa/cpu_dummy.hh" 587768SAli.Saidi@ARM.com#else 591717SN/A#include "cpu/base.hh" 607768SAli.Saidi@ARM.com#endif 617768SAli.Saidi@ARM.com 62695SN/A#include "sim/eventq.hh" 637822Ssteve.reinhardt@amd.com#include "sim/stat_control.hh" 64695SN/A 65695SN/Ausing namespace std; 66695SN/A 67729SN/AStats::Formula simSeconds; 687068Snate@binkert.orgStats::Value simTicks; 698720SAli.Saidi@ARM.comStats::Value finalTick; 707068Snate@binkert.orgStats::Value simFreq; 71695SN/A 72729SN/Anamespace Stats { 73695SN/A 74695SN/ATime statTime(true); 75695SN/ATick startTick; 76695SN/A 779262Ssascha.bischoff@arm.comEvent *dumpEvent; 789262Ssascha.bischoff@arm.com 794078Sbinkertn@umich.edustruct SimTicksReset : public Callback 80695SN/A{ 81695SN/A void process() 82695SN/A { 837840Snate@binkert.org statTime.setTimer(); 847823Ssteve.reinhardt@amd.com startTick = curTick(); 85695SN/A } 86695SN/A}; 87695SN/A 88695SN/Adouble 89695SN/AstatElapsedTime() 90695SN/A{ 917840Snate@binkert.org Time now; 927840Snate@binkert.org now.setTimer(); 937840Snate@binkert.org 94695SN/A Time elapsed = now - statTime; 957840Snate@binkert.org return elapsed; 96695SN/A} 97695SN/A 981020SN/ATick 991020SN/AstatElapsedTicks() 1001020SN/A{ 1017823Ssteve.reinhardt@amd.com return curTick() - startTick; 1021020SN/A} 1031020SN/A 1048720SAli.Saidi@ARM.comTick 1058720SAli.Saidi@ARM.comstatFinalTick() 1068720SAli.Saidi@ARM.com{ 1078720SAli.Saidi@ARM.com return curTick(); 1088720SAli.Saidi@ARM.com} 1098720SAli.Saidi@ARM.com 110695SN/ASimTicksReset simTicksReset; 111695SN/A 1125883Snate@binkert.orgstruct Global 1135883Snate@binkert.org{ 1145883Snate@binkert.org Stats::Formula hostInstRate; 1158834Satgutier@umich.edu Stats::Formula hostOpRate; 1165883Snate@binkert.org Stats::Formula hostTickRate; 1175883Snate@binkert.org Stats::Value hostMemory; 1185883Snate@binkert.org Stats::Value hostSeconds; 1195883Snate@binkert.org 1205883Snate@binkert.org Stats::Value simInsts; 1218834Satgutier@umich.edu Stats::Value simOps; 1225883Snate@binkert.org 1235883Snate@binkert.org Global(); 1245883Snate@binkert.org}; 1255883Snate@binkert.org 1265883Snate@binkert.orgGlobal::Global() 127695SN/A{ 128695SN/A simInsts 1298834Satgutier@umich.edu .functor(BaseCPU::numSimulatedInsts) 130695SN/A .name("sim_insts") 131695SN/A .desc("Number of instructions simulated") 132695SN/A .precision(0) 133695SN/A .prereq(simInsts) 134695SN/A ; 135695SN/A 1368834Satgutier@umich.edu simOps 1378834Satgutier@umich.edu .functor(BaseCPU::numSimulatedOps) 1388834Satgutier@umich.edu .name("sim_ops") 1398834Satgutier@umich.edu .desc("Number of ops (including micro ops) simulated") 1408834Satgutier@umich.edu .precision(0) 1418834Satgutier@umich.edu .prereq(simOps) 1428834Satgutier@umich.edu ; 1438834Satgutier@umich.edu 144695SN/A simSeconds 145695SN/A .name("sim_seconds") 146695SN/A .desc("Number of seconds simulated") 147695SN/A ; 148695SN/A 149707SN/A simFreq 1507064Snate@binkert.org .scalar(SimClock::Frequency) 151707SN/A .name("sim_freq") 152707SN/A .desc("Frequency of simulated ticks") 153707SN/A ; 154707SN/A 155695SN/A simTicks 1561020SN/A .functor(statElapsedTicks) 157695SN/A .name("sim_ticks") 158695SN/A .desc("Number of ticks simulated") 159695SN/A ; 160695SN/A 1618720SAli.Saidi@ARM.com finalTick 1628720SAli.Saidi@ARM.com .functor(statFinalTick) 1638720SAli.Saidi@ARM.com .name("final_tick") 1648720SAli.Saidi@ARM.com .desc("Number of ticks from beginning of simulation \ 1658720SAli.Saidi@ARM.com(restored from checkpoints and never reset)") 1668720SAli.Saidi@ARM.com ; 1678720SAli.Saidi@ARM.com 168695SN/A hostInstRate 169695SN/A .name("host_inst_rate") 170695SN/A .desc("Simulator instruction rate (inst/s)") 171695SN/A .precision(0) 172695SN/A .prereq(simInsts) 173695SN/A ; 174695SN/A 1758834Satgutier@umich.edu hostOpRate 1768834Satgutier@umich.edu .name("host_op_rate") 1778834Satgutier@umich.edu .desc("Simulator op (including micro ops) rate (op/s)") 1788834Satgutier@umich.edu .precision(0) 1798834Satgutier@umich.edu .prereq(simOps) 1808834Satgutier@umich.edu ; 1818834Satgutier@umich.edu 182695SN/A hostMemory 183707SN/A .functor(memUsage) 184695SN/A .name("host_mem_usage") 185695SN/A .desc("Number of bytes of host memory used") 186695SN/A .prereq(hostMemory) 187695SN/A ; 188695SN/A 189695SN/A hostSeconds 190707SN/A .functor(statElapsedTime) 191695SN/A .name("host_seconds") 192695SN/A .desc("Real time elapsed on the host") 193695SN/A .precision(2) 194695SN/A ; 195695SN/A 196695SN/A hostTickRate 197695SN/A .name("host_tick_rate") 198695SN/A .desc("Simulator tick rate (ticks/s)") 199695SN/A .precision(0) 200695SN/A ; 201695SN/A 202707SN/A simSeconds = simTicks / simFreq; 203695SN/A hostInstRate = simInsts / hostSeconds; 2048834Satgutier@umich.edu hostOpRate = simOps / hostSeconds; 205695SN/A hostTickRate = simTicks / hostSeconds; 206695SN/A 207695SN/A registerResetCallback(&simTicksReset); 208695SN/A} 209695SN/A 2105883Snate@binkert.orgvoid 2115883Snate@binkert.orginitSimStats() 2125883Snate@binkert.org{ 2135883Snate@binkert.org static Global global; 2145883Snate@binkert.org} 2155883Snate@binkert.org 2169262Ssascha.bischoff@arm.com/** 2179262Ssascha.bischoff@arm.com * Event to dump and/or reset the statistics. 2189262Ssascha.bischoff@arm.com */ 2197822Ssteve.reinhardt@amd.comclass StatEvent : public Event 220695SN/A{ 2214078Sbinkertn@umich.edu private: 2224078Sbinkertn@umich.edu bool dump; 2234078Sbinkertn@umich.edu bool reset; 224695SN/A Tick repeat; 225695SN/A 226695SN/A public: 2277822Ssteve.reinhardt@amd.com StatEvent(bool _dump, bool _reset, Tick _repeat) 2288581Ssteve.reinhardt@amd.com : Event(Stat_Event_Pri, AutoDelete), 2298581Ssteve.reinhardt@amd.com dump(_dump), reset(_reset), repeat(_repeat) 2304078Sbinkertn@umich.edu { 2314078Sbinkertn@umich.edu } 2324078Sbinkertn@umich.edu 2334078Sbinkertn@umich.edu virtual void 2344078Sbinkertn@umich.edu process() 2354078Sbinkertn@umich.edu { 2364078Sbinkertn@umich.edu if (dump) 2374078Sbinkertn@umich.edu Stats::dump(); 2384078Sbinkertn@umich.edu 2394078Sbinkertn@umich.edu if (reset) 2404078Sbinkertn@umich.edu Stats::reset(); 2414078Sbinkertn@umich.edu 2425606Snate@binkert.org if (repeat) { 2437823Ssteve.reinhardt@amd.com Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat); 2445606Snate@binkert.org } 2454078Sbinkertn@umich.edu } 246695SN/A}; 247695SN/A 2484078Sbinkertn@umich.eduvoid 2497822Ssteve.reinhardt@amd.comschedStatEvent(bool dump, bool reset, Tick when, Tick repeat) 250695SN/A{ 2519262Ssascha.bischoff@arm.com dumpEvent = new StatEvent(dump, reset, repeat); 2529262Ssascha.bischoff@arm.com mainEventQueue.schedule(dumpEvent, when); 2539262Ssascha.bischoff@arm.com} 2549262Ssascha.bischoff@arm.com 2559262Ssascha.bischoff@arm.comvoid 2569450Ssascha.bischoff@arm.comperiodicStatDump(Tick period) 2579262Ssascha.bischoff@arm.com{ 2589262Ssascha.bischoff@arm.com /* 2599262Ssascha.bischoff@arm.com * If the period is set to 0, then we do not want to dump periodically, 2609262Ssascha.bischoff@arm.com * thus we deschedule the event. Else, if the period is not 0, but the event 2619262Ssascha.bischoff@arm.com * has already been scheduled, we need to get rid of the old event before we 2629262Ssascha.bischoff@arm.com * create a new one, as the old event will no longer be moved forward in the 2639262Ssascha.bischoff@arm.com * event that we resume from a checkpoint. 2649262Ssascha.bischoff@arm.com */ 2659262Ssascha.bischoff@arm.com if (dumpEvent != NULL && (period == 0 || dumpEvent->scheduled())) { 2669262Ssascha.bischoff@arm.com // Event should AutoDelete, so we do not need to free it. 2679262Ssascha.bischoff@arm.com mainEventQueue.deschedule(dumpEvent); 2689262Ssascha.bischoff@arm.com } 2699262Ssascha.bischoff@arm.com 2709262Ssascha.bischoff@arm.com /* 2719262Ssascha.bischoff@arm.com * If the period is not 0, we schedule the event. If this is called with a 2729262Ssascha.bischoff@arm.com * period that is less than the current tick, then we shift the first dump 2739262Ssascha.bischoff@arm.com * by curTick. This ensures that we do not schedule the event is the past. 2749262Ssascha.bischoff@arm.com */ 2759262Ssascha.bischoff@arm.com if (period != 0) { 2769262Ssascha.bischoff@arm.com // Schedule the event 2779262Ssascha.bischoff@arm.com if (period >= curTick()) { 2789262Ssascha.bischoff@arm.com schedStatEvent(true, true, (Tick)period, (Tick)period); 2799262Ssascha.bischoff@arm.com } else { 2809262Ssascha.bischoff@arm.com schedStatEvent(true, true, (Tick)period + curTick(), (Tick)period); 2819262Ssascha.bischoff@arm.com } 2829262Ssascha.bischoff@arm.com } 2839262Ssascha.bischoff@arm.com} 2849262Ssascha.bischoff@arm.com 2859262Ssascha.bischoff@arm.comvoid 2869262Ssascha.bischoff@arm.comupdateEvents() 2879262Ssascha.bischoff@arm.com{ 2889262Ssascha.bischoff@arm.com /* 2899262Ssascha.bischoff@arm.com * If the dumpEvent has been scheduled, but is scheduled in the past, then 2909262Ssascha.bischoff@arm.com * we need to shift the event to be at a valid point in time. Therefore, we 2919262Ssascha.bischoff@arm.com * shift the event by curTick. 2929262Ssascha.bischoff@arm.com */ 2939262Ssascha.bischoff@arm.com if (dumpEvent != NULL && 2949262Ssascha.bischoff@arm.com (dumpEvent->scheduled() && dumpEvent->when() < curTick())) { 2959262Ssascha.bischoff@arm.com // shift by curTick() and reschedule 2969262Ssascha.bischoff@arm.com Tick _when = dumpEvent->when(); 2979262Ssascha.bischoff@arm.com mainEventQueue.reschedule(dumpEvent, _when + curTick()); 2989262Ssascha.bischoff@arm.com } 299695SN/A} 300695SN/A 3017811Ssteve.reinhardt@amd.com} // namespace Stats 302