2021-11-12 11:36:27 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-10-25 16:57:31 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include "uthash.h"
|
|
|
|
|
|
|
|
#include "ovni.h"
|
|
|
|
#include "emu.h"
|
|
|
|
#include "prv.h"
|
|
|
|
#include "chan.h"
|
|
|
|
|
|
|
|
/* --------------------------- init ------------------------------- */
|
|
|
|
|
|
|
|
void
|
2021-11-12 11:06:34 +01:00
|
|
|
hook_init_nanos6(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 */
|
|
|
|
for(i=0; i<emu->total_nthreads; i++)
|
|
|
|
{
|
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
|
|
|
uth = &emu->th_chan;
|
|
|
|
|
2021-11-12 11:36:27 +01:00
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_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 */
|
|
|
|
for(i=0; i<emu->total_ncpus; i++)
|
|
|
|
{
|
|
|
|
cpu = emu->global_cpu[i];
|
|
|
|
row = cpu->gindex + 1;
|
|
|
|
ucpu = &emu->cpu_chan;
|
|
|
|
|
2021-11-12 11:36:27 +01:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_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-11-12 11:36:27 +01:00
|
|
|
chan = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
2021-10-25 16:57:31 +02:00
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
|
|
|
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:
|
2021-11-12 11:36:27 +01:00
|
|
|
err("unexpected value '%c' (expecting '[' or ']')\n", emu->cur_ev->header.value);
|
2021-10-25 16:57:31 +02:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-11-12 11:06:34 +01:00
|
|
|
hook_pre_nanos6(struct ovni_emu *emu)
|
2021-10-25 16:57:31 +02:00
|
|
|
{
|
2021-11-12 11:36:27 +01:00
|
|
|
// Ensure that the thread is running
|
|
|
|
assert(emu->cur_thread->is_running != 0);
|
2021-10-25 16:57:31 +02:00
|
|
|
assert(emu->cur_ev->header.model == 'L');
|
|
|
|
|
|
|
|
switch(emu->cur_ev->header.category)
|
|
|
|
{
|
2021-11-12 16:15:33 +01:00
|
|
|
case 'R': pre_subsystem(emu, ST_NANOS6_REGISTER); break;
|
|
|
|
case 'U': pre_subsystem(emu, ST_NANOS6_UNREGISTER); break;
|
2021-11-12 11:36:27 +01:00
|
|
|
case 'W': pre_subsystem(emu, ST_NANOS6_IF0_WAIT); break;
|
|
|
|
case 'I': pre_subsystem(emu, ST_NANOS6_IF0_INLINE); break;
|
|
|
|
case 'T': pre_subsystem(emu, ST_NANOS6_TASKWAIT); break;
|
2021-11-12 16:15:33 +01:00
|
|
|
case 'C': pre_subsystem(emu, ST_NANOS6_CREATE); break;
|
|
|
|
case 'S': pre_subsystem(emu, ST_NANOS6_SUBMIT); break;
|
2021-11-12 11:36:27 +01:00
|
|
|
case 'P': pre_subsystem(emu, ST_NANOS6_SPAWN); break;
|
2021-10-25 16:57:31 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|