sim_events.cc revision 10905
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
452SN/A#include <string>
462SN/A
47601SN/A#include "base/callback.hh"
48601SN/A#include "base/hostinfo.hh"
499356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh"
5056SN/A#include "sim/sim_events.hh"
5156SN/A#include "sim/sim_exit.hh"
52695SN/A#include "sim/stats.hh"
532SN/A
542SN/Ausing namespace std;
552SN/A
569983Sstever@gmail.comGlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
579983Sstever@gmail.com                                               const std::string &_cause,
589983Sstever@gmail.com                                               int c, Tick r, bool serialize)
599983Sstever@gmail.com    : GlobalEvent(when, Sim_Exit_Pri,
609983Sstever@gmail.com                  IsExitEvent | (serialize ? AutoSerialize : 0)),
619983Sstever@gmail.com      cause(_cause), code(c), repeat(r)
629983Sstever@gmail.com{
639983Sstever@gmail.com}
649983Sstever@gmail.com
659983Sstever@gmail.comconst char *
669983Sstever@gmail.comGlobalSimLoopExitEvent::description() const
679983Sstever@gmail.com{
689983Sstever@gmail.com    return "global simulation loop exit";
699983Sstever@gmail.com}
709983Sstever@gmail.com
719983Sstever@gmail.com//
729983Sstever@gmail.com// handle termination event
739983Sstever@gmail.com//
749983Sstever@gmail.comvoid
759983Sstever@gmail.comGlobalSimLoopExitEvent::process()
769983Sstever@gmail.com{
779983Sstever@gmail.com    if (repeat) {
789983Sstever@gmail.com        schedule(curTick() + repeat);
799983Sstever@gmail.com    }
809983Sstever@gmail.com}
819983Sstever@gmail.com
829983Sstever@gmail.comvoid
839983Sstever@gmail.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
849983Sstever@gmail.com            bool serialize)
859983Sstever@gmail.com{
869983Sstever@gmail.com    new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat,
879983Sstever@gmail.com                               serialize);
889983Sstever@gmail.com}
899983Sstever@gmail.com
909983Sstever@gmail.comLocalSimLoopExitEvent::LocalSimLoopExitEvent()
919952Sdam.sunwoo@arm.com    : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
929952Sdam.sunwoo@arm.com      cause(""), code(0), repeat(0)
939952Sdam.sunwoo@arm.com{
949952Sdam.sunwoo@arm.com}
959952Sdam.sunwoo@arm.com
969983Sstever@gmail.comLocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
979983Sstever@gmail.com                                   Tick r, bool serialize)
989952Sdam.sunwoo@arm.com    : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
999952Sdam.sunwoo@arm.com      cause(_cause), code(c), repeat(r)
1005606Snate@binkert.org{
1015606Snate@binkert.org}
1025606Snate@binkert.org
1032SN/A//
1042SN/A// handle termination event
1052SN/A//
1062SN/Avoid
1079983Sstever@gmail.comLocalSimLoopExitEvent::process()
1082SN/A{
1099983Sstever@gmail.com    exitSimLoop(cause, 0);
1102SN/A}
1112SN/A
1122SN/A
1132SN/Aconst char *
1149983Sstever@gmail.comLocalSimLoopExitEvent::description() const
1152SN/A{
1162667Sstever@eecs.umich.edu    return "simulation loop exit";
1172667Sstever@eecs.umich.edu}
1182667Sstever@eecs.umich.edu
1192667Sstever@eecs.umich.eduvoid
12010905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::serialize(CheckpointOut &cp) const
1212667Sstever@eecs.umich.edu{
12210905Sandreas.sandberg@arm.com    paramOut(cp, "type", string("SimLoopExitEvent"));
12310905Sandreas.sandberg@arm.com    Event::serialize(cp);
1249952Sdam.sunwoo@arm.com
1259952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(cause);
1269952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(code);
1279952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(repeat);
1289952Sdam.sunwoo@arm.com}
1299952Sdam.sunwoo@arm.com
1309952Sdam.sunwoo@arm.comvoid
13110905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::unserialize(CheckpointIn &cp)
1329952Sdam.sunwoo@arm.com{
13310905Sandreas.sandberg@arm.com    Event::unserialize(cp);
1349952Sdam.sunwoo@arm.com
1359952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(cause);
1369952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(code);
1379952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(repeat);
1389952Sdam.sunwoo@arm.com}
1399952Sdam.sunwoo@arm.com
1409983Sstever@gmail.comvoid
14110905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::unserializeEvent(CheckpointIn &cp, EventQueue *eventq)
1429952Sdam.sunwoo@arm.com{
14310905Sandreas.sandberg@arm.com    Event::unserializeEvent(cp, eventq);
1449983Sstever@gmail.com
1459983Sstever@gmail.com    UNSERIALIZE_SCALAR(cause);
1469983Sstever@gmail.com    UNSERIALIZE_SCALAR(code);
1479983Sstever@gmail.com    UNSERIALIZE_SCALAR(repeat);
1489952Sdam.sunwoo@arm.com}
1499952Sdam.sunwoo@arm.com
1509983Sstever@gmail.comSerializable *
15110905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::createForUnserialize(CheckpointIn &cp,
1529983Sstever@gmail.com                                            const string &section)
1539983Sstever@gmail.com{
1549983Sstever@gmail.com    return new LocalSimLoopExitEvent();
1559983Sstever@gmail.com}
1569952Sdam.sunwoo@arm.com
1579983Sstever@gmail.comREGISTER_SERIALIZEABLE("LocalSimLoopExitEvent", LocalSimLoopExitEvent)
1582SN/A
1592SN/A//
1602SN/A// constructor: automatically schedules at specified time
1612SN/A//
1625606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
1635606Snate@binkert.org    : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
1642SN/A{
1652SN/A    // catch stupid mistakes
1662SN/A    assert(downCounter > 0);
1672SN/A}
1682SN/A
1692SN/A
1702SN/A//
1712SN/A// handle termination event
1722SN/A//
1732SN/Avoid
1742SN/ACountedExitEvent::process()
1752SN/A{
1762SN/A    if (--downCounter == 0) {
1772667Sstever@eecs.umich.edu        exitSimLoop(cause, 0);
1782SN/A    }
1792SN/A}
1802SN/A
1812SN/A
1822SN/Aconst char *
1835336Shines@cs.fsu.eduCountedExitEvent::description() const
1842SN/A{
1852SN/A    return "counted exit";
1862SN/A}
187