Declare and set variables close to usage

This commit is contained in:
Rodrigo Arias 2022-09-29 18:35:41 +02:00
parent 73aa7887ae
commit da1af8c133
16 changed files with 352 additions and 705 deletions

View File

@ -50,11 +50,8 @@ chan_th_init(struct ovni_ethread *th,
FILE *prv, FILE *prv,
int64_t *clock) int64_t *clock)
{ {
struct ovni_chan *chan; struct ovni_chan *chan = &th->chan[id];
int prvth; int prvth = chan_to_prvtype[id];
chan = &th->chan[id];
prvth = chan_to_prvtype[id];
chan_init(chan, track, row, prvth, prv, clock); chan_init(chan, track, row, prvth, prv, clock);
@ -79,11 +76,8 @@ chan_cpu_init(struct ovni_cpu *cpu,
FILE *prv, FILE *prv,
int64_t *clock) int64_t *clock)
{ {
struct ovni_chan *chan; struct ovni_chan *chan = &cpu->chan[id];
int prvcpu; int prvcpu = chan_to_prvtype[id];
chan = &cpu->chan[id];
prvcpu = chan_to_prvtype[id];
chan_init(chan, track, row, prvcpu, prv, clock); chan_init(chan, track, row, prvcpu, prv, clock);
@ -99,11 +93,9 @@ chan_cpu_init(struct ovni_cpu *cpu,
static void static void
chan_dump_update_list(struct ovni_chan *chan) chan_dump_update_list(struct ovni_chan *chan)
{ {
struct ovni_chan *c; dbg("update list for chan %d at %p:\n", chan->id, (void *) chan);
dbg("update list for chan %d at %p:\n", for (struct ovni_chan *c = *chan->update_list; c; c = c->next) {
chan->id, (void *) chan);
for (c = *chan->update_list; c; c = c->next) {
dbg(" chan %d at %p\n", c->id, (void *) c); dbg(" chan %d at %p\n", c->id, (void *) c);
} }
} }
@ -223,8 +215,6 @@ chan_push(struct ovni_chan *chan, int st)
int int
chan_pop(struct ovni_chan *chan, int expected_st) chan_pop(struct ovni_chan *chan, int expected_st)
{ {
int st;
dbg("chan_pop chan %d expected_st=%d\n", chan->id, expected_st); dbg("chan_pop chan %d expected_st=%d\n", chan->id, expected_st);
if (!chan->enabled) if (!chan->enabled)
@ -239,7 +229,7 @@ chan_pop(struct ovni_chan *chan, int expected_st)
abort(); abort();
} }
st = chan->stack[chan->n - 1]; int st = chan->stack[chan->n - 1];
if (expected_st >= 0 && st != expected_st) { if (expected_st >= 0 && st != expected_st) {
err("chan_pop: unexpected channel state %d (expected %d)\n", err("chan_pop: unexpected channel state %d (expected %d)\n",
@ -338,16 +328,14 @@ emit(struct ovni_chan *chan, int64_t t, int state)
static void static void
emit_ev(struct ovni_chan *chan) emit_ev(struct ovni_chan *chan)
{ {
int new, last;
if (!chan->enabled) if (!chan->enabled)
die("emit_ev: chan %d is not enabled\n", chan->id); die("emit_ev: chan %d is not enabled\n", chan->id);
if (chan->ev == -1) if (chan->ev == -1)
die("emit_ev: chan %d cannot emit -1 ev\n", chan->id); die("emit_ev: chan %d cannot emit -1 ev\n", chan->id);
new = chan->ev; int new = chan->ev;
last = chan_get_st(chan); int last = chan_get_st(chan);
emit(chan, chan->t - 1, new); emit(chan, chan->t - 1, new);
emit(chan, chan->t, last); emit(chan, chan->t, last);
@ -358,9 +346,7 @@ emit_ev(struct ovni_chan *chan)
static void static void
emit_st(struct ovni_chan *chan) emit_st(struct ovni_chan *chan)
{ {
int st; int st = chan_get_st(chan);
st = chan_get_st(chan);
emit(chan, chan->t, st); emit(chan, chan->t, st);
} }

View File

@ -21,33 +21,10 @@
int filter_tid = -1; int filter_tid = -1;
char *tracedir; char *tracedir;
// static void
// hexdump(uint8_t *buf, size_t size)
//{
// size_t i, j;
//
// //printf("writing %ld bytes in cpu=%d\n", size, rthread.cpu);
//
// for(i=0; i<size; i+=16)
// {
// for(j=0; j<16 && i+j < size; j++)
// {
// fprintf(stderr, "%02x ", buf[i+j]);
// }
// fprintf(stderr, "\n");
// }
// }
static void static void
emit(struct ovni_stream *stream, struct ovni_ev *ev) emit(struct ovni_stream *stream, struct ovni_ev *ev)
{ {
uint64_t clock; uint64_t clock = ovni_ev_get_clock(ev);
int i, payloadsize;
// printf("sizeof(*ev) = %d\n", sizeof(*ev));
// hexdump((uint8_t *) ev, sizeof(*ev));
clock = ovni_ev_get_clock(ev);
printf("%s.%d.%d %ld %c%c%c", printf("%s.%d.%d %ld %c%c%c",
stream->loom->hostname, stream->loom->hostname,
@ -58,10 +35,10 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
ev->header.category, ev->header.category,
ev->header.value); ev->header.value);
payloadsize = ovni_payload_size(ev); int payloadsize = ovni_payload_size(ev);
if (payloadsize > 0) { if (payloadsize > 0) {
printf(" "); printf(" ");
for (i = 0; i < payloadsize; i++) for (int i = 0; i < payloadsize; i++)
printf(":%02x", ev->payload.u8[i]); printf(":%02x", ev->payload.u8[i]);
} }
printf("\n"); printf("\n");
@ -73,15 +50,9 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
static void static void
dump_events(struct ovni_trace *trace) dump_events(struct ovni_trace *trace)
{ {
size_t i;
ssize_t f;
uint64_t minclock, lastclock;
struct ovni_ev *ev;
struct ovni_stream *stream;
/* Load events */ /* Load events */
for (i = 0; i < trace->nstreams; i++) { for (size_t i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i]; struct ovni_stream *stream = &trace->stream[i];
/* It can be inactive if it has been disabled by the /* It can be inactive if it has been disabled by the
* thread TID filter */ * thread TID filter */
@ -89,20 +60,21 @@ dump_events(struct ovni_trace *trace)
ovni_load_next_event(stream); ovni_load_next_event(stream);
} }
lastclock = 0; uint64_t lastclock = 0;
while (1) { while (1) {
f = -1; ssize_t f = -1;
minclock = 0; uint64_t minclock = 0;
struct ovni_stream *stream = NULL;
/* Select next event based on the clock */ /* Select next event based on the clock */
for (i = 0; i < trace->nstreams; i++) { for (size_t i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i]; stream = &trace->stream[i];
if (!stream->active) if (!stream->active)
continue; continue;
ev = stream->cur_ev; struct ovni_ev *ev = stream->cur_ev;
if (f < 0 || ovni_ev_get_clock(ev) < minclock) { if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
f = i; f = i;
minclock = ovni_ev_get_clock(ev); minclock = ovni_ev_get_clock(ev);
@ -136,11 +108,8 @@ dump_events(struct ovni_trace *trace)
} }
static void static void
usage(int argc, char *argv[]) usage(void)
{ {
UNUSED(argc);
UNUSED(argv);
err("Usage: ovnidump [-t TID] tracedir\n"); err("Usage: ovnidump [-t TID] tracedir\n");
err("\n"); err("\n");
err("Dumps the events of the trace to the standard output.\n"); err("Dumps the events of the trace to the standard output.\n");
@ -165,13 +134,13 @@ parse_args(int argc, char *argv[])
filter_tid = atoi(optarg); filter_tid = atoi(optarg);
break; break;
default: /* '?' */ default: /* '?' */
usage(argc, argv); usage();
} }
} }
if (optind >= argc) { if (optind >= argc) {
err("missing tracedir\n"); err("missing tracedir\n");
usage(argc, argv); usage();
} }
tracedir = argv[optind]; tracedir = argv[optind];

246
src/emu.c
View File

@ -34,26 +34,19 @@ evclock(struct ovni_stream *stream, struct ovni_ev *ev)
static void static void
print_ev(struct ovni_stream *stream, struct ovni_ev *ev) print_ev(struct ovni_stream *stream, struct ovni_ev *ev)
{ {
int64_t clock, delta = 0; int64_t clock = evclock(stream, ev);
int i, payloadsize;
int64_t delta = clock - stream->lastclock;
UNUSED(delta); UNUSED(delta);
// dbg("sizeof(*ev) = %d\n", sizeof(*ev));
// hexdump((uint8_t *) ev, sizeof(*ev));
clock = evclock(stream, ev);
delta = clock - stream->lastclock;
dbg(">>> %s.%d.%d %c %c %c % 20ld % 15ld ", dbg(">>> %s.%d.%d %c %c %c % 20ld % 15ld ",
stream->loom->hostname, stream->loom->hostname,
stream->proc->pid, stream->proc->pid,
stream->thread->tid, stream->thread->tid,
ev->header.model, ev->header.category, ev->header.value, clock, delta); ev->header.model, ev->header.category, ev->header.value, clock, delta);
payloadsize = ovni_payload_size(ev); int payloadsize = ovni_payload_size(ev);
for (i = 0; i < payloadsize; i++) { for (int i = 0; i < payloadsize; i++) {
dbg("%d ", ev->payload.u8[i]); dbg("%d ", ev->payload.u8[i]);
} }
dbg("\n"); dbg("\n");
@ -69,8 +62,7 @@ print_cur_ev(struct ovni_emu *emu)
static void static void
cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th) cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
{ {
int th_enabled, cpu_enabled, st; int cpu_enabled = 0;
struct ovni_chan *th_chan;
switch (cpu_chan->track) { switch (cpu_chan->track) {
case CHAN_TRACK_TH_RUNNING: case CHAN_TRACK_TH_RUNNING:
@ -85,8 +77,8 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
return; return;
} }
th_chan = &th->chan[cpu_chan->id]; struct ovni_chan *th_chan = &th->chan[cpu_chan->id];
th_enabled = chan_is_enabled(th_chan); int th_enabled = chan_is_enabled(th_chan);
/* Enable the cpu channel if needed */ /* Enable the cpu channel if needed */
if (cpu_enabled && !chan_is_enabled(cpu_chan)) if (cpu_enabled && !chan_is_enabled(cpu_chan))
@ -95,7 +87,7 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
/* Copy the state from the thread channel if needed */ /* Copy the state from the thread channel if needed */
if (th_enabled && cpu_enabled) { if (th_enabled && cpu_enabled) {
/* Both enabled: simply follow the same value */ /* Both enabled: simply follow the same value */
st = chan_get_st(th_chan); int st = chan_get_st(th_chan);
if (chan_get_st(cpu_chan) != st) if (chan_get_st(cpu_chan) != st)
chan_set(cpu_chan, st); chan_set(cpu_chan, st);
} else if (th_enabled && !cpu_enabled) { } else if (th_enabled && !cpu_enabled) {
@ -124,8 +116,8 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
void void
emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan) emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
{ {
int count; int count = 0;
struct ovni_ethread *th; struct ovni_ethread *th = NULL;
/* Determine the source of tracking */ /* Determine the source of tracking */
@ -173,9 +165,8 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
static void static void
propagate_channels(struct ovni_emu *emu) propagate_channels(struct ovni_emu *emu)
{ {
struct ovni_cpu *cpu; struct ovni_chan *th_chan = NULL;
struct ovni_chan *cpu_chan, *th_chan, *tmp; struct ovni_chan *tmp = NULL;
struct ovni_ethread *thread;
/* Only propagate thread channels to their corresponding CPU */ /* Only propagate thread channels to their corresponding CPU */
@ -184,15 +175,15 @@ propagate_channels(struct ovni_emu *emu)
if (th_chan->thread == NULL) if (th_chan->thread == NULL)
die("propagate_channels: channel thread is NULL\n"); die("propagate_channels: channel thread is NULL\n");
thread = th_chan->thread; struct ovni_ethread *thread = th_chan->thread;
/* No CPU in the thread */ /* No CPU in the thread */
if (thread->cpu == NULL) if (thread->cpu == NULL)
continue; continue;
cpu = thread->cpu; struct ovni_cpu *cpu = thread->cpu;
cpu_chan = &cpu->chan[th_chan->id]; struct ovni_chan *cpu_chan = &cpu->chan[th_chan->id];
dbg("propagate thread %d chan %d in cpu %s\n", dbg("propagate thread %d chan %d in cpu %s\n",
thread->tid, th_chan->id, cpu->name); thread->tid, th_chan->id, cpu->name);
@ -333,28 +324,24 @@ get_time(void)
static void static void
print_progress(struct ovni_emu *emu) print_progress(struct ovni_emu *emu)
{ {
double progress, time_now, time_elapsed, time_total, time_left; double cpu_written = (double) ftell(emu->prv_cpu);
double speed_in, speed_out; double th_written = (double) ftell(emu->prv_thread);
double cpu_written, th_written, written;
int min, sec;
cpu_written = (double) ftell(emu->prv_cpu); double written = cpu_written + th_written;
th_written = (double) ftell(emu->prv_thread);
written = cpu_written + th_written; double progress = ((double) emu->global_offset)
/ ((double) emu->global_size);
progress = ((double) emu->global_offset) / ((double) emu->global_size); double time_now = get_time();
double time_elapsed = time_now - emu->start_emulation_time;
double time_total = time_elapsed / progress;
double time_left = time_total - time_elapsed;
time_now = get_time(); double speed_in = (double) emu->nev_processed / time_elapsed;
time_elapsed = time_now - emu->start_emulation_time; double speed_out = written / time_elapsed;
time_total = time_elapsed / progress;
time_left = time_total - time_elapsed;
speed_in = (double) emu->nev_processed / time_elapsed; int tmin = (int) (time_left / 60.0);
speed_out = written / time_elapsed; int sec = (int) ((time_left / 60.0 - tmin) * 60);
min = (int) (time_left / 60.0);
sec = (int) ((time_left / 60.0 - min) * 60);
err("%.1f%% done at %.0f Kev/s, out %.1f GB CPU / %.1f GB TH at %.1f MB/s (%d min %d s left)\n", err("%.1f%% done at %.0f Kev/s, out %.1f GB CPU / %.1f GB TH at %.1f MB/s (%d min %d s left)\n",
100.0 * progress, 100.0 * progress,
@ -362,7 +349,7 @@ print_progress(struct ovni_emu *emu)
cpu_written / (1024.0 * 1024.0 * 1024.0), cpu_written / (1024.0 * 1024.0 * 1024.0),
th_written / (1024.0 * 1024.0 * 1024.0), th_written / (1024.0 * 1024.0 * 1024.0),
speed_out / (1024.0 * 1024), speed_out / (1024.0 * 1024),
min, sec); tmin, sec);
} }
/* Loads the next event and sets the lastclock in the stream. /* Loads the next event and sets the lastclock in the stream.
@ -383,19 +370,16 @@ emu_step_stream(struct ovni_emu *emu, struct ovni_stream *stream)
static int static int
next_event(struct ovni_emu *emu) next_event(struct ovni_emu *emu)
{ {
struct ovni_stream *stream;
heap_node_t *node;
static int done_first = 0; static int done_first = 0;
/* Extract the next stream based on the event clock */ /* Extract the next stream based on the event clock */
node = heap_pop_max(&emu->sorted_stream, stream_cmp); heap_node_t *node = heap_pop_max(&emu->sorted_stream, stream_cmp);
/* No more streams */ /* No more streams */
if (node == NULL) if (node == NULL)
return -1; return -1;
stream = heap_elem(node, struct ovni_stream, hh); struct ovni_stream *stream = heap_elem(node, struct ovni_stream, hh);
if (stream == NULL) if (stream == NULL)
die("next_event: heap_elem returned NULL\n"); die("next_event: heap_elem returned NULL\n");
@ -442,19 +426,15 @@ next_event(struct ovni_emu *emu)
static void static void
emu_load_first_events(struct ovni_emu *emu) emu_load_first_events(struct ovni_emu *emu)
{ {
size_t i;
struct ovni_trace *trace;
struct ovni_stream *stream;
/* Prepare the stream heap */ /* Prepare the stream heap */
heap_init(&emu->sorted_stream); heap_init(&emu->sorted_stream);
emu->lastclock = 0; emu->lastclock = 0;
/* Load initial streams and events */ /* Load initial streams and events */
trace = &emu->trace; struct ovni_trace *trace = &emu->trace;
for (i = 0; i < trace->nstreams; i++) { for (size_t i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i]; struct ovni_stream *stream = &trace->stream[i];
emu->global_size += stream->size; emu->global_size += stream->size;
if (emu_step_stream(emu, stream) < 0) { if (emu_step_stream(emu, stream) < 0) {
@ -471,8 +451,6 @@ emu_load_first_events(struct ovni_emu *emu)
static void static void
emulate(struct ovni_emu *emu) emulate(struct ovni_emu *emu)
{ {
size_t i;
emu->nev_processed = 0; emu->nev_processed = 0;
err("loading first events\n"); err("loading first events\n");
@ -486,7 +464,7 @@ emulate(struct ovni_emu *emu)
emit_channels(emu); emit_channels(emu);
/* Then process all events */ /* Then process all events */
for (i = 0; next_event(emu) == 0; i++) { for (size_t i = 0; next_event(emu) == 0; i++) {
print_cur_ev(emu); print_cur_ev(emu);
hook_pre(emu); hook_pre(emu);
@ -514,11 +492,8 @@ emulate(struct ovni_emu *emu)
struct ovni_ethread * struct ovni_ethread *
emu_get_thread(struct ovni_eproc *proc, int tid) emu_get_thread(struct ovni_eproc *proc, int tid)
{ {
size_t i; for (size_t i = 0; i < proc->nthreads; i++) {
struct ovni_ethread *thread; struct ovni_ethread *thread = &proc->thread[i];
for (i = 0; i < proc->nthreads; i++) {
thread = &proc->thread[i];
if (thread->tid == tid) if (thread->tid == tid)
return thread; return thread;
} }
@ -529,9 +504,7 @@ emu_get_thread(struct ovni_eproc *proc, int tid)
static void static void
add_new_cpu(struct ovni_emu *emu, struct ovni_loom *loom, int i, int phyid) add_new_cpu(struct ovni_emu *emu, struct ovni_loom *loom, int i, int phyid)
{ {
struct ovni_cpu *cpu; struct ovni_cpu *cpu = &loom->cpu[i];
cpu = &loom->cpu[i];
if (i < 0 || i >= (int) loom->ncpus) if (i < 0 || i >= (int) loom->ncpus)
die("CPU with index %d in loom %s is out of bounds\n", die("CPU with index %d in loom %s is out of bounds\n",
@ -619,21 +592,16 @@ proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom,
static void static void
load_metadata(struct ovni_emu *emu) load_metadata(struct ovni_emu *emu)
{ {
size_t i, j; struct ovni_trace *trace = &emu->trace;
struct ovni_loom *loom;
struct ovni_eproc *proc;
struct ovni_trace *trace;
trace = &emu->trace; for (size_t i = 0; i < trace->nlooms; i++) {
struct ovni_loom *loom = &trace->loom[i];
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
loom->offset_ncpus = emu->total_ncpus; loom->offset_ncpus = emu->total_ncpus;
struct ovni_eproc *metadata_proc = NULL; struct ovni_eproc *metadata_proc = NULL;
for (j = 0; j < loom->nprocs; j++) { for (size_t j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j]; struct ovni_eproc *proc = &loom->proc[j];
if (proc_load_cpus(emu, loom, proc, metadata_proc) < 0) if (proc_load_cpus(emu, loom, proc, metadata_proc) < 0)
continue; continue;
@ -658,17 +626,12 @@ load_metadata(struct ovni_emu *emu)
static int static int
destroy_metadata(struct ovni_emu *emu) destroy_metadata(struct ovni_emu *emu)
{ {
size_t i, j; struct ovni_trace *trace = &emu->trace;
struct ovni_loom *loom;
struct ovni_eproc *proc;
struct ovni_trace *trace;
trace = &emu->trace; for (size_t i = 0; i < trace->nlooms; i++) {
struct ovni_loom *loom = &trace->loom[i];
for (i = 0; i < trace->nlooms; i++) { for (size_t j = 0; j < loom->nprocs; j++) {
loom = &trace->loom[i]; struct ovni_eproc *proc = &loom->proc[j];
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
if (proc->meta == NULL) if (proc->meta == NULL)
die("cannot destroy metadata: is NULL\n"); die("cannot destroy metadata: is NULL\n");
@ -746,12 +709,9 @@ close_pcfs(struct ovni_emu *emu)
} }
static void static void
usage(int argc, char *argv[]) usage(void)
{ {
UNUSED(argc); err("Usage: ovniemu [-c offsetfile] tracedir\n");
UNUSED(argv);
err("Usage: emu [-c offsetfile] tracedir\n");
err("\n"); err("\n");
err("Options:\n"); err("Options:\n");
err(" -c offsetfile Use the given offset file to correct\n"); err(" -c offsetfile Use the given offset file to correct\n");
@ -779,13 +739,13 @@ parse_args(struct ovni_emu *emu, int argc, char *argv[])
emu->enable_linter = 1; emu->enable_linter = 1;
break; break;
default: /* '?' */ default: /* '?' */
usage(argc, argv); usage();
} }
} }
if (optind >= argc) { if (optind >= argc) {
err("missing tracedir\n"); err("missing tracedir\n");
usage(argc, argv); usage();
} }
emu->tracedir = argv[optind]; emu->tracedir = argv[optind];
@ -817,15 +777,7 @@ set_clock_offsets(struct ovni_emu *emu, const char *host, size_t offset)
static void static void
load_clock_offsets(struct ovni_emu *emu) load_clock_offsets(struct ovni_emu *emu)
{ {
FILE *f; FILE *f = NULL;
char buf[1024];
size_t i;
int rank, ret;
double offset, mean, std;
char host[OVNI_MAX_HOSTNAME];
struct ovni_loom *loom;
struct ovni_trace *trace;
struct ovni_stream *stream;
if (emu->clock_offset_file != NULL) { if (emu->clock_offset_file != NULL) {
f = fopen(emu->clock_offset_file, "r"); f = fopen(emu->clock_offset_file, "r");
@ -854,13 +806,17 @@ load_clock_offsets(struct ovni_emu *emu)
} }
/* Ignore header line */ /* Ignore header line */
char buf[1024];
if (fgets(buf, 1024, f) == NULL) { if (fgets(buf, 1024, f) == NULL) {
perror("fgets failed"); err("missing header line in clock offset file");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while (1) { while (1) {
errno = 0; errno = 0;
int rank, ret;
double offset, mean, std;
char host[OVNI_MAX_HOSTNAME];
ret = fscanf(f, "%d %s %lf %lf %lf", &rank, host, &offset, &mean, &std); ret = fscanf(f, "%d %s %lf %lf %lf", &rank, host, &offset, &mean, &std);
if (ret == EOF) { if (ret == EOF) {
@ -883,11 +839,11 @@ load_clock_offsets(struct ovni_emu *emu)
/* Then populate the stream offsets */ /* Then populate the stream offsets */
trace = &emu->trace; struct ovni_trace *trace = &emu->trace;
for (i = 0; i < trace->nstreams; i++) { for (size_t i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i]; struct ovni_stream *stream = &trace->stream[i];
loom = stream->loom; struct ovni_loom *loom = stream->loom;
stream->clock_offset = loom->clock_offset; stream->clock_offset = loom->clock_offset;
} }
@ -899,14 +855,11 @@ load_clock_offsets(struct ovni_emu *emu)
static void static void
write_row_cpu(struct ovni_emu *emu) write_row_cpu(struct ovni_emu *emu)
{ {
FILE *f;
size_t i;
char path[PATH_MAX]; char path[PATH_MAX];
struct ovni_cpu *cpu;
sprintf(path, "%s/%s", emu->tracedir, "cpu.row"); sprintf(path, "%s/%s", emu->tracedir, "cpu.row");
f = fopen(path, "w"); FILE *f = fopen(path, "w");
if (f == NULL) { if (f == NULL) {
perror("cannot open row file"); perror("cannot open row file");
@ -919,8 +872,8 @@ write_row_cpu(struct ovni_emu *emu)
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_ncpus); fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_ncpus);
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
fprintf(f, "%s\n", cpu->name); fprintf(f, "%s\n", cpu->name);
} }
@ -930,14 +883,11 @@ write_row_cpu(struct ovni_emu *emu)
static void static void
write_row_thread(struct ovni_emu *emu) write_row_thread(struct ovni_emu *emu)
{ {
FILE *f;
size_t i;
char path[PATH_MAX]; char path[PATH_MAX];
struct ovni_ethread *th;
sprintf(path, "%s/%s", emu->tracedir, "thread.row"); sprintf(path, "%s/%s", emu->tracedir, "thread.row");
f = fopen(path, "w"); FILE *f = fopen(path, "w");
if (f == NULL) { if (f == NULL) {
perror("cannot open row file"); perror("cannot open row file");
@ -950,8 +900,8 @@ write_row_thread(struct ovni_emu *emu)
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_nthreads); fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_nthreads);
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
fprintf(f, "THREAD %d.%d\n", th->proc->appid, th->tid); fprintf(f, "THREAD %d.%d\n", th->proc->appid, th->tid);
} }
@ -961,24 +911,18 @@ write_row_thread(struct ovni_emu *emu)
static void static void
init_threads(struct ovni_emu *emu) init_threads(struct ovni_emu *emu)
{ {
struct ovni_trace *trace;
struct ovni_loom *loom;
struct ovni_eproc *proc;
struct ovni_ethread *thread;
size_t i, j, k, gi;
emu->total_nthreads = 0; emu->total_nthreads = 0;
emu->total_nprocs = 0; emu->total_nprocs = 0;
trace = &emu->trace; struct ovni_trace *trace = &emu->trace;
for (i = 0; i < trace->nlooms; i++) { /* Count total processes and threads */
loom = &trace->loom[i]; for (size_t i = 0; i < trace->nlooms; i++) {
for (j = 0; j < loom->nprocs; j++) { struct ovni_loom *loom = &trace->loom[i];
proc = &loom->proc[j]; for (size_t j = 0; j < loom->nprocs; j++) {
struct ovni_eproc *proc = &loom->proc[j];
emu->total_nprocs++; emu->total_nprocs++;
for (k = 0; k < proc->nthreads; k++) { for (size_t k = 0; k < proc->nthreads; k++) {
thread = &proc->thread[k];
emu->total_nthreads++; emu->total_nthreads++;
} }
} }
@ -992,12 +936,15 @@ init_threads(struct ovni_emu *emu)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (gi = 0, i = 0; i < trace->nlooms; i++) { int gi = 0;
loom = &trace->loom[i];
for (j = 0; j < loom->nprocs; j++) { /* Populate global_thread array */
proc = &loom->proc[j]; for (size_t i = 0; i < trace->nlooms; i++) {
for (k = 0; k < proc->nthreads; k++) { struct ovni_loom *loom = &trace->loom[i];
thread = &proc->thread[k]; for (size_t j = 0; j < loom->nprocs; j++) {
struct ovni_eproc *proc = &loom->proc[j];
for (size_t k = 0; k < proc->nthreads; k++) {
struct ovni_ethread *thread = &proc->thread[k];
emu->global_thread[gi++] = thread; emu->global_thread[gi++] = thread;
} }
@ -1008,12 +955,7 @@ init_threads(struct ovni_emu *emu)
static void static void
init_cpus(struct ovni_emu *emu) init_cpus(struct ovni_emu *emu)
{ {
struct ovni_trace *trace; struct ovni_trace *trace = &emu->trace;
struct ovni_loom *loom;
struct ovni_cpu *cpu;
size_t i, j;
trace = &emu->trace;
emu->global_cpu = calloc(emu->total_ncpus, emu->global_cpu = calloc(emu->total_ncpus,
sizeof(*emu->global_cpu)); sizeof(*emu->global_cpu));
@ -1023,14 +965,13 @@ init_cpus(struct ovni_emu *emu)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (i = 0; i < trace->nlooms; i++) { for (size_t i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i]; struct ovni_loom *loom = &trace->loom[i];
for (j = 0; j < loom->ncpus; j++) { for (size_t j = 0; j < loom->ncpus; j++) {
cpu = &loom->cpu[j]; struct ovni_cpu *cpu = &loom->cpu[j];
emu->global_cpu[cpu->gindex] = cpu; emu->global_cpu[cpu->gindex] = cpu;
if (snprintf(cpu->name, MAX_CPU_NAME, "CPU %ld.%ld", if (snprintf(cpu->name, MAX_CPU_NAME, "CPU %ld.%ld", i, j)
i, j)
>= MAX_CPU_NAME) { >= MAX_CPU_NAME) {
err("error cpu %ld.%ld name too long\n", i, j); err("error cpu %ld.%ld name too long\n", i, j);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1039,8 +980,7 @@ init_cpus(struct ovni_emu *emu)
} }
emu->global_cpu[loom->vcpu.gindex] = &loom->vcpu; emu->global_cpu[loom->vcpu.gindex] = &loom->vcpu;
if (snprintf(loom->vcpu.name, MAX_CPU_NAME, "CPU %ld.*", if (snprintf(loom->vcpu.name, MAX_CPU_NAME, "CPU %ld.*", i)
i)
>= MAX_CPU_NAME) { >= MAX_CPU_NAME) {
err("error cpu %ld.* name too long\n", i); err("error cpu %ld.* name too long\n", i);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1171,9 +1111,7 @@ eerr(struct ovni_emu *emu, const char *fmt, ...)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct ovni_emu *emu; struct ovni_emu *emu = malloc(sizeof(struct ovni_emu));
emu = malloc(sizeof(struct ovni_emu));
if (emu == NULL) { if (emu == NULL) {
perror("malloc"); perror("malloc");

View File

@ -14,32 +14,24 @@
void void
hook_init_kernel(struct ovni_emu *emu) hook_init_kernel(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
size_t i; FILE *prv_cpu = emu->prv_cpu;
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 */ /* Init the channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_KERNEL_CS, CHAN_TRACK_NONE, 0, 1, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_KERNEL_CS, CHAN_TRACK_NONE, 0, 1, 1, row, prv_th, clock);
} }
/* Init the channels in all cpus */ /* Init the channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_KERNEL_CS, CHAN_TRACK_TH_ACTIVE, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_KERNEL_CS, CHAN_TRACK_TH_ACTIVE, 0, 0, 1, row, prv_cpu, clock);
} }
@ -50,11 +42,8 @@ hook_init_kernel(struct ovni_emu *emu)
static void static void
context_switch(struct ovni_emu *emu) context_switch(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan; struct ovni_chan *chan = &th->chan[CHAN_KERNEL_CS];
th = emu->cur_thread;
chan = &th->chan[CHAN_KERNEL_CS];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'O': case 'O':

View File

@ -13,23 +13,16 @@
void void
hook_init_nanos6(struct ovni_emu *emu) hook_init_nanos6(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
struct ovni_chan **uth, **ucpu; FILE *prv_cpu = emu->prv_cpu;
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 */ /* Init the channels in all threads */
for (size_t i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
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_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_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
@ -40,9 +33,9 @@ hook_init_nanos6(struct ovni_emu *emu)
/* Init the Nanos6 channels in all cpus */ /* Init the Nanos6 channels in all cpus */
for (size_t i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
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_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); chan_cpu_init(cpu, ucpu, CHAN_NANOS6_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
@ -53,7 +46,7 @@ hook_init_nanos6(struct ovni_emu *emu)
/* Init task stack */ /* Init task stack */
for (size_t i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
th->nanos6_task_stack.thread = th; th->nanos6_task_stack.thread = th;
} }
} }
@ -63,8 +56,7 @@ hook_init_nanos6(struct ovni_emu *emu)
static void static void
chan_task_stopped(struct ovni_emu *emu) chan_task_stopped(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
th = emu->cur_thread;
chan_set(&th->chan[CHAN_NANOS6_TASKID], 0); chan_set(&th->chan[CHAN_NANOS6_TASKID], 0);
chan_set(&th->chan[CHAN_NANOS6_TYPE], 0); chan_set(&th->chan[CHAN_NANOS6_TYPE], 0);
@ -76,11 +68,8 @@ chan_task_stopped(struct ovni_emu *emu)
static void static void
chan_task_running(struct ovni_emu *emu, struct task *task) chan_task_running(struct ovni_emu *emu, struct task *task)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_eproc *proc; struct ovni_eproc *proc = emu->cur_proc;
th = emu->cur_thread;
proc = emu->cur_proc;
if (task->id == 0) if (task->id == 0)
edie(emu, "task id cannot be 0\n"); edie(emu, "task id cannot be 0\n");
@ -311,11 +300,8 @@ pre_type(struct ovni_emu *emu)
static void static void
pre_deps(struct ovni_emu *emu) pre_deps(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'r': case 'r':
@ -338,11 +324,8 @@ pre_deps(struct ovni_emu *emu)
static void static void
pre_blocking(struct ovni_emu *emu) pre_blocking(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'b': case 'b':
@ -377,11 +360,8 @@ pre_blocking(struct ovni_emu *emu)
static void static void
pre_worker(struct ovni_emu *emu) pre_worker(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':
@ -431,11 +411,8 @@ pre_worker(struct ovni_emu *emu)
static void static void
pre_memory(struct ovni_emu *emu) pre_memory(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'a': case 'a':
@ -458,11 +435,8 @@ pre_memory(struct ovni_emu *emu)
static void static void
pre_sched(struct ovni_emu *emu) pre_sched(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':
@ -500,11 +474,8 @@ pre_sched(struct ovni_emu *emu)
static void static void
pre_thread(struct ovni_emu *emu) pre_thread(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_THREAD];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_THREAD];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'e': case 'e':
@ -539,11 +510,8 @@ pre_thread(struct ovni_emu *emu)
static void static void
pre_ss(struct ovni_emu *emu, int st) pre_ss(struct ovni_emu *emu, int st)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st); dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);

View File

@ -13,32 +13,24 @@
void void
hook_init_nodes(struct ovni_emu *emu) hook_init_nodes(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
size_t i; FILE *prv_cpu = emu->prv_cpu;
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 */ /* Init the channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
} }
/* Init the channels in all cpus */ /* Init the channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_NODES_SUBSYSTEM, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
} }
@ -49,11 +41,8 @@ hook_init_nodes(struct ovni_emu *emu)
static void static void
pre_subsystem(struct ovni_emu *emu, int st) pre_subsystem(struct ovni_emu *emu, int st)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan; struct ovni_chan *chan = &th->chan[CHAN_NODES_SUBSYSTEM];
th = emu->cur_thread;
chan = &th->chan[CHAN_NODES_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':

View File

@ -15,24 +15,16 @@
void void
hook_init_nosv(struct ovni_emu *emu) hook_init_nosv(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
struct ovni_chan **uth, **ucpu; FILE *prv_cpu = emu->prv_cpu;
size_t i;
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 */ /* Init the channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
chan_th_init(th, uth, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
@ -47,10 +39,10 @@ hook_init_nosv(struct ovni_emu *emu)
} }
/* Init the nosv channels in all cpus */ /* Init the nosv channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_NOSV_TASKID, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
chan_cpu_init(cpu, ucpu, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_NOSV_TYPE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
@ -60,8 +52,8 @@ hook_init_nosv(struct ovni_emu *emu)
} }
/* Init task stack */ /* Init task stack */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
th->nosv_task_stack.thread = th; th->nosv_task_stack.thread = th;
} }
} }
@ -87,11 +79,8 @@ chan_task_stopped(struct ovni_emu *emu)
static void static void
chan_task_running(struct ovni_emu *emu, struct task *task) chan_task_running(struct ovni_emu *emu, struct task *task)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_eproc *proc; struct ovni_eproc *proc = emu->cur_proc;
th = emu->cur_thread;
proc = emu->cur_proc;
if (task->id == 0) if (task->id == 0)
edie(emu, "task id cannot be 0\n"); edie(emu, "task id cannot be 0\n");
@ -308,11 +297,8 @@ pre_type(struct ovni_emu *emu)
static void static void
pre_sched(struct ovni_emu *emu) pre_sched(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'h': case 'h':
@ -344,11 +330,8 @@ pre_sched(struct ovni_emu *emu)
static void static void
pre_api(struct ovni_emu *emu) pre_api(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 's': case 's':
@ -389,11 +372,8 @@ pre_api(struct ovni_emu *emu)
static void static void
pre_mem(struct ovni_emu *emu) pre_mem(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'a': case 'a':
@ -416,11 +396,8 @@ pre_mem(struct ovni_emu *emu)
static void static void
pre_thread_type(struct ovni_emu *emu) pre_thread_type(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case 'a': case 'a':
@ -449,11 +426,8 @@ pre_thread_type(struct ovni_emu *emu)
static void static void
pre_ss(struct ovni_emu *emu, int st) pre_ss(struct ovni_emu *emu, int st)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st); dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);

View File

@ -13,32 +13,24 @@
void void
hook_init_openmp(struct ovni_emu *emu) hook_init_openmp(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
size_t i; FILE *prv_cpu = emu->prv_cpu;
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 */ /* Init the channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
} }
/* Init the channels in all cpus */ /* Init the channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_OPENMP_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
} }
@ -49,11 +41,8 @@ hook_init_openmp(struct ovni_emu *emu)
static void static void
pre_mode(struct ovni_emu *emu, int st) pre_mode(struct ovni_emu *emu, int st)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan; struct ovni_chan *chan = &th->chan[CHAN_OPENMP_MODE];
th = emu->cur_thread;
chan = &th->chan[CHAN_OPENMP_MODE];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':

View File

@ -15,23 +15,15 @@
void void
hook_init_ovni(struct ovni_emu *emu) hook_init_ovni(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
struct ovni_chan **uth, **ucpu; FILE *prv_cpu = emu->prv_cpu;
size_t i;
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 ovni channels in all threads */ /* Init the ovni channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_OVNI_TID, CHAN_TRACK_TH_RUNNING, th->tid, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_OVNI_TID, CHAN_TRACK_TH_RUNNING, th->tid, 0, 1, row, prv_th, clock);
chan_th_init(th, uth, CHAN_OVNI_PID, CHAN_TRACK_TH_RUNNING, th->proc->pid, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_OVNI_PID, CHAN_TRACK_TH_RUNNING, th->proc->pid, 0, 1, row, prv_th, clock);
@ -41,10 +33,10 @@ hook_init_ovni(struct ovni_emu *emu)
} }
/* Init the ovni channels in all cpus */ /* Init the ovni channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_OVNI_TID, CHAN_TRACK_TH_RUNNING, 0, 1, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_OVNI_TID, CHAN_TRACK_TH_RUNNING, 0, 1, 1, row, prv_cpu, clock);
chan_cpu_init(cpu, ucpu, CHAN_OVNI_PID, CHAN_TRACK_TH_RUNNING, 0, 1, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_OVNI_PID, CHAN_TRACK_TH_RUNNING, 0, 1, 1, row, prv_cpu, clock);
@ -59,7 +51,7 @@ hook_init_ovni(struct ovni_emu *emu)
static void static void
chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th) chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
{ {
int enabled; int enabled = 0;
if (th == NULL) if (th == NULL)
die("chan_tracking_update: thread is NULL"); die("chan_tracking_update: thread is NULL");
@ -91,8 +83,6 @@ chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
static void static void
thread_set_state(struct ovni_ethread *th, enum ethread_state state) thread_set_state(struct ovni_ethread *th, enum ethread_state state)
{ {
int i;
/* The state must be updated when a cpu is set */ /* The state must be updated when a cpu is set */
if (th->cpu == NULL) if (th->cpu == NULL)
die("thread_set_state: thread %d doesn't have a CPU\n", die("thread_set_state: thread %d doesn't have a CPU\n",
@ -114,7 +104,7 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
chan_set(&th->chan[CHAN_OVNI_STATE], th->state); chan_set(&th->chan[CHAN_OVNI_STATE], th->state);
/* Enable or disable the thread channels that track the thread state */ /* Enable or disable the thread channels that track the thread state */
for (i = 0; i < CHAN_MAX; i++) for (int i = 0; i < CHAN_MAX; i++)
chan_tracking_update(&th->chan[i], th); chan_tracking_update(&th->chan[i], th);
dbg("thread_set_state: done\n"); dbg("thread_set_state: done\n");
@ -123,7 +113,9 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
static void static void
cpu_update_th_stats(struct ovni_cpu *cpu) cpu_update_th_stats(struct ovni_cpu *cpu)
{ {
struct ovni_ethread *th, *th_running = NULL, *th_active = NULL; struct ovni_ethread *th = NULL;
struct ovni_ethread *th_running = NULL;
struct ovni_ethread *th_active = NULL;
int active = 0, running = 0; int active = 0, running = 0;
DL_FOREACH(cpu->thread, th) DL_FOREACH(cpu->thread, th)
@ -148,8 +140,6 @@ cpu_update_th_stats(struct ovni_cpu *cpu)
static void static void
update_cpu(struct ovni_cpu *cpu) update_cpu(struct ovni_cpu *cpu)
{ {
int i;
dbg("updating cpu %s\n", cpu->name); dbg("updating cpu %s\n", cpu->name);
/* Update the running and active threads first */ /* Update the running and active threads first */
@ -161,7 +151,7 @@ update_cpu(struct ovni_cpu *cpu)
chan_set(&cpu->chan[CHAN_OVNI_NRTHREADS], (int) cpu->nrunning_threads); chan_set(&cpu->chan[CHAN_OVNI_NRTHREADS], (int) cpu->nrunning_threads);
/* Update all tracking channels */ /* Update all tracking channels */
for (i = 0; i < CHAN_MAX; i++) for (int i = 0; i < CHAN_MAX; i++)
emu_cpu_update_chan(cpu, &cpu->chan[i]); emu_cpu_update_chan(cpu, &cpu->chan[i]);
dbg("updating cpu %s complete!\n", cpu->name); dbg("updating cpu %s complete!\n", cpu->name);
@ -213,9 +203,7 @@ cpu_add_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
static void static void
cpu_remove_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread) cpu_remove_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
{ {
struct ovni_ethread *p; struct ovni_ethread *p = emu_cpu_find_thread(cpu, thread);
p = emu_cpu_find_thread(cpu, thread);
/* Not found, abort */ /* Not found, abort */
if (p == NULL) { if (p == NULL) {
@ -286,17 +274,14 @@ thread_migrate_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu)
static void static void
pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th) pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th)
{ {
struct ovni_cpu *cpu;
int cpuid;
/* The thread cannot be already running */ /* The thread cannot be already running */
if (th->state == TH_ST_RUNNING) if (th->state == TH_ST_RUNNING)
edie(emu, "pre_thread_execute: thread %d already running\n", edie(emu, "pre_thread_execute: thread %d already running\n",
th->tid); th->tid);
cpuid = emu->cur_ev->payload.i32[0]; int cpuid = emu->cur_ev->payload.i32[0];
cpu = emu_get_cpu(emu->cur_loom, cpuid); struct ovni_cpu *cpu = emu_get_cpu(emu->cur_loom, cpuid);
dbg("pre_thread_execute: thread %d runs in CPU %s\n", th->tid, cpu->name); dbg("pre_thread_execute: thread %d runs in CPU %s\n", th->tid, cpu->name);
/* First set the CPU in the thread */ /* First set the CPU in the thread */
@ -393,13 +378,8 @@ pre_thread_warm(struct ovni_ethread *th)
static void static void
pre_thread(struct ovni_emu *emu) pre_thread(struct ovni_emu *emu)
{ {
struct ovni_ev *ev; struct ovni_ethread *th = emu->cur_thread;
struct ovni_ethread *th; struct ovni_ev *ev = emu->cur_ev;
// emu_emit(emu);
th = emu->cur_thread;
ev = emu->cur_ev;
switch (ev->header.value) { switch (ev->header.value) {
case 'C': /* create */ case 'C': /* create */
@ -438,12 +418,8 @@ pre_thread(struct ovni_emu *emu)
static void static void
pre_affinity_set(struct ovni_emu *emu) pre_affinity_set(struct ovni_emu *emu)
{ {
int cpuid; struct ovni_ethread *th = emu->cur_thread;
struct ovni_cpu *newcpu; int cpuid = emu->cur_ev->payload.i32[0];
struct ovni_ethread *th;
th = emu->cur_thread;
cpuid = emu->cur_ev->payload.i32[0];
if (th->cpu == NULL) if (th->cpu == NULL)
edie(emu, "pre_affinity_set: thread %d doesn't have a CPU\n", edie(emu, "pre_affinity_set: thread %d doesn't have a CPU\n",
@ -454,7 +430,7 @@ pre_affinity_set(struct ovni_emu *emu)
th->tid); th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */
newcpu = emu_get_cpu(emu->cur_loom, cpuid); struct ovni_cpu *newcpu = emu_get_cpu(emu->cur_loom, cpuid);
/* The CPU is already properly set, return */ /* The CPU is already properly set, return */
if (th->cpu == newcpu) if (th->cpu == newcpu)
@ -469,25 +445,18 @@ pre_affinity_set(struct ovni_emu *emu)
static void static void
pre_affinity_remote(struct ovni_emu *emu) pre_affinity_remote(struct ovni_emu *emu)
{ {
size_t i; int32_t cpuid = emu->cur_ev->payload.i32[0];
int32_t cpuid, tid; int32_t tid = emu->cur_ev->payload.i32[1];
struct ovni_cpu *newcpu;
struct ovni_ethread *remote_th;
struct ovni_loom *loom;
struct ovni_eproc *proc;
cpuid = emu->cur_ev->payload.i32[0]; struct ovni_ethread *remote_th = emu_get_thread(emu->cur_proc, tid);
tid = emu->cur_ev->payload.i32[1];
remote_th = emu_get_thread(emu->cur_proc, tid);
if (remote_th == NULL) { if (remote_th == NULL) {
/* Search the thread in other processes of the loom if /* Search the thread in other processes of the loom if
* not found in the current one */ * not found in the current one */
loom = emu->cur_loom; struct ovni_loom *loom = emu->cur_loom;
for (i = 0; i < loom->nprocs; i++) { for (size_t i = 0; i < loom->nprocs; i++) {
proc = &loom->proc[i]; struct ovni_eproc *proc = &loom->proc[i];
/* Skip the current process */ /* Skip the current process */
if (proc == emu->cur_proc) if (proc == emu->cur_proc)
@ -521,7 +490,7 @@ pre_affinity_remote(struct ovni_emu *emu)
remote_th->tid); remote_th->tid);
/* Migrate current cpu to the one at cpuid */ /* Migrate current cpu to the one at cpuid */
newcpu = emu_get_cpu(emu->cur_loom, cpuid); struct ovni_cpu *newcpu = emu_get_cpu(emu->cur_loom, cpuid);
cpu_migrate_thread(remote_th->cpu, remote_th, newcpu); cpu_migrate_thread(remote_th->cpu, remote_th, newcpu);
thread_migrate_cpu(remote_th, newcpu); thread_migrate_cpu(remote_th, newcpu);
@ -585,11 +554,8 @@ pre_burst(struct ovni_emu *emu)
static void static void
pre_flush(struct ovni_emu *emu) pre_flush(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th; struct ovni_chan *chan_th = &th->chan[CHAN_OVNI_FLUSH];
th = emu->cur_thread;
chan_th = &th->chan[CHAN_OVNI_FLUSH];
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':
@ -608,8 +574,6 @@ pre_flush(struct ovni_emu *emu)
void void
hook_pre_ovni(struct ovni_emu *emu) hook_pre_ovni(struct ovni_emu *emu)
{ {
// emu_emit(emu);
if (emu->cur_ev->header.model != 'O') if (emu->cur_ev->header.model != 'O')
return; return;

View File

@ -13,32 +13,24 @@
void void
hook_init_tampi(struct ovni_emu *emu) hook_init_tampi(struct ovni_emu *emu)
{ {
struct ovni_ethread *th; int64_t *clock = &emu->delta_time;
struct ovni_cpu *cpu; FILE *prv_th = emu->prv_thread;
size_t i; FILE *prv_cpu = emu->prv_cpu;
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 */ /* Init the channels in all threads */
for (i = 0; i < emu->total_nthreads; i++) { for (size_t i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i]; struct ovni_ethread *th = emu->global_thread[i];
row = th->gindex + 1; int row = th->gindex + 1;
uth = &emu->th_chan; struct ovni_chan **uth = &emu->th_chan;
chan_th_init(th, uth, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock); chan_th_init(th, uth, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_th, clock);
} }
/* Init the channels in all cpus */ /* Init the channels in all cpus */
for (i = 0; i < emu->total_ncpus; i++) { for (size_t i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i]; struct ovni_cpu *cpu = emu->global_cpu[i];
row = cpu->gindex + 1; int row = cpu->gindex + 1;
ucpu = &emu->cpu_chan; struct ovni_chan **ucpu = &emu->cpu_chan;
chan_cpu_init(cpu, ucpu, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock); chan_cpu_init(cpu, ucpu, CHAN_TAMPI_MODE, CHAN_TRACK_TH_RUNNING, 0, 0, 1, row, prv_cpu, clock);
} }
@ -49,9 +41,7 @@ hook_init_tampi(struct ovni_emu *emu)
static void static void
pre_tampi_mode(struct ovni_emu *emu, int state) pre_tampi_mode(struct ovni_emu *emu, int state)
{ {
struct ovni_ethread *th; struct ovni_ethread *th = emu->cur_thread;
th = emu->cur_thread;
switch (emu->cur_ev->header.value) { switch (emu->cur_ev->header.value) {
case '[': case '[':

View File

@ -229,8 +229,7 @@ void
task_create_pcf_types(struct pcf_type *pcftype, struct task_type *types) task_create_pcf_types(struct pcf_type *pcftype, struct task_type *types)
{ {
/* Emit types for all task types */ /* Emit types for all task types */
struct task_type *tt; for (struct task_type *tt = types; tt != NULL; tt = tt->hh.next) {
for (tt = types; tt != NULL; tt = tt->hh.next) {
struct pcf_value *pcfvalue = pcf_find_value(pcftype, tt->gid); struct pcf_value *pcfvalue = pcf_find_value(pcftype, tt->gid);
if (pcfvalue != NULL) { if (pcfvalue != NULL) {
/* Ensure the label is the same, so we know that /* Ensure the label is the same, so we know that

View File

@ -243,7 +243,6 @@ static int
move_thread_to_final(const char *src, const char *dst) move_thread_to_final(const char *src, const char *dst)
{ {
char buffer[1024]; char buffer[1024];
size_t bytes;
FILE *infile = fopen(src, "r"); FILE *infile = fopen(src, "r");
@ -259,6 +258,7 @@ move_thread_to_final(const char *src, const char *dst)
return -1; return -1;
} }
size_t bytes;
while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0) while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0)
fwrite(buffer, 1, bytes, outfile); fwrite(buffer, 1, bytes, outfile);
@ -276,10 +276,7 @@ move_thread_to_final(const char *src, const char *dst)
static void static void
move_procdir_to_final(const char *procdir, const char *procdir_final) move_procdir_to_final(const char *procdir, const char *procdir_final)
{ {
struct dirent *dirent;
DIR *dir; DIR *dir;
char thread[PATH_MAX];
char thread_final[PATH_MAX];
int err = 0; int err = 0;
if ((dir = opendir(procdir)) == NULL) { if ((dir = opendir(procdir)) == NULL) {
@ -287,12 +284,14 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
return; return;
} }
struct dirent *dirent;
const char *prefix = "thread."; const char *prefix = "thread.";
while ((dirent = readdir(dir)) != NULL) { while ((dirent = readdir(dir)) != NULL) {
/* It should only contain thread.* directories, skip others */ /* It should only contain thread.* directories, skip others */
if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0) if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
continue; continue;
char thread[PATH_MAX];
if (snprintf(thread, PATH_MAX, "%s/%s", procdir, if (snprintf(thread, PATH_MAX, "%s/%s", procdir,
dirent->d_name) dirent->d_name)
>= PATH_MAX) { >= PATH_MAX) {
@ -302,6 +301,7 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
continue; continue;
} }
char thread_final[PATH_MAX];
if (snprintf(thread_final, PATH_MAX, "%s/%s", procdir_final, if (snprintf(thread_final, PATH_MAX, "%s/%s", procdir_final,
dirent->d_name) dirent->d_name)
>= PATH_MAX) { >= PATH_MAX) {
@ -336,7 +336,6 @@ ovni_proc_fini(void)
/* Mark the process no longer ready */ /* Mark the process no longer ready */
rproc.ready = 0; rproc.ready = 0;
if (rproc.move_to_final) { if (rproc.move_to_final) {
proc_metadata_store(rproc.meta, rproc.procdir_final); proc_metadata_store(rproc.meta, rproc.procdir_final);
move_procdir_to_final(rproc.procdir, rproc.procdir_final); move_procdir_to_final(rproc.procdir, rproc.procdir_final);
@ -488,12 +487,10 @@ get_jumbo_payload_size(const struct ovni_ev *ev)
int int
ovni_payload_size(const struct ovni_ev *ev) ovni_payload_size(const struct ovni_ev *ev)
{ {
int size;
if (ev->header.flags & OVNI_EV_JUMBO) if (ev->header.flags & OVNI_EV_JUMBO)
return get_jumbo_payload_size(ev); return get_jumbo_payload_size(ev);
size = ev->header.flags & 0x0f; int size = ev->header.flags & 0x0f;
if (size == 0) if (size == 0)
return 0; return 0;

View File

@ -74,10 +74,8 @@ get_time(clockid_t clock, int use_ns)
static int static int
cmp_double(const void *pa, const void *pb) cmp_double(const void *pa, const void *pb)
{ {
double a, b; double a = *(const double *) pa;
double b = *(const double *) pb;
a = *(const double *) pa;
b = *(const double *) pb;
if (a < b) if (a < b)
return -1; return -1;
@ -116,9 +114,6 @@ try_mkdir(const char *path, mode_t mode)
static int static int
mkpath(const char *path, mode_t mode) mkpath(const char *path, mode_t mode)
{ {
char *pp;
char *sp;
int status;
char *copypath = strdup(path); char *copypath = strdup(path);
/* Remove trailing slash */ /* Remove trailing slash */
@ -126,8 +121,9 @@ mkpath(const char *path, mode_t mode)
while (last > 0 && copypath[last] == '/') while (last > 0 && copypath[last] == '/')
copypath[last--] = '\0'; copypath[last--] = '\0';
status = 0; int status = 0;
pp = copypath; char *pp = copypath;
char *sp;
while (status == 0 && (sp = strchr(pp, '/')) != 0) { while (status == 0 && (sp = strchr(pp, '/')) != 0) {
if (sp != pp) { if (sp != pp) {
/* Neither root nor double slash in path */ /* Neither root nor double slash in path */
@ -145,8 +141,6 @@ mkpath(const char *path, mode_t mode)
static void static void
parse_options(struct options *options, int argc, char *argv[]) parse_options(struct options *options, int argc, char *argv[])
{ {
int opt;
/* Default options */ /* Default options */
options->ndrift_samples = 1; options->ndrift_samples = 1;
options->nsamples = 100; options->nsamples = 100;
@ -154,6 +148,7 @@ parse_options(struct options *options, int argc, char *argv[])
options->drift_wait = 5; options->drift_wait = 5;
options->outpath = "ovni/clock-offsets.txt"; options->outpath = "ovni/clock-offsets.txt";
int opt;
while ((opt = getopt(argc, argv, "d:vn:w:o:h")) != -1) { while ((opt = getopt(argc, argv, "d:vn:w:o:h")) != -1) {
switch (opt) { switch (opt) {
case 'd': case 'd':
@ -186,14 +181,12 @@ parse_options(struct options *options, int argc, char *argv[])
static void static void
get_clock_samples(struct offset *offset, int nsamples) get_clock_samples(struct offset *offset, int nsamples)
{ {
int i;
/* Keep the wall time as well */ /* Keep the wall time as well */
offset->wall_t0 = get_time(CLOCK_REALTIME, 0); offset->wall_t0 = get_time(CLOCK_REALTIME, 0);
offset->nsamples = nsamples; offset->nsamples = nsamples;
for (i = 0; i < nsamples; i++) { for (int i = 0; i < nsamples; i++) {
MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD);
offset->clock_sample[i] = get_time(CLOCK_MONOTONIC, 1); offset->clock_sample[i] = get_time(CLOCK_MONOTONIC, 1);
} }
@ -204,8 +197,6 @@ get_clock_samples(struct offset *offset, int nsamples)
static void static void
fill_offset(struct offset *offset, int nsamples) fill_offset(struct offset *offset, int nsamples)
{ {
int warmup_nsamples;
/* Identify the rank */ /* Identify the rank */
MPI_Comm_rank(MPI_COMM_WORLD, &offset->rank); MPI_Comm_rank(MPI_COMM_WORLD, &offset->rank);
@ -218,7 +209,7 @@ fill_offset(struct offset *offset, int nsamples)
// printf("rank=%d hostname=%s\n", offset->rank, offset->hostname); // printf("rank=%d hostname=%s\n", offset->rank, offset->hostname);
/* Warm up iterations */ /* Warm up iterations */
warmup_nsamples = nsamples >= 20 ? 20 : nsamples; int warmup_nsamples = nsamples >= 20 ? 20 : nsamples;
get_clock_samples(offset, warmup_nsamples); get_clock_samples(offset, warmup_nsamples);
get_clock_samples(offset, nsamples); get_clock_samples(offset, nsamples);
@ -227,17 +218,14 @@ fill_offset(struct offset *offset, int nsamples)
static void static void
offset_compute_delta(struct offset *ref, struct offset *cur, int nsamples, int verbose) offset_compute_delta(struct offset *ref, struct offset *cur, int nsamples, int verbose)
{ {
int i; double *delta = malloc(sizeof(double) * nsamples);
double *delta;
delta = malloc(sizeof(double) * nsamples);
if (delta == NULL) { if (delta == NULL) {
perror("malloc"); perror("malloc");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (i = 0; i < nsamples; i++) { for (int i = 0; i < nsamples; i++) {
delta[i] = ref->clock_sample[i] - cur->clock_sample[i]; delta[i] = ref->clock_sample[i] - cur->clock_sample[i];
if (verbose) { if (verbose) {
printf("rank=%d sample=%d delta=%f ref=%f cur=%f\n", printf("rank=%d sample=%d delta=%f ref=%f cur=%f\n",
@ -250,13 +238,13 @@ offset_compute_delta(struct offset *ref, struct offset *cur, int nsamples, int v
qsort(delta, nsamples, sizeof(double), cmp_double); qsort(delta, nsamples, sizeof(double), cmp_double);
cur->delta_median = delta[nsamples / 2]; cur->delta_median = delta[nsamples / 2];
cur->delta_mean = 0;
for (cur->delta_mean = 0, i = 0; i < nsamples; i++) for (int i = 0; i < nsamples; i++)
cur->delta_mean += delta[i]; cur->delta_mean += delta[i];
cur->delta_mean /= nsamples; cur->delta_mean /= nsamples;
cur->delta_var = 0;
for (cur->delta_var = 0, i = 0; i < nsamples; i++) for (int i = 0; i < nsamples; i++)
cur->delta_var += (delta[i] - cur->delta_mean) * (delta[i] - cur->delta_mean); cur->delta_var += (delta[i] - cur->delta_mean) * (delta[i] - cur->delta_mean);
cur->delta_var /= (double) (nsamples - 1); cur->delta_var /= (double) (nsamples - 1);
@ -277,9 +265,7 @@ offset_size(int nsamples)
static struct offset * static struct offset *
table_get_offset(struct offset_table *table, int i, int nsamples) table_get_offset(struct offset_table *table, int i, int nsamples)
{ {
char *p; char *p = (char *) table->_offset;
p = (char *) table->_offset;
p += i * offset_size(nsamples); p += i * offset_size(nsamples);
return (struct offset *) p; return (struct offset *) p;
@ -288,10 +274,8 @@ table_get_offset(struct offset_table *table, int i, int nsamples)
static struct offset_table * static struct offset_table *
build_offset_table(int nsamples, int rank, int verbose) build_offset_table(int nsamples, int rank, int verbose)
{ {
int i;
struct offset_table *table = NULL; struct offset_table *table = NULL;
struct offset *offset = NULL; struct offset *offset = NULL;
void *sendbuf;
/* The rank 0 must build the table */ /* The rank 0 must build the table */
if (rank == 0) { if (rank == 0) {
@ -318,7 +302,7 @@ build_offset_table(int nsamples, int rank, int verbose)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (i = 0; i < table->nprocs; i++) for (int i = 0; i < table->nprocs; i++)
table->offset[i] = table_get_offset(table, i, nsamples); table->offset[i] = table_get_offset(table, i, nsamples);
offset = table->offset[0]; offset = table->offset[0];
@ -337,7 +321,7 @@ build_offset_table(int nsamples, int rank, int verbose)
/* Each rank fills its own offset */ /* Each rank fills its own offset */
fill_offset(offset, nsamples); fill_offset(offset, nsamples);
sendbuf = rank == 0 ? MPI_IN_PLACE : offset; void *sendbuf = rank == 0 ? MPI_IN_PLACE : offset;
/* Then collect all the offsets into the rank 0 */ /* Then collect all the offsets into the rank 0 */
MPI_Gather(sendbuf, offset_size(nsamples), MPI_CHAR, MPI_Gather(sendbuf, offset_size(nsamples), MPI_CHAR,
@ -346,7 +330,7 @@ build_offset_table(int nsamples, int rank, int verbose)
/* Finish the offsets by computing the deltas on rank 0 */ /* Finish the offsets by computing the deltas on rank 0 */
if (rank == 0) { if (rank == 0) {
for (i = 0; i < table->nprocs; i++) { for (int i = 0; i < table->nprocs; i++) {
offset_compute_delta(offset, table->offset[i], offset_compute_delta(offset, table->offset[i],
nsamples, verbose); nsamples, verbose);
} }
@ -362,15 +346,10 @@ build_offset_table(int nsamples, int rank, int verbose)
static void static void
print_drift_header(FILE *out, struct offset_table *table) print_drift_header(FILE *out, struct offset_table *table)
{ {
int i;
// char buf[64];
fprintf(out, "%-20s", "wallclock"); fprintf(out, "%-20s", "wallclock");
for (i = 0; i < table->nprocs; i++) { for (int i = 0; i < table->nprocs; i++)
// sprintf(buf, "rank%d", i);
fprintf(out, " %-20s", table->offset[i]->hostname); fprintf(out, " %-20s", table->offset[i]->hostname);
}
fprintf(out, "\n"); fprintf(out, "\n");
} }
@ -378,11 +357,9 @@ print_drift_header(FILE *out, struct offset_table *table)
static void static void
print_drift_row(FILE *out, struct offset_table *table) print_drift_row(FILE *out, struct offset_table *table)
{ {
int i;
fprintf(out, "%-20f", table->offset[0]->wall_t1); fprintf(out, "%-20f", table->offset[0]->wall_t1);
for (i = 0; i < table->nprocs; i++) for (int i = 0; i < table->nprocs; i++)
fprintf(out, " %-20ld", table->offset[i]->offset); fprintf(out, " %-20ld", table->offset[i]->offset);
fprintf(out, "\n"); fprintf(out, "\n");
@ -391,14 +368,11 @@ print_drift_row(FILE *out, struct offset_table *table)
static void static void
print_table_detailed(FILE *out, struct offset_table *table) print_table_detailed(FILE *out, struct offset_table *table)
{ {
int i;
struct offset *offset;
fprintf(out, "%-10s %-20s %-20s %-20s %-20s\n", fprintf(out, "%-10s %-20s %-20s %-20s %-20s\n",
"rank", "hostname", "offset_median", "offset_mean", "offset_std"); "rank", "hostname", "offset_median", "offset_mean", "offset_std");
for (i = 0; i < table->nprocs; i++) { for (int i = 0; i < table->nprocs; i++) {
offset = table->offset[i]; struct offset *offset = table->offset[i];
fprintf(out, "%-10d %-20s %-20ld %-20f %-20f\n", fprintf(out, "%-10d %-20s %-20ld %-20f %-20f\n",
i, offset->hostname, offset->offset, i, offset->hostname, offset->offset,
offset->delta_mean, offset->delta_std); offset->delta_mean, offset->delta_std);
@ -408,12 +382,9 @@ print_table_detailed(FILE *out, struct offset_table *table)
static void static void
do_work(struct options *options, int rank) do_work(struct options *options, int rank)
{ {
int drift_mode;
int i;
struct offset_table *table;
FILE *out = NULL; FILE *out = NULL;
drift_mode = options->ndrift_samples > 1 ? 1 : 0; int drift_mode = options->ndrift_samples > 1 ? 1 : 0;
if (rank == 0) { if (rank == 0) {
if (mkpath(options->outpath, 0755) != 0) { if (mkpath(options->outpath, 0755) != 0) {
@ -430,8 +401,9 @@ do_work(struct options *options, int rank)
} }
} }
for (i = 0; i < options->ndrift_samples; i++) { for (int i = 0; i < options->ndrift_samples; i++) {
table = build_offset_table(options->nsamples, rank, options->verbose); struct offset_table *table = build_offset_table(
options->nsamples, rank, options->verbose);
if (rank == 0) { if (rank == 0) {
if (drift_mode) { if (drift_mode) {
@ -459,13 +431,12 @@ do_work(struct options *options, int rank)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int rank;
struct options options;
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
struct options options;
parse_options(&options, argc, argv); parse_options(&options, argc, argv);
do_work(&options, rank); do_work(&options, rank);

View File

@ -321,13 +321,11 @@ write_header(FILE *f)
static void static void
write_colors(FILE *f, const uint32_t *palette, int n) write_colors(FILE *f, const uint32_t *palette, int n)
{ {
int i;
uint8_t r, g, b;
fprintf(f, "\n\n"); fprintf(f, "\n\n");
fprintf(f, "STATES_COLOR\n"); fprintf(f, "STATES_COLOR\n");
for (i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
uint8_t r, g, b;
decompose_rgb(palette[i], &r, &g, &b); decompose_rgb(palette[i], &r, &g, &b);
fprintf(f, "%-3d {%3d, %3d, %3d}\n", i, r, g, b); fprintf(f, "%-3d {%3d, %3d, %3d}\n", i, r, g, b);
} }
@ -348,9 +346,7 @@ write_type(FILE *f, struct pcf_type *type)
static void static void
write_types(struct pcf_file *pcf) write_types(struct pcf_file *pcf)
{ {
struct pcf_type *t; for (struct pcf_type *t = pcf->types; t != NULL; t = t->hh.next)
for (t = pcf->types; t != NULL; t = t->hh.next)
write_type(pcf->f, t); write_type(pcf->f, t);
} }
@ -369,7 +365,6 @@ create_values(struct pcf_type *t, enum chan c)
static void static void
create_type(struct pcf_file *pcf, enum chan c) create_type(struct pcf_file *pcf, enum chan c)
{ {
char label[MAX_PCF_LABEL];
enum chan_type ct = pcf->chantype; enum chan_type ct = pcf->chantype;
int prv_type = chan_to_prvtype[c]; int prv_type = chan_to_prvtype[c];
@ -381,6 +376,7 @@ create_type(struct pcf_file *pcf, enum chan c)
int isuffix = pcf_chan_suffix[c][ct]; int isuffix = pcf_chan_suffix[c][ct];
char *suffix = pcf_suffix_name[isuffix]; char *suffix = pcf_suffix_name[isuffix];
char label[MAX_PCF_LABEL];
int ret = snprintf(label, MAX_PCF_LABEL, "%s %s", int ret = snprintf(label, MAX_PCF_LABEL, "%s %s",
prefix, suffix); prefix, suffix);
@ -429,9 +425,7 @@ pcf_find_type(struct pcf_file *pcf, int type_id)
struct pcf_type * struct pcf_type *
pcf_add_type(struct pcf_file *pcf, int type_id, const char *label) pcf_add_type(struct pcf_file *pcf, int type_id, const char *label)
{ {
struct pcf_type *pcftype; struct pcf_type *pcftype = pcf_find_type(pcf, type_id);
pcftype = pcf_find_type(pcf, type_id);
if (pcftype != NULL) if (pcftype != NULL)
die("PCF type %d already defined\n", type_id); die("PCF type %d already defined\n", type_id);

View File

@ -86,14 +86,14 @@ ring_add(struct ring *r, struct ovni_ev *ev)
static ssize_t static ssize_t
find_destination(struct ring *r, uint64_t clock) find_destination(struct ring *r, uint64_t clock)
{ {
ssize_t i, start, end, nback = 0; ssize_t nback = 0;
(void) nback; UNUSED(nback);
start = r->tail - 1 >= 0 ? r->tail - 1 : r->size - 1; ssize_t start = r->tail - 1 >= 0 ? r->tail - 1 : r->size - 1;
end = r->head - 1 >= 0 ? r->head - 1 : r->size - 1; ssize_t end = r->head - 1 >= 0 ? r->head - 1 : r->size - 1;
for (i = start; i != end; i = i - 1 < 0 ? r->size - 1 : i - 1) { for (ssize_t i = start; i != end; i = i - 1 < 0 ? r->size - 1 : i - 1) {
if (r->ev[i]->header.clock < clock) { if (r->ev[i]->header.clock < clock) {
dbg("found suitable position %ld events backwards\n", dbg("found suitable position %ld events backwards\n",
nback); nback);
@ -119,64 +119,23 @@ ends_unsorted_region(struct ovni_ev *ev)
return ev->header.model == 'O' && ev->header.category == 'U' && ev->header.value == ']'; return ev->header.model == 'O' && ev->header.category == 'U' && ev->header.value == ']';
} }
#if 0
static void
hexdump(uint8_t *buf, size_t size)
{
UNUSED(buf);
UNUSED(size);
size_t i, j;
//printf("writing %ld bytes in cpu=%d\n", size, rthread.cpu);
for(i=0; i<size; i+=16)
{
for(j=0; j<16; j++)
{
if(i+j < size)
fprintf(stderr, "%02x ", buf[i+j]);
else
fprintf(stderr, " ");
}
fprintf(stderr, " | ");
for(j=0; j<16; j++)
{
if(i+j < size)
{
if(isprint(buf[i+j]))
fprintf(stderr, "%c", buf[i+j]);
else
fprintf(stderr, ".");
}
else
{
fprintf(stderr, " ");
}
}
fprintf(stderr, "\n");
}
}
#endif
static void static void
sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize, sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
uint8_t *srcbad, uint8_t *srcnext) uint8_t *srcbad, uint8_t *srcnext)
{ {
uint8_t *p, *q; int64_t injected = 0;
int64_t evsize, injected = 0;
struct ovni_ev *ep, *eq, *ev;
(void) injected; UNUSED(injected);
p = src; uint8_t *p = src;
q = srcbad; uint8_t *q = srcbad;
while (1) { while (1) {
ep = (struct ovni_ev *) p; struct ovni_ev *ep = (struct ovni_ev *) p;
eq = (struct ovni_ev *) q; struct ovni_ev *eq = (struct ovni_ev *) q;
struct ovni_ev *ev = NULL;
int64_t evsize = 0;
if (p < srcbad && ep->header.clock < eq->header.clock) { if (p < srcbad && ep->header.clock < eq->header.clock) {
ev = ep; ev = ep;
@ -225,32 +184,27 @@ write_stream(int fd, void *base, void *dst, const void *src, size_t size)
static int static int
execute_sort_plan(struct sortplan *sp) execute_sort_plan(struct sortplan *sp)
{ {
int64_t i0, bufsize;
uint8_t *buf;
/* The first event in the stream that may be affected */
struct ovni_ev *first;
dbg("attempt to sort: start clock %ld\n", sp->bad0->header.clock); dbg("attempt to sort: start clock %ld\n", sp->bad0->header.clock);
/* Cannot sort in one pass; just fail for now */ /* Cannot sort in one pass; just fail for now */
if ((i0 = find_destination(sp->r, sp->bad0->header.clock)) < 0) { int64_t i0 = find_destination(sp->r, sp->bad0->header.clock);
if (i0 < 0) {
err("cannot find destination for region starting at clock %ld\n", err("cannot find destination for region starting at clock %ld\n",
sp->bad0->header.clock); sp->bad0->header.clock);
return -1; return -1;
} }
/* Set the pointer to the first event */ /* Set the pointer to the first event that may be affected */
first = sp->r->ev[i0]; struct ovni_ev *first = sp->r->ev[i0];
/* Allocate a working buffer */ /* Allocate a working buffer */
bufsize = ((int64_t) sp->next) - ((int64_t) first); int64_t bufsize = ((int64_t) sp->next) - ((int64_t) first);
if (bufsize <= 0) if (bufsize <= 0)
die("bufsize is non-positive\n"); die("bufsize is non-positive\n");
buf = malloc(bufsize); uint8_t *buf = malloc(bufsize);
if (!buf) if (!buf)
die("malloc failed: %s\n", strerror(errno)); die("malloc failed: %s\n", strerror(errno));
@ -270,11 +224,6 @@ execute_sort_plan(struct sortplan *sp)
static int static int
stream_winsort(struct ovni_stream *stream, struct ring *r) stream_winsort(struct ovni_stream *stream, struct ring *r)
{ {
struct ovni_ev *ev;
struct sortplan sp = {0};
// uint64_t lastclock = 0;
char st = 'S';
char *fn = stream->thread->tracefile; char *fn = stream->thread->tracefile;
int fd = open(fn, O_WRONLY); int fd = open(fn, O_WRONLY);
@ -282,16 +231,19 @@ stream_winsort(struct ovni_stream *stream, struct ring *r)
die("open %s failed: %s\n", fn, strerror(errno)); die("open %s failed: %s\n", fn, strerror(errno));
ring_reset(r); ring_reset(r);
struct sortplan sp = {0};
sp.r = r; sp.r = r;
sp.fd = fd; sp.fd = fd;
sp.base = stream->buf; sp.base = stream->buf;
size_t empty_regions = 0; size_t empty_regions = 0;
size_t updated = 0; size_t updated = 0;
char st = 'S';
while (stream->active) { while (stream->active) {
ovni_load_next_event(stream); ovni_load_next_event(stream);
ev = stream->cur_ev; struct ovni_ev *ev = stream->cur_ev;
if (st == 'S' && starts_unsorted_region(ev)) { if (st == 'S' && starts_unsorted_region(ev)) {
st = 'U'; st = 'U';
@ -369,8 +321,6 @@ stream_check(struct ovni_stream *stream)
static int static int
process_trace(struct ovni_trace *trace) process_trace(struct ovni_trace *trace)
{ {
size_t i;
struct ovni_stream *stream;
struct ring ring; struct ring ring;
int ret = 0; int ret = 0;
@ -380,8 +330,8 @@ process_trace(struct ovni_trace *trace)
if (ring.ev == NULL) if (ring.ev == NULL)
die("malloc failed: %s\n", strerror(errno)); die("malloc failed: %s\n", strerror(errno));
for (i = 0; i < trace->nstreams; i++) { for (size_t i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i]; struct ovni_stream *stream = &trace->stream[i];
if (operation_mode == SORT) { if (operation_mode == SORT) {
dbg("sorting stream tid=%d\n", stream->tid); dbg("sorting stream tid=%d\n", stream->tid);
if (stream_winsort(stream, &ring) != 0) { if (stream_winsort(stream, &ring) != 0) {
@ -414,11 +364,8 @@ process_trace(struct ovni_trace *trace)
} }
static void static void
usage(int argc, char *argv[]) usage(void)
{ {
UNUSED(argc);
UNUSED(argv);
err("Usage: ovnisort [-c] tracedir\n"); err("Usage: ovnisort [-c] tracedir\n");
err("\n"); err("\n");
err("Sorts the events in each stream of the trace given in\n"); err("Sorts the events in each stream of the trace given in\n");
@ -449,13 +396,13 @@ parse_args(int argc, char *argv[])
operation_mode = CHECK; operation_mode = CHECK;
break; break;
default: /* '?' */ default: /* '?' */
usage(argc, argv); usage();
} }
} }
if (optind >= argc) { if (optind >= argc) {
err("missing tracedir\n"); err("missing tracedir\n");
usage(argc, argv); usage();
} }
tracedir = argv[optind]; tracedir = argv[optind];
@ -465,11 +412,10 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int ret = 0; int ret = 0;
struct ovni_trace *trace;
parse_args(argc, argv); parse_args(argc, argv);
trace = calloc(1, sizeof(struct ovni_trace)); struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
if (trace == NULL) { if (trace == NULL) {
perror("calloc"); perror("calloc");

View File

@ -23,9 +23,7 @@
static int static int
find_dir_prefix_str(const char *dirname, const char *prefix, const char **str) find_dir_prefix_str(const char *dirname, const char *prefix, const char **str)
{ {
const char *p; const char *p = dirname;
p = dirname;
/* Check the prefix */ /* Check the prefix */
if (strncmp(p, prefix, strlen(prefix)) != 0) if (strncmp(p, prefix, strlen(prefix)) != 0)
@ -48,7 +46,7 @@ find_dir_prefix_str(const char *dirname, const char *prefix, const char **str)
static int static int
find_dir_prefix_int(const char *dirname, const char *prefix, int *num) find_dir_prefix_int(const char *dirname, const char *prefix, int *num)
{ {
const char *p; const char *p = NULL;
if (find_dir_prefix_str(dirname, prefix, &p) != 0) if (find_dir_prefix_str(dirname, prefix, &p) != 0)
return -1; return -1;
@ -99,9 +97,7 @@ load_thread(struct ovni_ethread *thread, struct ovni_eproc *proc, int index, int
static void static void
load_proc_metadata(struct ovni_eproc *proc, int *rank_enabled) load_proc_metadata(struct ovni_eproc *proc, int *rank_enabled)
{ {
JSON_Object *meta; JSON_Object *meta = json_value_get_object(proc->meta);
meta = json_value_get_object(proc->meta);
if (meta == NULL) if (meta == NULL)
die("load_proc_metadata: json_value_get_object() failed\n"); die("load_proc_metadata: json_value_get_object() failed\n");
@ -176,16 +172,12 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
{ {
static int total_procs = 0; static int total_procs = 0;
struct dirent *dirent;
DIR *dir;
char path[PATH_MAX];
struct ovni_ethread *thread;
proc->pid = pid; proc->pid = pid;
proc->index = index; proc->index = index;
proc->gindex = total_procs++; proc->gindex = total_procs++;
proc->loom = loom; proc->loom = loom;
char path[PATH_MAX];
if (snprintf(path, PATH_MAX, "%s/%s", procdir, "metadata.json") >= PATH_MAX) { if (snprintf(path, PATH_MAX, "%s/%s", procdir, "metadata.json") >= PATH_MAX) {
err("snprintf: path too large: %s\n", procdir); err("snprintf: path too large: %s\n", procdir);
abort(); abort();
@ -202,6 +194,7 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
/* The appid is populated from the metadata */ /* The appid is populated from the metadata */
load_proc_metadata(proc, &loom->rank_enabled); load_proc_metadata(proc, &loom->rank_enabled);
DIR *dir;
if ((dir = opendir(procdir)) == NULL) { if ((dir = opendir(procdir)) == NULL) {
fprintf(stderr, "opendir %s failed: %s\n", fprintf(stderr, "opendir %s failed: %s\n",
procdir, strerror(errno)); procdir, strerror(errno));
@ -233,7 +226,7 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
rewinddir(dir); rewinddir(dir);
for (size_t i = 0; i < proc->nthreads;) { for (size_t i = 0; i < proc->nthreads;) {
dirent = readdir(dir); struct dirent *dirent = readdir(dir);
if (dirent == NULL) { if (dirent == NULL) {
err("inconsistent: readdir returned NULL\n"); err("inconsistent: readdir returned NULL\n");
@ -259,7 +252,7 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
abort(); abort();
} }
thread = &proc->thread[i]; struct ovni_ethread *thread = &proc->thread[i];
if (load_thread(thread, proc, i, tid, path) != 0) if (load_thread(thread, proc, i, tid, path) != 0)
return -1; return -1;
@ -273,11 +266,7 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
static int static int
load_loom(struct ovni_loom *loom, char *loomdir) load_loom(struct ovni_loom *loom, char *loomdir)
{ {
int pid; DIR *dir = NULL;
size_t i;
char path[PATH_MAX];
DIR *dir;
struct dirent *dirent;
if ((dir = opendir(loomdir)) == NULL) { if ((dir = opendir(loomdir)) == NULL) {
fprintf(stderr, "opendir %s failed: %s\n", fprintf(stderr, "opendir %s failed: %s\n",
@ -303,11 +292,14 @@ load_loom(struct ovni_loom *loom, char *loomdir)
rewinddir(dir); rewinddir(dir);
i = 0; size_t i = 0;
struct dirent *dirent = NULL;
while ((dirent = readdir(dir)) != NULL) { while ((dirent = readdir(dir)) != NULL) {
int pid;
if (find_dir_prefix_int(dirent->d_name, "proc", &pid) != 0) if (find_dir_prefix_int(dirent->d_name, "proc", &pid) != 0)
continue; continue;
char path[PATH_MAX];
sprintf(path, "%s/%s", loomdir, dirent->d_name); sprintf(path, "%s/%s", loomdir, dirent->d_name);
if (i >= loom->nprocs) { if (i >= loom->nprocs) {
@ -353,8 +345,7 @@ compare_looms(const void *a, const void *b)
static void static void
loom_to_host(const char *loom_name, char *host, int n) loom_to_host(const char *loom_name, char *host, int n)
{ {
int i; int i = 0;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
/* Copy until dot or end */ /* Copy until dot or end */
if (loom_name[i] != '.' && loom_name[i] != '\0') if (loom_name[i] != '.' && loom_name[i] != '\0')
@ -372,7 +363,7 @@ loom_to_host(const char *loom_name, char *host, int n)
int int
ovni_load_trace(struct ovni_trace *trace, char *tracedir) ovni_load_trace(struct ovni_trace *trace, char *tracedir)
{ {
DIR *dir; DIR *dir = NULL;
if ((dir = opendir(tracedir)) == NULL) { if ((dir = opendir(tracedir)) == NULL) {
err("opendir %s failed: %s\n", tracedir, strerror(errno)); err("opendir %s failed: %s\n", tracedir, strerror(errno));
@ -396,7 +387,7 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
rewinddir(dir); rewinddir(dir);
size_t l = 0; size_t l = 0;
struct dirent *dirent; struct dirent *dirent = NULL;
while ((dirent = readdir(dir)) != NULL) { while ((dirent = readdir(dir)) != NULL) {
struct ovni_loom *loom = &trace->loom[l]; struct ovni_loom *loom = &trace->loom[l];
@ -550,19 +541,13 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
int int
ovni_load_streams(struct ovni_trace *trace) ovni_load_streams(struct ovni_trace *trace)
{ {
size_t i, j, k, s;
struct ovni_loom *loom;
struct ovni_eproc *proc;
struct ovni_ethread *thread;
struct ovni_stream *stream;
trace->nstreams = 0; trace->nstreams = 0;
for (i = 0; i < trace->nlooms; i++) { for (size_t i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i]; struct ovni_loom *loom = &trace->loom[i];
for (j = 0; j < loom->nprocs; j++) { for (size_t j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j]; struct ovni_eproc *proc = &loom->proc[j];
for (k = 0; k < proc->nthreads; k++) { for (size_t k = 0; k < proc->nthreads; k++) {
trace->nstreams++; trace->nstreams++;
} }
} }
@ -577,13 +562,14 @@ ovni_load_streams(struct ovni_trace *trace)
err("loaded %ld streams\n", trace->nstreams); err("loaded %ld streams\n", trace->nstreams);
for (s = 0, i = 0; i < trace->nlooms; i++) { size_t s = 0;
loom = &trace->loom[i]; for (size_t i = 0; i < trace->nlooms; i++) {
for (j = 0; j < loom->nprocs; j++) { struct ovni_loom *loom = &trace->loom[i];
proc = &loom->proc[j]; for (size_t j = 0; j < loom->nprocs; j++) {
for (k = 0; k < proc->nthreads; k++) { struct ovni_eproc *proc = &loom->proc[j];
thread = &proc->thread[k]; for (size_t k = 0; k < proc->nthreads; k++) {
stream = &trace->stream[s++]; struct ovni_ethread *thread = &proc->thread[k];
struct ovni_stream *stream = &trace->stream[s++];
stream->tid = thread->tid; stream->tid = thread->tid;
stream->thread = thread; stream->thread = thread;
@ -619,10 +605,8 @@ ovni_free_streams(struct ovni_trace *trace)
void void
ovni_free_trace(struct ovni_trace *trace) ovni_free_trace(struct ovni_trace *trace)
{ {
size_t i, j; for (size_t i = 0; i < trace->nlooms; i++) {
for (size_t j = 0; j < trace->loom[i].nprocs; j++) {
for (i = 0; i < trace->nlooms; i++) {
for (j = 0; j < trace->loom[i].nprocs; j++) {
free(trace->loom[i].proc[j].thread); free(trace->loom[i].proc[j].thread);
} }