32 #ifdef HAVE_PREEMPTION 34 #include <timestretch.h> 42 extern void preempt_callback(
void);
44 static simtime_t *
volatile min_in_transit_lvt;
50 __thread
volatile bool platform_mode =
true;
52 void preempt_init(
void)
54 register unsigned int i;
62 min_in_transit_lvt[i] =
INFTY;
67 if (ret == TS_OPEN_ERROR) {
68 rootsim_error(
false,
"libtimestretch unavailable: is the module mounted? Will run without preemption...\n");
77 void preempt_fini(
void)
83 rsfree(min_in_transit_lvt);
85 printf(
"Total preemptions: %d\n",
atomic_read(&preempt_count));
92 void reset_min_in_transit(
unsigned int thread)
99 local_min = min_in_transit_lvt[thread];
107 void update_min_in_transit(
unsigned int thread,
simtime_t lvt)
115 local_min = min_in_transit_lvt[thread];
117 if (lvt >= local_min) {
121 }
while (!CAS((uint64_t *) & min_in_transit_lvt[thread],
UNION_CAST(local_min, uint64_t),
UNION_CAST(lvt, uint64_t)));
124 __thread
bool rolling_back =
false;
133 __attribute__((used))
152 if (platform_mode || rolling_back) {
155 }
else if (min_in_transit_lvt[
local_tid] < current_lvt) {
158 switch_to_platform_mode();
193 void enable_preemption(
void)
195 if (register_ts_thread() != TS_REGISTER_OK) {
196 rootsim_error(
true,
"Error activating high-frequency interrupts. Aborting...\n");
199 if (register_callback(preempt_callback) != TS_REGISTER_CALLBACK_OK) {
200 rootsim_error(
true,
"Error registering callback from kernel module. Aborting...\n");
203 if (ts_start(0) != TS_START_OK) {
204 rootsim_error(
true,
"General error\n");
209 void disable_preemption(
void)
211 if (deregister_ts_thread() != TS_DEREGISTER_OK) {
212 rootsim_error(
true,
"Error de-activating high-frequency interrupts. Aborting...\n",);
#define context_switch(context_old, context_new)
Swicth machine context for userspace context switch. This is used to schedule a LP or return control ...
#define atomic_read(v)
Read operation on an atomic counter.
Core ROOT-Sim functionalities.
unsigned int n_cores
Total number of cores required for simulation.
#define UNION_CAST(x, destType)
Macro to "legitimately" pun a type.
static simtime_t * local_min
The local (per-thread) minimum. It's not TLS, rather an array, to allow reduction by master thread...
Dynamic Memory Logger and Restorer (DyMeLoR)
The ROOT-Sim scheduler main module header.
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
#define atomic_set(v, i)
Set operation on an atomic counter.
#define INFTY
Infinite timestamp: this is the highest timestamp in a simulation run.
double simtime_t
This defines the type with whom timestamps are represented.
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
__thread kernel_context_t kernel_context
This is the execution context of the simulation kernel.
short unsigned int state
Current execution state of the LP.
LP_context_t context
LP execution state.
__thread unsigned int local_tid
bool disable_preemption
If compiled for preemptive Time Warp, it can be disabled at runtime.