sim_events.hh revision 11294
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, 6611070Sandreas.sandberg@arm.com Tick repeat = 0); 672SN/A 689983Sstever@gmail.com const std::string getCause() const { return cause; } 6911294Sandreas.hansson@arm.com 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(); 8611070Sandreas.sandberg@arm.com LocalSimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0); 879983Sstever@gmail.com 889983Sstever@gmail.com const std::string getCause() const { return cause; } 8911294Sandreas.hansson@arm.com int getCode() const { return code; } 902SN/A 9111169Sandreas.hansson@arm.com void process() override; // process event 922SN/A 9311169Sandreas.hansson@arm.com const char *description() const override; 949952Sdam.sunwoo@arm.com 9511168Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 9611168Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override; 9710905Sandreas.sandberg@arm.com static Serializable *createForUnserialize(CheckpointIn &cp, 989952Sdam.sunwoo@arm.com const std::string §ion); 992SN/A}; 1002SN/A 1017821Ssteve.reinhardt@amd.comclass CountedDrainEvent : public Event 1022797Sktlim@umich.edu{ 1032797Sktlim@umich.edu private: 1042839Sktlim@umich.edu // Count of how many objects have not yet drained 1052797Sktlim@umich.edu int count; 1065606Snate@binkert.org 1072797Sktlim@umich.edu public: 1085606Snate@binkert.org CountedDrainEvent(); 1095606Snate@binkert.org 11011169Sandreas.hansson@arm.com void process() override; 1112797Sktlim@umich.edu 1122797Sktlim@umich.edu void setCount(int _count) { count = _count; } 1132797Sktlim@umich.edu 11411294Sandreas.hansson@arm.com int getCount() const { return count; } 1152797Sktlim@umich.edu}; 1162797Sktlim@umich.edu 1172SN/A// 1182SN/A// Event class to terminate simulation after 'n' related events have 1192SN/A// occurred using a shared counter: used to terminate when *all* 1202SN/A// threads have reached a particular instruction count 1212SN/A// 1222SN/Aclass CountedExitEvent : public Event 1232SN/A{ 1242SN/A private: 1255543Ssaidi@eecs.umich.edu std::string cause; // string explaining why we're terminating 1265543Ssaidi@eecs.umich.edu int &downCounter; // decrement & terminate if zero 1272SN/A 1282SN/A public: 1295606Snate@binkert.org CountedExitEvent(const std::string &_cause, int &_downCounter); 1302SN/A 13111169Sandreas.hansson@arm.com void process() override; // process event 1322SN/A 13311169Sandreas.hansson@arm.com const char *description() const override; 1342SN/A}; 1352SN/A 1362SN/A 1371798SN/A#endif // __SIM_SIM_EVENTS_HH__ 138