2022-09-19 12:39:02 +02:00
|
|
|
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
2021-11-12 11:36:27 +01:00
|
|
|
|
2021-10-25 16:57:31 +02:00
|
|
|
#include "uthash.h"
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "chan.h"
|
2021-10-25 16:57:31 +02:00
|
|
|
#include "emu.h"
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "ovni.h"
|
2021-10-25 16:57:31 +02:00
|
|
|
#include "prv.h"
|
|
|
|
|
|
|
|
/* --------------------------- init ------------------------------- */
|
|
|
|
|
|
|
|
void
|
2021-12-03 16:24:41 +01:00
|
|
|
hook_init_nodes(struct ovni_emu *emu)
|
2021-10-25 16:57:31 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_cpu *cpu;
|
|
|
|
size_t i;
|
|
|
|
int row;
|
|
|
|
FILE *prv_th, *prv_cpu;
|
|
|
|
int64_t *clock;
|
|
|
|
struct ovni_chan **uth, **ucpu;
|
|
|
|
|
|
|
|
clock = &emu->delta_time;
|
|
|
|
prv_th = emu->prv_thread;
|
|
|
|
prv_cpu = emu->prv_cpu;
|
|
|
|
|
|
|
|
/* Init the channels in all threads */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (i = 0; i < emu->total_nthreads; i++) {
|
2021-10-25 16:57:31 +02:00
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
|
|
|
uth = &emu->th_chan;
|
|
|
|
|
2021-12-03 16:24:41 +01:00
|
|
|
chan_th_init(th, uth, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2021-10-25 16:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the channels in all cpus */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (i = 0; i < emu->total_ncpus; i++) {
|
2021-10-25 16:57:31 +02:00
|
|
|
cpu = emu->global_cpu[i];
|
|
|
|
row = cpu->gindex + 1;
|
|
|
|
ucpu = &emu->cpu_chan;
|
|
|
|
|
2021-12-03 16:24:41 +01:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-10-25 16:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- pre ------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2021-11-12 11:36:27 +01:00
|
|
|
pre_subsystem(struct ovni_emu *emu, int st)
|
2021-10-25 16:57:31 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-11-12 11:36:27 +01:00
|
|
|
struct ovni_chan *chan;
|
2021-10-25 16:57:31 +02:00
|
|
|
|
|
|
|
th = emu->cur_thread;
|
2021-12-03 16:24:41 +01:00
|
|
|
chan = &th->chan[CHAN_NODES_SUBSYSTEM];
|
2021-10-25 16:57:31 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
2021-10-25 16:57:31 +02:00
|
|
|
case '[':
|
2021-11-12 11:36:27 +01:00
|
|
|
chan_push(chan, st);
|
2021-10-25 16:57:31 +02:00
|
|
|
break;
|
|
|
|
case ']':
|
2021-11-12 11:36:27 +01:00
|
|
|
chan_pop(chan, st);
|
2021-10-25 16:57:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.value);
|
2021-10-25 16:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-12-03 16:24:41 +01:00
|
|
|
hook_pre_nodes(struct ovni_emu *emu)
|
2021-10-25 16:57:31 +02:00
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->cur_ev->header.model != 'D')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nodes: unexpected event with model %c\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.model);
|
2021-12-07 19:52:48 +01:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (!emu->cur_thread->is_running)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nodes: current thread %d not running\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_thread->tid);
|
|
|
|
|
|
|
|
switch (emu->cur_ev->header.category) {
|
|
|
|
case 'R':
|
|
|
|
pre_subsystem(emu, ST_NODES_REGISTER);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
pre_subsystem(emu, ST_NODES_UNREGISTER);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
pre_subsystem(emu, ST_NODES_IF0_WAIT);
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
pre_subsystem(emu, ST_NODES_IF0_INLINE);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
pre_subsystem(emu, ST_NODES_TASKWAIT);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
pre_subsystem(emu, ST_NODES_CREATE);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
pre_subsystem(emu, ST_NODES_SUBMIT);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
pre_subsystem(emu, ST_NODES_SPAWN);
|
|
|
|
break;
|
2021-10-25 16:57:31 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|