stat_control.cc revision 11793:ef606668d247
18544Sguodeyuan@tsinghua.org.cn/* 211274Sshingarov@labware.com * Copyright (c) 2012 ARM Limited 310595Sgabeblack@google.com * All rights reserved 48544Sguodeyuan@tsinghua.org.cn * 58544Sguodeyuan@tsinghua.org.cn * The license below extends only to copyright in the software and shall 68544Sguodeyuan@tsinghua.org.cn * not be construed as granting a license to any other intellectual 78544Sguodeyuan@tsinghua.org.cn * property including but not limited to intellectual property relating 88544Sguodeyuan@tsinghua.org.cn * to a hardware implementation of the functionality of the software 98544Sguodeyuan@tsinghua.org.cn * licensed hereunder. You may use the software subject to the license 108544Sguodeyuan@tsinghua.org.cn * terms below provided that you ensure that this notice is replicated 118544Sguodeyuan@tsinghua.org.cn * unmodified and in its entirety in all distributions of the software, 128544Sguodeyuan@tsinghua.org.cn * modified or unmodified, in source code or in binary form. 138544Sguodeyuan@tsinghua.org.cn * 148544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2004-2005 The Regents of The University of Michigan 158544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2013 Advanced Micro Devices, Inc. 168544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2013 Mark D. Hill and David A. Wood 178544Sguodeyuan@tsinghua.org.cn * All rights reserved. 188544Sguodeyuan@tsinghua.org.cn * 198544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without 208544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions are 218544Sguodeyuan@tsinghua.org.cn * met: redistributions of source code must retain the above copyright 228544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer; 238544Sguodeyuan@tsinghua.org.cn * redistributions in binary form must reproduce the above copyright 248544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer in the 258544Sguodeyuan@tsinghua.org.cn * documentation and/or other materials provided with the distribution; 268544Sguodeyuan@tsinghua.org.cn * neither the name of the copyright holders nor the names of its 278544Sguodeyuan@tsinghua.org.cn * contributors may be used to endorse or promote products derived from 288544Sguodeyuan@tsinghua.org.cn * this software without specific prior written permission. 298544Sguodeyuan@tsinghua.org.cn * 308544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 318544Sguodeyuan@tsinghua.org.cn * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 328544Sguodeyuan@tsinghua.org.cn * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 338544Sguodeyuan@tsinghua.org.cn * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 348544Sguodeyuan@tsinghua.org.cn * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 358544Sguodeyuan@tsinghua.org.cn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 368544Sguodeyuan@tsinghua.org.cn * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 378544Sguodeyuan@tsinghua.org.cn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 388544Sguodeyuan@tsinghua.org.cn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 398544Sguodeyuan@tsinghua.org.cn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 408544Sguodeyuan@tsinghua.org.cn * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 418544Sguodeyuan@tsinghua.org.cn * 428544Sguodeyuan@tsinghua.org.cn * Authors: Nathan Binkert 438544Sguodeyuan@tsinghua.org.cn * Sascha Bischoff 448544Sguodeyuan@tsinghua.org.cn */ 4511274Sshingarov@labware.com 468544Sguodeyuan@tsinghua.org.cn// This file will contain default statistics for the simulator that 478544Sguodeyuan@tsinghua.org.cn// don't really belong to a specific simulator object 488544Sguodeyuan@tsinghua.org.cn 498544Sguodeyuan@tsinghua.org.cn#include "sim/stat_control.hh" 508544Sguodeyuan@tsinghua.org.cn 518544Sguodeyuan@tsinghua.org.cn#include <fstream> 528544Sguodeyuan@tsinghua.org.cn#include <iostream> 538544Sguodeyuan@tsinghua.org.cn#include <list> 548544Sguodeyuan@tsinghua.org.cn 558544Sguodeyuan@tsinghua.org.cn#include "base/callback.hh" 568544Sguodeyuan@tsinghua.org.cn#include "base/hostinfo.hh" 578544Sguodeyuan@tsinghua.org.cn#include "base/statistics.hh" 588544Sguodeyuan@tsinghua.org.cn#include "base/time.hh" 598544Sguodeyuan@tsinghua.org.cn#include "cpu/base.hh" 608544Sguodeyuan@tsinghua.org.cn#include "sim/global_event.hh" 618544Sguodeyuan@tsinghua.org.cn 628544Sguodeyuan@tsinghua.org.cnusing namespace std; 638544Sguodeyuan@tsinghua.org.cn 648544Sguodeyuan@tsinghua.org.cnStats::Formula simSeconds; 658544Sguodeyuan@tsinghua.org.cnStats::Value simTicks; 668544Sguodeyuan@tsinghua.org.cnStats::Value finalTick; 678544Sguodeyuan@tsinghua.org.cnStats::Value simFreq; 688544Sguodeyuan@tsinghua.org.cn 698544Sguodeyuan@tsinghua.org.cnnamespace Stats { 708544Sguodeyuan@tsinghua.org.cn 718544Sguodeyuan@tsinghua.org.cnTime statTime(true); 728544Sguodeyuan@tsinghua.org.cnTick startTick; 738544Sguodeyuan@tsinghua.org.cn 748544Sguodeyuan@tsinghua.org.cnGlobalEvent *dumpEvent; 758544Sguodeyuan@tsinghua.org.cn 768544Sguodeyuan@tsinghua.org.cnstruct SimTicksReset : public Callback 778544Sguodeyuan@tsinghua.org.cn{ 788544Sguodeyuan@tsinghua.org.cn void process() 798544Sguodeyuan@tsinghua.org.cn { 808544Sguodeyuan@tsinghua.org.cn statTime.setTimer(); 818544Sguodeyuan@tsinghua.org.cn startTick = curTick(); 828544Sguodeyuan@tsinghua.org.cn } 838544Sguodeyuan@tsinghua.org.cn}; 848544Sguodeyuan@tsinghua.org.cn 858544Sguodeyuan@tsinghua.org.cndouble 868544Sguodeyuan@tsinghua.org.cnstatElapsedTime() 878544Sguodeyuan@tsinghua.org.cn{ 888544Sguodeyuan@tsinghua.org.cn Time now; 898544Sguodeyuan@tsinghua.org.cn now.setTimer(); 908544Sguodeyuan@tsinghua.org.cn 918544Sguodeyuan@tsinghua.org.cn Time elapsed = now - statTime; 928544Sguodeyuan@tsinghua.org.cn return elapsed; 938544Sguodeyuan@tsinghua.org.cn} 948544Sguodeyuan@tsinghua.org.cn 958544Sguodeyuan@tsinghua.org.cnTick 968544Sguodeyuan@tsinghua.org.cnstatElapsedTicks() 978544Sguodeyuan@tsinghua.org.cn{ 988544Sguodeyuan@tsinghua.org.cn return curTick() - startTick; 998544Sguodeyuan@tsinghua.org.cn} 1008544Sguodeyuan@tsinghua.org.cn 1018544Sguodeyuan@tsinghua.org.cnTick 1028544Sguodeyuan@tsinghua.org.cnstatFinalTick() 1038544Sguodeyuan@tsinghua.org.cn{ 1048544Sguodeyuan@tsinghua.org.cn return curTick(); 1058544Sguodeyuan@tsinghua.org.cn} 1068544Sguodeyuan@tsinghua.org.cn 1078544Sguodeyuan@tsinghua.org.cnSimTicksReset simTicksReset; 1088544Sguodeyuan@tsinghua.org.cn 1098544Sguodeyuan@tsinghua.org.cnstruct Global 1108544Sguodeyuan@tsinghua.org.cn{ 1118544Sguodeyuan@tsinghua.org.cn Stats::Formula hostInstRate; 1128544Sguodeyuan@tsinghua.org.cn Stats::Formula hostOpRate; 1138544Sguodeyuan@tsinghua.org.cn Stats::Formula hostTickRate; 1148544Sguodeyuan@tsinghua.org.cn Stats::Value hostMemory; 1158544Sguodeyuan@tsinghua.org.cn Stats::Value hostSeconds; 1168544Sguodeyuan@tsinghua.org.cn 1178544Sguodeyuan@tsinghua.org.cn Stats::Value simInsts; 1188544Sguodeyuan@tsinghua.org.cn Stats::Value simOps; 1198544Sguodeyuan@tsinghua.org.cn 1208544Sguodeyuan@tsinghua.org.cn Global(); 1218544Sguodeyuan@tsinghua.org.cn}; 1228544Sguodeyuan@tsinghua.org.cn 1238544Sguodeyuan@tsinghua.org.cnGlobal::Global() 1248544Sguodeyuan@tsinghua.org.cn{ 1258544Sguodeyuan@tsinghua.org.cn simInsts 1268544Sguodeyuan@tsinghua.org.cn .functor(BaseCPU::numSimulatedInsts) 1278544Sguodeyuan@tsinghua.org.cn .name("sim_insts") 1288544Sguodeyuan@tsinghua.org.cn .desc("Number of instructions simulated") 1298544Sguodeyuan@tsinghua.org.cn .precision(0) 1308544Sguodeyuan@tsinghua.org.cn .prereq(simInsts) 1318544Sguodeyuan@tsinghua.org.cn ; 1328544Sguodeyuan@tsinghua.org.cn 1338544Sguodeyuan@tsinghua.org.cn simOps 1348544Sguodeyuan@tsinghua.org.cn .functor(BaseCPU::numSimulatedOps) 1358544Sguodeyuan@tsinghua.org.cn .name("sim_ops") 13611793Sbrandon.potter@amd.com .desc("Number of ops (including micro ops) simulated") 13711793Sbrandon.potter@amd.com .precision(0) 1388544Sguodeyuan@tsinghua.org.cn .prereq(simOps) 1398544Sguodeyuan@tsinghua.org.cn ; 1408544Sguodeyuan@tsinghua.org.cn 1418544Sguodeyuan@tsinghua.org.cn simSeconds 1428544Sguodeyuan@tsinghua.org.cn .name("sim_seconds") 1439020Sgblack@eecs.umich.edu .desc("Number of seconds simulated") 1448544Sguodeyuan@tsinghua.org.cn ; 1458544Sguodeyuan@tsinghua.org.cn 1468544Sguodeyuan@tsinghua.org.cn simFreq 1478544Sguodeyuan@tsinghua.org.cn .scalar(SimClock::Frequency) 1488544Sguodeyuan@tsinghua.org.cn .name("sim_freq") 1498775Sgblack@eecs.umich.edu .desc("Frequency of simulated ticks") 1508544Sguodeyuan@tsinghua.org.cn ; 1518544Sguodeyuan@tsinghua.org.cn 1528544Sguodeyuan@tsinghua.org.cn simTicks 1538544Sguodeyuan@tsinghua.org.cn .functor(statElapsedTicks) 1548544Sguodeyuan@tsinghua.org.cn .name("sim_ticks") 15511274Sshingarov@labware.com .desc("Number of ticks simulated") 1568544Sguodeyuan@tsinghua.org.cn ; 1578544Sguodeyuan@tsinghua.org.cn 1588544Sguodeyuan@tsinghua.org.cn finalTick 1598544Sguodeyuan@tsinghua.org.cn .functor(statFinalTick) 1608544Sguodeyuan@tsinghua.org.cn .name("final_tick") 1618544Sguodeyuan@tsinghua.org.cn .desc("Number of ticks from beginning of simulation " 1628544Sguodeyuan@tsinghua.org.cn "(restored from checkpoints and never reset)") 1638544Sguodeyuan@tsinghua.org.cn ; 1648544Sguodeyuan@tsinghua.org.cn 1658544Sguodeyuan@tsinghua.org.cn hostInstRate 1668544Sguodeyuan@tsinghua.org.cn .name("host_inst_rate") 1678544Sguodeyuan@tsinghua.org.cn .desc("Simulator instruction rate (inst/s)") 1688775Sgblack@eecs.umich.edu .precision(0) 1698775Sgblack@eecs.umich.edu .prereq(simInsts) 1708775Sgblack@eecs.umich.edu ; 1718775Sgblack@eecs.umich.edu 1728544Sguodeyuan@tsinghua.org.cn hostOpRate 1738544Sguodeyuan@tsinghua.org.cn .name("host_op_rate") 1748544Sguodeyuan@tsinghua.org.cn .desc("Simulator op (including micro ops) rate (op/s)") 17511274Sshingarov@labware.com .precision(0) 1768544Sguodeyuan@tsinghua.org.cn .prereq(simOps) 1778544Sguodeyuan@tsinghua.org.cn ; 1788544Sguodeyuan@tsinghua.org.cn 17911274Sshingarov@labware.com hostMemory 18011274Sshingarov@labware.com .functor(memUsage) 18111274Sshingarov@labware.com .name("host_mem_usage") 18211274Sshingarov@labware.com .desc("Number of bytes of host memory used") 18311274Sshingarov@labware.com .prereq(hostMemory) 18411274Sshingarov@labware.com ; 18511274Sshingarov@labware.com 18611274Sshingarov@labware.com hostSeconds 18711274Sshingarov@labware.com .functor(statElapsedTime) 18811274Sshingarov@labware.com .name("host_seconds") 1898544Sguodeyuan@tsinghua.org.cn .desc("Real time elapsed on the host") 1908544Sguodeyuan@tsinghua.org.cn .precision(2) 1918544Sguodeyuan@tsinghua.org.cn ; 19211274Sshingarov@labware.com 1938544Sguodeyuan@tsinghua.org.cn hostTickRate 1948544Sguodeyuan@tsinghua.org.cn .name("host_tick_rate") 1958544Sguodeyuan@tsinghua.org.cn .desc("Simulator tick rate (ticks/s)") 19611274Sshingarov@labware.com .precision(0) 19711274Sshingarov@labware.com ; 19811274Sshingarov@labware.com 19911274Sshingarov@labware.com simSeconds = simTicks / simFreq; 20011274Sshingarov@labware.com hostInstRate = simInsts / hostSeconds; 20111274Sshingarov@labware.com hostOpRate = simOps / hostSeconds; 20211274Sshingarov@labware.com hostTickRate = simTicks / hostSeconds; 20311274Sshingarov@labware.com 20411274Sshingarov@labware.com registerResetCallback(&simTicksReset); 20511274Sshingarov@labware.com} 2068544Sguodeyuan@tsinghua.org.cn 20711274Sshingarov@labware.comvoid 20811274Sshingarov@labware.cominitSimStats() 20911274Sshingarov@labware.com{ 21011274Sshingarov@labware.com static Global global; 21111274Sshingarov@labware.com} 212 213/** 214 * Event to dump and/or reset the statistics. 215 */ 216class StatEvent : public GlobalEvent 217{ 218 private: 219 bool dump; 220 bool reset; 221 Tick repeat; 222 223 public: 224 StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat) 225 : GlobalEvent(_when, Stat_Event_Pri, 0), 226 dump(_dump), reset(_reset), repeat(_repeat) 227 { 228 } 229 230 virtual void 231 process() 232 { 233 if (dump) 234 Stats::dump(); 235 236 if (reset) 237 Stats::reset(); 238 239 if (repeat) { 240 Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat); 241 } 242 } 243 244 const char *description() const { return "GlobalStatEvent"; } 245}; 246 247void 248schedStatEvent(bool dump, bool reset, Tick when, Tick repeat) 249{ 250 // simQuantum is being added to the time when the stats would be 251 // dumped so as to ensure that this event happens only after the next 252 // sync amongst the event queues. Asingle event queue simulation 253 // should remain unaffected. 254 dumpEvent = new StatEvent(when + simQuantum, dump, reset, repeat); 255} 256 257void 258periodicStatDump(Tick period) 259{ 260 /* 261 * If the period is set to 0, then we do not want to dump periodically, 262 * thus we deschedule the event. Else, if the period is not 0, but the event 263 * has already been scheduled, we need to get rid of the old event before we 264 * create a new one, as the old event will no longer be moved forward in the 265 * event that we resume from a checkpoint. 266 */ 267 if (dumpEvent != NULL && (period == 0 || dumpEvent->scheduled())) { 268 // Event should AutoDelete, so we do not need to free it. 269 dumpEvent->deschedule(); 270 } 271 272 /* 273 * If the period is not 0, we schedule the event. If this is called with a 274 * period that is less than the current tick, then we shift the first dump 275 * by curTick. This ensures that we do not schedule the event is the past. 276 */ 277 if (period != 0) { 278 // Schedule the event 279 if (period >= curTick()) { 280 schedStatEvent(true, true, (Tick)period, (Tick)period); 281 } else { 282 schedStatEvent(true, true, (Tick)period + curTick(), (Tick)period); 283 } 284 } 285} 286 287void 288updateEvents() 289{ 290 /* 291 * If the dumpEvent has been scheduled, but is scheduled in the past, then 292 * we need to shift the event to be at a valid point in time. Therefore, we 293 * shift the event by curTick. 294 */ 295 if (dumpEvent != NULL && 296 (dumpEvent->scheduled() && dumpEvent->when() < curTick())) { 297 // shift by curTick() and reschedule 298 Tick _when = dumpEvent->when(); 299 dumpEvent->reschedule(_when + curTick()); 300 } 301} 302 303} // namespace Stats 304