2021-10-26 18:42:41 +02: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-08-02 10:08:58 +02:00
|
|
|
#include "uthash.h"
|
2021-12-07 18:56:05 +01:00
|
|
|
#include "utlist.h"
|
2021-08-02 10:08:58 +02:00
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
#include "ovni.h"
|
|
|
|
#include "emu.h"
|
2022-07-01 17:54:18 +02:00
|
|
|
#include "emu_task.h"
|
2021-08-02 10:08:58 +02:00
|
|
|
#include "prv.h"
|
2021-10-21 16:15:29 +02:00
|
|
|
#include "chan.h"
|
2021-07-28 11:56:35 +02:00
|
|
|
|
2021-10-21 16:15:29 +02:00
|
|
|
/* --------------------------- init ------------------------------- */
|
|
|
|
|
|
|
|
void
|
2021-10-21 16:46:42 +02:00
|
|
|
hook_init_nosv(struct ovni_emu *emu)
|
2021-10-21 16:15:29 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
2021-10-21 16:46:42 +02:00
|
|
|
struct ovni_cpu *cpu;
|
2021-10-18 12:47:51 +02:00
|
|
|
struct ovni_chan **uth, **ucpu;
|
|
|
|
size_t i;
|
|
|
|
int row;
|
2021-10-21 16:46:42 +02:00
|
|
|
FILE *prv_th, *prv_cpu;
|
2021-10-21 16:15:29 +02:00
|
|
|
int64_t *clock;
|
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
clock = &emu->delta_time;
|
|
|
|
prv_th = emu->prv_thread;
|
|
|
|
prv_cpu = emu->prv_cpu;
|
|
|
|
|
|
|
|
/* Init the channels in all threads */
|
2021-10-21 16:15:29 +02:00
|
|
|
for(i=0; i<emu->total_nthreads; i++)
|
|
|
|
{
|
|
|
|
th = emu->global_thread[i];
|
|
|
|
row = th->gindex + 1;
|
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
uth = &emu->th_chan;
|
2021-10-21 16:46:42 +02:00
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
chan_th_init(th, uth, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2022-06-02 15:28:04 +02:00
|
|
|
chan_th_init(th, uth, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2021-10-18 12:47:51 +02:00
|
|
|
chan_th_init(th, uth, CHAN_NOSV_APPID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2021-12-10 18:20:31 +01:00
|
|
|
chan_th_init(th, uth, CHAN_NOSV_RANK, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
|
2021-10-11 11:12:26 +02:00
|
|
|
|
|
|
|
/* We allow threads to emit subsystem events in cooling and
|
|
|
|
* warming states as well, as they may be allocating memory.
|
|
|
|
* However, these information won't be presented in the CPU
|
|
|
|
* channel, as it only shows the thread in the running state */
|
2021-10-18 12:47:51 +02:00
|
|
|
chan_th_init(th, uth, CHAN_NOSV_SUBSYSTEM, CHAN_TRACK_TH_ACTIVE, 0, 0, 1, row, prv_th, clock);
|
2021-10-21 16:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the nosv channels in all cpus */
|
|
|
|
for(i=0; i<emu->total_ncpus; i++)
|
|
|
|
{
|
|
|
|
cpu = emu->global_cpu[i];
|
|
|
|
row = cpu->gindex + 1;
|
2021-10-18 12:47:51 +02:00
|
|
|
ucpu = &emu->cpu_chan;
|
|
|
|
|
2021-10-21 15:46:32 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2022-06-02 15:28:04 +02:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-11-17 12:11:13 +01:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NOSV_APPID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-12-10 18:20:31 +01:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NOSV_RANK, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-11-17 12:11:13 +01:00
|
|
|
chan_cpu_init(cpu, ucpu, CHAN_NOSV_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
|
2021-10-21 16:15:29 +02:00
|
|
|
}
|
2022-09-01 17:02:02 +02:00
|
|
|
|
|
|
|
/* Init task stack */
|
|
|
|
for(i=0; i<emu->total_nthreads; i++)
|
|
|
|
{
|
|
|
|
th = emu->global_thread[i];
|
|
|
|
th->nosv_task_stack.thread = th;
|
|
|
|
}
|
2021-10-21 16:15:29 +02:00
|
|
|
}
|
|
|
|
|
2021-07-29 18:13:41 +02:00
|
|
|
/* --------------------------- pre ------------------------------- */
|
|
|
|
|
2021-07-29 17:46:25 +02:00
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_task_stopped(struct ovni_emu *emu)
|
2021-12-07 18:56:05 +01:00
|
|
|
{
|
2022-09-01 17:02:02 +02:00
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
2022-06-03 11:36:27 +02:00
|
|
|
|
2021-12-07 18:56:05 +01:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_TASKID], 0);
|
2022-06-02 15:28:04 +02:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_TYPE], 0);
|
2021-12-07 18:56:05 +01:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_APPID], 0);
|
|
|
|
|
2022-05-30 15:11:58 +02:00
|
|
|
if(emu->cur_loom->rank_enabled)
|
|
|
|
chan_set(&th->chan[CHAN_NOSV_RANK], 0);
|
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* XXX: Do we need this transition? */
|
2021-12-07 18:56:05 +01:00
|
|
|
chan_pop(&th->chan[CHAN_NOSV_SUBSYSTEM], ST_NOSV_TASK_RUNNING);
|
|
|
|
}
|
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_task_running(struct ovni_emu *emu, struct task *task)
|
2021-10-21 16:46:42 +02:00
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_eproc *proc;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
proc = emu->cur_proc;
|
|
|
|
|
2022-06-02 15:31:35 +02:00
|
|
|
if(task->id == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "task id cannot be 0\n");
|
2021-12-07 19:52:48 +01:00
|
|
|
|
2022-06-02 15:31:35 +02:00
|
|
|
if(task->type->gid == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "task type gid cannot be 0\n");
|
2021-12-07 19:52:48 +01:00
|
|
|
|
|
|
|
if(proc->appid <= 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "app id must be positive\n");
|
2021-10-29 17:48:04 +02:00
|
|
|
|
|
|
|
chan_set(&th->chan[CHAN_NOSV_TASKID], task->id);
|
2022-06-02 15:28:04 +02:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_TYPE], task->type->gid);
|
2021-10-29 17:48:04 +02:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_APPID], proc->appid);
|
2021-10-11 11:12:26 +02:00
|
|
|
|
2021-12-10 18:20:31 +01:00
|
|
|
if(emu->cur_loom->rank_enabled)
|
|
|
|
chan_set(&th->chan[CHAN_NOSV_RANK], proc->rank + 1);
|
|
|
|
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_push(&th->chan[CHAN_NOSV_SUBSYSTEM], ST_NOSV_TASK_RUNNING);
|
2021-10-21 16:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_task_switch(struct ovni_emu *emu,
|
|
|
|
struct task *prev, struct task *next)
|
2021-10-21 16:46:42 +02:00
|
|
|
{
|
2022-09-01 17:02:02 +02:00
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
2021-10-21 16:46:42 +02:00
|
|
|
|
2022-09-01 17:02:02 +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-05-05 15:11:07 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
if(prev == next)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot switch to the same task\n");
|
2022-05-05 15:11:07 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
if(next->id == 0)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "next task id cannot be 0\n");
|
2022-05-05 15:11:07 +02:00
|
|
|
|
2022-09-01 17:02:02 +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");
|
2021-10-11 11:12:26 +02:00
|
|
|
|
2022-09-01 17:02:02 +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");
|
2021-12-10 18:20:31 +01:00
|
|
|
|
2022-06-02 15:32:40 +02:00
|
|
|
/* No need to change the rank or app ID, as we can only switch
|
|
|
|
* to tasks of the same thread */
|
2022-09-01 17:02:02 +02:00
|
|
|
chan_set(&th->chan[CHAN_NOSV_TASKID], next->id);
|
2022-05-30 15:11:58 +02:00
|
|
|
|
2022-06-02 15:28:04 +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-01 17:02:02 +02:00
|
|
|
if(prev->type->gid != next->type->gid)
|
|
|
|
chan_set(&th->chan[CHAN_NOSV_TYPE], next->type->gid);
|
2021-10-21 16:46:42 +02:00
|
|
|
}
|
|
|
|
|
2021-07-29 17:46:25 +02:00
|
|
|
static void
|
2022-09-01 17:02:02 +02:00
|
|
|
update_task_state(struct ovni_emu *emu)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2022-09-01 17:02:02 +02:00
|
|
|
if(ovni_payload_size(emu->cur_ev) < 4)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "missing task id in payload\n");
|
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->nosv_task_info;
|
|
|
|
struct task_stack *stack = &th->nosv_task_stack;
|
|
|
|
|
|
|
|
struct task *task = task_find(info->tasks, task_id);
|
|
|
|
|
|
|
|
if(task == NULL)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cannot find task with id %u\n", task_id);
|
2021-10-21 16:46:42 +02:00
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
switch(emu->cur_ev->header.value)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2022-09-21 12:59:31 +02:00
|
|
|
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;
|
2021-07-29 17:46:25 +02:00
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected Nanos6 task event value %c\n",
|
|
|
|
emu->cur_ev->header.value);
|
2021-10-21 16:46:42 +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;
|
2021-10-21 16:46:42 +02:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* Ensure we don't clobber the value */
|
|
|
|
if(tr == 'X' || tr == 'E')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected event value %c\n", tr);
|
2021-12-07 18:56:05 +01:00
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
/* Modify the event value to detect nested transitions */
|
|
|
|
if(tr == 'x' && was_running)
|
|
|
|
tr = 'X'; /* Execute a new nested task */
|
|
|
|
else if(tr == 'e' && runs_now)
|
|
|
|
tr = 'E'; /* End a nested task */
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_task_channels(struct ovni_emu *emu,
|
|
|
|
char tr, struct task *prev, struct task *next)
|
|
|
|
{
|
|
|
|
switch(tr)
|
2022-05-05 15:11:07 +02:00
|
|
|
{
|
2022-09-01 17:02:02 +02:00
|
|
|
case 'x': chan_task_running(emu, next); break;
|
|
|
|
case 'r': chan_task_running(emu, next); break;
|
|
|
|
case 'e': chan_task_stopped(emu); break;
|
|
|
|
case 'p': chan_task_stopped(emu); break;
|
|
|
|
/* Additional nested transitions */
|
|
|
|
case 'X': chan_task_switch(emu, prev, next); break;
|
|
|
|
case 'E': chan_task_switch(emu, prev, next); break;
|
2022-06-03 11:36:27 +02:00
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected transition value %c\n", tr);
|
2021-07-29 17:46:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 18:13:41 +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->nosv_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);
|
|
|
|
|
|
|
|
/* Update the channels now */
|
|
|
|
update_task_channels(emu, tr, prev, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_task(struct ovni_emu *emu)
|
2021-07-29 18:13:41 +02:00
|
|
|
{
|
2022-09-01 17:02:02 +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->nosv_task_info;
|
2021-12-07 18:56:05 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2021-07-30 20:08:40 +02:00
|
|
|
switch(emu->cur_ev->header.value)
|
2021-07-29 18:13:41 +02:00
|
|
|
{
|
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;
|
2021-07-29 18:13:41 +02:00
|
|
|
default:
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected task event value %c\n",
|
2022-09-01 17:02:02 +02:00
|
|
|
emu->cur_ev->header.value);
|
2021-07-29 18:13:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 17:02:02 +02:00
|
|
|
static void
|
|
|
|
pre_type(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
if(emu->cur_ev->header.value != 'c')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "unexpected event value %c\n",
|
2022-09-01 17:02:02 +02:00
|
|
|
emu->cur_ev->header.value);
|
|
|
|
|
|
|
|
if((emu->cur_ev->header.flags & OVNI_EV_JUMBO) == 0)
|
2022-09-13 14:22:44 +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->nosv_task_info, typeid, label);
|
|
|
|
}
|
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
static void
|
|
|
|
pre_sched(struct ovni_emu *emu)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-10-21 16:46:42 +02:00
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-10-21 16:46:42 +02:00
|
|
|
case 'h':
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_push(chan_th, ST_NOSV_SCHED_HUNGRY);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case 'f': /* Fill: no longer hungry */
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_pop(chan_th, ST_NOSV_SCHED_HUNGRY);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case '[': /* Server enter */
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_push(chan_th, ST_NOSV_SCHED_SERVING);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case ']': /* Server exit */
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_pop(chan_th, ST_NOSV_SCHED_SERVING);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case '@':
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_ev(chan_th, EV_NOSV_SCHED_SELF);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case 'r':
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_ev(chan_th, EV_NOSV_SCHED_RECV);
|
2021-10-21 16:46:42 +02:00
|
|
|
break;
|
|
|
|
case 's':
|
2021-10-14 07:30:27 +02:00
|
|
|
chan_ev(chan_th, EV_NOSV_SCHED_SEND);
|
2021-09-27 17:42:14 +02:00
|
|
|
break;
|
2021-07-29 17:46:25 +02:00
|
|
|
default:
|
2021-09-27 17:42:14 +02:00
|
|
|
break;
|
2021-07-29 17:46:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 11:31:23 +02:00
|
|
|
static void
|
|
|
|
pre_api(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
2021-10-19 10:21:10 +02:00
|
|
|
case 's': chan_push(chan_th, ST_NOSV_API_SUBMIT); break;
|
|
|
|
case 'S': chan_pop (chan_th, ST_NOSV_API_SUBMIT); break;
|
|
|
|
case 'p': chan_push(chan_th, ST_NOSV_API_PAUSE); break;
|
|
|
|
case 'P': chan_pop (chan_th, ST_NOSV_API_PAUSE); break;
|
|
|
|
case 'y': chan_push(chan_th, ST_NOSV_API_YIELD); break;
|
|
|
|
case 'Y': chan_pop (chan_th, ST_NOSV_API_YIELD); break;
|
|
|
|
case 'w': chan_push(chan_th, ST_NOSV_API_WAITFOR); break;
|
|
|
|
case 'W': chan_pop (chan_th, ST_NOSV_API_WAITFOR); break;
|
|
|
|
case 'c': chan_push(chan_th, ST_NOSV_API_SCHEDPOINT); break;
|
|
|
|
case 'C': chan_pop (chan_th, ST_NOSV_API_SCHEDPOINT); break;
|
|
|
|
default: break;
|
2021-10-15 11:31:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 12:35:05 +02:00
|
|
|
static void
|
|
|
|
pre_mem(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
|
|
|
case 'a': chan_push(chan_th, ST_NOSV_MEM_ALLOCATING); break;
|
|
|
|
case 'A': chan_pop (chan_th, ST_NOSV_MEM_ALLOCATING); break;
|
|
|
|
case 'f': chan_push(chan_th, ST_NOSV_MEM_FREEING); break;
|
|
|
|
case 'F': chan_pop (chan_th, ST_NOSV_MEM_FREEING); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 18:27:49 +02:00
|
|
|
static void
|
|
|
|
pre_thread_type(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
|
|
|
|
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
|
|
|
|
|
|
|
switch(emu->cur_ev->header.value)
|
|
|
|
{
|
|
|
|
case 'a': chan_push(chan_th, ST_NOSV_ATTACH); break;
|
|
|
|
case 'A': chan_pop (chan_th, ST_NOSV_ATTACH); break;
|
|
|
|
case 'w': chan_push(chan_th, ST_NOSV_WORKER); break;
|
|
|
|
case 'W': chan_pop (chan_th, ST_NOSV_WORKER); break;
|
|
|
|
case 'd': chan_push(chan_th, ST_NOSV_DELEGATE); break;
|
|
|
|
case 'D': chan_pop (chan_th, ST_NOSV_DELEGATE); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-13 14:44:20 +02:00
|
|
|
static void
|
2021-10-14 07:05:59 +02:00
|
|
|
pre_ss(struct ovni_emu *emu, int st)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-10-21 16:46:42 +02:00
|
|
|
struct ovni_ethread *th;
|
|
|
|
struct ovni_chan *chan_th;
|
2021-07-29 17:46:25 +02:00
|
|
|
|
2021-10-21 16:46:42 +02:00
|
|
|
th = emu->cur_thread;
|
|
|
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
2021-07-29 17:46:25 +02:00
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);
|
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
switch(emu->cur_ev->header.value)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-10-15 11:31:23 +02:00
|
|
|
case '[':
|
2021-10-14 07:05:59 +02:00
|
|
|
chan_push(chan_th, st);
|
2021-08-02 10:08:58 +02:00
|
|
|
break;
|
2021-10-21 16:46:42 +02:00
|
|
|
case ']':
|
2021-10-14 07:05:59 +02:00
|
|
|
chan_pop(chan_th, st);
|
2021-08-02 10:08:58 +02:00
|
|
|
break;
|
2021-07-29 17:46:25 +02:00
|
|
|
default:
|
2021-10-14 07:05:59 +02:00
|
|
|
err("unexpected value '%c' (expecting '[' or ']')\n",
|
|
|
|
emu->cur_ev->header.value);
|
|
|
|
abort();
|
2021-10-11 11:12:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 11:03:25 +01:00
|
|
|
static void
|
|
|
|
check_affinity(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
struct ovni_ethread *th = emu->cur_thread;
|
|
|
|
struct ovni_cpu *cpu = th->cpu;
|
|
|
|
|
|
|
|
if(!cpu || cpu->virtual)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(th->state != TH_ST_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(cpu->nrunning_threads > 1)
|
|
|
|
{
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "cpu %s has more than one thread running\n",
|
2021-11-29 11:03:25 +01:00
|
|
|
cpu->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 17:46:25 +02:00
|
|
|
void
|
2021-10-21 16:46:42 +02:00
|
|
|
hook_pre_nosv(struct ovni_emu *emu)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-12-07 19:52:48 +01:00
|
|
|
if(emu->cur_ev->header.model != 'V')
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nosv: unexpected event with model %c\n",
|
2021-12-07 19:52:48 +01:00
|
|
|
emu->cur_ev->header.model);
|
2021-10-21 16:15:29 +02:00
|
|
|
|
2021-12-07 19:52:48 +01:00
|
|
|
if(!emu->cur_thread->is_active)
|
2022-09-13 14:22:44 +02:00
|
|
|
edie(emu, "hook_pre_nosv: current thread %d not active\n",
|
2021-12-07 19:52:48 +01:00
|
|
|
emu->cur_thread->tid);
|
2021-10-18 12:47:51 +02:00
|
|
|
|
2021-10-11 15:46:49 +02:00
|
|
|
switch(emu->cur_ev->header.category)
|
2021-07-29 17:46:25 +02:00
|
|
|
{
|
2021-10-21 16:46:42 +02:00
|
|
|
case 'T': pre_task(emu); break;
|
|
|
|
case 'Y': pre_type(emu); break;
|
|
|
|
case 'S': pre_sched(emu); break;
|
2021-10-14 07:30:27 +02:00
|
|
|
case 'U': pre_ss(emu, ST_NOSV_SCHED_SUBMITTING); break;
|
2021-10-25 12:35:05 +02:00
|
|
|
case 'M': pre_mem(emu); break;
|
2021-10-29 18:27:49 +02:00
|
|
|
case 'H': pre_thread_type(emu); break;
|
2021-10-15 11:31:23 +02:00
|
|
|
case 'A': pre_api(emu); break;
|
2021-07-29 17:46:25 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-11-29 11:03:25 +01:00
|
|
|
|
|
|
|
if(emu->enable_linter)
|
|
|
|
check_affinity(emu);
|
2021-09-23 12:41:43 +02:00
|
|
|
}
|
2022-06-01 16:30:46 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
hook_end_nosv(struct ovni_emu *emu)
|
|
|
|
{
|
|
|
|
/* Emit types for all channel types and processes */
|
|
|
|
for(enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++)
|
|
|
|
{
|
|
|
|
struct pcf_file *pcf = &emu->pcf[ct];
|
2022-07-01 17:54:18 +02:00
|
|
|
int typeid = chan_to_prvtype[CHAN_NOSV_TYPE];
|
2022-06-01 16:30:46 +02:00
|
|
|
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < emu->trace.nlooms; i++)
|
|
|
|
{
|
|
|
|
struct ovni_loom *loom = &emu->trace.loom[i];
|
|
|
|
for(size_t j = 0; j < loom->nprocs; j++)
|
|
|
|
{
|
|
|
|
struct ovni_eproc *proc = &loom->proc[j];
|
2022-09-01 17:02:02 +02:00
|
|
|
task_create_pcf_types(pcftype, proc->nosv_task_info.types);
|
2022-06-01 16:30:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|