gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_main.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "base/types.hh"
29#include "sim/eventq.hh"
36
37namespace sc_core
38{
39
40namespace
41{
42
43sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA;
44
45} // anonymous namespace
46
47int
49{
50 return ::sc_gem5::scMainFiber.argc();
51}
52
53const char *const *
55{
56 return ::sc_gem5::scMainFiber.argv();
57}
58
59void
61{
63 sc_start(sc_time::from_value(gem5::MaxTick - now), SC_EXIT_ON_STARVATION);
64}
65
66void
72
73void
75{
76 if (time.value() == 0) {
78 } else {
80 if (gem5::MaxTick - now < time.value())
81 SC_REPORT_ERROR(SC_ID_SIMULATION_TIME_OVERFLOW_, "");
82 ::sc_gem5::scheduler.start(now + time.value(), p == SC_RUN_TO_TIME);
83 }
84}
85
86void
88{
89 if (sc_is_running()) {
90 SC_REPORT_ERROR(SC_ID_STOP_MODE_AFTER_START_, "");
91 return;
92 }
93 _stop_mode = mode;
94}
95
96sc_stop_mode
98{
99 return _stop_mode;
100}
101
102void
104{
105 static bool stop_called = false;
106 if (stop_called) {
107 static bool stop_warned = false;
108 if (!stop_warned)
109 SC_REPORT_WARNING(SC_ID_SIMULATION_STOP_CALLED_TWICE_, "");
110 stop_warned = true;
111 return;
112 }
113 stop_called = true;
114
115 if (::sc_gem5::Kernel::status() == SC_STOPPED)
116 return;
117
118 if ((sc_get_status() & SC_RUNNING)) {
119 bool finish_delta = (_stop_mode == SC_STOP_FINISH_DELTA);
121 } else {
123 }
124}
125
126const sc_time &
128{
129 static sc_time tstamp(1.0, SC_SEC);
130 tstamp = sc_time::from_value(::sc_gem5::scheduler.getCurTick());
131 return tstamp;
132}
133
139
140bool
142{
143 return sc_get_status() & (SC_RUNNING | SC_PAUSED);
144}
145
146bool
148{
149 return ::sc_gem5::scheduler.pendingCurr();
150}
151
152bool
154{
155 return ::sc_gem5::scheduler.pendingFuture();
156}
157
158bool
164
165sc_time
170
171sc_status
173{
174 return ::sc_gem5::kernel ? ::sc_gem5::kernel->status() : SC_ELABORATION;
175}
176
177std::ostream &
178operator << (std::ostream &os, sc_status s)
179{
180 switch (s) {
181 case SC_ELABORATION:
182 os << "SC_ELABORATION";
183 break;
185 os << "SC_BEFORE_END_OF_ELABORATION";
186 break;
188 os << "SC_END_OF_ELABORATION";
189 break;
191 os << "SC_START_OF_SIMULATION";
192 break;
193 case SC_RUNNING:
194 os << "SC_RUNNING";
195 break;
196 case SC_PAUSED:
197 os << "SC_PAUSED";
198 break;
199 case SC_STOPPED:
200 os << "SC_STOPPED";
201 break;
203 os << "SC_END_OF_SIMULATION";
204 break;
205
206 // Nonstandard
208 os << "SC_END_OF_INITIALIZATION";
209 break;
210 case SC_END_OF_UPDATE:
211 os << "SC_END_OF_UPDATE";
212 break;
214 os << "SC_BEFORE_TIMESTEP";
215 break;
216
217 default:
218 if (s & SC_STATUS_ANY) {
219 const char *prefix = "(";
220 for (sc_status m = (sc_status)0x1;
221 m < SC_STATUS_ANY; m = (sc_status)(m << 1)) {
222 if (m & s) {
223 os << prefix;
224 prefix = "|";
225 os << m;
226 }
227 }
228 os << ")";
229 } else {
230 gem5::ccprintf(os, "%#x", s);
231 }
232 }
233
234 return os;
235}
236
237} // namespace sc_core
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
static sc_time from_value(sc_dt::uint64)
Definition sc_time.cc:210
sc_dt::uint64 value() const
Definition sc_time.cc:115
static sc_core::sc_status status()
Definition kernel.cc:54
static void stop()
Definition kernel.cc:143
gem5::Tick getCurTick()
Definition scheduler.hh:243
void start(gem5::Tick max_tick, bool run_to_time)
Definition scheduler.cc:404
uint64_t numCycles()
Definition scheduler.hh:184
void scheduleStop(bool finish_delta)
Definition scheduler.cc:473
uint64_t Tick
Tick count type.
Definition types.hh:58
const Tick MaxTick
Definition types.hh:60
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
bool sc_pending_activity()
Definition sc_main.cc:159
bool sc_pending_activity_at_future_time()
Definition sc_main.cc:153
void sc_stop()
Definition sc_main.cc:103
sc_dt::uint64 sc_delta_count()
Definition sc_main.cc:135
sc_time sc_time_to_pending_activity()
Definition sc_main.cc:166
int sc_argc()
Definition sc_main.cc:48
bool sc_pending_activity_at_current_time()
Definition sc_main.cc:147
sc_status sc_get_status()
Definition sc_main.cc:172
@ SC_BEFORE_TIMESTEP
Definition sc_main.hh:95
@ SC_END_OF_ELABORATION
Definition sc_main.hh:85
@ SC_END_OF_SIMULATION
Definition sc_main.hh:90
@ SC_STATUS_ANY
Definition sc_main.hh:96
@ SC_END_OF_UPDATE
Definition sc_main.hh:94
@ SC_ELABORATION
Definition sc_main.hh:83
@ SC_STOPPED
Definition sc_main.hh:89
@ SC_RUNNING
Definition sc_main.hh:87
@ SC_BEFORE_END_OF_ELABORATION
Definition sc_main.hh:84
@ SC_PAUSED
Definition sc_main.hh:88
@ SC_END_OF_INITIALIZATION
Definition sc_main.hh:93
@ SC_START_OF_SIMULATION
Definition sc_main.hh:86
bool sc_is_running()
Definition sc_main.cc:141
void sc_start()
Definition sc_main.cc:60
sc_stop_mode
Definition sc_main.hh:63
@ SC_STOP_FINISH_DELTA
Definition sc_main.hh:64
std::ostream & operator<<(std::ostream &os, sc_status s)
Definition sc_main.cc:178
const char *const * sc_argv()
Definition sc_main.cc:54
void sc_pause()
Definition sc_main.cc:67
sc_starvation_policy
Definition sc_main.hh:47
void sc_set_stop_mode(sc_stop_mode mode)
Definition sc_main.cc:87
const sc_time & sc_time_stamp()
Definition sc_main.cc:127
sc_stop_mode sc_get_stop_mode()
Definition sc_main.cc:97
uint64_t uint64
Definition sc_nbdefs.hh:172
Scheduler scheduler
Definition scheduler.cc:494
Kernel * kernel
Definition kernel.cc:184
#define SC_REPORT_WARNING(msg_type, msg)
#define SC_REPORT_ERROR(msg_type, msg)

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0