sim_events.cc revision 9356
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"
359356Snilay@cs.wisc.edu#include "sim/eventq_impl.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
862SN/A//
872SN/A// constructor: automatically schedules at specified time
882SN/A//
895606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
905606Snate@binkert.org    : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
912SN/A{
922SN/A    // catch stupid mistakes
932SN/A    assert(downCounter > 0);
942SN/A}
952SN/A
962SN/A
972SN/A//
982SN/A// handle termination event
992SN/A//
1002SN/Avoid
1012SN/ACountedExitEvent::process()
1022SN/A{
1032SN/A    if (--downCounter == 0) {
1042667Sstever@eecs.umich.edu        exitSimLoop(cause, 0);
1052SN/A    }
1062SN/A}
1072SN/A
1082SN/A
1092SN/Aconst char *
1105336Shines@cs.fsu.eduCountedExitEvent::description() const
1112SN/A{
1122SN/A    return "counted exit";
1132SN/A}
114