sim_events.cc revision 11070
12SN/A/* 29952Sdam.sunwoo@arm.com * Copyright (c) 2013 ARM Limited 39952Sdam.sunwoo@arm.com * All rights reserved 49952Sdam.sunwoo@arm.com * 59952Sdam.sunwoo@arm.com * The license below extends only to copyright in the software and shall 69952Sdam.sunwoo@arm.com * not be construed as granting a license to any other intellectual 79952Sdam.sunwoo@arm.com * property including but not limited to intellectual property relating 89952Sdam.sunwoo@arm.com * to a hardware implementation of the functionality of the software 99952Sdam.sunwoo@arm.com * licensed hereunder. You may use the software subject to the license 109952Sdam.sunwoo@arm.com * terms below provided that you ensure that this notice is replicated 119952Sdam.sunwoo@arm.com * unmodified and in its entirety in all distributions of the software, 129952Sdam.sunwoo@arm.com * modified or unmodified, in source code or in binary form. 139952Sdam.sunwoo@arm.com * 141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 159983Sstever@gmail.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 169983Sstever@gmail.com * Copyright (c) 2013 Mark D. Hill and David A. Wood 172SN/A * All rights reserved. 182SN/A * 192SN/A * Redistribution and use in source and binary forms, with or without 202SN/A * modification, are permitted provided that the following conditions are 212SN/A * met: redistributions of source code must retain the above copyright 222SN/A * notice, this list of conditions and the following disclaimer; 232SN/A * redistributions in binary form must reproduce the above copyright 242SN/A * notice, this list of conditions and the following disclaimer in the 252SN/A * documentation and/or other materials provided with the distribution; 262SN/A * neither the name of the copyright holders nor the names of its 272SN/A * contributors may be used to endorse or promote products derived from 282SN/A * this software without specific prior written permission. 292SN/A * 302SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 312SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 322SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 332SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 342SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 352SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 362SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 372SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 382SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 392SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 402SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 412665Ssaidi@eecs.umich.edu * 422665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 432SN/A */ 442SN/A 452SN/A#include <string> 462SN/A 47601SN/A#include "base/callback.hh" 48601SN/A#include "base/hostinfo.hh" 499356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh" 5056SN/A#include "sim/sim_events.hh" 5156SN/A#include "sim/sim_exit.hh" 52695SN/A#include "sim/stats.hh" 532SN/A 542SN/Ausing namespace std; 552SN/A 569983Sstever@gmail.comGlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when, 579983Sstever@gmail.com const std::string &_cause, 5811070Sandreas.sandberg@arm.com int c, Tick r) 5911070Sandreas.sandberg@arm.com : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent), 609983Sstever@gmail.com cause(_cause), code(c), repeat(r) 619983Sstever@gmail.com{ 629983Sstever@gmail.com} 639983Sstever@gmail.com 649983Sstever@gmail.comconst char * 659983Sstever@gmail.comGlobalSimLoopExitEvent::description() const 669983Sstever@gmail.com{ 679983Sstever@gmail.com return "global simulation loop exit"; 689983Sstever@gmail.com} 699983Sstever@gmail.com 709983Sstever@gmail.com// 719983Sstever@gmail.com// handle termination event 729983Sstever@gmail.com// 739983Sstever@gmail.comvoid 749983Sstever@gmail.comGlobalSimLoopExitEvent::process() 759983Sstever@gmail.com{ 769983Sstever@gmail.com if (repeat) { 779983Sstever@gmail.com schedule(curTick() + repeat); 789983Sstever@gmail.com } 799983Sstever@gmail.com} 809983Sstever@gmail.com 819983Sstever@gmail.comvoid 829983Sstever@gmail.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, 839983Sstever@gmail.com bool serialize) 849983Sstever@gmail.com{ 8511070Sandreas.sandberg@arm.com warn_if(serialize && (when != curTick() || repeat), 8611070Sandreas.sandberg@arm.com "exitSimLoop called with a delay and auto serialization. This is " 8711070Sandreas.sandberg@arm.com "currently unsupported."); 889983Sstever@gmail.com 8911070Sandreas.sandberg@arm.com new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat); 909952Sdam.sunwoo@arm.com} 919952Sdam.sunwoo@arm.com 929983Sstever@gmail.comLocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c, 9311070Sandreas.sandberg@arm.com Tick r) 9411070Sandreas.sandberg@arm.com : Event(Sim_Exit_Pri, IsExitEvent), 959952Sdam.sunwoo@arm.com cause(_cause), code(c), repeat(r) 965606Snate@binkert.org{ 975606Snate@binkert.org} 985606Snate@binkert.org 992SN/A// 1002SN/A// handle termination event 1012SN/A// 1022SN/Avoid 1039983Sstever@gmail.comLocalSimLoopExitEvent::process() 1042SN/A{ 1059983Sstever@gmail.com exitSimLoop(cause, 0); 1062SN/A} 1072SN/A 1082SN/A 1092SN/Aconst char * 1109983Sstever@gmail.comLocalSimLoopExitEvent::description() const 1112SN/A{ 1122667Sstever@eecs.umich.edu return "simulation loop exit"; 1132667Sstever@eecs.umich.edu} 1142667Sstever@eecs.umich.edu 1152667Sstever@eecs.umich.eduvoid 11610905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::serialize(CheckpointOut &cp) const 1172667Sstever@eecs.umich.edu{ 11810905Sandreas.sandberg@arm.com Event::serialize(cp); 1199952Sdam.sunwoo@arm.com 1209952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(cause); 1219952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(code); 1229952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(repeat); 1239952Sdam.sunwoo@arm.com} 1249952Sdam.sunwoo@arm.com 1259952Sdam.sunwoo@arm.comvoid 12610905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::unserialize(CheckpointIn &cp) 1279952Sdam.sunwoo@arm.com{ 12810905Sandreas.sandberg@arm.com Event::unserialize(cp); 1299952Sdam.sunwoo@arm.com 1309952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(cause); 1319952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(code); 1329952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(repeat); 1339952Sdam.sunwoo@arm.com} 1349952Sdam.sunwoo@arm.com 1352SN/A// 1362SN/A// constructor: automatically schedules at specified time 1372SN/A// 1385606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter) 1395606Snate@binkert.org : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter) 1402SN/A{ 1412SN/A // catch stupid mistakes 1422SN/A assert(downCounter > 0); 1432SN/A} 1442SN/A 1452SN/A 1462SN/A// 1472SN/A// handle termination event 1482SN/A// 1492SN/Avoid 1502SN/ACountedExitEvent::process() 1512SN/A{ 1522SN/A if (--downCounter == 0) { 1532667Sstever@eecs.umich.edu exitSimLoop(cause, 0); 1542SN/A } 1552SN/A} 1562SN/A 1572SN/A 1582SN/Aconst char * 1595336Shines@cs.fsu.eduCountedExitEvent::description() const 1602SN/A{ 1612SN/A return "counted exit"; 1622SN/A} 163