SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
simulation.h
Go to the documentation of this file.
1/*
2 © 2014 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_SIMULATION_H
15#define SIMICS_SYSTEMC_SIMULATION_H
16
17#include <systemc>
18
19#include <simics/base/iface-call.h>
20
21#include <simics/devs/frequency.h>
22#include <simics/model-iface/event-delta.h>
23#include <simics/model-iface/co-execute.h>
34
35#include <vector>
36
37namespace simics {
38namespace systemc {
39
53 public:
54 Simulation(ConfObjectRef o, InternalInterface *internal);
55 virtual ~Simulation();
56
57 // ExecuteInterface
58 void run() override;
59 void stop() override;
60 void switch_in() override;
61 void switch_out() override;
62
63 // EventDeltaInterface
64 uint64 set_delta(conf_object_t *NOTNULL event_handler_obj,
65 const event_class_t *next_event_ec,
66 uint64 delta) override;
67 uint64 get_delta(conf_object_t *NOTNULL event_handler_obj) override;
68
69 // FrequencyInterface
70 double get() const override;
71
72 // ConcurrencyGroupInterface
73 std::vector<conf_object_t *> serialized_memory_group(
74 unsigned group_index) override;
75 std::vector<conf_object_t *> execution_group(unsigned group_index) override;
76
77 // ConcurrencyModeInterface
78 concurrency_mode_t supported_modes() override;
79 concurrency_mode_t current_mode() override;
80 void switch_mode(concurrency_mode_t mode) override;
81
82 // ExecuteControlInterface
83 void message_pending() override;
84 void yield_request() override;
85
86 // SimulationInterface
87 int runDeltaPhase(int count) override;
88 bool runSimulation(sc_core::sc_time t) override;
89 void stopSimulation() override;
90 sc_core::sc_simcontext* context() const override;
91 ConfObjectRef simics_object() const override;
92
93 protected:
94 // methods called from Adapter
95 void set_run_next_delta(int count);
96 uint64_t get_sc_time_resolution() const {
97 return time_resolution_;
98 }
99 void set_sc_time_resolution(uint64_t time_resolution);
100 void set_frequency(double frequency);
101 void finalize();
102
103 virtual void callHandleEvent();
104
105 const std::vector<conf_object_t*>& instances() const;
106
107 private:
108 int runDeltaPhaseNoStateCheck(int count);
109 bool isPausePending();
110 bool hasPendingAsyncActivity() const;
111 bool runSimulationNoCallHandleEvent(const sc_core::sc_time &t);
112
113 static void atSimulationStopped(lang_void *simulation, conf_object_t *obj);
114 static std::vector<conf_object_t*> instancesNotInCell(conf_object_t *cell);
115 static void onCellChange(lang_void *callback_data, conf_object_t *obj,
116 conf_object_t *old_cell, conf_object_t *new_cell);
117
118 // Helper to group all instances in the same TD
119 struct InstanceTracker {
120 explicit InstanceTracker(conf_object_t *NOTNULL object);
121 virtual ~InstanceTracker();
122 conf_object_t *object_;
123 };
124 static std::vector<conf_object_t*> instances_;
125
126 class YieldRequest : public sc_core::sc_prim_channel {
127 public:
128 YieldRequest(conf_object_t *co_execute, const char* name)
129 : sc_core::sc_prim_channel(name) {
130 INIT_IFACE(&execute_, execute, co_execute);
131 }
132 void update(void) override {
133 if (execute_.obj)
134 CALL(execute_, stop)();
135 }
136 IFACE_OBJ(execute) execute_;
137 };
138
139 ConfObjectRef simics_object_;
140 SimulationDeleter *simulation_deleter_;
141 Kernel kernel_;
142 uint64 delta_;
143 sc_core::sc_time sc_time_when_set_delta_;
144 IFACE_OBJ(event_handler) event_handler_;
145 concurrency_mode_t concurrency_mode_;
146 YieldRequest yield_request_;
147 bool break_pending_;
148 InternalInterface *internal_;
149 InstanceTracker instance_tracker_;
150 // The frequency value returned for the FrequencyInterface. It represents
151 // the number of Simics cycles that equate to one second in SystemC.
152 double frequency_;
153 // The SystemC time resolution in number of ps
154 uint64_t time_resolution_;
155 // True only after sc_start has advanced SC time since the last
156 // set_delta call. Allows get_delta to skip the SC context switch in
157 // the common case.
158 bool sc_time_stamp_changed_ {false};
159};
160
161} // namespace systemc
162} // namespace simics
163
164#endif
Definition: internal_interface.h:23
Provides the interface to the SystemC kernel.
Definition: simulation.h:52
bool runSimulation(sc_core::sc_time t) override
ConfObjectRef simics_object() const override
uint64_t get_sc_time_resolution() const
Definition: simulation.h:96
void switch_mode(concurrency_mode_t mode) override
void set_sc_time_resolution(uint64_t time_resolution)
uint64 set_delta(conf_object_t *NOTNULL event_handler_obj, const event_class_t *next_event_ec, uint64 delta) override
virtual void callHandleEvent()
double get() const override
int runDeltaPhase(int count) override
void yield_request() override
sc_core::sc_simcontext * context() const override
concurrency_mode_t supported_modes() override
void set_run_next_delta(int count)
concurrency_mode_t current_mode() override
void switch_out() override
uint64 get_delta(conf_object_t *NOTNULL event_handler_obj) override
Simulation(ConfObjectRef o, InternalInterface *internal)
void set_frequency(double frequency)
std::vector< conf_object_t * > execution_group(unsigned group_index) override
void message_pending() override
void stopSimulation() override
const std::vector< conf_object_t * > & instances() const
std::vector< conf_object_t * > serialized_memory_group(unsigned group_index) override
Simics concurrency group interface.
Definition: concurrency_group_interface.h:26
Simics concurrency mode interface.
Definition: concurrency_mode_interface.h:24
Definition: event_delta_interface.h:25
Simics execute control interface.
Definition: execute_control_interface.h:24
Definition: execute_interface.h:22
Definition: frequency_interface.h:24
Interface to the SystemC simulation.
Definition: simulation_interface.h:25
Definition: argument_registry.h:24
Definition: adapter.h:79