gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sim_events.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * Copyright (c) 2013 Mark D. Hill and David A. Wood
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met: redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer;
23  * redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution;
26  * neither the name of the copyright holders nor the names of its
27  * contributors may be used to endorse or promote products derived from
28  * this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  * Authors: Nathan Binkert
43  */
44 
45 #include "sim/sim_events.hh"
46 
47 #include <string>
48 
49 #include "base/callback.hh"
50 #include "base/hostinfo.hh"
51 #include "sim/eventq_impl.hh"
52 #include "sim/sim_exit.hh"
53 #include "sim/stats.hh"
54 
55 using namespace std;
56 
58  const std::string &_cause,
59  int c, Tick r)
60  : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent),
61  cause(_cause), code(c), repeat(r)
62 {
63 }
64 
66  int c, Tick r)
68  cause(_cause), code(c), repeat(r)
69 {
70 }
71 
72 const char *
74 {
75  return "global simulation loop exit";
76 }
77 
78 //
79 // handle termination event
80 //
81 void
83 {
84  if (repeat) {
85  schedule(curTick() + repeat);
86  }
87 }
88 
89 void
90 exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
91  bool serialize)
92 {
93  warn_if(serialize && (when != curTick() || repeat),
94  "exitSimLoop called with a delay and auto serialization. This is "
95  "currently unsupported.");
96 
97  new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
98 }
99 
100 void
101 exitSimLoopNow(const std::string &message, int exit_code, Tick repeat,
102  bool serialize)
103 {
104  new GlobalSimLoopExitEvent(message, exit_code, repeat);
105 }
106 
107 LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
108  Tick r)
110  cause(_cause), code(c), repeat(r)
111 {
112 }
113 
114 //
115 // handle termination event
116 //
117 void
119 {
120  exitSimLoop(cause, 0);
121 }
122 
123 
124 const char *
126 {
127  return "simulation loop exit";
128 }
129 
130 void
132 {
133  Event::serialize(cp);
134 
138 }
139 
140 void
142 {
143  Event::unserialize(cp);
144 
148 }
149 
150 //
151 // constructor: automatically schedules at specified time
152 //
153 CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
154  : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
155 {
156  // catch stupid mistakes
157  assert(downCounter > 0);
158 }
159 
160 
161 //
162 // handle termination event
163 //
164 void
166 {
167  if (--downCounter == 0) {
168  exitSimLoop(cause, 0);
169  }
170 }
171 
172 
173 const char *
175 {
176  return "counted exit";
177 }
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: eventq.cc:244
std::string cause
Definition: sim_events.hh:106
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: eventq.cc:253
const char * description() const override
Return a C string describing the event.
Definition: sim_events.cc:174
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: sim_events.cc:131
Definition: cprintf.cc:42
Tick when() const
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
Tick curTick()
The current simulated tick.
Definition: core.hh:47
GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c, Tick repeat=0)
Definition: sim_events.cc:57
uint64_t Tick
Tick count type.
Definition: types.hh:63
static const Priority Sim_Exit_Pri
If we want to exit on this cycle, it&#39;s the very last thing we do.
Definition: eventq.hh:176
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:228
CountedExitEvent(const std::string &_cause, int &_downCounter)
Definition: sim_events.cc:153
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
void exitSimLoopNow(const std::string &message, int exit_code, Tick repeat, bool serialize)
Schedule an event as above, but make it high priority so it runs before any normal events which are s...
Definition: sim_events.cc:101
const char * description() const override
Return a C string describing the event.
Definition: sim_events.cc:125
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
The main global event class.
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
Definition: sim_events.cc:90
void schedule(Tick when)
Definition: global_event.cc:53
Bitfield< 29 > c
std::ostream CheckpointOut
Definition: serialize.hh:68
Definition: eventq.hh:189
void process() override
Definition: sim_events.cc:165
static const Priority Minimum_Pri
Event priorities, to provide tie-breakers for events scheduled at the same cycle. ...
Definition: eventq.hh:125
void process() override
Definition: sim_events.cc:118
virtual const char * description() const
Definition: sim_events.cc:73
static const FlagsType IsExitEvent
Definition: eventq.hh:111
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:50
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: sim_events.cc:141

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13