2022-09-19 12:39:02 +02:00
|
|
|
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
2021-10-26 18:42:41 +02:00
|
|
|
|
2021-10-11 17:29:45 +02:00
|
|
|
#include "uthash.h"
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "chan.h"
|
2021-10-11 17:29:45 +02:00
|
|
|
#include "emu.h"
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "ovni.h"
|
2021-10-11 17:29:45 +02:00
|
|
|
#include "prv.h"
|
|
|
|
|
|
|
|
/* --------------------------- init ------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_init_tampi(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_cpu *cpu;
|
2021-10-18 12:47:51 +02:00
|
|
|
size_t i;
|
|
|
|
int row;
|
2021-10-11 17:29:45 +02:00
|
|
|
FILE *prv_th, *prv_cpu;
|
|
|
|
int64_t *clock;
|
2021-10-18 12:47:51 +02:00
|
|
|
struct ovni_chan **uth, **ucpu;
|
2021-10-11 17:29:45 +02:00
|
|
|
|
|
|
|
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-11 17:29:45 +02:00
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
2021-10-18 12:47:51 +02:00
|
|
|
uth = &emu->th_chan;
|
2021-10-11 17:29:45 +02:00
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
chan_th_init(th, uth, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2021-10-11 17:29:45 +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-11 17:29:45 +02:00
|
|
|
cpu = emu->global_cpu[i];
|
|
|
|
row = cpu->gindex + 1;
|
2021-10-18 12:47:51 +02:00
|
|
|
ucpu = &emu->cpu_chan;
|
2021-10-11 17:29:45 +02:00
|
|
|
|
2021-10-21 15:46:32 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-10-11 17:29:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- pre ------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2021-11-29 13:21:06 +01:00
|
|
|
pre_tampi_mode(struct ovni_emu *emu, int state)
|
2021-10-11 17:29:45 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
2021-10-11 17:29:45 +02:00
|
|
|
case '[':
|
2021-11-29 13:21:06 +01:00
|
|
|
chan_push(&th->chan[CHAN_TAMPI_MODE], state);
|
2021-10-11 17:29:45 +02:00
|
|
|
break;
|
|
|
|
case ']':
|
2021-11-29 13:21:06 +01:00
|
|
|
chan_pop(&th->chan[CHAN_TAMPI_MODE], state);
|
2021-10-11 17:29:45 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected event value %c for tampi mode\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.value);
|
2021-10-11 17:29:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_pre_tampi(struct ovni_emu *emu)
|
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->cur_ev->header.model != 'T')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_tampi: unexpected event with model %c\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.model);
|
2021-10-11 17:29:45 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.category) {
|
|
|
|
case 'S':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_SEND);
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_RECV);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_ISEND);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_IRECV);
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_WAIT);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
pre_tampi_mode(emu, ST_TAMPI_WAITALL);
|
|
|
|
break;
|
2021-10-11 17:29:45 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|