2022-09-19 12:39:02 +02:00
|
|
|
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
2022-07-01 17:54:18 +02:00
|
|
|
|
|
|
|
#include "uthash.h"
|
|
|
|
#include "utlist.h"
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "chan.h"
|
2022-07-01 17:54:18 +02:00
|
|
|
#include "emu.h"
|
|
|
|
#include "emu_task.h"
|
2022-09-29 15:34:44 +02:00
|
|
|
#include "ovni.h"
|
2022-07-01 17:54:18 +02:00
|
|
|
#include "prv.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_init_nanos6(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_cpu *cpu;
|
|
|
|
struct ovni_chan **uth, **ucpu;
|
|
|
|
int row;
|
|
|
|
FILE *prv_th, *prv_cpu;
|
|
|
|
int64_t *clock;
|
|
|
|
|
|
|
|
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 (size_t i = 0; i < emu->total_nthreads; i++) {
|
2022-07-01 17:54:18 +02:00
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
|
|
|
|
|
|
|
uth = &emu->th_chan;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_SUBSYSTEM, CHAN_TRACK_TH_ACTIVE, 0, 0, 1, row, prv_th, clock);
|
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_RANK, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
|
|
|
chan_th_init(th, uth, CHAN_NANOS6_THREAD, CHAN_TRACK_NONE, 0, 1, 1, row, prv_th, clock);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the Nanos6 channels in all cpus */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (size_t i = 0; i < emu->total_ncpus; i++) {
|
2022-07-01 17:54:18 +02:00
|
|
|
cpu = emu->global_cpu[i];
|
|
|
|
row = cpu->gindex + 1;
|
|
|
|
ucpu = &emu->cpu_chan;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2022-07-01 17:54:18 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2022-09-29 15:34:44 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_RANK, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_THREAD, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2022-09-01 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init task stack */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (size_t i = 0; i < emu->total_nthreads; i++) {
|
2022-09-01 17:02:02 +02:00
|
|
|
th = emu->global_thread[i];
|
|
|
|
th->nanos6_task_stack.thread = th;
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- pre ------------------------------- */
|
|
|
|
|
2022-09-21 13:02:24 +02:00
|
|
|
static void
|
|
|
|
chan_task_stopped(struct ovni_emu *emu)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
th = emu->cur_thread;
|
|
|
|
|
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TASKID], 0);
|
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TYPE], 0);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->cur_loom->rank_enabled)
|
2022-07-01 17:54:18 +02:00
|
|
|
chan_set(&th->chan[CHAN_NANOS6_RANK], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-09-21 13:02:24 +02:00
|
|
|
chan_task_running(struct ovni_emu *emu, struct task *task)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_eproc *proc;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
proc = emu->cur_proc;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (task->id == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "task id cannot be 0\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (task->type->gid == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "task type gid cannot be 0\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (proc->appid <= 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "app id must be positive\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TASKID], task->id);
|
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TYPE], task->type->gid);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->cur_loom->rank_enabled)
|
2022-07-01 17:54:18 +02:00
|
|
|
chan_set(&th->chan[CHAN_NANOS6_RANK], proc->rank + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_task_switch(struct ovni_emu *emu,
|
2022-09-29 15:34:44 +02:00
|
|
|
struct task *prev, struct task *next)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
2022-09-01 17:02:02 +02:00
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (!prev || !next)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot switch to or from a NULL task\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (prev == next)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot switch to the same task\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (next->id == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "next task id cannot be 0\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (next->type->gid == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "next task type id cannot be 0\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (prev->thread != next->thread)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot switch to a task of another thread\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* No need to change the rank as we will switch to tasks from
|
|
|
|
* same thread */
|
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TASKID], next->id);
|
2022-07-01 17:54:18 +02:00
|
|
|
|
|
|
|
/* FIXME: We should emit a PRV event even if we are switching to
|
|
|
|
* the same type event, to mark the end of the current task. For
|
|
|
|
* now we only emit a new type if we switch to a type with a
|
|
|
|
* different gid. */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (prev->type->gid != next->type->gid)
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_set(&th->chan[CHAN_NANOS6_TYPE], next->type->gid);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
update_task_state(struct ovni_emu *emu)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
if (ovni_payload_size(emu->cur_ev) < 4)
|
2022-09-07 14:51:56 +02:00
|
|
|
edie(emu, "missing task id in payload\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
uint32_t task_id = emu->cur_ev->payload.u32[0];
|
|
|
|
|
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
|
|
|
struct ovni_eproc *proc = emu->cur_proc;
|
|
|
|
|
|
|
|
struct task_info *info = &proc->nanos6_task_info;
|
|
|
|
struct task_stack *stack = &th->nanos6_task_stack;
|
|
|
|
|
|
|
|
struct task *task = task_find(info->tasks, task_id);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (task == NULL)
|
2022-09-07 14:51:56 +02:00
|
|
|
edie(emu, "cannot find task with id %u\n", task_id);
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case 'x':
|
|
|
|
task_execute(emu, stack, task);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
task_end(emu, stack, task);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
task_pause(emu, stack, task);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
task_resume(emu, stack, task);
|
|
|
|
break;
|
2022-07-01 17:54:18 +02:00
|
|
|
default:
|
2022-09-29 15:34:44 +02:00
|
|
|
edie(emu, "unexpected Nanos6 task event\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
2022-09-01 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char
|
|
|
|
expand_transition_value(struct ovni_emu *emu, int was_running, int runs_now)
|
|
|
|
{
|
|
|
|
char tr = emu->cur_ev->header.value;
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* Ensure we don't clobber the value */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (tr == 'X' || tr == 'E')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected event value %c\n", tr);
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* Modify the event value to detect nested transitions */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (tr == 'x' && was_running)
|
2022-09-01 17:02:02 +02:00
|
|
|
tr = 'X'; /* Execute a new nested task */
|
2022-09-29 15:34:44 +02:00
|
|
|
else if (tr == 'e' && runs_now)
|
2022-09-01 17:02:02 +02:00
|
|
|
tr = 'E'; /* End a nested task */
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_task_channels(struct ovni_emu *emu,
|
2022-09-29 15:34:44 +02:00
|
|
|
char tr, struct task *prev, struct task *next)
|
2022-09-01 17:02:02 +02:00
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (tr) {
|
2022-09-01 17:02:02 +02:00
|
|
|
case 'x':
|
|
|
|
case 'r':
|
2022-09-21 13:02:24 +02:00
|
|
|
chan_task_running(emu, next);
|
2022-09-13 14:22:44 +02:00
|
|
|
break;
|
2022-09-01 17:02:02 +02:00
|
|
|
case 'e':
|
|
|
|
case 'p':
|
2022-09-21 13:02:24 +02:00
|
|
|
chan_task_stopped(emu);
|
2022-09-13 14:22:44 +02:00
|
|
|
break;
|
|
|
|
/* Additional nested transitions */
|
2022-09-01 17:02:02 +02:00
|
|
|
case 'X':
|
|
|
|
case 'E':
|
2022-09-13 14:22:44 +02:00
|
|
|
chan_task_switch(emu, prev, next);
|
|
|
|
break;
|
2022-07-01 17:54:18 +02:00
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected transition value %c\n", tr);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 13:02:24 +02:00
|
|
|
static void
|
|
|
|
enforce_task_rules(struct ovni_emu *emu,
|
2022-09-29 15:34:44 +02:00
|
|
|
char tr, struct task *prev, struct task *next)
|
2022-09-21 13:02:24 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
UNUSED(prev);
|
|
|
|
|
|
|
|
/* If a task has just entered the running state, it must show
|
|
|
|
* the running task body subsystem */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (tr == 'x' || tr == 'X') {
|
|
|
|
if (next->state != TASK_ST_RUNNING)
|
2022-09-21 13:02:24 +02:00
|
|
|
edie(emu, "a Nanos6 task starts running but not in the running state\n");
|
|
|
|
|
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
|
|
|
struct ovni_chan *sschan = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
int st = chan_get_st(sschan);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (st != 0 && st != ST_NANOS6_TASK_BODY)
|
2022-09-21 13:02:24 +02:00
|
|
|
edie(emu, "a Nanos6 task starts running but not in the \"running body\" subsystem state\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:54:18 +02:00
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
update_task(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
|
|
|
struct task_stack *stack = &th->nanos6_task_stack;
|
|
|
|
|
|
|
|
struct task *prev = task_get_running(stack);
|
|
|
|
|
|
|
|
/* Update the emulator state, but don't modify the channels */
|
|
|
|
update_task_state(emu);
|
|
|
|
|
|
|
|
struct task *next = task_get_running(stack);
|
|
|
|
|
|
|
|
int was_running = (prev != NULL);
|
|
|
|
int runs_now = (next != NULL);
|
|
|
|
char tr = expand_transition_value(emu, was_running, runs_now);
|
|
|
|
|
2022-09-21 13:02:24 +02:00
|
|
|
/* Update the task related channels now */
|
2022-09-01 17:02:02 +02:00
|
|
|
update_task_channels(emu, tr, prev, next);
|
2022-09-21 13:02:24 +02:00
|
|
|
|
|
|
|
enforce_task_rules(emu, tr, prev, next);
|
2022-09-01 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_task(struct ovni_emu *emu)
|
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
if (ovni_payload_size(emu->cur_ev) != 8)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot create task: unexpected payload size\n");
|
2022-09-01 17:02:02 +02:00
|
|
|
|
|
|
|
uint32_t task_id = emu->cur_ev->payload.u32[0];
|
|
|
|
uint32_t type_id = emu->cur_ev->payload.u32[1];
|
|
|
|
|
|
|
|
struct task_info *info = &emu->cur_proc->nanos6_task_info;
|
|
|
|
|
2022-09-21 12:59:31 +02:00
|
|
|
task_create(emu, info, type_id, task_id);
|
2022-09-01 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_task(struct ovni_emu *emu)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
2022-07-01 17:54:18 +02:00
|
|
|
case 'c':
|
2022-09-01 17:02:02 +02:00
|
|
|
create_task(emu);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'e':
|
|
|
|
case 'r':
|
|
|
|
case 'p': /* Wet floor */
|
|
|
|
update_task(emu);
|
2022-07-01 17:54:18 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-09-07 14:51:56 +02:00
|
|
|
edie(emu, "unexpected Nanos6 task event value\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
static void
|
|
|
|
pre_type(struct ovni_emu *emu)
|
|
|
|
{
|
2022-09-13 14:22:44 +02:00
|
|
|
uint8_t value = emu->cur_ev->header.value;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (value != 'c')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected event value %c\n", value);
|
2022-09-01 17:02:02 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if ((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0)
|
2022-09-12 15:42:54 +02:00
|
|
|
edie(emu, "expecting a jumbo event\n");
|
2022-09-01 17:02:02 +02:00
|
|
|
|
|
|
|
uint8_t *data = &emu->cur_ev->payload.jumbo.data[0];
|
|
|
|
uint32_t typeid = *(uint32_t *) data;
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
const char *label = (const char *) data;
|
|
|
|
|
|
|
|
struct ovni_eproc *proc = emu->cur_proc;
|
|
|
|
|
|
|
|
task_type_create(&proc->nanos6_task_info, typeid, label);
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:54:18 +02:00
|
|
|
static void
|
|
|
|
pre_deps(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case 'r':
|
|
|
|
chan_push(chan_th, ST_NANOS6_DEP_REG);
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_DEP_REG);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
chan_push(chan_th, ST_NANOS6_DEP_UNREG);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_DEP_UNREG);
|
|
|
|
break;
|
2022-09-07 14:51:56 +02:00
|
|
|
default:
|
|
|
|
edie(emu, "unknown Nanos6 dependency event\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_blocking(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case 'b':
|
|
|
|
chan_push(chan_th, ST_NANOS6_BLK_BLOCKING);
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_BLK_BLOCKING);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
chan_push(chan_th, ST_NANOS6_BLK_UNBLOCKING);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_BLK_UNBLOCKING);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
chan_push(chan_th, ST_NANOS6_BLK_TASKWAIT);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_BLK_TASKWAIT);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
chan_push(chan_th, ST_NANOS6_BLK_WAITFOR);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_BLK_WAITFOR);
|
|
|
|
break;
|
2022-09-07 14:51:56 +02:00
|
|
|
default:
|
|
|
|
edie(emu, "unknown Nanos6 blocking event\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 20:18:42 +02:00
|
|
|
static void
|
|
|
|
pre_worker(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case '[':
|
|
|
|
chan_push(chan_th, ST_NANOS6_WORKER_LOOP);
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_WORKER_LOOP);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
chan_push(chan_th, ST_NANOS6_HANDLING_TASK);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_HANDLING_TASK);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
chan_push(chan_th, ST_NANOS6_SWITCH_TO);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_SWITCH_TO);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
chan_push(chan_th, ST_NANOS6_MIGRATE);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_MIGRATE);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
chan_push(chan_th, ST_NANOS6_SUSPEND);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_SUSPEND);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
chan_push(chan_th, ST_NANOS6_RESUME);
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_RESUME);
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
chan_ev(chan_th, EV_NANOS6_SIGNAL);
|
|
|
|
break;
|
2022-09-07 14:51:56 +02:00
|
|
|
default:
|
|
|
|
edie(emu, "unknown Nanos6 worker event\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_memory(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case 'a':
|
|
|
|
chan_push(chan_th, ST_NANOS6_ALLOCATING);
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_ALLOCATING);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
chan_push(chan_th, ST_NANOS6_FREEING);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_FREEING);
|
|
|
|
break;
|
2022-09-07 14:51:56 +02:00
|
|
|
default:
|
|
|
|
edie(emu, "unknown Nanos6 memory event\n");
|
2022-09-05 20:18:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:54:18 +02:00
|
|
|
static void
|
|
|
|
pre_sched(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case '[':
|
|
|
|
chan_push(chan_th, ST_NANOS6_SCHED_SERVING);
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_SCHED_SERVING);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
chan_push(chan_th, ST_NANOS6_SCHED_ADDING);
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_SCHED_ADDING);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
chan_push(chan_th, ST_NANOS6_SCHED_PROCESSING);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_SCHED_PROCESSING);
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
chan_ev(chan_th, EV_NANOS6_SCHED_SELF);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
chan_ev(chan_th, EV_NANOS6_SCHED_RECV);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
chan_ev(chan_th, EV_NANOS6_SCHED_SEND);
|
|
|
|
break;
|
2022-09-05 20:18:42 +02:00
|
|
|
default:
|
2022-09-07 14:51:56 +02:00
|
|
|
edie(emu, "unknown Nanos6 scheduler event\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
pre_thread(struct ovni_emu *emu)
|
2022-07-01 17:54:18 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_th = &th->chan[CHAN_NANOS6_THREAD];
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case 'e':
|
|
|
|
chan_push(chan_th, ST_NANOS6_TH_EXTERNAL);
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_TH_EXTERNAL);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
chan_push(chan_th, ST_NANOS6_TH_WORKER);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_TH_WORKER);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
chan_push(chan_th, ST_NANOS6_TH_LEADER);
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_TH_LEADER);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
chan_push(chan_th, ST_NANOS6_TH_MAIN);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
chan_pop(chan_th, ST_NANOS6_TH_MAIN);
|
|
|
|
break;
|
2022-09-12 15:42:54 +02:00
|
|
|
default:
|
|
|
|
edie(emu, "unknown Nanos6 thread type event\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_ss(struct ovni_emu *emu, int st)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
|
|
|
|
|
|
|
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.value) {
|
|
|
|
case '[':
|
|
|
|
chan_push(chan_th, st);
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
chan_pop(chan_th, st);
|
|
|
|
break;
|
2022-07-01 17:54:18 +02:00
|
|
|
default:
|
2022-09-12 15:42:54 +02:00
|
|
|
edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.value);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_affinity(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
|
|
|
struct ovni_cpu *cpu = th->cpu;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (!cpu || cpu->virtual)
|
2022-07-01 17:54:18 +02:00
|
|
|
return;
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (cpu->nrunning_threads > 1) {
|
2022-09-08 12:35:55 +02:00
|
|
|
eerr(emu, "cpu %s has more than one thread running\n", cpu->name);
|
2022-09-13 14:22:44 +02:00
|
|
|
|
|
|
|
/* Only abort in linter mode so we can still see the
|
|
|
|
* trace to find out what was happening */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->enable_linter)
|
2022-09-13 14:22:44 +02:00
|
|
|
abort();
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hook_pre_nanos6(struct ovni_emu *emu)
|
|
|
|
{
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->cur_ev->header.model != '6')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nanos6: unexpected event with model %c\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_ev->header.model);
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (!emu->cur_thread->is_active) {
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nanos6: current thread %d not active\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
emu->cur_thread->tid);
|
2022-09-07 14:51:56 +02:00
|
|
|
}
|
2022-07-01 17:54:18 +02:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
switch (emu->cur_ev->header.category) {
|
|
|
|
case 'T':
|
|
|
|
pre_task(emu);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
pre_ss(emu, ST_NANOS6_TASK_CREATING);
|
|
|
|
break;
|
|
|
|
case 'Y':
|
|
|
|
pre_type(emu);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
pre_sched(emu);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
pre_ss(emu, ST_NANOS6_TASK_SUBMIT);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
pre_ss(emu, ST_NANOS6_TASK_SPAWNING);
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
pre_ss(emu, ST_NANOS6_TASK_FOR);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
pre_ss(emu, ST_NANOS6_TASK_BODY);
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
pre_thread(emu);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
pre_deps(emu);
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
pre_blocking(emu);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
pre_worker(emu);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
pre_memory(emu);
|
|
|
|
break;
|
2022-07-01 17:54:18 +02:00
|
|
|
default:
|
2022-09-07 14:51:56 +02:00
|
|
|
edie(emu, "unknown Nanos6 event category\n");
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
check_affinity(emu);
|
|
|
|
}
|
|
|
|
|
2022-08-23 16:40:44 +02:00
|
|
|
static void
|
|
|
|
end_lint(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
/* Ensure we run out of subsystem states */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (size_t i = 0; i < emu->total_nthreads; i++) {
|
2022-08-23 16:40:44 +02:00
|
|
|
struct ovni_ethread *th = emu->global_thread[i];
|
|
|
|
struct ovni_chan *ch = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
2022-09-29 15:34:44 +02:00
|
|
|
if (ch->n != 1) {
|
2022-08-23 16:40:44 +02:00
|
|
|
int top = ch->stack[ch->n - 1];
|
2022-09-01 17:02:02 +02:00
|
|
|
|
|
|
|
struct pcf_value_label *pv;
|
|
|
|
char *name = "(unknown)";
|
2022-09-29 15:34:44 +02:00
|
|
|
for (pv = &nanos6_ss_values[0]; pv->label; pv++) {
|
|
|
|
if (pv->value == top) {
|
2022-09-01 17:02:02 +02:00
|
|
|
name = pv->label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
die("thread %d ended with %d extra stacked nanos6 subsystems, top=\"%s\"\n",
|
2022-09-29 15:34:44 +02:00
|
|
|
th->tid, ch->n - 1, name);
|
2022-08-23 16:40:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:54:18 +02:00
|
|
|
void
|
|
|
|
hook_end_nanos6(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
/* Emit types for all channel types and processes */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++) {
|
2022-07-01 17:54:18 +02:00
|
|
|
struct pcf_file *pcf = &emu->pcf[ct];
|
|
|
|
int typeid = chan_to_prvtype[CHAN_NANOS6_TYPE];
|
|
|
|
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
for (size_t i = 0; i < emu->trace.nlooms; i++) {
|
2022-07-01 17:54:18 +02:00
|
|
|
struct ovni_loom *loom = &emu->trace.loom[i];
|
2022-09-29 15:34:44 +02:00
|
|
|
for (size_t j = 0; j < loom->nprocs; j++) {
|
2022-07-01 17:54:18 +02:00
|
|
|
struct ovni_eproc *proc = &loom->proc[j];
|
2022-09-01 17:02:02 +02:00
|
|
|
task_create_pcf_types(pcftype, proc->nanos6_task_info.types);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-23 16:40:44 +02:00
|
|
|
|
|
|
|
/* When running in linter mode perform additional checks */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (emu->enable_linter)
|
2022-08-23 16:40:44 +02:00
|
|
|
end_lint(emu);
|
2022-07-01 17:54:18 +02:00
|
|
|
}
|