Add support for tracking modes in channels

This commit is contained in:
Rodrigo Arias 2021-10-21 16:41:52 +02:00
parent d6afd5c528
commit dd1567e0ec
3 changed files with 63 additions and 10 deletions

60
chan.c
View File

@ -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)
{

8
chan.h
View File

@ -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);

5
emu.h
View File

@ -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;