gem5  v20.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/core.hh"
30 #include "sim/eventq.hh"
31 #include "systemc/core/kernel.hh"
37 
38 namespace sc_core
39 {
40 
41 namespace
42 {
43 
45 
46 } // anonymous namespace
47 
48 int
50 {
52 }
53 
54 const char *const *
56 {
58 }
59 
60 void
62 {
65 }
66 
67 void
69 {
72 }
73 
74 void
76 {
77  if (time.value() == 0) {
79  } else {
81  if (MaxTick - now < time.value())
84  }
85 }
86 
87 void
89 {
90  if (sc_is_running()) {
92  return;
93  }
94  _stop_mode = mode;
95 }
96 
99 {
100  return _stop_mode;
101 }
102 
103 void
105 {
106  static bool stop_called = false;
107  if (stop_called) {
108  static bool stop_warned = false;
109  if (!stop_warned)
111  stop_warned = true;
112  return;
113  }
114  stop_called = true;
115 
117  return;
118 
119  if ((sc_get_status() & SC_RUNNING)) {
120  bool finish_delta = (_stop_mode == SC_STOP_FINISH_DELTA);
121  ::sc_gem5::scheduler.scheduleStop(finish_delta);
122  } else {
124  }
125 }
126 
127 const sc_time &
129 {
130  static sc_time tstamp(1.0, SC_SEC);
131  tstamp = sc_time::from_value(::sc_gem5::scheduler.getCurTick());
132  return tstamp;
133 }
134 
137 {
138  return sc_gem5::scheduler.numCycles();
139 }
140 
141 bool
143 {
144  return sc_get_status() & (SC_RUNNING | SC_PAUSED);
145 }
146 
147 bool
149 {
151 }
152 
153 bool
155 {
157 }
158 
159 bool
161 {
164 }
165 
166 sc_time
168 {
169  return sc_time::from_value(::sc_gem5::scheduler.timeToPending());
170 }
171 
172 sc_status
174 {
176 }
177 
178 std::ostream &
179 operator << (std::ostream &os, sc_status s)
180 {
181  switch (s) {
182  case SC_ELABORATION:
183  os << "SC_ELABORATION";
184  break;
186  os << "SC_BEFORE_END_OF_ELABORATION";
187  break;
189  os << "SC_END_OF_ELABORATION";
190  break;
192  os << "SC_START_OF_SIMULATION";
193  break;
194  case SC_RUNNING:
195  os << "SC_RUNNING";
196  break;
197  case SC_PAUSED:
198  os << "SC_PAUSED";
199  break;
200  case SC_STOPPED:
201  os << "SC_STOPPED";
202  break;
204  os << "SC_END_OF_SIMULATION";
205  break;
206 
207  // Nonstandard
209  os << "SC_END_OF_INITIALIZATION";
210  break;
211  case SC_END_OF_UPDATE:
212  os << "SC_END_OF_UPDATE";
213  break;
214  case SC_BEFORE_TIMESTEP:
215  os << "SC_BEFORE_TIMESTEP";
216  break;
217 
218  default:
219  if (s & SC_STATUS_ANY) {
220  const char *prefix = "(";
221  for (sc_status m = (sc_status)0x1;
222  m < SC_STATUS_ANY; m = (sc_status)(m << 1)) {
223  if (m & s) {
224  os << prefix;
225  prefix = "|";
226  os << m;
227  }
228  }
229  os << ")";
230  } else {
231  ccprintf(os, "%#x", s);
232  }
233  }
234 
235  return os;
236 }
237 
238 } // namespace sc_core
sc_core::sc_start
void sc_start()
Definition: sc_main.cc:61
kernel.hh
sc_core::sc_time::from_value
static sc_time from_value(sc_dt::uint64)
Definition: sc_time.cc:210
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
sc_core::sc_get_status
sc_status sc_get_status()
Definition: sc_main.cc:173
sc_core::sc_pending_activity_at_current_time
bool sc_pending_activity_at_current_time()
Definition: sc_main.cc:148
sc_main_fiber.hh
sc_gem5::Scheduler::scheduleStop
void scheduleStop(bool finish_delta)
Definition: scheduler.cc:468
sc_gem5::Kernel::stop
static void stop()
Definition: kernel.cc:140
sc_gem5::ScMainFiber::argc
int argc()
Definition: sc_main_fiber.hh:50
sc_core
Definition: messages.cc:31
sc_core::SC_ID_SIMULATION_TIME_OVERFLOW_
const char SC_ID_SIMULATION_TIME_OVERFLOW_[]
Definition: messages.cc:107
sc_gem5::Scheduler::pendingCurr
bool pendingCurr()
Definition: scheduler.hh:307
sc_core::sc_argv
const char *const * sc_argv()
Definition: sc_main.cc:55
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
sc_gem5::Scheduler::getCurTick
Tick getCurTick()
Definition: scheduler.hh:228
sc_core::SC_RUN_TO_TIME
@ SC_RUN_TO_TIME
Definition: sc_main.hh:48
sc_gem5::kernel
Kernel * kernel
Definition: kernel.cc:181
sc_core::SC_BEFORE_END_OF_ELABORATION
@ SC_BEFORE_END_OF_ELABORATION
Definition: sc_main.hh:84
sc_core::SC_ID_STOP_MODE_AFTER_START_
const char SC_ID_STOP_MODE_AFTER_START_[]
Definition: messages.cc:113
sc_core::sc_pending_activity_at_future_time
bool sc_pending_activity_at_future_time()
Definition: sc_main.cc:154
sc_core::SC_ELABORATION
@ SC_ELABORATION
Definition: sc_main.hh:83
sc_core::SC_END_OF_ELABORATION
@ SC_END_OF_ELABORATION
Definition: sc_main.hh:85
sc_core::SC_STOPPED
@ SC_STOPPED
Definition: sc_main.hh:89
sc_core::sc_stop
void sc_stop()
Definition: sc_main.cc:104
sc_gem5::Scheduler::numCycles
uint64_t numCycles()
Definition: scheduler.hh:169
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
sc_main.hh
sc_core::SC_BEFORE_TIMESTEP
@ SC_BEFORE_TIMESTEP
Definition: sc_main.hh:95
sc_core::sc_time
Definition: sc_time.hh:49
sc_core::sc_time::value
sc_dt::uint64 value() const
Definition: sc_time.cc:115
sc_core::operator<<
std::ostream & operator<<(std::ostream &os, sc_status s)
Definition: sc_main.cc:179
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
sc_gem5::ScMainFiber::argv
const char *const * argv()
Definition: sc_main_fiber.hh:51
messages.hh
sc_core::SC_SEC
@ SC_SEC
Definition: sc_time.hh:46
sc_gem5::Scheduler::schedulePause
void schedulePause()
Definition: scheduler.cc:445
core.hh
sc_core::SC_START_OF_SIMULATION
@ SC_START_OF_SIMULATION
Definition: sc_main.hh:86
sc_core::sc_time_to_pending_activity
sc_time sc_time_to_pending_activity()
Definition: sc_main.cc:167
sc_core::sc_argc
int sc_argc()
Definition: sc_main.cc:49
sc_core::sc_set_stop_mode
void sc_set_stop_mode(sc_stop_mode mode)
Definition: sc_main.cc:88
sc_core::SC_END_OF_SIMULATION
@ SC_END_OF_SIMULATION
Definition: sc_main.hh:90
sc_core::SC_STOP_FINISH_DELTA
@ SC_STOP_FINISH_DELTA
Definition: sc_main.hh:64
sc_core::SC_EXIT_ON_STARVATION
@ SC_EXIT_ON_STARVATION
Definition: sc_main.hh:49
sc_gem5::scMainFiber
ScMainFiber scMainFiber
Definition: sc_main_fiber.cc:78
SC_REPORT_WARNING
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report_handler.hh:123
sc_core::SC_ID_SIMULATION_STOP_CALLED_TWICE_
const char SC_ID_SIMULATION_STOP_CALLED_TWICE_[]
Definition: messages.cc:109
sc_report_handler.hh
sc_core::sc_delta_count
sc_dt::uint64 sc_delta_count()
Definition: sc_main.cc:136
types.hh
sc_gem5::Scheduler::oneCycle
void oneCycle()
Definition: scheduler.cc:437
sc_core::sc_pause
void sc_pause()
Definition: sc_main.cc:68
sc_core::sc_status
sc_status
Definition: sc_main.hh:81
sc_core::SC_END_OF_UPDATE
@ SC_END_OF_UPDATE
Definition: sc_main.hh:94
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
sc_gem5::Scheduler::start
void start(Tick max_tick, bool run_to_time)
Definition: scheduler.cc:399
sc_core::sc_stop_mode
sc_stop_mode
Definition: sc_main.hh:62
sc_core::SC_STATUS_ANY
@ SC_STATUS_ANY
Definition: sc_main.hh:96
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
sc_gem5::Scheduler::pendingFuture
bool pendingFuture()
Definition: scheduler.hh:315
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:489
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
sc_gem5::Kernel::status
static sc_core::sc_status status()
Definition: kernel.cc:54
sc_core::sc_starvation_policy
sc_starvation_policy
Definition: sc_main.hh:46
sc_core::SC_RUNNING
@ SC_RUNNING
Definition: sc_main.hh:87
sc_core::SC_PAUSED
@ SC_PAUSED
Definition: sc_main.hh:88
MaxTick
const Tick MaxTick
Definition: types.hh:65
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:128
scheduler.hh
sc_core::SC_END_OF_INITIALIZATION
@ SC_END_OF_INITIALIZATION
Definition: sc_main.hh:93
sc_core::sc_get_stop_mode
sc_stop_mode sc_get_stop_mode()
Definition: sc_main.cc:98
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
sc_core::sc_is_running
bool sc_is_running()
Definition: sc_main.cc:142
sc_core::sc_pending_activity
bool sc_pending_activity()
Definition: sc_main.cc:160
eventq.hh

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17