sim_events.cc revision 9328
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292SN/A */ 302SN/A 312SN/A#include <string> 322SN/A 33601SN/A#include "base/callback.hh" 34601SN/A#include "base/hostinfo.hh" 35601SN/A#include "sim/eventq.hh" 3656SN/A#include "sim/sim_events.hh" 3756SN/A#include "sim/sim_exit.hh" 38695SN/A#include "sim/stats.hh" 392SN/A 402SN/Ausing namespace std; 412SN/A 425606Snate@binkert.orgSimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r) 438581Ssteve.reinhardt@amd.com : Event(Sim_Exit_Pri, IsExitEvent), cause(_cause), code(c), repeat(r) 445606Snate@binkert.org{ 455606Snate@binkert.org} 465606Snate@binkert.org 475606Snate@binkert.org 482SN/A// 492SN/A// handle termination event 502SN/A// 512SN/Avoid 522667Sstever@eecs.umich.eduSimLoopExitEvent::process() 532SN/A{ 542667Sstever@eecs.umich.edu // if this got scheduled on a different queue (e.g. the committed 552667Sstever@eecs.umich.edu // instruction queue) then make a corresponding event on the main 562667Sstever@eecs.umich.edu // queue. 578581Ssteve.reinhardt@amd.com if (!isFlagSet(IsMainQueue)) { 582667Sstever@eecs.umich.edu exitSimLoop(cause, code); 599328SAli.Saidi@ARM.com setFlags(AutoDelete); 602SN/A } 612667Sstever@eecs.umich.edu 622667Sstever@eecs.umich.edu // otherwise do nothing... the IsExitEvent flag takes care of 632667Sstever@eecs.umich.edu // exiting the simulation loop and returning this object to Python 643144Shsul@eecs.umich.edu 653144Shsul@eecs.umich.edu // but if you are doing this on intervals, don't forget to make another 663144Shsul@eecs.umich.edu if (repeat) { 678581Ssteve.reinhardt@amd.com assert(isFlagSet(IsMainQueue)); 687823Ssteve.reinhardt@amd.com mainEventQueue.schedule(this, curTick() + repeat); 693144Shsul@eecs.umich.edu } 702SN/A} 712SN/A 722SN/A 732SN/Aconst char * 745336Shines@cs.fsu.eduSimLoopExitEvent::description() const 752SN/A{ 762667Sstever@eecs.umich.edu return "simulation loop exit"; 772667Sstever@eecs.umich.edu} 782667Sstever@eecs.umich.edu 792667Sstever@eecs.umich.eduvoid 807819Ssteve.reinhardt@amd.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat) 812667Sstever@eecs.umich.edu{ 827819Ssteve.reinhardt@amd.com Event *event = new SimLoopExitEvent(message, exit_code, repeat); 837819Ssteve.reinhardt@amd.com mainEventQueue.schedule(event, when); 842SN/A} 852SN/A 865606Snate@binkert.orgCountedDrainEvent::CountedDrainEvent() 877821Ssteve.reinhardt@amd.com : count(0) 885606Snate@binkert.org{ } 895606Snate@binkert.org 902797Sktlim@umich.eduvoid 912839Sktlim@umich.eduCountedDrainEvent::process() 922797Sktlim@umich.edu{ 935606Snate@binkert.org if (--count == 0) 947821Ssteve.reinhardt@amd.com exitSimLoop("Finished drain", 0); 952797Sktlim@umich.edu} 962797Sktlim@umich.edu 972SN/A// 982SN/A// constructor: automatically schedules at specified time 992SN/A// 1005606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter) 1015606Snate@binkert.org : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter) 1022SN/A{ 1032SN/A // catch stupid mistakes 1042SN/A assert(downCounter > 0); 1052SN/A} 1062SN/A 1072SN/A 1082SN/A// 1092SN/A// handle termination event 1102SN/A// 1112SN/Avoid 1122SN/ACountedExitEvent::process() 1132SN/A{ 1142SN/A if (--downCounter == 0) { 1152667Sstever@eecs.umich.edu exitSimLoop(cause, 0); 1162SN/A } 1172SN/A} 1182SN/A 1192SN/A 1202SN/Aconst char * 1215336Shines@cs.fsu.eduCountedExitEvent::description() const 1222SN/A{ 1232SN/A return "counted exit"; 1242SN/A} 125