sim_events.hh revision 9983
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 451798SN/A#ifndef __SIM_SIM_EVENTS_HH__ 461798SN/A#define __SIM_SIM_EVENTS_HH__ 472SN/A 489983Sstever@gmail.com#include "sim/global_event.hh" 499952Sdam.sunwoo@arm.com#include "sim/serialize.hh" 502SN/A 512SN/A// 522SN/A// Event to terminate simulation at a particular cycle/instruction 532SN/A// 549983Sstever@gmail.comclass GlobalSimLoopExitEvent : public GlobalEvent 552SN/A{ 565606Snate@binkert.org protected: 572SN/A // string explaining why we're terminating 582SN/A std::string cause; 592SN/A int code; 603144Shsul@eecs.umich.edu Tick repeat; 612SN/A 622SN/A public: 639952Sdam.sunwoo@arm.com // non-scheduling version for createForUnserialize() 649983Sstever@gmail.com GlobalSimLoopExitEvent(); 659983Sstever@gmail.com GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c, 669983Sstever@gmail.com Tick repeat = 0, bool serialize = false); 672SN/A 689983Sstever@gmail.com const std::string getCause() const { return cause; } 699983Sstever@gmail.com const int getCode() const { return code; } 709983Sstever@gmail.com 719983Sstever@gmail.com void process(); // process event 729983Sstever@gmail.com 739983Sstever@gmail.com virtual const char *description() const; 749983Sstever@gmail.com}; 759983Sstever@gmail.com 769983Sstever@gmail.comclass LocalSimLoopExitEvent : public Event 779983Sstever@gmail.com{ 789983Sstever@gmail.com protected: 799983Sstever@gmail.com // string explaining why we're terminating 809983Sstever@gmail.com std::string cause; 819983Sstever@gmail.com int code; 829983Sstever@gmail.com Tick repeat; 839983Sstever@gmail.com 849983Sstever@gmail.com public: 859983Sstever@gmail.com LocalSimLoopExitEvent(); 869983Sstever@gmail.com LocalSimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0, 879983Sstever@gmail.com bool serialize = false); 889983Sstever@gmail.com 899983Sstever@gmail.com const std::string getCause() const { return cause; } 909983Sstever@gmail.com const int getCode() const { return code; } 912SN/A 925543Ssaidi@eecs.umich.edu void process(); // process event 932SN/A 945336Shines@cs.fsu.edu virtual const char *description() const; 959952Sdam.sunwoo@arm.com 969952Sdam.sunwoo@arm.com virtual void serialize(std::ostream &os); 979952Sdam.sunwoo@arm.com virtual void unserialize(Checkpoint *cp, const std::string §ion); 989983Sstever@gmail.com virtual void unserialize(Checkpoint *cp, const std::string §ion, 999983Sstever@gmail.com EventQueue *eventq); 1009952Sdam.sunwoo@arm.com static Serializable *createForUnserialize(Checkpoint *cp, 1019952Sdam.sunwoo@arm.com const std::string §ion); 1022SN/A}; 1032SN/A 1047821Ssteve.reinhardt@amd.comclass CountedDrainEvent : public Event 1052797Sktlim@umich.edu{ 1062797Sktlim@umich.edu private: 1072839Sktlim@umich.edu // Count of how many objects have not yet drained 1082797Sktlim@umich.edu int count; 1095606Snate@binkert.org 1102797Sktlim@umich.edu public: 1115606Snate@binkert.org CountedDrainEvent(); 1125606Snate@binkert.org 1132797Sktlim@umich.edu void process(); 1142797Sktlim@umich.edu 1152797Sktlim@umich.edu void setCount(int _count) { count = _count; } 1162797Sktlim@umich.edu 1179983Sstever@gmail.com const int getCount() const { return count; } 1182797Sktlim@umich.edu}; 1192797Sktlim@umich.edu 1202SN/A// 1212SN/A// Event class to terminate simulation after 'n' related events have 1222SN/A// occurred using a shared counter: used to terminate when *all* 1232SN/A// threads have reached a particular instruction count 1242SN/A// 1252SN/Aclass CountedExitEvent : public Event 1262SN/A{ 1272SN/A private: 1285543Ssaidi@eecs.umich.edu std::string cause; // string explaining why we're terminating 1295543Ssaidi@eecs.umich.edu int &downCounter; // decrement & terminate if zero 1302SN/A 1312SN/A public: 1325606Snate@binkert.org CountedExitEvent(const std::string &_cause, int &_downCounter); 1332SN/A 1345543Ssaidi@eecs.umich.edu void process(); // process event 1352SN/A 1365336Shines@cs.fsu.edu virtual const char *description() const; 1372SN/A}; 1382SN/A 1392SN/A 1401798SN/A#endif // __SIM_SIM_EVENTS_HH__ 141