ovni/emu_openmp.c

87 lines
1.7 KiB
C
Raw Normal View History

2021-10-11 12:29:12 +02:00
#include <assert.h>
#include "uthash.h"
#include "ovni.h"
#include "ovni_trace.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
/* --------------------------- init ------------------------------- */
void
hook_init_openmp(struct ovni_emu *emu)
{
struct ovni_ethread *th;
struct ovni_cpu *cpu;
size_t i;
int row;
2021-10-11 12:29:12 +02:00
FILE *prv_th, *prv_cpu;
int64_t *clock;
struct ovni_chan **uth, **ucpu;
2021-10-11 12:29:12 +02:00
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-10-11 12:29:12 +02:00
chan_th_init(th, uth, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
2021-10-11 12:29:12 +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-10-11 12:29:12 +02:00
chan_cpu_init(cpu, ucpu, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, row, prv_cpu, clock);
2021-10-11 12:29:12 +02:00
}
}
/* --------------------------- pre ------------------------------- */
static void
2021-10-19 10:25:08 +02:00
pre_mode(struct ovni_emu *emu, int st)
2021-10-11 12:29:12 +02:00
{
struct ovni_ethread *th;
2021-10-19 10:25:08 +02:00
struct ovni_chan *chan;
2021-10-11 12:29:12 +02:00
th = emu->cur_thread;
2021-10-19 10:25:08 +02:00
chan = &th->chan[CHAN_OPENMP_MODE];
2021-10-11 12:29:12 +02:00
switch(emu->cur_ev->header.value)
{
case '[':
2021-10-19 10:25:08 +02:00
chan_push(chan, st);
2021-10-11 12:29:12 +02:00
break;
case ']':
2021-10-19 10:25:08 +02:00
chan_pop(chan, st);
2021-10-11 12:29:12 +02:00
break;
default:
2021-10-19 10:25:08 +02:00
err("unexpected value '%c' (expecting '[' or ']')\n",
emu->cur_ev->header.value);
abort();
2021-10-11 12:29:12 +02:00
}
}
void
hook_pre_openmp(struct ovni_emu *emu)
{
assert(emu->cur_ev->header.model == 'M');
switch(emu->cur_ev->header.category)
{
2021-10-19 10:25:08 +02:00
case 'T': pre_mode(emu, ST_OPENMP_TASK); break;
case 'P': pre_mode(emu, ST_OPENMP_PARALLEL); break;
2021-10-11 12:29:12 +02:00
default:
break;
}
}