gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
28  */
29 
30 #include "base/types.hh"
31 #include "sim/core.hh"
32 #include "sim/eventq.hh"
33 #include "systemc/core/kernel.hh"
39 
40 namespace sc_core
41 {
42 
43 namespace
44 {
45 
47 
48 } // anonymous namespace
49 
50 int
52 {
54 }
55 
56 const char *const *
58 {
60 }
61 
62 void
64 {
67 }
68 
69 void
71 {
74 }
75 
76 void
78 {
79  if (time.value() == 0) {
81  } else {
83  if (MaxTick - now < time.value())
85  ::sc_gem5::scheduler.start(now + time.value(), p == SC_RUN_TO_TIME);
86  }
87 }
88 
89 void
91 {
92  if (sc_is_running()) {
94  return;
95  }
96  _stop_mode = mode;
97 }
98 
101 {
102  return _stop_mode;
103 }
104 
105 void
107 {
108  static bool stop_called = false;
109  if (stop_called) {
110  static bool stop_warned = false;
111  if (!stop_warned)
113  stop_warned = true;
114  return;
115  }
116  stop_called = true;
117 
119  return;
120 
121  if ((sc_get_status() & SC_RUNNING)) {
122  bool finish_delta = (_stop_mode == SC_STOP_FINISH_DELTA);
123  ::sc_gem5::scheduler.scheduleStop(finish_delta);
124  } else {
126  }
127 }
128 
129 const sc_time &
131 {
132  static sc_time tstamp(1.0, SC_SEC);
133  tstamp = sc_time::from_value(::sc_gem5::scheduler.getCurTick());
134  return tstamp;
135 }
136 
139 {
140  return sc_gem5::scheduler.numCycles();
141 }
142 
143 bool
145 {
146  return sc_get_status() & (SC_RUNNING | SC_PAUSED);
147 }
148 
149 bool
151 {
153 }
154 
155 bool
157 {
159 }
160 
161 bool
163 {
166 }
167 
168 sc_time
170 {
171  return sc_time::from_value(::sc_gem5::scheduler.timeToPending());
172 }
173 
174 sc_status
176 {
178 }
179 
180 std::ostream &
181 operator << (std::ostream &os, sc_status s)
182 {
183  switch (s) {
184  case SC_ELABORATION:
185  os << "SC_ELABORATION";
186  break;
188  os << "SC_BEFORE_END_OF_ELABORATION";
189  break;
191  os << "SC_END_OF_ELABORATION";
192  break;
194  os << "SC_START_OF_SIMULATION";
195  break;
196  case SC_RUNNING:
197  os << "SC_RUNNING";
198  break;
199  case SC_PAUSED:
200  os << "SC_PAUSED";
201  break;
202  case SC_STOPPED:
203  os << "SC_STOPPED";
204  break;
206  os << "SC_END_OF_SIMULATION";
207  break;
208 
209  // Nonstandard
211  os << "SC_END_OF_INITIALIZATION";
212  break;
213  case SC_END_OF_UPDATE:
214  os << "SC_END_OF_UPDATE";
215  break;
216  case SC_BEFORE_TIMESTEP:
217  os << "SC_BEFORE_TIMESTEP";
218  break;
219 
220  default:
221  if (s & SC_STATUS_ANY) {
222  const char *prefix = "(";
223  for (sc_status m = (sc_status)0x1;
224  m < SC_STATUS_ANY; m = (sc_status)(m << 1)) {
225  if (m & s) {
226  os << prefix;
227  prefix = "|";
228  os << m;
229  }
230  }
231  os << ")";
232  } else {
233  ccprintf(os, "%#x", s);
234  }
235  }
236 
237  return os;
238 }
239 
240 } // namespace sc_core
void ccprintf(cp::Print &print)
Definition: cprintf.hh:131
sc_stop_mode sc_get_stop_mode()
Definition: sc_main.cc:100
bool sc_is_running()
Definition: sc_main.cc:144
void sc_start()
Definition: sc_main.cc:63
bool sc_pending_activity_at_future_time()
Definition: sc_main.cc:156
Bitfield< 0 > m
void sc_set_stop_mode(sc_stop_mode mode)
Definition: sc_main.cc:90
void start(Tick max_tick, bool run_to_time)
Definition: scheduler.cc:401
bool sc_pending_activity()
Definition: sc_main.cc:162
const char *const * argv()
static sc_core::sc_status status()
Definition: kernel.cc:56
Bitfield< 4, 0 > mode
uint64_t numCycles()
Definition: scheduler.hh:171
std::ostream & operator<<(std::ostream &os, sc_status s)
Definition: sc_main.cc:181
const char SC_ID_STOP_MODE_AFTER_START_[]
Definition: messages.cc:115
#define SC_REPORT_WARNING(msg_type, msg)
Bitfield< 17 > os
Definition: misc.hh:805
void scheduleStop(bool finish_delta)
Definition: scheduler.cc:470
static sc_time from_value(sc_dt::uint64)
Definition: sc_time.cc:212
const Tick MaxTick
Definition: types.hh:65
sc_dt::uint64 value() const
Definition: sc_time.cc:117
Bitfield< 4 > s
uint64_t Tick
Tick count type.
Definition: types.hh:63
void sc_stop()
Definition: sc_main.cc:106
bool sc_pending_activity_at_current_time()
Definition: sc_main.cc:150
Scheduler scheduler
Definition: scheduler.cc:491
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
sc_status sc_get_status()
Definition: sc_main.cc:175
const sc_time & sc_time_stamp()
Definition: sc_main.cc:130
sc_starvation_policy
Definition: sc_main.hh:48
uint64_t uint64
Definition: sc_nbdefs.hh:172
static void stop()
Definition: kernel.cc:142
const char *const * sc_argv()
Definition: sc_main.cc:57
sc_stop_mode
Definition: sc_main.hh:64
#define SC_REPORT_ERROR(msg_type, msg)
const char SC_ID_SIMULATION_TIME_OVERFLOW_[]
Definition: messages.cc:109
const char SC_ID_SIMULATION_STOP_CALLED_TWICE_[]
Definition: messages.cc:111
void sc_pause()
Definition: sc_main.cc:70
int sc_argc()
Definition: sc_main.cc:51
sc_dt::uint64 sc_delta_count()
Definition: sc_main.cc:138
ScMainFiber scMainFiber
Bitfield< 0 > p
sc_time sc_time_to_pending_activity()
Definition: sc_main.cc:169
sc_status
Definition: sc_main.hh:83

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13