sim_events.cc revision 11793
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 4511793Sbrandon.potter@amd.com#include "sim/sim_events.hh" 4611793Sbrandon.potter@amd.com 472SN/A#include <string> 482SN/A 49601SN/A#include "base/callback.hh" 50601SN/A#include "base/hostinfo.hh" 519356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh" 5256SN/A#include "sim/sim_exit.hh" 53695SN/A#include "sim/stats.hh" 542SN/A 552SN/Ausing namespace std; 562SN/A 579983Sstever@gmail.comGlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when, 589983Sstever@gmail.com const std::string &_cause, 5911070Sandreas.sandberg@arm.com int c, Tick r) 6011070Sandreas.sandberg@arm.com : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent), 619983Sstever@gmail.com cause(_cause), code(c), repeat(r) 629983Sstever@gmail.com{ 639983Sstever@gmail.com} 649983Sstever@gmail.com 659983Sstever@gmail.comconst char * 669983Sstever@gmail.comGlobalSimLoopExitEvent::description() const 679983Sstever@gmail.com{ 689983Sstever@gmail.com return "global simulation loop exit"; 699983Sstever@gmail.com} 709983Sstever@gmail.com 719983Sstever@gmail.com// 729983Sstever@gmail.com// handle termination event 739983Sstever@gmail.com// 749983Sstever@gmail.comvoid 759983Sstever@gmail.comGlobalSimLoopExitEvent::process() 769983Sstever@gmail.com{ 779983Sstever@gmail.com if (repeat) { 789983Sstever@gmail.com schedule(curTick() + repeat); 799983Sstever@gmail.com } 809983Sstever@gmail.com} 819983Sstever@gmail.com 829983Sstever@gmail.comvoid 839983Sstever@gmail.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, 849983Sstever@gmail.com bool serialize) 859983Sstever@gmail.com{ 8611070Sandreas.sandberg@arm.com warn_if(serialize && (when != curTick() || repeat), 8711070Sandreas.sandberg@arm.com "exitSimLoop called with a delay and auto serialization. This is " 8811070Sandreas.sandberg@arm.com "currently unsupported."); 899983Sstever@gmail.com 9011070Sandreas.sandberg@arm.com new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat); 919952Sdam.sunwoo@arm.com} 929952Sdam.sunwoo@arm.com 939983Sstever@gmail.comLocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c, 9411070Sandreas.sandberg@arm.com Tick r) 9511070Sandreas.sandberg@arm.com : Event(Sim_Exit_Pri, IsExitEvent), 969952Sdam.sunwoo@arm.com cause(_cause), code(c), repeat(r) 975606Snate@binkert.org{ 985606Snate@binkert.org} 995606Snate@binkert.org 1002SN/A// 1012SN/A// handle termination event 1022SN/A// 1032SN/Avoid 1049983Sstever@gmail.comLocalSimLoopExitEvent::process() 1052SN/A{ 1069983Sstever@gmail.com exitSimLoop(cause, 0); 1072SN/A} 1082SN/A 1092SN/A 1102SN/Aconst char * 1119983Sstever@gmail.comLocalSimLoopExitEvent::description() const 1122SN/A{ 1132667Sstever@eecs.umich.edu return "simulation loop exit"; 1142667Sstever@eecs.umich.edu} 1152667Sstever@eecs.umich.edu 1162667Sstever@eecs.umich.eduvoid 11710905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::serialize(CheckpointOut &cp) const 1182667Sstever@eecs.umich.edu{ 11910905Sandreas.sandberg@arm.com Event::serialize(cp); 1209952Sdam.sunwoo@arm.com 1219952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(cause); 1229952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(code); 1239952Sdam.sunwoo@arm.com SERIALIZE_SCALAR(repeat); 1249952Sdam.sunwoo@arm.com} 1259952Sdam.sunwoo@arm.com 1269952Sdam.sunwoo@arm.comvoid 12710905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::unserialize(CheckpointIn &cp) 1289952Sdam.sunwoo@arm.com{ 12910905Sandreas.sandberg@arm.com Event::unserialize(cp); 1309952Sdam.sunwoo@arm.com 1319952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(cause); 1329952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(code); 1339952Sdam.sunwoo@arm.com UNSERIALIZE_SCALAR(repeat); 1349952Sdam.sunwoo@arm.com} 1359952Sdam.sunwoo@arm.com 1362SN/A// 1372SN/A// constructor: automatically schedules at specified time 1382SN/A// 1395606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter) 1405606Snate@binkert.org : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter) 1412SN/A{ 1422SN/A // catch stupid mistakes 1432SN/A assert(downCounter > 0); 1442SN/A} 1452SN/A 1462SN/A 1472SN/A// 1482SN/A// handle termination event 1492SN/A// 1502SN/Avoid 1512SN/ACountedExitEvent::process() 1522SN/A{ 1532SN/A if (--downCounter == 0) { 1542667Sstever@eecs.umich.edu exitSimLoop(cause, 0); 1552SN/A } 1562SN/A} 1572SN/A 1582SN/A 1592SN/Aconst char * 1605336Shines@cs.fsu.eduCountedExitEvent::description() const 1612SN/A{ 1622SN/A return "counted exit"; 1632SN/A} 164