gem5  v21.0.1.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 
43 #include "sim/sim_events.hh"
44 
45 #include <string>
46 
47 #include "base/callback.hh"
48 #include "sim/eventq.hh"
49 #include "sim/sim_exit.hh"
50 #include "sim/stats.hh"
51 
53  const std::string &_cause,
54  int c, Tick r)
55  : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent),
56  cause(_cause), code(c), repeat(r)
57 {
58 }
59 
61  int c, Tick r)
62  : GlobalEvent(curTick(), Minimum_Pri, IsExitEvent),
63  cause(_cause), code(c), repeat(r)
64 {
65 }
66 
67 const char *
69 {
70  return "global simulation loop exit";
71 }
72 
73 //
74 // handle termination event
75 //
76 void
78 {
79  if (repeat) {
80  schedule(curTick() + repeat);
81  }
82 }
83 
84 void
85 exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
86  bool serialize)
87 {
88  warn_if(serialize && (when != curTick() || repeat),
89  "exitSimLoop called with a delay and auto serialization. This is "
90  "currently unsupported.");
91 
92  new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
93 }
94 
95 void
96 exitSimLoopNow(const std::string &message, int exit_code, Tick repeat,
97  bool serialize)
98 {
99  new GlobalSimLoopExitEvent(message, exit_code, repeat);
100 }
101 
102 LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
103  Tick r)
104  : Event(Sim_Exit_Pri, IsExitEvent),
105  cause(_cause), code(c), repeat(r)
106 {
107 }
108 
109 //
110 // handle termination event
111 //
112 void
114 {
115  exitSimLoop(cause, 0);
116 }
117 
118 
119 const char *
121 {
122  return "simulation loop exit";
123 }
124 
125 void
127 {
129 
133 }
134 
135 void
137 {
139 
143 }
144 
145 //
146 // constructor: automatically schedules at specified time
147 //
148 CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
149  : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
150 {
151  // catch stupid mistakes
152  assert(downCounter > 0);
153 }
154 
155 
156 //
157 // handle termination event
158 //
159 void
161 {
162  if (--downCounter == 0) {
163  exitSimLoop(cause, 0);
164  }
165 }
166 
167 
168 const char *
170 {
171  return "counted exit";
172 }
Event::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: eventq.cc:246
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
LocalSimLoopExitEvent::code
int code
Definition: sim_events.hh:78
sim_events.hh
LocalSimLoopExitEvent::description
const char * description() const override
Return a C string describing the event.
Definition: sim_events.cc:120
CountedExitEvent::CountedExitEvent
CountedExitEvent(const std::string &_cause, int &_downCounter)
Definition: sim_events.cc:148
CountedExitEvent::downCounter
int & downCounter
Definition: sim_events.hh:105
LocalSimLoopExitEvent::cause
std::string cause
Definition: sim_events.hh:77
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
serialize
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
Definition: thread_context.cc:142
GlobalSimLoopExitEvent::GlobalSimLoopExitEvent
GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c, Tick repeat=0)
Definition: sim_events.cc:52
LocalSimLoopExitEvent::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: sim_events.cc:136
sim_exit.hh
CountedExitEvent::process
void process() override
Definition: sim_events.cc:160
LocalSimLoopExitEvent::repeat
Tick repeat
Definition: sim_events.hh:79
stats.hh
GlobalSimLoopExitEvent::repeat
Tick repeat
Definition: sim_events.hh:58
cp
Definition: cprintf.cc:37
Event
Definition: eventq.hh:248
GlobalSimLoopExitEvent
Definition: sim_events.hh:52
MipsISA::r
r
Definition: pra_constants.hh:95
CountedExitEvent::description
const char * description() const override
Return a C string describing the event.
Definition: sim_events.cc:169
exitSimLoop
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:85
LocalSimLoopExitEvent::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: sim_events.cc:126
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
warn_if
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:263
LocalSimLoopExitEvent::LocalSimLoopExitEvent
LocalSimLoopExitEvent()
CountedExitEvent::cause
std::string cause
Definition: sim_events.hh:104
GlobalSimLoopExitEvent::process
void process()
Definition: sim_events.cc:77
exitSimLoopNow
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:96
LocalSimLoopExitEvent::process
void process() override
Definition: sim_events.cc:113
simQuantum
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:46
BaseGlobalEvent::schedule
void schedule(Tick when)
Definition: global_event.cc:53
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
GlobalSimLoopExitEvent::description
virtual const char * description() const
Definition: sim_events.cc:68
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
CheckpointIn
Definition: serialize.hh:68
GlobalEvent
The main global event class.
Definition: global_event.hh:173
callback.hh
Event::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: eventq.cc:237
eventq.hh

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17