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

View File

@ -21,33 +21,10 @@
int filter_tid = -1;
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
emit(struct ovni_stream *stream, struct ovni_ev *ev)
{
uint64_t clock;
int i, payloadsize;
// printf("sizeof(*ev) = %d\n", sizeof(*ev));
// hexdump((uint8_t *) ev, sizeof(*ev));
clock = ovni_ev_get_clock(ev);
uint64_t clock = ovni_ev_get_clock(ev);
printf("%s.%d.%d %ld %c%c%c",
stream->loom->hostname,
@ -58,10 +35,10 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
ev->header.category,
ev->header.value);
payloadsize = ovni_payload_size(ev);
int payloadsize = ovni_payload_size(ev);
if (payloadsize > 0) {
printf(" ");
for (i = 0; i < payloadsize; i++)
for (int i = 0; i < payloadsize; i++)
printf(":%02x", ev->payload.u8[i]);
}
printf("\n");
@ -73,15 +50,9 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
static void
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 */
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
for (size_t i = 0; i < trace->nstreams; i++) {
struct ovni_stream *stream = &trace->stream[i];
/* It can be inactive if it has been disabled by the
* thread TID filter */
@ -89,20 +60,21 @@ dump_events(struct ovni_trace *trace)
ovni_load_next_event(stream);
}
lastclock = 0;
uint64_t lastclock = 0;
while (1) {
f = -1;
minclock = 0;
ssize_t f = -1;
uint64_t minclock = 0;
struct ovni_stream *stream = NULL;
/* 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];
if (!stream->active)
continue;
ev = stream->cur_ev;
struct ovni_ev *ev = stream->cur_ev;
if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
f = i;
minclock = ovni_ev_get_clock(ev);
@ -136,11 +108,8 @@ dump_events(struct ovni_trace *trace)
}
static void
usage(int argc, char *argv[])
usage(void)
{
UNUSED(argc);
UNUSED(argv);
err("Usage: ovnidump [-t TID] tracedir\n");
err("\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);
break;
default: /* '?' */
usage(argc, argv);
usage();
}
}
if (optind >= argc) {
err("missing tracedir\n");
usage(argc, argv);
usage();
}
tracedir = argv[optind];

