gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
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
52namespace gem5
53{
54
56 const std::string &_cause,
57 int c, Tick r,
58 uint64_t hypercall_id,
59 std::map<std::string, std::string> payload)
63{
64}
65
67 int c, Tick r,
68 uint64_t hypercall_id,
69 std::map<std::string, std::string> payload)
73{
74}
75
77 uint64_t hypercall_id, std::map<std::string, std::string> payload)
79{
80}
81
83 std::map<std::string, std::string> payload)
85{
86 assert(hypercall_id != 0); // 0 is reserved for the "old style" exitSimLoop
87}
88
89const char *
91{
92 return "global simulation loop exit";
93}
94
95//
96// handle termination event
97//
98void
100{
101 if (repeat) {
103 }
104}
105
109
110void
111exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
112 bool serialize)
113{
114 warn_if(serialize && (when != curTick() || repeat),
115 "exitSimLoop called with a delay and auto serialization. This is "
116 "currently unsupported.");
117
118 new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
119}
120
121
122void
123exitSimLoopNow(const std::string &message, int exit_code, Tick repeat,
124 bool serialize)
125{
126 new GlobalSimLoopExitEvent(message, exit_code, repeat);
127}
128
129void
130exitSimLoopWithHypercall (const::std::string &message, int exit_code,
131 Tick when, Tick repeat, std::map<std::string,
132 std::string> payload, uint64_t hypercall_id,
133 bool serialize)
134{
135 new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat,
136 hypercall_id, payload);
137}
138
141void exitSimulationLoop(uint64_t type_id,
142 std::map<std::string, std::string> payload, Tick when)
143{
144 new GlobalSimLoopExitEvent(when, type_id, payload);
145}
146
147void
148exitSimulationLoopNow(uint64_t type_id,
149 std::map<std::string, std::string> payload)
150{
151 new GlobalSimLoopExitEvent(type_id, payload);
152}
153
154LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
155 Tick r)
157 cause(_cause), code(c), repeat(r)
158{
159}
160
161//
162// handle termination event
163//
164void
169
170
171const char *
173{
174 return "simulation loop exit";
175}
176
177void
186
187void
196
197//
198// constructor: automatically schedules at specified time
199//
200CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
201 : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
202{
203 // catch stupid mistakes
204 assert(downCounter > 0);
205}
206
207
208//
209// handle termination event
210//
211void
213{
214 if (--downCounter == 0) {
215 exitSimLoop(cause, 0);
216 }
217}
218
219
220const char *
222{
223 return "counted exit";
224}
225
226} // namespace gem5
void schedule(Tick when)
CountedExitEvent(const std::string &_cause, int &_downCounter)
const char * description() const override
Return a C string describing the event.
void process() override
static const FlagsType IsExitEvent
Definition eventq.hh:117
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition eventq.cc:274
Event(Priority p=Default_Pri, Flags f=0)
Definition eventq.hh:407
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition eventq.cc:265
GlobalEvent(Priority p, Flags f)
virtual const char * description() const
Definition sim_events.cc:90
std::map< std::string, std::string > payload
Definition sim_events.hh:63
GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c, Tick repeat=0, uint64_t hypercall_id=0, std::map< std::string, std::string > payload=std::map< std::string, std::string >())
The "old style" constructor for GlobalSimLoopExitEvent.
Definition sim_events.cc:55
const char * description() const override
Return a C string describing the event.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static const Priority Sim_Exit_Pri
If we want to exit on this cycle, it's the very last thing we do.
Definition eventq.hh:237
static const Priority Minimum_Pri
Event priorities, to provide tie-breakers for events scheduled at the same cycle.
Definition eventq.hh:138
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:315
Bitfield< 29 > c
Definition misc_types.hh:53
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition eventq.cc:48
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
std::ostream CheckpointOut
Definition serialize.hh:66
void exitSimLoopWithHypercall(const::std::string &message, int exit_code, Tick when, Tick repeat, std::map< std::string, std::string > payload, uint64_t hypercall_id, bool serialize)
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
The "old style" exitSimLoop functions.
uint64_t Tick
Tick count type.
Definition types.hh:58
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...
void exitSimulationLoopNow(uint64_t type_id, std::map< std::string, std::string > payload)
void exitSimulationLoop(uint64_t type_id, std::map< std::string, std::string > payload, Tick when)
The "new style" exitSimLoop functions.
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Mon May 26 2025 09:19:13 for gem5 by doxygen 1.13.2