From dd1567e0ec159cd2c38000b641284be32b2540cd Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 21 Oct 2021 16:41:52 +0200 Subject: [PATCH] Add support for tracking modes in channels --- chan.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++--------- chan.h | 8 +++++++- emu.h | 5 +++++ 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/chan.c b/chan.c index 74244f4..e86f9eb 100644 --- a/chan.c +++ b/chan.c @@ -4,7 +4,7 @@ #include "prv.h" void -chan_init(struct ovni_chan *chan, int row, int type, FILE *prv, int64_t *clock) +chan_init(struct ovni_chan *chan, int track, int row, int type, FILE *prv, int64_t *clock) { chan->n = 0; chan->type = type; @@ -13,15 +13,52 @@ chan_init(struct ovni_chan *chan, int row, int type, FILE *prv, int64_t *clock) chan->ev = -1; chan->prv = prv; chan->clock = clock; - chan->t = -1; + chan->t = *clock; chan->row = row; chan->dirty = 0; + chan->track = track; +} + +void +chan_th_init(struct ovni_ethread *th, int chan_index, int track, int row, FILE *prv, int64_t *clock) +{ + struct ovni_chan *chan; + int prvth; + + chan = &th->chan[chan_index]; + prvth = chan_to_prvtype[chan_index][1]; + + chan_init(chan, track, row, prvth, prv, clock); +} + +void +chan_cpu_init(struct ovni_cpu *cpu, int chan_index, int track, int row, FILE *prv, int64_t *clock) +{ + struct ovni_chan *chan; + int prvcpu; + + chan = &cpu->chan[chan_index]; + prvcpu = chan_to_prvtype[chan_index][2]; + + chan_init(chan, track, row, prvcpu, prv, clock); } void chan_enable(struct ovni_chan *chan, int enabled) { + /* Can be dirty */ + + dbg("chan_enable chan=%p enabled=%d\n", (void*) chan, enabled); + + if(chan->enabled == enabled) + { + err("chan already in enabled=%d\n", enabled); + abort(); + } + chan->enabled = enabled; + chan->t = *chan->clock; + chan->dirty = 1; } int @@ -33,15 +70,15 @@ chan_is_enabled(struct ovni_chan *chan) void chan_set(struct ovni_chan *chan, int st) { - dbg("chan_set st=%d", st); + //dbg("chan_set chan=%p st=%d\n", (void*) chan, st); assert(chan->enabled); - assert(chan->dirty == 0); + //assert(chan->dirty == 0); if(chan->n == 0) chan->n = 1; - chan->stack[chan->n] = st; + chan->stack[chan->n - 1] = st; chan->t = *chan->clock; chan->dirty = 1; } @@ -49,7 +86,7 @@ chan_set(struct ovni_chan *chan, int st) void chan_push(struct ovni_chan *chan, int st) { - dbg("chan_push st=%d", st); + //dbg("chan_push chan=%p st=%d\n", (void*) chan, st); assert(chan->enabled); assert(chan->dirty == 0); @@ -70,7 +107,7 @@ chan_pop(struct ovni_chan *chan, int expected_st) { int st; - dbg("chan_pop expexted_st=%d", expected_st); + //dbg("chan_pop chan=%p expected_st=%d\n", (void*) chan, expected_st); assert(chan->enabled); assert(chan->dirty == 0); @@ -100,6 +137,8 @@ chan_pop(struct ovni_chan *chan, int expected_st) void chan_ev(struct ovni_chan *chan, int ev) { + dbg("chan_ev chan=%p ev=%d\n", (void*) chan, ev); + assert(chan->enabled); assert(chan->dirty == 0); assert(ev >= 0); @@ -115,6 +154,9 @@ chan_get_st(struct ovni_chan *chan) if(chan->enabled == 0) return chan->badst; + if(chan->n == 0) + return 0; + assert(chan->n > 0); return chan->stack[chan->n-1]; } @@ -141,8 +183,6 @@ emit_st(struct ovni_chan *chan) { int st; - assert(chan->enabled); - st = chan_get_st(chan); prv_ev(chan->prv, chan->row, chan->t, chan->type, st); @@ -155,6 +195,8 @@ chan_emit(struct ovni_chan *chan) if(chan->dirty == 0) return; + //dbg("chan_emit chan=%p\n", (void*) chan); + /* Emit badst if disabled */ if(chan->enabled == 0) { diff --git a/chan.h b/chan.h index 2e60c35..3c4cbd8 100644 --- a/chan.h +++ b/chan.h @@ -4,7 +4,13 @@ #include "emu.h" void -chan_init(struct ovni_chan *chan, int row, int type, FILE *prv, int64_t *clock); +chan_init(struct ovni_chan *chan, int track, int row, int type, FILE *prv, int64_t *clock); + +void +chan_th_init(struct ovni_ethread *th, int chan_index, int track, int row, FILE *prv, int64_t *clock); + +void +chan_cpu_init(struct ovni_cpu *cpu, int chan_index, int track, int row, FILE *prv, int64_t *clock); void chan_enable(struct ovni_chan *chan, int enabled); diff --git a/emu.h b/emu.h index 53dcd31..15e3ab1 100644 --- a/emu.h +++ b/emu.h @@ -66,6 +66,11 @@ struct nosv_task_type { #define MAX_CHAN_STACK 128 +enum chan_track { + CHAN_TRACK_NONE = 0, + CHAN_TRACK_TH_RUNNING, +}; + struct ovni_chan { /* Number of states in the stack */ int n;