gem5  v21.1.0.2
sc_spawn.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/logging.hh"
29 #include "systemc/core/process.hh"
40 
41 namespace sc_gem5
42 {
43 
44 Process *
45 spawnWork(ProcessFuncWrapper *func, const char *name,
46  const ::sc_core::sc_spawn_options *opts)
47 {
48  bool method = false;
49  bool dontInitialize = false;
50  if (opts) {
51  if (opts->_spawnMethod)
52  method = true;
53  if (opts->_dontInitialize)
54  dontInitialize = true;
55  if (opts->_stackSize != -1)
56  warn("Ignoring request to set stack size.\n");
57  }
58 
59  if (!name || name[0] == '\0') {
60  if (method)
61  name = ::sc_core::sc_gen_unique_name("method_p");
62  else
63  name = ::sc_core::sc_gen_unique_name("thread_p");
64  }
65 
66  Process *proc;
67  if (method)
68  proc = new Method(name, func);
69  else
70  proc = new Thread(name, func);
71 
72  proc->dontInitialize(dontInitialize);
73 
74  if (opts) {
75  for (auto e: opts->_events)
77 
78  for (auto p: opts->_ports)
80 
81  for (auto e: opts->_exports)
83 
84  for (auto i: opts->_interfaces)
86 
87  for (auto f: opts->_finders)
89 
90  for (auto p: opts->_in_resets)
91  newReset(p.target, proc, p.sync, p.value);
92 
93  for (auto p: opts->_inout_resets)
94  newReset(p.target, proc, p.sync, p.value);
95 
96  for (auto p: opts->_out_resets)
97  newReset(p.target, proc, p.sync, p.value);
98 
99  for (auto i: opts->_if_resets)
100  newReset(i.target, proc, i.sync, i.value);
101  }
102 
103  if (opts && opts->_dontInitialize &&
104  opts->_events.empty() && opts->_ports.empty() &&
105  opts->_exports.empty() && opts->_interfaces.empty() &&
106  opts->_finders.empty()) {
108  proc->name());
109  }
110 
111  scheduler.reg(proc);
112 
113  return proc;
114 }
115 
116 } // namespace sc_gem5
117 
118 namespace sc_core
119 {
120 
122  _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
123 {}
124 
125 
126 void
128 {
129  _spawnMethod = true;
130 }
131 
132 void
134 {
135  _dontInitialize = true;
136 }
137 
138 void
140 {
141  _stackSize = ss;
142 }
143 
144 
145 void
147 {
148  _events.push_back(e);
149 }
150 
151 void
153 {
154  _ports.push_back(p);
155 }
156 
157 void
159 {
160  _exports.push_back(e);
161 }
162 
163 void
165 {
166  _interfaces.push_back(i);
167 }
168 
169 void
171 {
172  _finders.push_back(f);
173 }
174 
175 
176 void
178 {
179  _in_resets.emplace_back(&port, value, true);
180 }
181 
182 void
184 {
185  _inout_resets.emplace_back(&port, value, true);
186 }
187 
188 void
190 {
191  _out_resets.emplace_back(&port, value, true);
192 }
193 
194 void
196  const sc_signal_in_if<bool> &iface, bool value)
197 {
198  _if_resets.emplace_back(&iface, value, true);
199 }
200 
201 
202 void
204 {
205  _in_resets.emplace_back(&port, value, false);
206 }
207 
208 void
210 {
211  _inout_resets.emplace_back(&port, value, false);
212 }
213 
214 void
216 {
217  _out_resets.emplace_back(&port, value, false);
218 }
219 
220 void
222  const sc_signal_in_if<bool> &iface, bool value)
223 {
224  _if_resets.emplace_back(&iface, value, false);
225 }
226 
227 } // namespace sc_core
sc_core::sc_port_base
Definition: sc_port.hh:74
sc_core::sc_in< bool >
Definition: sc_in.hh:165
sc_core::sc_spawn_options::_if_resets
std::vector< Reset< const sc_signal_in_if< bool > > > _if_resets
Definition: sc_spawn.hh:145
sc_gem5::Scheduler::reg
void reg(Process *p)
Definition: scheduler.cc:146
warn
#define warn(...)
Definition: logging.hh:245
sc_core::sc_spawn_options::_events
std::vector< const sc_event * > _events
Definition: sc_spawn.hh:126
sc_core::sc_spawn_options::async_reset_signal_is
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:203
sc_core::sc_signal_in_if< bool >
Definition: sc_signal_in_if.hh:74
sc_gem5::newStaticSensitivityEvent
void newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
Definition: sensitivity.cc:122
sc_gem5::ProcessFuncWrapper
Definition: sc_process_handle.hh:43
sc_core::sc_export_base
Definition: sc_export.hh:41
sc_core::sc_spawn_options::set_sensitivity
void set_sensitivity(const sc_event *)
Definition: sc_spawn.cc:146
sc_core::sc_spawn_options::reset_signal_is
void reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:177
sc_core
Definition: messages.cc:31
gem5::ArmISA::f
Bitfield< 6 > f
Definition: misc_types.hh:67
sc_gem5::spawnWork
Process * spawnWork(ProcessFuncWrapper *func, const char *name, const ::sc_core::sc_spawn_options *opts)
Definition: sc_spawn.cc:45
sc_inout.hh
sc_core::sc_interface
Definition: sc_interface.hh:37
sc_core::sc_spawn_options::dont_initialize
void dont_initialize()
Definition: sc_spawn.cc:133
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:64
sc_gem5::Thread
Definition: process_types.hh:53
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
sc_gem5::newStaticSensitivityFinder
void newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
Definition: sensitivity.cc:155
sc_core::sc_spawn_options::_inout_resets
std::vector< Reset< const sc_inout< bool > > > _inout_resets
Definition: sc_spawn.hh:143
sc_core::sc_spawn_options::_out_resets
std::vector< Reset< const sc_out< bool > > > _out_resets
Definition: sc_spawn.hh:144
sc_core::sc_spawn_options::_stackSize
int _stackSize
Definition: sc_spawn.hh:125
sc_core::sc_spawn_options::_in_resets
std::vector< Reset< const sc_in< bool > > > _in_resets
Definition: sc_spawn.hh:142
sc_gem5::newStaticSensitivityExport
void newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
Definition: sensitivity.cc:147
sc_core::sc_event
Definition: sc_event.hh:169
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
sc_core::sc_spawn_options::_finders
std::vector< sc_event_finder * > _finders
Definition: sc_spawn.hh:130
sc_main.hh
sc_core::sc_spawn_options::spawn_method
void spawn_method()
Definition: sc_spawn.cc:127
sc_gem5::Method
Definition: process_types.hh:37
sc_signal_in_if.hh
sc_gem5::newStaticSensitivityPort
void newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
Definition: sensitivity.cc:138
ss
std::stringstream ss
Definition: trace.test.cc:45
sc_core::sc_spawn_options::_ports
std::vector< sc_port_base * > _ports
Definition: sc_spawn.hh:127
messages.hh
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_core::sc_spawn_options::set_stack_size
void set_stack_size(int)
Definition: sc_spawn.cc:139
sc_core::sc_spawn_options::sc_spawn_options
sc_spawn_options()
Definition: sc_spawn.cc:121
sc_in.hh
sc_gem5::newReset
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition: process.cc:425
sc_core::sc_spawn_options::_exports
std::vector< sc_export_base * > _exports
Definition: sc_spawn.hh:128
sc_gem5::Process
Definition: process.hh:62
name
const std::string & name()
Definition: trace.cc:49
sc_module.hh
process.hh
SC_REPORT_WARNING
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report_handler.hh:123
sc_core::SC_ID_DISABLE_WILL_ORPHAN_PROCESS_
const char SC_ID_DISABLE_WILL_ORPHAN_PROCESS_[]
Definition: messages.cc:132
sc_out.hh
sc_gem5::newStaticSensitivityInterface
void newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
Definition: sensitivity.cc:130
sc_gem5::Process::dontInitialize
bool dontInitialize()
Definition: process.hh:133
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
process_types.hh
sc_core::sc_out< bool >
logging.hh
sc_core::sc_inout< bool >
Definition: sc_inout.hh:193
sc_gem5
Definition: sc_clock.cc:41
sc_spawn.hh
sc_core::sc_event_finder
Definition: sc_event.hh:212
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:494
sc_core::sc_spawn_options::_interfaces
std::vector< sc_interface * > _interfaces
Definition: sc_spawn.hh:129
sc_core::sc_spawn_options::_dontInitialize
bool _dontInitialize
Definition: sc_spawn.hh:124
scheduler.hh
sc_core::sc_spawn_options::_spawnMethod
bool _spawnMethod
Definition: sc_spawn.hh:123

Generated on Tue Sep 21 2021 12:25:50 for gem5 by doxygen 1.8.17