sim_events.hh revision 9952
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 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272SN/A * 282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 412SN/A */ 422SN/A 431798SN/A#ifndef __SIM_SIM_EVENTS_HH__ 441798SN/A#define __SIM_SIM_EVENTS_HH__ 452SN/A 4656SN/A#include "sim/eventq.hh" 479952Sdam.sunwoo@arm.com#include "sim/serialize.hh" 482SN/A 492SN/A// 502SN/A// Event to terminate simulation at a particular cycle/instruction 512SN/A// 522667Sstever@eecs.umich.educlass SimLoopExitEvent : public Event 532SN/A{ 545606Snate@binkert.org protected: 552SN/A // string explaining why we're terminating 562SN/A std::string cause; 572SN/A int code; 583144Shsul@eecs.umich.edu Tick repeat; 592SN/A 602SN/A public: 619952Sdam.sunwoo@arm.com // non-scheduling version for createForUnserialize() 629952Sdam.sunwoo@arm.com SimLoopExitEvent(); 639952Sdam.sunwoo@arm.com SimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0, 649952Sdam.sunwoo@arm.com bool serialize = false); 652SN/A 662667Sstever@eecs.umich.edu std::string getCause() { return cause; } 672667Sstever@eecs.umich.edu int getCode() { return code; } 682SN/A 695543Ssaidi@eecs.umich.edu void process(); // process event 702SN/A 715336Shines@cs.fsu.edu virtual const char *description() const; 729952Sdam.sunwoo@arm.com 739952Sdam.sunwoo@arm.com virtual void serialize(std::ostream &os); 749952Sdam.sunwoo@arm.com virtual void unserialize(Checkpoint *cp, const std::string §ion); 759952Sdam.sunwoo@arm.com static Serializable *createForUnserialize(Checkpoint *cp, 769952Sdam.sunwoo@arm.com const std::string §ion); 772SN/A}; 782SN/A 797821Ssteve.reinhardt@amd.comclass CountedDrainEvent : public Event 802797Sktlim@umich.edu{ 812797Sktlim@umich.edu private: 822839Sktlim@umich.edu // Count of how many objects have not yet drained 832797Sktlim@umich.edu int count; 845606Snate@binkert.org 852797Sktlim@umich.edu public: 865606Snate@binkert.org CountedDrainEvent(); 875606Snate@binkert.org 882797Sktlim@umich.edu void process(); 892797Sktlim@umich.edu 902797Sktlim@umich.edu void setCount(int _count) { count = _count; } 912797Sktlim@umich.edu 922797Sktlim@umich.edu int getCount() { return count; } 932797Sktlim@umich.edu}; 942797Sktlim@umich.edu 952SN/A// 962SN/A// Event class to terminate simulation after 'n' related events have 972SN/A// occurred using a shared counter: used to terminate when *all* 982SN/A// threads have reached a particular instruction count 992SN/A// 1002SN/Aclass CountedExitEvent : public Event 1012SN/A{ 1022SN/A private: 1035543Ssaidi@eecs.umich.edu std::string cause; // string explaining why we're terminating 1045543Ssaidi@eecs.umich.edu int &downCounter; // decrement & terminate if zero 1052SN/A 1062SN/A public: 1075606Snate@binkert.org CountedExitEvent(const std::string &_cause, int &_downCounter); 1082SN/A 1095543Ssaidi@eecs.umich.edu void process(); // process event 1102SN/A 1115336Shines@cs.fsu.edu virtual const char *description() const; 1122SN/A}; 1132SN/A 1142SN/A 1151798SN/A#endif // __SIM_SIM_EVENTS_HH__ 116