2021-09-23 10:41:53 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include "uthash.h"
|
|
|
|
|
|
|
|
#include "ovni.h"
|
|
|
|
#include "ovni_trace.h"
|
|
|
|
#include "emu.h"
|
|
|
|
#include "prv.h"
|
2021-10-21 16:15:29 +02:00
|
|
|
#include "chan.h"
|
2021-09-23 10:41:53 +02:00
|
|
|
|
|
|
|
/* This module manages the nos-v subsystem (ss) events, to track which
|
|
|
|
* actions are being performed by each thread at a given time. A stack
|
|
|
|
* of states is stored in each thread, so we remember the path of
|
|
|
|
* execution. Events such as task received by a thread are emitted as
|
|
|
|
* fake events with very short period. */
|
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
/* --------------------------- init ------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_init_nosv_ss(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
int i, row, type, track;
|
|
|
|
FILE *prv;
|
|
|
|
int64_t *clock;
|
|
|
|
|
|
|
|
clock = &emu->delta_time;
|
|
|
|
prv = emu->prv_thread;
|
|
|
|
track = CHAN_TRACK_TH_RUNNING;
|
|
|
|
|
|
|
|
/* Init the channels in all threads */
|
|
|
|
for(i=0; i<emu->total_nthreads; i++)
|
|
|
|
{
|
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
|
|
|
|
|
|
|
chan_th_init(th, CHAN_NOSV_SUBSYSTEM, track, row, prv, clock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 10:41:53 +02:00
|
|
|
/* --------------------------- pre ------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_sched(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-10-21 16:15:29 +02:00
|
|
|
struct ovni_chan *chan;
|
2021-09-23 10:41:53 +02:00
|
|
|
|
|
|
|
th = emu->cur_thread;
|
2021-10-21 16:46:42 +02:00
|
|
|
chan = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
2021-10-21 16:15:29 +02:00
|
|
|
|
2021-09-23 10:41:53 +02:00
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
|
|
|
case 'h':
|
2021-10-21 16:15:29 +02:00
|
|
|
chan_push(chan, ST_SCHED_HUNGRY);
|
2021-09-23 10:41:53 +02:00
|
|
|
break;
|
|
|
|
case 'f': /* Fill: no longer hungry */
|
2021-10-21 16:15:29 +02:00
|
|
|
chan_pop(chan, ST_SCHED_HUNGRY);
|
2021-09-23 10:41:53 +02:00
|
|
|
break;
|
|
|
|
case '[': /* Server enter */
|
2021-10-21 16:15:29 +02:00
|
|
|
chan_push(chan, ST_SCHED_SERVING);
|
2021-09-23 10:41:53 +02:00
|
|
|
break;
|
|
|
|
case ']': /* Server exit */
|
2021-10-21 16:15:29 +02:00
|
|
|
chan_pop(chan, ST_SCHED_SERVING);
|
2021-09-23 10:41:53 +02:00
|
|
|
break;
|
2021-10-21 16:15:29 +02:00
|
|
|
case '@': chan_ev(chan, EV_SCHED_SELF); break;
|
|
|
|
case 'r': chan_ev(chan, EV_SCHED_RECV); break;
|
|
|
|
case 's': chan_ev(chan, EV_SCHED_SEND); break;
|
2021-09-23 10:41:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_submit(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-10-21 16:15:29 +02:00
|
|
|
struct ovni_chan *chan;
|
2021-09-23 10:41:53 +02:00
|
|
|
|
|
|
|
th = emu->cur_thread;
|
2021-10-21 16:46:42 +02:00
|
|
|
chan = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
2021-09-23 10:41:53 +02:00
|
|
|
|
2021-09-23 15:12:55 +02:00
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
2021-10-21 16:15:29 +02:00
|
|
|
case '[': chan_push(chan, ST_SCHED_SUBMITTING); break;
|
|
|
|
case ']': chan_pop(chan, ST_SCHED_SUBMITTING); break;
|
2021-09-23 15:12:55 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 16:05:01 +02:00
|
|
|
static void
|
2021-10-21 16:15:29 +02:00
|
|
|
pre_memory(struct ovni_emu *emu)
|
2021-10-21 16:05:01 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-10-21 16:15:29 +02:00
|
|
|
struct ovni_chan *chan;
|
2021-10-21 16:05:01 +02:00
|
|
|
|
|
|
|
th = emu->cur_thread;
|
2021-10-21 16:46:42 +02:00
|
|
|
chan = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
2021-10-21 16:05:01 +02:00
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
2021-10-21 16:15:29 +02:00
|
|
|
case '[': chan_push(chan, ST_MEM_ALLOCATING); break;
|
|
|
|
case ']': chan_pop(chan, ST_MEM_ALLOCATING); break;
|
2021-10-21 16:05:01 +02:00
|
|
|
default:
|
2021-10-21 16:15:29 +02:00
|
|
|
break;
|
2021-10-21 16:05:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 10:41:53 +02:00
|
|
|
void
|
|
|
|
hook_pre_nosv_ss(struct ovni_emu *emu)
|
|
|
|
{
|
2021-10-21 16:15:29 +02:00
|
|
|
assert(emu->cur_ev->header.model == 'V');
|
|
|
|
|
2021-10-11 15:46:49 +02:00
|
|
|
switch(emu->cur_ev->header.category)
|
2021-09-23 10:41:53 +02:00
|
|
|
{
|
2021-10-21 16:15:29 +02:00
|
|
|
case 'S': pre_sched(emu); break;
|
|
|
|
case 'U': pre_submit(emu); break;
|
|
|
|
case 'M': pre_memory(emu); break;
|
2021-09-23 10:41:53 +02:00
|
|
|
default:
|
2021-09-27 17:42:14 +02:00
|
|
|
break;
|
2021-09-23 10:41:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- emit ------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_emit_nosv_ss(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-10-21 16:15:29 +02:00
|
|
|
struct ovni_chan *chan;
|
2021-09-23 10:41:53 +02:00
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
chan_emit(&th->chan[CHAN_NOSV_SUBSYSTEM]);
|
2021-09-23 10:41:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- post ------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_post_nosv_ss(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
}
|