Refactor emu_nanos6 into a simpler function

This commit is contained in:
Antoni Navarro 2021-11-12 11:36:27 +01:00
parent 04895a7aea
commit c9b189feb8
3 changed files with 58 additions and 168 deletions

18
emu.h
View File

@ -86,7 +86,7 @@ enum nosv_ss_values {
EV_NOSV_SCHED_SELF, EV_NOSV_SCHED_SELF,
}; };
enum nosv_tampi_state { enum tampi_state {
ST_TAMPI_SEND = 1, ST_TAMPI_SEND = 1,
ST_TAMPI_RECV = 2, ST_TAMPI_RECV = 2,
ST_TAMPI_ISEND = 3, ST_TAMPI_ISEND = 3,
@ -95,19 +95,19 @@ enum nosv_tampi_state {
ST_TAMPI_WAITALL = 6, ST_TAMPI_WAITALL = 6,
}; };
enum nosv_openmp_state { enum openmp_state {
ST_OPENMP_TASK = 1, ST_OPENMP_TASK = 1,
ST_OPENMP_PARALLEL = 2, ST_OPENMP_PARALLEL = 2,
}; };
enum nosv_nanos6_state { enum nanos6_state {
ST_NANOS6_REGISTER = 1, ST_NANOS6_REGISTERING = 1,
ST_NANOS6_UNREGISTER = 2, ST_NANOS6_UNREGISTERING = 2,
ST_NANOS6_IF0_WAIT = 3, ST_NANOS6_IF0_WAIT = 3,
ST_NANOS6_IF0_INLINE = 4, ST_NANOS6_IF0_INLINE = 4,
ST_NANOS6_TASKWAIT = 5, ST_NANOS6_TASKWAIT = 5,
ST_NANOS6_CREATE = 6, ST_NANOS6_CREATING = 6,
ST_NANOS6_SUBMIT = 7, ST_NANOS6_SUBMITTING = 7,
ST_NANOS6_SPAWN = 8, ST_NANOS6_SPAWN = 8,
}; };
@ -159,7 +159,7 @@ enum chan {
CHAN_TAMPI_MODE, CHAN_TAMPI_MODE,
CHAN_OPENMP_MODE, CHAN_OPENMP_MODE,
CHAN_NANOS6_MODE, CHAN_NANOS6_SUBSYSTEM,
CHAN_MAX CHAN_MAX
}; };
@ -190,7 +190,7 @@ static const int chan_to_prvtype[CHAN_MAX][3] = {
{ CHAN_OPENMP_MODE, 40, 90 }, { CHAN_OPENMP_MODE, 40, 90 },
{ CHAN_NANOS6_MODE, 50, 100 }, { CHAN_NANOS6_SUBSYSTEM, 50, 100 },
}; };
struct ovni_chan { struct ovni_chan {

View File

@ -1,3 +1,20 @@
/*
* 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/>.
*/
#include <assert.h> #include <assert.h>
#include "uthash.h" #include "uthash.h"
@ -31,7 +48,7 @@ hook_init_nanos6(struct ovni_emu *emu)
row = th->gindex + 1; row = th->gindex + 1;
uth = &emu->th_chan; uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_NANOS6_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_NANOS6_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
} }
/* Init the channels in all cpus */ /* Init the channels in all cpus */
@ -41,160 +58,31 @@ hook_init_nanos6(struct ovni_emu *emu)
row = cpu->gindex + 1; row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_NANOS6_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_NANOS6_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
} }
} }
/* --------------------------- pre ------------------------------- */ /* --------------------------- pre ------------------------------- */
static void static void
pre_register(struct ovni_emu *emu) pre_subsystem(struct ovni_emu *emu, int st)
{ {
struct ovni_ethread *th; struct ovni_ethread *th;
struct ovni_chan *chan;
th = emu->cur_thread; th = emu->cur_thread;
chan = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value) switch(emu->cur_ev->header.value)
{ {
case '[': case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_REGISTER); chan_push(chan, st);
break; break;
case ']': case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_REGISTER); chan_pop(chan, st);
break;
default:
abort();
}
}
static void
pre_unregister(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_UNREGISTER);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_UNREGISTER);
break;
default:
abort();
}
}
static void
pre_wait(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_IF0_WAIT);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_IF0_WAIT);
break;
default:
abort();
}
}
static void
pre_inline(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_IF0_INLINE);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_IF0_INLINE);
break;
default:
abort();
}
}
static void
pre_taskwait(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_TASKWAIT);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_TASKWAIT);
break;
default:
abort();
}
}
static void
pre_create(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_CREATE);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_CREATE);
break;
default:
abort();
}
}
static void
pre_submit(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_SUBMIT);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_SUBMIT);
break;
default:
abort();
}
}
static void
pre_spawn(struct ovni_emu *emu)
{
struct ovni_ethread *th;
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
case '[':
chan_push(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_SPAWN);
break;
case ']':
chan_pop(&th->chan[CHAN_NANOS6_MODE], ST_NANOS6_SPAWN);
break; break;
default: default:
err("unexpected value '%c' (expecting '[' or ']')\n", emu->cur_ev->header.value);
abort(); abort();
} }
} }
@ -202,18 +90,20 @@ pre_spawn(struct ovni_emu *emu)
void void
hook_pre_nanos6(struct ovni_emu *emu) hook_pre_nanos6(struct ovni_emu *emu)
{ {
// Ensure that the thread is running
assert(emu->cur_thread->is_running != 0);
assert(emu->cur_ev->header.model == 'L'); assert(emu->cur_ev->header.model == 'L');
switch(emu->cur_ev->header.category) switch(emu->cur_ev->header.category)
{ {
case 'R': pre_register(emu); break; case 'R': pre_subsystem(emu, ST_NANOS6_REGISTERING); break;
case 'U': pre_unregister(emu); break; case 'U': pre_subsystem(emu, ST_NANOS6_UNREGISTERING); break;
case 'W': pre_wait(emu); break; case 'W': pre_subsystem(emu, ST_NANOS6_IF0_WAIT); break;
case 'I': pre_inline(emu); break; case 'I': pre_subsystem(emu, ST_NANOS6_IF0_INLINE); break;
case 'T': pre_taskwait(emu); break; case 'T': pre_subsystem(emu, ST_NANOS6_TASKWAIT); break;
case 'C': pre_create(emu); break; case 'C': pre_subsystem(emu, ST_NANOS6_CREATING); break;
case 'S': pre_submit(emu); break; case 'S': pre_subsystem(emu, ST_NANOS6_SUBMITTING); break;
case 'P': pre_spawn(emu); break; case 'P': pre_subsystem(emu, ST_NANOS6_SPAWN); break;
default: default:
break; break;
} }

14
pcf.c
View File

@ -362,30 +362,30 @@ struct event_type thread_openmp_mode = {
openmp_mode_values openmp_mode_values
}; };
/* ---------------- CHAN_NANOS6_MODE ---------------- */ /* ---------------- CHAN_NANOS6_SUBSYSTEM ---------------- */
struct event_value nanos6_mode_values[] = { struct event_value nanos6_mode_values[] = {
{ ST_NULL, "NULL" }, { ST_NULL, "NULL" },
{ ST_TOO_MANY_TH, "Nanos6: Multiple threads running" }, { ST_TOO_MANY_TH, "Nanos6: Multiple threads running" },
{ ST_NANOS6_REGISTER, "Dependencies: Register task accesses" }, { ST_NANOS6_REGISTERING, "Dependencies: Register task accesses" },
{ ST_NANOS6_UNREGISTER, "Dependencies: Unregister task accesses" }, { ST_NANOS6_UNREGISTERING, "Dependencies: Unregister task accesses" },
{ ST_NANOS6_IF0_WAIT, "If0: Wait for If0 task" }, { ST_NANOS6_IF0_WAIT, "If0: Wait for If0 task" },
{ ST_NANOS6_IF0_INLINE, "If0: Execute If0 task inline" }, { ST_NANOS6_IF0_INLINE, "If0: Execute If0 task inline" },
{ ST_NANOS6_TASKWAIT, "Taskwait: Taskwait" }, { ST_NANOS6_TASKWAIT, "Taskwait: Taskwait" },
{ ST_NANOS6_CREATE, "Add Task: Create a task" }, { ST_NANOS6_CREATING, "Add Task: Create a task" },
{ ST_NANOS6_SUBMIT, "Add Task: Submit a task" }, { ST_NANOS6_SUBMITTING, "Add Task: Submit a task" },
{ ST_NANOS6_SPAWN, "Spawn Function: Spawn a function" }, { ST_NANOS6_SPAWN, "Spawn Function: Spawn a function" },
{ -1, NULL }, { -1, NULL },
}; };
struct event_type cpu_nanos6_mode = { struct event_type cpu_nanos6_mode = {
0, chan_to_prvtype[CHAN_NANOS6_MODE][CHAN_CPU], 0, chan_to_prvtype[CHAN_NANOS6_SUBSYSTEM][CHAN_CPU],
"CPU: Nanos6 mode of the RUNNING thread", "CPU: Nanos6 mode of the RUNNING thread",
nanos6_mode_values nanos6_mode_values
}; };
struct event_type thread_nanos6_mode = { struct event_type thread_nanos6_mode = {
0, chan_to_prvtype[CHAN_NANOS6_MODE][CHAN_TH], 0, chan_to_prvtype[CHAN_NANOS6_SUBSYSTEM][CHAN_TH],
"Thread: Nanos6 mode of the RUNNING thread", "Thread: Nanos6 mode of the RUNNING thread",
nanos6_mode_values nanos6_mode_values
}; };