91 memset(area, 0,
size);
133 while (!ca_tlist_is_empty(&state->
ss_future)) {
164 ca_tlist_add_before(
found, call);
228 err(EX_UNAVAILABLE,
"resume: swapcontext");
243 err(EX_UNAVAILABLE,
"suspend: swapcontext");
262 return (
void *)((((uint64_t)p0) << 32) | (((uint64_t)p1) & 0xffffffff));
267 return ((uint64_t)
p) >> 32;
272 return ((uint64_t)
p) & 0xffffffff;
276 int state0,
int state1,
int thread0,
int thread1,
277 int datum0,
int datum1)
294 unsigned stacksize,
sim_func_t func,
void *arg)
306 stacksize = 4 * 1024 *
sizeof(
int);
307 if (stacksize < MINSIGSTKSZ)
308 stacksize = MINSIGSTKSZ;
312 err(EX_UNAVAILABLE,
"getcontext");
315 thread->st_ctx.uc_stack.ss_sp =
thread->st_stack = valloc(stacksize);
316 thread->st_ctx.uc_stack.ss_size =
thread->st_size = stacksize;
317 thread->st_ctx.uc_stack.ss_flags = 0;
318 sim_thr_tlink_init(
thread);
320 err(EX_TEMPFAIL,
"malloc(%d) of a stack", stacksize);
337 sim_thr_tlink_fini(
thread);
387 sim_thr_tlist_init(&
chan->ch_threads);
402 sim_thr_tlist_fini(&
chan->ch_threads);
414 sim_thr_tlist_add_tail(&
chan->ch_threads,
thread);
439 t = sim_thr_tlist_pop(&
chan->ch_threads);
440 cnt_mod(&
chan->ch_cnt_sleep,
t->st_sim->ss_bolt -
t->st_blocked);
449 if (!sim_thr_tlist_is_empty(&
chan->ch_threads))
458 while (!sim_thr_tlist_is_empty(&
chan->ch_threads))
471 M0_INTERNAL
unsigned long long sim_rnd(
unsigned long long a,
472 unsigned long long b)
479 unsigned long long scaled;
484 scaled = ((random()*(b - a + 1)) >> 31) + a;
486 static unsigned long seed = 1;
488 seed = (1103515245 *
seed + 12345) & 0xffffffff;
490 scaled = ((
seed * (b - a + 1)) >> 32) + a;
519 err(EX_SOFTWARE,
"vasprintf");
535 printf(
"[%15.9f] ",
s->ss_bolt / 1000000000.);
537 printf(
"[---------------] ");
static void sim_thread_fix(struct sim_thread *thread)
int sim_call_t(struct sim_callout *)
static void ptr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
static struct m0_addb2_philter p
static struct sim_thread * sim_current
M0_INTERNAL void sim_thread_init(struct sim *state, struct sim_thread *thread, unsigned stacksize, sim_func_t func, void *arg)
M0_INTERNAL void sim_init(struct sim *state)
M0_INTERNAL void sim_chan_fini(struct sim_chan *chan)
M0_INTERNAL void sim_free(void *ptr)
M0_INTERNAL struct sim_thread * sim_thread_current(void)
enum m0_trace_level level
void sim_func_t(struct sim *, struct sim_thread *, void *)
M0_INTERNAL void sim_log(struct sim *s, enum sim_log_level level, const char *format,...)
static int sim_encode1(void *p)
M0_INTERNAL void sim_chan_broadcast(struct sim_chan *chan)
static int sim_wakeup(struct sim_callout *call)
M0_INTERNAL void cnt_init(struct cnt *cnt, struct cnt *parent, const char *format,...)
M0_INTERNAL void cnt_global_fini(void)
M0_INTERNAL void sim_chan_init(struct sim_chan *chan, char *format,...)
M0_INTERNAL void sim_thread_exit(struct sim_thread *thread)
static void sim_wakeup_post(struct sim *sim, struct sim_thread *thread, sim_time_t nap)
static void sim_thread_suspend(struct sim_thread *thread)
M0_INTERNAL void sim_run(struct sim *state)
M0_INTERNAL void sim_global_fini(void)
M0_INTERNAL void cnt_mod(struct cnt *cnt, cnt_t val)
M0_INTERNAL void sim_thread_fini(struct sim_thread *thread)
M0_TL_DEFINE(ca, static, struct sim_callout)
static struct m0_thread t[8]
M0_INTERNAL void sim_timer_add(struct sim *state, sim_time_t delta, sim_call_t *cfunc, void *datum)
char * fmt(const char *format,...) __attribute__((format(printf
M0_INTERNAL void sim_sleep(struct sim_thread *thread, sim_time_t nap)
M0_INTERNAL void sim_chan_wait(struct sim_chan *chan, struct sim_thread *thread)
unsigned long long sim_time_t
static void sim_thread_resume(struct sim_thread *thread)
M0_INTERNAL void sim_chan_signal(struct sim_chan *chan)
M0_INTERNAL unsigned long long sim_rnd(unsigned long long a, unsigned long long b)
M0_INTERNAL void * sim_alloc(size_t size)
M0_TL_DESCR_DEFINE(ca, "call-outs", static, struct sim_callout, sc_linkage, sc_magic, M0_DESIM_SIM_CALLOUT_MAGIC, M0_DESIM_SIM_CALLOUT_HEAD_MAGIC)
static int sim_encode0(void *p)
M0_INTERNAL void sim_name_vaset(char **name, const char *format, va_list valist)
int vasprintf(char **strp, const char *fmt, va_list ap)
static struct m0_chan chan[RDWR_REQUEST_MAX]
M0_INTERNAL void cnt_global_init(void)
static void sim_trampoline(int func0, int func1, int state0, int state1, int thread0, int thread1, int datum0, int datum1)
M0_INTERNAL void sim_timer_rearm(struct sim_callout *call, sim_time_t delta, sim_call_t *cfunc, void *datum)
static void sim_call_place(struct sim *sim, struct sim_callout *call)
static void sim_timer_init(struct sim *state, struct sim_callout *call, sim_time_t delta, sim_call_t *cfunc, void *datum)
M0_INTERNAL void sim_name_set(char **name, const char *format,...)
static void sim_chan_wake_head(struct sim_chan *chan)
M0_INTERNAL void sim_fini(struct sim *state)
static int scan(struct scanner *s)
#define m0_tl_find(name, var, head,...)
static struct m0_addb2_source * s
static ucontext_t sim_idle_ctx
static void * sim_decode(int p0, int p1)
M0_INTERNAL int sim_global_init(void)
M0_INTERNAL void cnt_fini(struct cnt *cnt)