gem5  v22.1.0.0
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"
30 #include "systemc/core/kernel.hh"
36 
37 namespace sc_core
38 {
39 
40 namespace
41 {
42 
44 
45 } // anonymous namespace
46 
47 int
49 {
51 }
52 
53 const char *const *
55 {
57 }
58 
59 void
61 {
64 }
65 
66 void
68 {
71 }
72 
73 void
75 {
76  if (time.value() == 0) {
78  } else {
80  if (gem5::MaxTick - now < time.value())
83  }
84 }
85 
86 void
88 {
89  if (sc_is_running()) {
91  return;
92  }
93  _stop_mode = mode;
94 }
95 
98 {
99  return _stop_mode;
100 }
101 
102 void
104 {
105  static bool stop_called = false;
106  if (stop_called) {
107  static bool stop_warned = false;
108  if (!stop_warned)
110  stop_warned = true;
111  return;
112  }
113  stop_called = true;
114 
116  return;
117 
118  if ((sc_get_status() & SC_RUNNING)) {
119  bool finish_delta = (_stop_mode == SC_STOP_FINISH_DELTA);
120  ::sc_gem5::scheduler.scheduleStop(finish_delta);
121  } else {
123  }
124 }
125 
126 const 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 
136 {
137  return sc_gem5::scheduler.numCycles();
138 }
139 
140 bool
142 {
143  return sc_get_status() & (SC_RUNNING | SC_PAUSED);
144 }
145 
146 bool
148 {
150 }
151 
152 bool
154 {
156 }
157 
158 bool
160 {
163 }
164 
165 sc_time
167 {
168  return sc_time::from_value(::sc_gem5::scheduler.timeToPending());
169 }
170 
171 sc_status
173 {
175 }
176 
177 std::ostream &
178 operator << (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;
213  case SC_BEFORE_TIMESTEP:
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
const char *const * argv()
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
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 17 > os
Definition: misc.hh:810
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
const char SC_ID_SIMULATION_STOP_CALLED_TWICE_[]
Definition: messages.cc:109
sc_status
Definition: sc_main.hh:82
@ 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
@ SC_SEC
Definition: sc_time.hh:46
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
const char SC_ID_STOP_MODE_AFTER_START_[]
Definition: messages.cc:113
sc_starvation_policy
Definition: sc_main.hh:47
@ SC_RUN_TO_TIME
Definition: sc_main.hh:48
@ SC_EXIT_ON_STARVATION
Definition: sc_main.hh:49
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
const char SC_ID_SIMULATION_TIME_OVERFLOW_[]
Definition: messages.cc:107
uint64_t uint64
Definition: sc_nbdefs.hh:172
ScMainFiber scMainFiber
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 Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1