246
src/emu.c
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,23 +15,15 @@
void
hook_init_ovni(struct ovni_emu *emu)
{
struct ovni_ethread *th;
struct ovni_cpu *cpu;
struct ovni_chan **uth, **ucpu;
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;
int64_t *clock = &emu->delta_time;
FILE *prv_th = emu->prv_thread;
FILE *prv_cpu = emu->prv_cpu;
/* Init the ovni 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;
for (size_t i = 0; i < emu->total_nthreads; i++) {
struct ovni_ethread *th = emu->global_thread[i];
int row = th->gindex + 1;
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_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 */
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
for (size_t i = 0; i < emu->total_ncpus; i++) {
struct ovni_cpu *cpu = emu->global_cpu[i];
int row = cpu->gindex + 1;
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_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
chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
{
int enabled;
int enabled = 0;
if (th == 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
thread_set_state(struct ovni_ethread *th, enum ethread_state state)
{
int i;
/* The state must be updated when a cpu is set */
if (th->cpu == NULL)
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);
/* 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);
dbg("thread_set_state: done\n");
@ -123,7 +113,9 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
static void
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;
DL_FOREACH(cpu->thread, th)
@ -148,8 +140,6 @@ cpu_update_th_stats(struct ovni_cpu *cpu)
static void
update_cpu(struct ovni_cpu *cpu)
{
int i;
dbg("updating cpu %s\n", cpu->name);
/* 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);
/* 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]);
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
cpu_remove_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
{
struct ovni_ethread *p;
p = emu_cpu_find_thread(cpu, thread);
struct ovni_ethread *p = emu_cpu_find_thread(cpu, thread);
/* Not found, abort */
if (p == NULL) {
@ -286,17 +274,14 @@ thread_migrate_cpu(struct ovni_ethread *th, struct ovni_cpu *cpu)
static void
pre_thread_execute(struct ovni_emu *emu, struct ovni_ethread *th)
{
struct ovni_cpu *cpu;
int cpuid;
/* The thread cannot be already running */
if (th->state == TH_ST_RUNNING)
edie(emu, "pre_thread_execute: thread %d already running\n",
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);
/* First set the CPU in the thread */
@ -393,13 +378,8 @@ pre_thread_warm(struct ovni_ethread *th)
static void
pre_thread(struct ovni_emu *emu)
{
struct ovni_ev *ev;
struct ovni_ethread *th;
// emu_emit(emu);
th = emu->cur_thread;
ev = emu->cur_ev;
struct ovni_ethread *th = emu->cur_thread;
struct ovni_ev *ev = emu->cur_ev;
switch (ev->header.value) {
case 'C': /* create */
@ -438,12 +418,8 @@ pre_thread(struct ovni_emu *emu)
static void
pre_affinity_set(struct ovni_emu *emu)
{
int cpuid;
struct ovni_cpu *newcpu;
struct ovni_ethread *th;
th = emu->cur_thread;
cpuid = emu->cur_ev->payload.i32[0];
struct ovni_ethread *th = emu->cur_thread;
int cpuid = emu->cur_ev->payload.i32[0];
if (th->cpu == NULL)
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);
/* 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 */
if (th->cpu == newcpu)
@ -469,25 +445,18 @@ pre_affinity_set(struct ovni_emu *emu)
static void
pre_affinity_remote(struct ovni_emu *emu)
{
size_t i;
int32_t cpuid, tid;
struct ovni_cpu *newcpu;
struct ovni_ethread *remote_th;
struct ovni_loom *loom;
struct ovni_eproc *proc;
int32_t cpuid = emu->cur_ev->payload.i32[0];
int32_t tid = emu->cur_ev->payload.i32[1];
cpuid = emu->cur_ev->payload.i32[0];
tid = emu->cur_ev->payload.i32[1];
remote_th = emu_get_thread(emu->cur_proc, tid);
struct ovni_ethread *remote_th = emu_get_thread(emu->cur_proc, tid);
if (remote_th == NULL) {
/* Search the thread in other processes of the loom if
* not found in the current one */
loom = emu->cur_loom;
struct ovni_loom *loom = emu->cur_loom;
for (i = 0; i < loom->nprocs; i++) {
proc = &loom->proc[i];
for (size_t i = 0; i < loom->nprocs; i++) {
struct ovni_eproc *proc = &loom->proc[i];
/* Skip the current process */
if (proc == emu->cur_proc)
@ -521,7 +490,7 @@ pre_affinity_remote(struct ovni_emu *emu)
remote_th->tid);
/* 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);
thread_migrate_cpu(remote_th, newcpu);
@ -585,11 +554,8 @@ pre_burst(struct ovni_emu *emu)
static void
pre_flush(struct ovni_emu *emu)
{
struct ovni_ethread *th;
struct ovni_chan *chan_th;
th = emu->cur_thread;
chan_th = &th->chan[CHAN_OVNI_FLUSH];
struct ovni_ethread *th = emu->cur_thread;
struct ovni_chan *chan_th = &th->chan[CHAN_OVNI_FLUSH];
switch (emu->cur_ev->header.value) {
case '[':
@ -608,8 +574,6 @@ pre_flush(struct ovni_emu *emu)
void
hook_pre_ovni(struct ovni_emu *emu)
{
// emu_emit(emu);
if (emu->cur_ev->header.model != 'O')
return;

View File

@ -13,32 +13,24 @@
void
hook_init_tampi(struct ovni_emu *emu)
{
struct ovni_ethread *th;
struct ovni_cpu *cpu;
size_t i;
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;
int64_t *clock = &emu->delta_time;
FILE *prv_th = emu->prv_thread;
FILE *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;
for (size_t i = 0; i < emu->total_nthreads; i++) {
struct ovni_ethread *th = emu->global_thread[i];
int row = th->gindex + 1;
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);
}
/* 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;
for (size_t i = 0; i < emu->total_ncpus; i++) {
struct ovni_cpu *cpu = emu->global_cpu[i];
int row = cpu->gindex + 1;
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);
}
@ -49,9 +41,7 @@ hook_init_tampi(struct ovni_emu *emu)
static void
pre_tampi_mode(struct ovni_emu *emu, int state)
{
struct ovni_ethread *th;
th = emu->cur_thread;
struct ovni_ethread *th = emu->cur_thread;
switch (emu->cur_ev->header.value) {
case '[':

View File

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

View File

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

View File

@ -321,13 +321,11 @@ write_header(FILE *f)
static void
write_colors(FILE *f, const uint32_t *palette, int n)
{
int i;
uint8_t r, g, b;
fprintf(f, "\n\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);
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
write_types(struct pcf_file *pcf)
{
struct pcf_type *t;
for (t = pcf->types; t != NULL; t = t->hh.next)
for (struct pcf_type *t = pcf->types; t != NULL; t = t->hh.next)
write_type(pcf->f, t);
}
@ -369,7 +365,6 @@ create_values(struct pcf_type *t, enum chan c)
static void
create_type(struct pcf_file *pcf, enum chan c)
{
char label[MAX_PCF_LABEL];
enum chan_type ct = pcf->chantype;
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];
char *suffix = pcf_suffix_name[isuffix];
char label[MAX_PCF_LABEL];
int ret = snprintf(label, MAX_PCF_LABEL, "%s %s",
prefix, suffix);
@ -429,9 +425,7 @@ pcf_find_type(struct pcf_file *pcf, int type_id)
struct pcf_type *
pcf_add_type(struct pcf_file *pcf, int type_id, const char *label)
{
struct pcf_type *pcftype;
pcftype = pcf_find_type(pcf, type_id);
struct pcf_type *pcftype = pcf_find_type(pcf, type_id);
if (pcftype != NULL)
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
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;
end = r->head - 1 >= 0 ? r->head - 1 : r->size - 1;
ssize_t start = r->tail - 1 >= 0 ? r->tail - 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) {
dbg("found suitable position %ld events backwards\n",
nback);
@ -119,64 +119,23 @@ ends_unsorted_region(struct ovni_ev *ev)
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
sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
uint8_t *srcbad, uint8_t *srcnext)
{
uint8_t *p, *q;
int64_t evsize, injected = 0;
struct ovni_ev *ep, *eq, *ev;
int64_t injected = 0;
(void) injected;
UNUSED(injected);
p = src;
q = srcbad;
uint8_t *p = src;
uint8_t *q = srcbad;
while (1) {
ep = (struct ovni_ev *) p;
eq = (struct ovni_ev *) q;
struct ovni_ev *ep = (struct ovni_ev *) p;
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) {
ev = ep;
@ -225,32 +184,27 @@ write_stream(int fd, void *base, void *dst, const void *src, size_t size)
static int
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);
/* 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",
sp->bad0->header.clock);
return -1;
}
/* Set the pointer to the first event */
first = sp->r->ev[i0];
/* Set the pointer to the first event that may be affected */
struct ovni_ev *first = sp->r->ev[i0];
/* 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)
die("bufsize is non-positive\n");
buf = malloc(bufsize);
uint8_t *buf = malloc(bufsize);
if (!buf)
die("malloc failed: %s\n", strerror(errno));
@ -270,11 +224,6 @@ execute_sort_plan(struct sortplan *sp)
static int
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;
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));
ring_reset(r);
struct sortplan sp = {0};
sp.r = r;
sp.fd = fd;
sp.base = stream->buf;
size_t empty_regions = 0;
size_t updated = 0;
char st = 'S';
while (stream->active) {
ovni_load_next_event(stream);
ev = stream->cur_ev;
struct ovni_ev *ev = stream->cur_ev;
if (st == 'S' && starts_unsorted_region(ev)) {
st = 'U';
@ -369,8 +321,6 @@ stream_check(struct ovni_stream *stream)
static int
process_trace(struct ovni_trace *trace)
{
size_t i;
struct ovni_stream *stream;
struct ring ring;
int ret = 0;
@ -380,8 +330,8 @@ process_trace(struct ovni_trace *trace)
if (ring.ev == NULL)
die("malloc failed: %s\n", strerror(errno));
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
for (size_t i = 0; i < trace->nstreams; i++) {
struct ovni_stream *stream = &trace->stream[i];
if (operation_mode == SORT) {
dbg("sorting stream tid=%d\n", stream->tid);
if (stream_winsort(stream, &ring) != 0) {
@ -414,11 +364,8 @@ process_trace(struct ovni_trace *trace)
}
static void
usage(int argc, char *argv[])
usage(void)
{
UNUSED(argc);
UNUSED(argv);
err("Usage: ovnisort [-c] tracedir\n");
err("\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;
break;
default: /* '?' */
usage(argc, argv);
usage();
}
}
if (optind >= argc) {
err("missing tracedir\n");
usage(argc, argv);
usage();
}
tracedir = argv[optind];
@ -465,11 +412,10 @@ int
main(int argc, char *argv[])
{
int ret = 0;
struct ovni_trace *trace;
parse_args(argc, argv);
trace = calloc(1, sizeof(struct ovni_trace));
struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
if (trace == NULL) {
perror("calloc");

View File

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