sim_events.cc 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
432SN/A#include <string>
442SN/A
45601SN/A#include "base/callback.hh"
46601SN/A#include "base/hostinfo.hh"
479356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh"
4856SN/A#include "sim/sim_events.hh"
4956SN/A#include "sim/sim_exit.hh"
50695SN/A#include "sim/stats.hh"
512SN/A
522SN/Ausing namespace std;
532SN/A
549952Sdam.sunwoo@arm.comSimLoopExitEvent::SimLoopExitEvent()
559952Sdam.sunwoo@arm.com    : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
569952Sdam.sunwoo@arm.com      cause(""), code(0), repeat(0)
579952Sdam.sunwoo@arm.com{
589952Sdam.sunwoo@arm.com}
599952Sdam.sunwoo@arm.com
609952Sdam.sunwoo@arm.comSimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r,
619952Sdam.sunwoo@arm.com                                   bool serialize)
629952Sdam.sunwoo@arm.com    : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
639952Sdam.sunwoo@arm.com      cause(_cause), code(c), repeat(r)
645606Snate@binkert.org{
655606Snate@binkert.org}
665606Snate@binkert.org
675606Snate@binkert.org
682SN/A//
692SN/A// handle termination event
702SN/A//
712SN/Avoid
722667Sstever@eecs.umich.eduSimLoopExitEvent::process()
732SN/A{
742667Sstever@eecs.umich.edu    // if this got scheduled on a different queue (e.g. the committed
752667Sstever@eecs.umich.edu    // instruction queue) then make a corresponding event on the main
762667Sstever@eecs.umich.edu    // queue.
778581Ssteve.reinhardt@amd.com    if (!isFlagSet(IsMainQueue)) {
782667Sstever@eecs.umich.edu        exitSimLoop(cause, code);
799328SAli.Saidi@ARM.com        setFlags(AutoDelete);
802SN/A    }
812667Sstever@eecs.umich.edu
822667Sstever@eecs.umich.edu    // otherwise do nothing... the IsExitEvent flag takes care of
832667Sstever@eecs.umich.edu    // exiting the simulation loop and returning this object to Python
843144Shsul@eecs.umich.edu
853144Shsul@eecs.umich.edu    // but if you are doing this on intervals, don't forget to make another
863144Shsul@eecs.umich.edu    if (repeat) {
878581Ssteve.reinhardt@amd.com        assert(isFlagSet(IsMainQueue));
887823Ssteve.reinhardt@amd.com        mainEventQueue.schedule(this, curTick() + repeat);
893144Shsul@eecs.umich.edu    }
902SN/A}
912SN/A
922SN/A
932SN/Aconst char *
945336Shines@cs.fsu.eduSimLoopExitEvent::description() const
952SN/A{
962667Sstever@eecs.umich.edu    return "simulation loop exit";
972667Sstever@eecs.umich.edu}
982667Sstever@eecs.umich.edu
992667Sstever@eecs.umich.eduvoid
1009952Sdam.sunwoo@arm.comSimLoopExitEvent::serialize(ostream &os)
1012667Sstever@eecs.umich.edu{
1029952Sdam.sunwoo@arm.com    paramOut(os, "type", string("SimLoopExitEvent"));
1039952Sdam.sunwoo@arm.com    Event::serialize(os);
1049952Sdam.sunwoo@arm.com
1059952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(cause);
1069952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(code);
1079952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(repeat);
1089952Sdam.sunwoo@arm.com}
1099952Sdam.sunwoo@arm.com
1109952Sdam.sunwoo@arm.comvoid
1119952Sdam.sunwoo@arm.comSimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
1129952Sdam.sunwoo@arm.com{
1139952Sdam.sunwoo@arm.com    Event::unserialize(cp, section);
1149952Sdam.sunwoo@arm.com
1159952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(cause);
1169952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(code);
1179952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(repeat);
1189952Sdam.sunwoo@arm.com}
1199952Sdam.sunwoo@arm.com
1209952Sdam.sunwoo@arm.comSerializable *
1219952Sdam.sunwoo@arm.comSimLoopExitEvent::createForUnserialize(Checkpoint *cp, const string &section)
1229952Sdam.sunwoo@arm.com{
1239952Sdam.sunwoo@arm.com    return new SimLoopExitEvent();
1249952Sdam.sunwoo@arm.com}
1259952Sdam.sunwoo@arm.com
1269952Sdam.sunwoo@arm.comREGISTER_SERIALIZEABLE("SimLoopExitEvent", SimLoopExitEvent)
1279952Sdam.sunwoo@arm.com
1289952Sdam.sunwoo@arm.comvoid
1299952Sdam.sunwoo@arm.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
1309952Sdam.sunwoo@arm.com            bool serialize)
1319952Sdam.sunwoo@arm.com{
1329952Sdam.sunwoo@arm.com    Event *event = new SimLoopExitEvent(message, exit_code, repeat, serialize);
1337819Ssteve.reinhardt@amd.com    mainEventQueue.schedule(event, when);
1342SN/A}
1352SN/A
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