Follow K&R coding style using clang-format

This commit is contained in:
Rodrigo Arias 2022-09-29 15:34:44 +02:00
parent baefb2b01c
commit 177429fabc
49 changed files with 6229 additions and 5685 deletions

31
.clang-format Normal file
View File

@ -0,0 +1,31 @@
Language: Cpp
BasedOnStyle: LLVM
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: None
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BraceWrapping:
AfterControlStatement: false
AfterFunction: true
AfterStruct: false
AfterUnion: false
BeforeElse: false
ColumnLimit: 0
ContinuationIndentWidth: 8
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentWidth: 8
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
SortIncludes: true
SpaceAfterCStyleCast: true
SpacesBeforeTrailingComments: 0
TabWidth: 8
UseTab: Always
...

53
chan.c
View File

@ -103,8 +103,7 @@ chan_dump_update_list(struct ovni_chan *chan)
dbg("update list for chan %d at %p:\n",
chan->id, (void *) chan);
for(c = *chan->update_list; c; c = c->next)
{
for (c = *chan->update_list; c; c = c->next) {
dbg(" chan %d at %p\n", c->id, (void *) c);
}
}
@ -116,8 +115,7 @@ chan_enable(struct ovni_chan *chan, int enabled)
dbg("chan_enable chan=%d enabled=%d\n", chan->id, enabled);
if(chan->enabled == enabled)
{
if (chan->enabled == enabled) {
err("chan_enable: chan already in enabled=%d\n", enabled);
abort();
}
@ -126,12 +124,9 @@ chan_enable(struct ovni_chan *chan, int enabled)
chan->t = *chan->clock;
/* Only append if not dirty */
if(!chan->dirty)
{
if (!chan->dirty) {
mark_dirty(chan, CHAN_DIRTY_ACTIVE);
}
else
{
} else {
dbg("already dirty chan %d: skip update list\n",
chan->id);
chan_dump_update_list(chan);
@ -169,8 +164,7 @@ chan_set(struct ovni_chan *chan, int st)
* used by the tracking channels */
if (chan->dirty != CHAN_DIRTY_ACTIVE
&& chan->lastst >= 0
&& chan->lastst == st)
{
&& chan->lastst == st) {
err("chan_set id=%d cannot emit the state %d twice\n",
chan->id, st);
abort();
@ -183,12 +177,9 @@ chan_set(struct ovni_chan *chan, int st)
chan->t = *chan->clock;
/* Only append if not dirty */
if(!chan->dirty)
{
if (!chan->dirty) {
mark_dirty(chan, CHAN_DIRTY_VALUE);
}
else
{
} else {
dbg("already dirty chan %d: skip update list\n",
chan->id);
chan_dump_update_list(chan);
@ -203,8 +194,7 @@ chan_push(struct ovni_chan *chan, int st)
if (!chan->enabled)
die("chan_push: chan %d not enabled\n", chan->id);
if(st <= 0)
{
if (st <= 0) {
err("chan_push: cannot push a non-positive state %d\n", st);
abort();
}
@ -213,15 +203,13 @@ chan_push(struct ovni_chan *chan, int st)
if (chan->dirty != CHAN_CLEAN)
die("chan_push: chan %d not clean", chan->id);
if(chan->lastst >= 0 && chan->lastst == st)
{
if (chan->lastst >= 0 && chan->lastst == st) {
err("chan_push id=%d cannot emit the state %d twice\n",
chan->id, st);
abort();
}
if(chan->n >= MAX_CHAN_STACK)
{
if (chan->n >= MAX_CHAN_STACK) {
err("chan_push: channel stack full\n");
abort();
}
@ -246,16 +234,14 @@ chan_pop(struct ovni_chan *chan, int expected_st)
if (chan->dirty != CHAN_CLEAN)
die("chan_pop: chan %d not clean", chan->id);
if(chan->n <= 0)
{
if (chan->n <= 0) {
err("chan_pop: channel empty\n");
abort();
}
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",
st, expected_st);
abort();
@ -267,14 +253,12 @@ chan_pop(struct ovni_chan *chan, int expected_st)
st = chan_get_st(chan);
/* A st == 0 can be obtained when returning to the initial state */
if(st < 0)
{
if (st < 0) {
err("chan_pop: obtained negative state %d from the stack\n", st);
abort();
}
if(chan->lastst >= 0 && chan->lastst == st)
{
if (chan->lastst >= 0 && chan->lastst == st) {
err("chan_pop id=%d cannot emit the state %d twice\n",
chan->id, st);
abort();
@ -338,15 +322,13 @@ emit(struct ovni_chan *chan, int64_t t, int state)
* consecutive ovni events?) */
if (chan->lastst != -1
&& chan->dirty == CHAN_DIRTY_VALUE
&& chan->lastst == state)
{
&& chan->lastst == state) {
/* TODO: Print the raw clock of the offending event */
die("emit: chan %d cannot emit the same state %d twice\n",
chan->id, state);
}
if(chan->lastst != state)
{
if (chan->lastst != state) {
prv_ev(chan->prv, chan->row, t, chan->type, state);
chan->lastst = state;
@ -393,8 +375,7 @@ chan_emit(struct ovni_chan *chan)
dbg("chan_emit chan %d\n", chan->id);
/* Emit badst if disabled */
if(chan->enabled == 0)
{
if (chan->enabled == 0) {
/* No punctual events allowed when disabled */
if (chan->ev != -1)
die("chan_emit: no punctual event allowed when disabled\n");

View File

@ -11,7 +11,8 @@
/* Define gettid for older glibc versions (below 2.30) */
#if defined(__GLIBC__)
#if !__GLIBC_PREREQ(2, 30)
static inline pid_t gettid(void)
static inline pid_t
gettid(void)
{
return (pid_t) syscall(SYS_gettid);
}

49
dump.c
View File

@ -3,20 +3,20 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <linux/limits.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <stdatomic.h>
#include <dirent.h>
#include <unistd.h>
#include "emu.h"
#include "ovni.h"
#include "trace.h"
#include "emu.h"
int filter_tid = -1;
char *tracedir;
@ -59,8 +59,7 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
ev->header.value);
payloadsize = ovni_payload_size(ev);
if(payloadsize > 0)
{
if (payloadsize > 0) {
printf(" ");
for (i = 0; i < payloadsize; i++)
printf(":%02x", ev->payload.u8[i]);
@ -81,8 +80,7 @@ dump_events(struct ovni_trace *trace)
struct ovni_stream *stream;
/* Load events */
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
/* It can be inactive if it has been disabled by the
@ -93,22 +91,19 @@ dump_events(struct ovni_trace *trace)
lastclock = 0;
while(1)
{
while (1) {
f = -1;
minclock = 0;
/* Select next event based on the clock */
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
if (!stream->active)
continue;
ev = stream->cur_ev;
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
{
if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
f = i;
minclock = ovni_ev_get_clock(ev);
}
@ -121,8 +116,7 @@ dump_events(struct ovni_trace *trace)
stream = &trace->stream[f];
if(lastclock > ovni_ev_get_clock(stream->cur_ev))
{
if (lastclock > ovni_ev_get_clock(stream->cur_ev)) {
fprintf(stdout, "warning: backwards jump in time %lu -> %lu\n",
lastclock, ovni_ev_get_clock(stream->cur_ev));
}
@ -138,7 +132,6 @@ dump_events(struct ovni_trace *trace)
/* Unset the index */
f = -1;
minclock = 0;
}
}
@ -166,10 +159,8 @@ parse_args(int argc, char *argv[])
{
int opt;
while((opt = getopt(argc, argv, "t:")) != -1)
{
switch(opt)
{
while ((opt = getopt(argc, argv, "t:")) != -1) {
switch (opt) {
case 't':
filter_tid = atoi(optarg);
break;
@ -178,8 +169,7 @@ parse_args(int argc, char *argv[])
}
}
if(optind >= argc)
{
if (optind >= argc) {
err("missing tracedir\n");
usage(argc, argv);
}
@ -187,7 +177,8 @@ parse_args(int argc, char *argv[])
tracedir = argv[optind];
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
parse_args(argc, argv);
@ -199,10 +190,8 @@ int main(int argc, char *argv[])
if (ovni_load_streams(trace))
return 1;
if(filter_tid != -1)
{
for(size_t i=0; i<trace->nstreams; i++)
{
if (filter_tid != -1) {
for (size_t i = 0; i < trace->nstreams; i++) {
struct ovni_stream *stream;
stream = &trace->stream[i];
if (stream->tid != filter_tid)

249
emu.c
View File

@ -3,25 +3,25 @@
#define _POSIX_C_SOURCE 200112L
#include <dirent.h>
#include <errno.h>
#include <linux/limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <stdatomic.h>
#include <dirent.h>
#include <unistd.h>
#include <time.h>
#include <unistd.h>
#include "ovni.h"
#include "trace.h"
#include "emu.h"
#include "prv.h"
#include "pcf.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "pcf.h"
#include "prv.h"
#include "trace.h"
#include "utlist.h"
/* Obtains the corrected clock of the given event */
@ -53,8 +53,7 @@ print_ev(struct ovni_stream *stream, struct ovni_ev *ev)
ev->header.model, ev->header.category, ev->header.value, clock, delta);
payloadsize = ovni_payload_size(ev);
for(i=0; i<payloadsize; i++)
{
for (i = 0; i < payloadsize; i++) {
dbg("%d ", ev->payload.u8[i]);
}
dbg("\n");
@ -73,8 +72,7 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
int th_enabled, cpu_enabled, st;
struct ovni_chan *th_chan;
switch (cpu_chan->track)
{
switch (cpu_chan->track) {
case CHAN_TRACK_TH_RUNNING:
cpu_enabled = th->is_running;
break;
@ -95,30 +93,23 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
chan_enable(cpu_chan, cpu_enabled);
/* 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 */
st = chan_get_st(th_chan);
if (chan_get_st(cpu_chan) != st)
chan_set(cpu_chan, st);
}
else if(th_enabled && !cpu_enabled)
{
} else if (th_enabled && !cpu_enabled) {
/* Only thread enabled: disable CPU */
if (chan_is_enabled(cpu_chan))
chan_disable(cpu_chan);
}
else if(!th_enabled && cpu_enabled)
{
} else if (!th_enabled && cpu_enabled) {
/* Only CPU enabled: is this possible? Set to bad */
chan_set(cpu_chan, ST_BAD);
err("warning: cpu %s chan %d enabled but tracked thread %d chan disabled\n",
cpu_chan->cpu->name,
cpu_chan->id,
th->tid);
}
else
{
} else {
/* Both disabled: disable CPU channel if needed */
if (chan_is_enabled(cpu_chan))
chan_disable(cpu_chan);
@ -128,7 +119,6 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
cpu_chan->cpu->name, cpu_chan->id,
chan_is_enabled(cpu_chan),
chan_get_st(cpu_chan));
}
void
@ -139,8 +129,7 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
/* Determine the source of tracking */
switch (cpu_chan->track)
{
switch (cpu_chan->track) {
case CHAN_TRACK_TH_RUNNING:
count = cpu->nrunning_threads;
th = cpu->th_running;
@ -156,15 +145,12 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
}
/* Based on how many threads, determine the state */
if(count == 0)
{
if (count == 0) {
/* The channel can be already disabled (migration of paused
* thread) so only disable it if needed. */
if (chan_is_enabled(cpu_chan))
chan_disable(cpu_chan);
}
else if(count == 1)
{
} else if (count == 1) {
if (th == NULL)
die("emu_cpu_update_chan: tracking thread is NULL\n");
@ -173,9 +159,7 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
th->tid, cpu_chan->id);
cpu_update_tracking_chan(cpu_chan, th);
}
else
{
} else {
/* More than one thread: enable the channel and set it to a
* error value */
if (!chan_is_enabled(cpu_chan))
@ -266,15 +250,28 @@ hook_end(struct ovni_emu *emu)
static void
hook_pre(struct ovni_emu *emu)
{
switch(emu->cur_ev->header.model)
{
case 'O': hook_pre_ovni(emu); break;
case 'V': hook_pre_nosv(emu); break;
case 'T': hook_pre_tampi(emu); break;
case 'M': hook_pre_openmp(emu); break;
case 'D': hook_pre_nodes(emu); break;
case 'K': hook_pre_kernel(emu); break;
case '6': hook_pre_nanos6(emu); break;
switch (emu->cur_ev->header.model) {
case 'O':
hook_pre_ovni(emu);
break;
case 'V':
hook_pre_nosv(emu);
break;
case 'T':
hook_pre_tampi(emu);
break;
case 'M':
hook_pre_openmp(emu);
break;
case 'D':
hook_pre_nodes(emu);
break;
case 'K':
hook_pre_kernel(emu);
break;
case '6':
hook_pre_nanos6(emu);
break;
default:
break;
}
@ -283,8 +280,7 @@ hook_pre(struct ovni_emu *emu)
static void
hook_post(struct ovni_emu *emu)
{
switch(emu->cur_ev->header.model)
{
switch (emu->cur_ev->header.model) {
default:
// dbg("unknown model %c\n", emu->cur_ev->model);
break;
@ -310,7 +306,8 @@ set_current(struct ovni_emu *emu, struct ovni_stream *stream)
*
* Invert the comparison function to get a min-heap instead
*/
static inline int stream_cmp(heap_node_t *a, heap_node_t *b)
static inline int
stream_cmp(heap_node_t *a, heap_node_t *b)
{
struct ovni_stream *sa, *sb;
@ -346,8 +343,7 @@ print_progress(struct ovni_emu *emu)
written = cpu_written + th_written;
progress = ((double) emu->global_offset) /
((double) emu->global_size);
progress = ((double) emu->global_offset) / ((double) emu->global_size);
time_now = get_time();
time_elapsed = time_now - emu->start_emulation_time;
@ -423,8 +419,7 @@ next_event(struct ovni_emu *emu)
* 12
* ...
* */
if(emu->lastclock > stream->lastclock)
{
if (emu->lastclock > stream->lastclock) {
err("warning: backwards jump in time %lu -> %lu for tid %d\n",
emu->lastclock, stream->lastclock, stream->tid);
@ -434,8 +429,7 @@ next_event(struct ovni_emu *emu)
emu->lastclock = stream->lastclock;
if(!done_first)
{
if (!done_first) {
done_first = 1;
emu->firstclock = emu->lastclock;
}
@ -459,13 +453,11 @@ emu_load_first_events(struct ovni_emu *emu)
/* Load initial streams and events */
trace = &emu->trace;
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
emu->global_size += stream->size;
if(emu_step_stream(emu, stream) < 0)
{
if (emu_step_stream(emu, stream) < 0) {
err("warning: empty stream for tid %d\n", stream->tid);
if (emu->enable_linter)
@ -494,8 +486,7 @@ emulate(struct ovni_emu *emu)
emit_channels(emu);
/* Then process all events */
for(i=0; next_event(emu) == 0; i++)
{
for (i = 0; next_event(emu) == 0; i++) {
print_cur_ev(emu);
hook_pre(emu);
@ -505,8 +496,7 @@ emulate(struct ovni_emu *emu)
hook_post(emu);
if(i >= 50000)
{
if (i >= 50000) {
print_progress(emu);
i = 0;
}
@ -527,8 +517,7 @@ emu_get_thread(struct ovni_eproc *proc, int tid)
size_t i;
struct ovni_ethread *thread;
for(i=0; i<proc->nthreads; i++)
{
for (i = 0; i < proc->nthreads; i++) {
thread = &proc->thread[i];
if (thread->tid == tid)
return thread;
@ -595,8 +584,7 @@ proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom,
if (loom->cpu == NULL)
die("calloc failed: %s\n", strerror(errno));
for(size_t i = 0; i < loom->ncpus; i++)
{
for (size_t i = 0; i < loom->ncpus; i++) {
JSON_Object *cpu = json_array_get_object(cpuarray, i);
if (cpu == NULL)
@ -638,15 +626,13 @@ load_metadata(struct ovni_emu *emu)
trace = &emu->trace;
for(i=0; i<trace->nlooms; i++)
{
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
loom->offset_ncpus = emu->total_ncpus;
struct ovni_eproc *metadata_proc = NULL;
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
if (proc_load_cpus(emu, loom, proc, metadata_proc) < 0)
@ -679,11 +665,9 @@ destroy_metadata(struct ovni_emu *emu)
trace = &emu->trace;
for(i=0; i<trace->nlooms; i++)
{
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
if (proc->meta == NULL)
@ -707,8 +691,7 @@ open_prvs(struct ovni_emu *emu, char *tracedir)
emu->prv_thread = fopen(path, "w");
if(emu->prv_thread == NULL)
{
if (emu->prv_thread == NULL) {
err("error opening thread PRV file %s: %s\n", path,
strerror(errno));
exit(EXIT_FAILURE);
@ -718,8 +701,7 @@ open_prvs(struct ovni_emu *emu, char *tracedir)
emu->prv_cpu = fopen(path, "w");
if(emu->prv_cpu == NULL)
{
if (emu->prv_cpu == NULL) {
err("error opening cpu PRV file %s: %s\n", path,
strerror(errno));
exit(EXIT_FAILURE);
@ -788,10 +770,8 @@ parse_args(struct ovni_emu *emu, int argc, char *argv[])
{
int opt;
while((opt = getopt(argc, argv, "c:l")) != -1)
{
switch(opt)
{
while ((opt = getopt(argc, argv, "c:l")) != -1) {
switch (opt) {
case 'c':
emu->clock_offset_file = optarg;
break;
@ -803,8 +783,7 @@ parse_args(struct ovni_emu *emu, int argc, char *argv[])
}
}
if(optind >= argc)
{
if (optind >= argc) {
err("missing tracedir\n");
usage(argc, argv);
}
@ -817,8 +796,7 @@ set_clock_offsets(struct ovni_emu *emu, const char *host, size_t offset)
{
size_t matches = 0;
for(size_t i = 0; i < emu->trace.nlooms; i++)
{
for (size_t i = 0; i < emu->trace.nlooms; i++) {
struct ovni_loom *loom = &emu->trace.loom[i];
/* Match the hostname exactly */
@ -849,53 +827,44 @@ load_clock_offsets(struct ovni_emu *emu)
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");
/* If provided by the user, it must exist */
if(f == NULL)
{
if (f == NULL) {
err("error opening clock offset file %s: %s\n",
emu->clock_offset_file,
strerror(errno));
exit(EXIT_FAILURE);
}
}
else
{
} else {
char path[PATH_MAX];
if (snprintf(path, PATH_MAX, "%s/clock-offsets.txt",
emu->tracedir) >= PATH_MAX)
{
emu->tracedir)
>= PATH_MAX) {
die("clock offset path too long\n");
}
f = fopen(path, "r");
if(f == NULL)
{
if (f == NULL) {
/* May not exist, but is fine */
return;
}
}
/* Ignore header line */
if(fgets(buf, 1024, f) == NULL)
{
if (fgets(buf, 1024, f) == NULL) {
perror("fgets failed");
exit(EXIT_FAILURE);
}
while(1)
{
while (1) {
errno = 0;
ret = fscanf(f, "%d %s %lf %lf %lf", &rank, host, &offset, &mean, &std);
if(ret == EOF)
{
if(errno != 0)
{
if (ret == EOF) {
if (errno != 0) {
perror("fscanf failed");
exit(EXIT_FAILURE);
}
@ -903,8 +872,7 @@ load_clock_offsets(struct ovni_emu *emu)
break;
}
if(ret != 5)
{
if (ret != 5) {
err("fscanf read %d instead of 5 fields in %s\n",
ret, emu->clock_offset_file);
exit(EXIT_FAILURE);
@ -917,8 +885,7 @@ load_clock_offsets(struct ovni_emu *emu)
trace = &emu->trace;
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
loom = stream->loom;
stream->clock_offset = loom->clock_offset;
@ -941,8 +908,7 @@ write_row_cpu(struct ovni_emu *emu)
f = fopen(path, "w");
if(f == NULL)
{
if (f == NULL) {
perror("cannot open row file");
exit(EXIT_FAILURE);
}
@ -953,8 +919,7 @@ 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++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
fprintf(f, "%s\n", cpu->name);
}
@ -974,8 +939,7 @@ write_row_thread(struct ovni_emu *emu)
f = fopen(path, "w");
if(f == NULL)
{
if (f == NULL) {
perror("cannot open row file");
exit(EXIT_FAILURE);
}
@ -986,8 +950,7 @@ 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++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
fprintf(f, "THREAD %d.%d\n", th->proc->appid, th->tid);
}
@ -1009,15 +972,12 @@ init_threads(struct ovni_emu *emu)
trace = &emu->trace;
for(i=0; i<trace->nlooms; i++)
{
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
emu->total_nprocs++;
for(k=0; k<proc->nthreads; k++)
{
for (k = 0; k < proc->nthreads; k++) {
thread = &proc->thread[k];
emu->total_nthreads++;
}
@ -1027,20 +987,16 @@ init_threads(struct ovni_emu *emu)
emu->global_thread = calloc(emu->total_nthreads,
sizeof(*emu->global_thread));
if(emu->global_thread == NULL)
{
if (emu->global_thread == NULL) {
perror("calloc failed");
exit(EXIT_FAILURE);
}
for(gi=0, i=0; i<trace->nlooms; i++)
{
for (gi = 0, i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
for(k=0; k<proc->nthreads; k++)
{
for (k = 0; k < proc->nthreads; k++) {
thread = &proc->thread[k];
emu->global_thread[gi++] = thread;
@ -1062,23 +1018,20 @@ init_cpus(struct ovni_emu *emu)
emu->global_cpu = calloc(emu->total_ncpus,
sizeof(*emu->global_cpu));
if(emu->global_cpu == NULL)
{
if (emu->global_cpu == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}
for(i=0; i<trace->nlooms; i++)
{
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->ncpus; j++)
{
for (j = 0; j < loom->ncpus; j++) {
cpu = &loom->cpu[j];
emu->global_cpu[cpu->gindex] = cpu;
if (snprintf(cpu->name, MAX_CPU_NAME, "CPU %ld.%ld",
i, j) >= MAX_CPU_NAME)
{
i, j)
>= MAX_CPU_NAME) {
err("error cpu %ld.%ld name too long\n", i, j);
exit(EXIT_FAILURE);
}
@ -1087,8 +1040,8 @@ 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) >= MAX_CPU_NAME)
{
i)
>= MAX_CPU_NAME) {
err("error cpu %ld.* name too long\n", i);
exit(EXIT_FAILURE);
}
@ -1107,8 +1060,7 @@ create_pcf_cpus(struct ovni_emu *emu)
if (type == NULL)
die("cannot find PCF type for CHAN_OVNI_CPU\n");
for(size_t i=0; i<emu->total_ncpus; i++)
{
for (size_t i = 0; i < emu->total_ncpus; i++) {
int value = i + 1;
char *label = emu->global_cpu[i]->name;
@ -1123,14 +1075,12 @@ emu_init(struct ovni_emu *emu, int argc, char *argv[])
parse_args(emu, argc, argv);
if(ovni_load_trace(&emu->trace, emu->tracedir))
{
if (ovni_load_trace(&emu->trace, emu->tracedir)) {
err("error loading ovni trace\n");
exit(EXIT_FAILURE);
}
if(ovni_load_streams(&emu->trace))
{
if (ovni_load_streams(&emu->trace)) {
err("error loading streams\n");
exit(EXIT_FAILURE);
}
@ -1225,8 +1175,7 @@ main(int argc, char *argv[])
emu = malloc(sizeof(struct ovni_emu));
if(emu == NULL)
{
if (emu == NULL) {
perror("malloc");
return 1;
}

6
emu.h
View File

@ -7,11 +7,11 @@
#include <stdio.h>
#include "common.h"
#include "ovni.h"
#include "uthash.h"
#include "parson.h"
#include "heap.h"
#include "ovni.h"
#include "parson.h"
#include "pcf.h"
#include "uthash.h"
/* Emulated thread runtime status */
enum ethread_state {

View File

@ -3,11 +3,11 @@
#include "uthash.h"
#include "ovni.h"
#include "trace.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
#include "trace.h"
/* --------------------------- init ------------------------------- */
@ -27,8 +27,7 @@ hook_init_kernel(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
uth = &emu->th_chan;
@ -37,8 +36,7 @@ hook_init_kernel(struct ovni_emu *emu)
}
/* Init the channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -58,8 +56,7 @@ context_switch(struct ovni_emu *emu)
th = emu->cur_thread;
chan = &th->chan[CHAN_KERNEL_CS];
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case 'O':
chan_push(chan, ST_KERNEL_CSOUT);
break;
@ -79,8 +76,7 @@ hook_pre_kernel(struct ovni_emu *emu)
edie(emu, "hook_pre_kernel: unexpected event with model %c\n",
emu->cur_ev->header.model);
switch(emu->cur_ev->header.category)
{
switch (emu->cur_ev->header.category) {
case 'C':
context_switch(emu);
break;

View File

@ -4,11 +4,11 @@
#include "uthash.h"
#include "utlist.h"
#include "ovni.h"
#include "chan.h"
#include "emu.h"
#include "emu_task.h"
#include "ovni.h"
#include "prv.h"
#include "chan.h"
void
hook_init_nanos6(struct ovni_emu *emu)
@ -25,8 +25,7 @@ hook_init_nanos6(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* 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];
row = th->gindex + 1;
@ -40,8 +39,7 @@ hook_init_nanos6(struct ovni_emu *emu)
}
/* 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];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -54,8 +52,7 @@ hook_init_nanos6(struct ovni_emu *emu)
}
/* 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];
th->nanos6_task_stack.thread = th;
}
@ -153,12 +150,19 @@ update_task_state(struct ovni_emu *emu)
if (task == NULL)
edie(emu, "cannot find task with id %u\n", task_id);
switch(emu->cur_ev->header.value)
{
case 'x': task_execute(emu, stack, task); break;
case 'e': task_end(emu, stack, task); break;
case 'p': task_pause(emu, stack, task); break;
case 'r': task_resume(emu, stack, task); break;
switch (emu->cur_ev->header.value) {
case 'x':
task_execute(emu, stack, task);
break;
case 'e':
task_end(emu, stack, task);
break;
case 'p':
task_pause(emu, stack, task);
break;
case 'r':
task_resume(emu, stack, task);
break;
default:
edie(emu, "unexpected Nanos6 task event\n");
}
@ -186,8 +190,7 @@ static void
update_task_channels(struct ovni_emu *emu,
char tr, struct task *prev, struct task *next)
{
switch(tr)
{
switch (tr) {
case 'x':
case 'r':
chan_task_running(emu, next);
@ -215,8 +218,7 @@ enforce_task_rules(struct ovni_emu *emu,
/* If a task has just entered the running state, it must show
* the running task body subsystem */
if(tr == 'x' || tr == 'X')
{
if (tr == 'x' || tr == 'X') {
if (next->state != TASK_ST_RUNNING)
edie(emu, "a Nanos6 task starts running but not in the running state\n");
@ -269,8 +271,7 @@ create_task(struct ovni_emu *emu)
static void
pre_task(struct ovni_emu *emu)
{
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case 'c':
create_task(emu);
break;
@ -316,12 +317,19 @@ pre_deps(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 'r': chan_push(chan_th, ST_NANOS6_DEP_REG); break;
case 'R': chan_pop (chan_th, ST_NANOS6_DEP_REG); break;
case 'u': chan_push(chan_th, ST_NANOS6_DEP_UNREG); break;
case 'U': chan_pop (chan_th, ST_NANOS6_DEP_UNREG); break;
switch (emu->cur_ev->header.value) {
case 'r':
chan_push(chan_th, ST_NANOS6_DEP_REG);
break;
case 'R':
chan_pop(chan_th, ST_NANOS6_DEP_REG);
break;
case 'u':
chan_push(chan_th, ST_NANOS6_DEP_UNREG);
break;
case 'U':
chan_pop(chan_th, ST_NANOS6_DEP_UNREG);
break;
default:
edie(emu, "unknown Nanos6 dependency event\n");
}
@ -336,16 +344,31 @@ pre_blocking(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 'b': chan_push(chan_th, ST_NANOS6_BLK_BLOCKING); break;
case 'B': chan_pop (chan_th, ST_NANOS6_BLK_BLOCKING); break;
case 'u': chan_push(chan_th, ST_NANOS6_BLK_UNBLOCKING); break;
case 'U': chan_pop (chan_th, ST_NANOS6_BLK_UNBLOCKING); break;
case 'w': chan_push(chan_th, ST_NANOS6_BLK_TASKWAIT); break;
case 'W': chan_pop (chan_th, ST_NANOS6_BLK_TASKWAIT); break;
case 'f': chan_push(chan_th, ST_NANOS6_BLK_WAITFOR); break;
case 'F': chan_pop (chan_th, ST_NANOS6_BLK_WAITFOR); break;
switch (emu->cur_ev->header.value) {
case 'b':
chan_push(chan_th, ST_NANOS6_BLK_BLOCKING);
break;
case 'B':
chan_pop(chan_th, ST_NANOS6_BLK_BLOCKING);
break;
case 'u':
chan_push(chan_th, ST_NANOS6_BLK_UNBLOCKING);
break;
case 'U':
chan_pop(chan_th, ST_NANOS6_BLK_UNBLOCKING);
break;
case 'w':
chan_push(chan_th, ST_NANOS6_BLK_TASKWAIT);
break;
case 'W':
chan_pop(chan_th, ST_NANOS6_BLK_TASKWAIT);
break;
case 'f':
chan_push(chan_th, ST_NANOS6_BLK_WAITFOR);
break;
case 'F':
chan_pop(chan_th, ST_NANOS6_BLK_WAITFOR);
break;
default:
edie(emu, "unknown Nanos6 blocking event\n");
}
@ -360,21 +383,46 @@ pre_worker(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case '[': chan_push(chan_th, ST_NANOS6_WORKER_LOOP); break;
case ']': chan_pop (chan_th, ST_NANOS6_WORKER_LOOP); break;
case 't': chan_push(chan_th, ST_NANOS6_HANDLING_TASK); break;
case 'T': chan_pop (chan_th, ST_NANOS6_HANDLING_TASK); break;
case 'w': chan_push(chan_th, ST_NANOS6_SWITCH_TO); break;
case 'W': chan_pop (chan_th, ST_NANOS6_SWITCH_TO); break;
case 'm': chan_push(chan_th, ST_NANOS6_MIGRATE); break;
case 'M': chan_pop (chan_th, ST_NANOS6_MIGRATE); break;
case 's': chan_push(chan_th, ST_NANOS6_SUSPEND); break;
case 'S': chan_pop (chan_th, ST_NANOS6_SUSPEND); break;
case 'r': chan_push(chan_th, ST_NANOS6_RESUME); break;
case 'R': chan_pop (chan_th, ST_NANOS6_RESUME); break;
case '*': chan_ev (chan_th, EV_NANOS6_SIGNAL); break;
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan_th, ST_NANOS6_WORKER_LOOP);
break;
case ']':
chan_pop(chan_th, ST_NANOS6_WORKER_LOOP);
break;
case 't':
chan_push(chan_th, ST_NANOS6_HANDLING_TASK);
break;
case 'T':
chan_pop(chan_th, ST_NANOS6_HANDLING_TASK);
break;
case 'w':
chan_push(chan_th, ST_NANOS6_SWITCH_TO);
break;
case 'W':
chan_pop(chan_th, ST_NANOS6_SWITCH_TO);
break;
case 'm':
chan_push(chan_th, ST_NANOS6_MIGRATE);
break;
case 'M':
chan_pop(chan_th, ST_NANOS6_MIGRATE);
break;
case 's':
chan_push(chan_th, ST_NANOS6_SUSPEND);
break;
case 'S':
chan_pop(chan_th, ST_NANOS6_SUSPEND);
break;
case 'r':
chan_push(chan_th, ST_NANOS6_RESUME);
break;
case 'R':
chan_pop(chan_th, ST_NANOS6_RESUME);
break;
case '*':
chan_ev(chan_th, EV_NANOS6_SIGNAL);
break;
default:
edie(emu, "unknown Nanos6 worker event\n");
}
@ -389,12 +437,19 @@ pre_memory(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 'a': chan_push(chan_th, ST_NANOS6_ALLOCATING); break;
case 'A': chan_pop (chan_th, ST_NANOS6_ALLOCATING); break;
case 'f': chan_push(chan_th, ST_NANOS6_FREEING); break;
case 'F': chan_pop (chan_th, ST_NANOS6_FREEING); break;
switch (emu->cur_ev->header.value) {
case 'a':
chan_push(chan_th, ST_NANOS6_ALLOCATING);
break;
case 'A':
chan_pop(chan_th, ST_NANOS6_ALLOCATING);
break;
case 'f':
chan_push(chan_th, ST_NANOS6_FREEING);
break;
case 'F':
chan_pop(chan_th, ST_NANOS6_FREEING);
break;
default:
edie(emu, "unknown Nanos6 memory event\n");
}
@ -409,17 +464,34 @@ pre_sched(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case '[': chan_push(chan_th, ST_NANOS6_SCHED_SERVING); break;
case ']': chan_pop (chan_th, ST_NANOS6_SCHED_SERVING); break;
case 'a': chan_push(chan_th, ST_NANOS6_SCHED_ADDING); break;
case 'A': chan_pop (chan_th, ST_NANOS6_SCHED_ADDING); break;
case 'p': chan_push(chan_th, ST_NANOS6_SCHED_PROCESSING); break;
case 'P': chan_pop (chan_th, ST_NANOS6_SCHED_PROCESSING); break;
case '@': chan_ev (chan_th, EV_NANOS6_SCHED_SELF); break;
case 'r': chan_ev (chan_th, EV_NANOS6_SCHED_RECV); break;
case 's': chan_ev (chan_th, EV_NANOS6_SCHED_SEND); break;
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan_th, ST_NANOS6_SCHED_SERVING);
break;
case ']':
chan_pop(chan_th, ST_NANOS6_SCHED_SERVING);
break;
case 'a':
chan_push(chan_th, ST_NANOS6_SCHED_ADDING);
break;
case 'A':
chan_pop(chan_th, ST_NANOS6_SCHED_ADDING);
break;
case 'p':
chan_push(chan_th, ST_NANOS6_SCHED_PROCESSING);
break;
case 'P':
chan_pop(chan_th, ST_NANOS6_SCHED_PROCESSING);
break;
case '@':
chan_ev(chan_th, EV_NANOS6_SCHED_SELF);
break;
case 'r':
chan_ev(chan_th, EV_NANOS6_SCHED_RECV);
break;
case 's':
chan_ev(chan_th, EV_NANOS6_SCHED_SEND);
break;
default:
edie(emu, "unknown Nanos6 scheduler event\n");
}
@ -434,16 +506,31 @@ pre_thread(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NANOS6_THREAD];
switch(emu->cur_ev->header.value)
{
case 'e': chan_push(chan_th, ST_NANOS6_TH_EXTERNAL); break;
case 'E': chan_pop (chan_th, ST_NANOS6_TH_EXTERNAL); break;
case 'w': chan_push(chan_th, ST_NANOS6_TH_WORKER); break;
case 'W': chan_pop (chan_th, ST_NANOS6_TH_WORKER); break;
case 'l': chan_push(chan_th, ST_NANOS6_TH_LEADER); break;
case 'L': chan_pop (chan_th, ST_NANOS6_TH_LEADER); break;
case 'm': chan_push(chan_th, ST_NANOS6_TH_MAIN); break;
case 'M': chan_pop (chan_th, ST_NANOS6_TH_MAIN); break;
switch (emu->cur_ev->header.value) {
case 'e':
chan_push(chan_th, ST_NANOS6_TH_EXTERNAL);
break;
case 'E':
chan_pop(chan_th, ST_NANOS6_TH_EXTERNAL);
break;
case 'w':
chan_push(chan_th, ST_NANOS6_TH_WORKER);
break;
case 'W':
chan_pop(chan_th, ST_NANOS6_TH_WORKER);
break;
case 'l':
chan_push(chan_th, ST_NANOS6_TH_LEADER);
break;
case 'L':
chan_pop(chan_th, ST_NANOS6_TH_LEADER);
break;
case 'm':
chan_push(chan_th, ST_NANOS6_TH_MAIN);
break;
case 'M':
chan_pop(chan_th, ST_NANOS6_TH_MAIN);
break;
default:
edie(emu, "unknown Nanos6 thread type event\n");
}
@ -460,10 +547,13 @@ pre_ss(struct ovni_emu *emu, int st)
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);
switch(emu->cur_ev->header.value)
{
case '[': chan_push(chan_th, st); break;
case ']': chan_pop(chan_th, st); break;
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan_th, st);
break;
case ']':
chan_pop(chan_th, st);
break;
default:
edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
emu->cur_ev->header.value);
@ -479,8 +569,7 @@ check_affinity(struct ovni_emu *emu)
if (!cpu || cpu->virtual)
return;
if(cpu->nrunning_threads > 1)
{
if (cpu->nrunning_threads > 1) {
eerr(emu, "cpu %s has more than one thread running\n", cpu->name);
/* Only abort in linter mode so we can still see the
@ -502,21 +591,46 @@ hook_pre_nanos6(struct ovni_emu *emu)
emu->cur_thread->tid);
}
switch(emu->cur_ev->header.category)
{
case 'T': pre_task(emu); break;
case 'C': pre_ss(emu, ST_NANOS6_TASK_CREATING); break;
case 'Y': pre_type(emu); break;
case 'S': pre_sched(emu); break;
case 'U': pre_ss(emu, ST_NANOS6_TASK_SUBMIT); break;
case 'F': pre_ss(emu, ST_NANOS6_TASK_SPAWNING); break;
case 'O': pre_ss(emu, ST_NANOS6_TASK_FOR); break;
case 't': pre_ss(emu, ST_NANOS6_TASK_BODY); break;
case 'H': pre_thread(emu); break;
case 'D': pre_deps(emu); break;
case 'B': pre_blocking(emu); break;
case 'W': pre_worker(emu); break;
case 'M': pre_memory(emu); break;
switch (emu->cur_ev->header.category) {
case 'T':
pre_task(emu);
break;
case 'C':
pre_ss(emu, ST_NANOS6_TASK_CREATING);
break;
case 'Y':
pre_type(emu);
break;
case 'S':
pre_sched(emu);
break;
case 'U':
pre_ss(emu, ST_NANOS6_TASK_SUBMIT);
break;
case 'F':
pre_ss(emu, ST_NANOS6_TASK_SPAWNING);
break;
case 'O':
pre_ss(emu, ST_NANOS6_TASK_FOR);
break;
case 't':
pre_ss(emu, ST_NANOS6_TASK_BODY);
break;
case 'H':
pre_thread(emu);
break;
case 'D':
pre_deps(emu);
break;
case 'B':
pre_blocking(emu);
break;
case 'W':
pre_worker(emu);
break;
case 'M':
pre_memory(emu);
break;
default:
edie(emu, "unknown Nanos6 event category\n");
}
@ -528,20 +642,16 @@ static void
end_lint(struct ovni_emu *emu)
{
/* Ensure we run out of subsystem states */
for(size_t i = 0; i < emu->total_nthreads; i++)
{
for (size_t i = 0; i < emu->total_nthreads; i++) {
struct ovni_ethread *th = emu->global_thread[i];
struct ovni_chan *ch = &th->chan[CHAN_NANOS6_SUBSYSTEM];
if(ch->n != 1)
{
if (ch->n != 1) {
int top = ch->stack[ch->n - 1];
struct pcf_value_label *pv;
char *name = "(unknown)";
for(pv = &nanos6_ss_values[0]; pv->label; pv++)
{
if(pv->value == top)
{
for (pv = &nanos6_ss_values[0]; pv->label; pv++) {
if (pv->value == top) {
name = pv->label;
break;
}
@ -557,17 +667,14 @@ void
hook_end_nanos6(struct ovni_emu *emu)
{
/* Emit types for all channel types and processes */
for(enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++)
{
for (enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++) {
struct pcf_file *pcf = &emu->pcf[ct];
int typeid = chan_to_prvtype[CHAN_NANOS6_TYPE];
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
for(size_t i = 0; i < emu->trace.nlooms; i++)
{
for (size_t i = 0; i < emu->trace.nlooms; i++) {
struct ovni_loom *loom = &emu->trace.loom[i];
for(size_t j = 0; j < loom->nprocs; j++)
{
for (size_t j = 0; j < loom->nprocs; j++) {
struct ovni_eproc *proc = &loom->proc[j];
task_create_pcf_types(pcftype, proc->nanos6_task_info.types);
}

View File

@ -3,10 +3,10 @@
#include "uthash.h"
#include "ovni.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
/* --------------------------- init ------------------------------- */
@ -26,8 +26,7 @@ hook_init_nodes(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
uth = &emu->th_chan;
@ -36,8 +35,7 @@ hook_init_nodes(struct ovni_emu *emu)
}
/* Init the channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -57,8 +55,7 @@ pre_subsystem(struct ovni_emu *emu, int st)
th = emu->cur_thread;
chan = &th->chan[CHAN_NODES_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan, st);
break;
@ -82,16 +79,31 @@ hook_pre_nodes(struct ovni_emu *emu)
edie(emu, "hook_pre_nodes: current thread %d not running\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category)
{
case 'R': pre_subsystem(emu, ST_NODES_REGISTER); break;
case 'U': pre_subsystem(emu, ST_NODES_UNREGISTER); break;
case 'W': pre_subsystem(emu, ST_NODES_IF0_WAIT); break;
case 'I': pre_subsystem(emu, ST_NODES_IF0_INLINE); break;
case 'T': pre_subsystem(emu, ST_NODES_TASKWAIT); break;
case 'C': pre_subsystem(emu, ST_NODES_CREATE); break;
case 'S': pre_subsystem(emu, ST_NODES_SUBMIT); break;
case 'P': pre_subsystem(emu, ST_NODES_SPAWN); break;
switch (emu->cur_ev->header.category) {
case 'R':
pre_subsystem(emu, ST_NODES_REGISTER);
break;
case 'U':
pre_subsystem(emu, ST_NODES_UNREGISTER);
break;
case 'W':
pre_subsystem(emu, ST_NODES_IF0_WAIT);
break;
case 'I':
pre_subsystem(emu, ST_NODES_IF0_INLINE);
break;
case 'T':
pre_subsystem(emu, ST_NODES_TASKWAIT);
break;
case 'C':
pre_subsystem(emu, ST_NODES_CREATE);
break;
case 'S':
pre_subsystem(emu, ST_NODES_SUBMIT);
break;
case 'P':
pre_subsystem(emu, ST_NODES_SPAWN);
break;
default:
break;
}

View File

@ -4,11 +4,11 @@
#include "uthash.h"
#include "utlist.h"
#include "ovni.h"
#include "chan.h"
#include "emu.h"
#include "emu_task.h"
#include "ovni.h"
#include "prv.h"
#include "chan.h"
/* --------------------------- init ------------------------------- */
@ -28,8 +28,7 @@ hook_init_nosv(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
@ -48,8 +47,7 @@ hook_init_nosv(struct ovni_emu *emu)
}
/* Init the nosv channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -62,8 +60,7 @@ hook_init_nosv(struct ovni_emu *emu)
}
/* Init task stack */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
th->nosv_task_stack.thread = th;
}
@ -167,12 +164,19 @@ update_task_state(struct ovni_emu *emu)
if (task == NULL)
edie(emu, "cannot find task with id %u\n", task_id);
switch(emu->cur_ev->header.value)
{
case 'x': task_execute(emu, stack, task); break;
case 'e': task_end(emu, stack, task); break;
case 'p': task_pause(emu, stack, task); break;
case 'r': task_resume(emu, stack, task); break;
switch (emu->cur_ev->header.value) {
case 'x':
task_execute(emu, stack, task);
break;
case 'e':
task_end(emu, stack, task);
break;
case 'p':
task_pause(emu, stack, task);
break;
case 'r':
task_resume(emu, stack, task);
break;
default:
edie(emu, "unexpected Nanos6 task event value %c\n",
emu->cur_ev->header.value);
@ -201,15 +205,26 @@ static void
update_task_channels(struct ovni_emu *emu,
char tr, struct task *prev, struct task *next)
{
switch(tr)
{
case 'x': chan_task_running(emu, next); break;
case 'r': chan_task_running(emu, next); break;
case 'e': chan_task_stopped(emu); break;
case 'p': chan_task_stopped(emu); break;
switch (tr) {
case 'x':
chan_task_running(emu, next);
break;
case 'r':
chan_task_running(emu, next);
break;
case 'e':
chan_task_stopped(emu);
break;
case 'p':
chan_task_stopped(emu);
break;
/* Additional nested transitions */
case 'X': chan_task_switch(emu, prev, next); break;
case 'E': chan_task_switch(emu, prev, next); break;
case 'X':
chan_task_switch(emu, prev, next);
break;
case 'E':
chan_task_switch(emu, prev, next);
break;
default:
edie(emu, "unexpected transition value %c\n", tr);
}
@ -253,8 +268,7 @@ create_task(struct ovni_emu *emu)
static void
pre_task(struct ovni_emu *emu)
{
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case 'c':
create_task(emu);
break;
@ -300,8 +314,7 @@ pre_sched(struct ovni_emu *emu)
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':
chan_push(chan_th, ST_NOSV_SCHED_HUNGRY);
break;
@ -337,19 +350,39 @@ pre_api(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 's': chan_push(chan_th, ST_NOSV_API_SUBMIT); break;
case 'S': chan_pop (chan_th, ST_NOSV_API_SUBMIT); break;
case 'p': chan_push(chan_th, ST_NOSV_API_PAUSE); break;
case 'P': chan_pop (chan_th, ST_NOSV_API_PAUSE); break;
case 'y': chan_push(chan_th, ST_NOSV_API_YIELD); break;
case 'Y': chan_pop (chan_th, ST_NOSV_API_YIELD); break;
case 'w': chan_push(chan_th, ST_NOSV_API_WAITFOR); break;
case 'W': chan_pop (chan_th, ST_NOSV_API_WAITFOR); break;
case 'c': chan_push(chan_th, ST_NOSV_API_SCHEDPOINT); break;
case 'C': chan_pop (chan_th, ST_NOSV_API_SCHEDPOINT); break;
default: break;
switch (emu->cur_ev->header.value) {
case 's':
chan_push(chan_th, ST_NOSV_API_SUBMIT);
break;
case 'S':
chan_pop(chan_th, ST_NOSV_API_SUBMIT);
break;
case 'p':
chan_push(chan_th, ST_NOSV_API_PAUSE);
break;
case 'P':
chan_pop(chan_th, ST_NOSV_API_PAUSE);
break;
case 'y':
chan_push(chan_th, ST_NOSV_API_YIELD);
break;
case 'Y':
chan_pop(chan_th, ST_NOSV_API_YIELD);
break;
case 'w':
chan_push(chan_th, ST_NOSV_API_WAITFOR);
break;
case 'W':
chan_pop(chan_th, ST_NOSV_API_WAITFOR);
break;
case 'c':
chan_push(chan_th, ST_NOSV_API_SCHEDPOINT);
break;
case 'C':
chan_pop(chan_th, ST_NOSV_API_SCHEDPOINT);
break;
default:
break;
}
}
@ -362,13 +395,21 @@ pre_mem(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 'a': chan_push(chan_th, ST_NOSV_MEM_ALLOCATING); break;
case 'A': chan_pop (chan_th, ST_NOSV_MEM_ALLOCATING); break;
case 'f': chan_push(chan_th, ST_NOSV_MEM_FREEING); break;
case 'F': chan_pop (chan_th, ST_NOSV_MEM_FREEING); break;
default: break;
switch (emu->cur_ev->header.value) {
case 'a':
chan_push(chan_th, ST_NOSV_MEM_ALLOCATING);
break;
case 'A':
chan_pop(chan_th, ST_NOSV_MEM_ALLOCATING);
break;
case 'f':
chan_push(chan_th, ST_NOSV_MEM_FREEING);
break;
case 'F':
chan_pop(chan_th, ST_NOSV_MEM_FREEING);
break;
default:
break;
}
}
@ -381,15 +422,27 @@ pre_thread_type(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
switch(emu->cur_ev->header.value)
{
case 'a': chan_push(chan_th, ST_NOSV_ATTACH); break;
case 'A': chan_pop (chan_th, ST_NOSV_ATTACH); break;
case 'w': chan_push(chan_th, ST_NOSV_WORKER); break;
case 'W': chan_pop (chan_th, ST_NOSV_WORKER); break;
case 'd': chan_push(chan_th, ST_NOSV_DELEGATE); break;
case 'D': chan_pop (chan_th, ST_NOSV_DELEGATE); break;
default: break;
switch (emu->cur_ev->header.value) {
case 'a':
chan_push(chan_th, ST_NOSV_ATTACH);
break;
case 'A':
chan_pop(chan_th, ST_NOSV_ATTACH);
break;
case 'w':
chan_push(chan_th, ST_NOSV_WORKER);
break;
case 'W':
chan_pop(chan_th, ST_NOSV_WORKER);
break;
case 'd':
chan_push(chan_th, ST_NOSV_DELEGATE);
break;
case 'D':
chan_pop(chan_th, ST_NOSV_DELEGATE);
break;
default:
break;
}
}
@ -404,8 +457,7 @@ pre_ss(struct ovni_emu *emu, int st)
dbg("pre_ss chan id %d st=%d\n", chan_th->id, st);
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan_th, st);
break;
@ -431,8 +483,7 @@ check_affinity(struct ovni_emu *emu)
if (th->state != TH_ST_RUNNING)
return;
if(cpu->nrunning_threads > 1)
{
if (cpu->nrunning_threads > 1) {
edie(emu, "cpu %s has more than one thread running\n",
cpu->name);
}
@ -449,15 +500,28 @@ hook_pre_nosv(struct ovni_emu *emu)
edie(emu, "hook_pre_nosv: current thread %d not active\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category)
{
case 'T': pre_task(emu); break;
case 'Y': pre_type(emu); break;
case 'S': pre_sched(emu); break;
case 'U': pre_ss(emu, ST_NOSV_SCHED_SUBMITTING); break;
case 'M': pre_mem(emu); break;
case 'H': pre_thread_type(emu); break;
case 'A': pre_api(emu); break;
switch (emu->cur_ev->header.category) {
case 'T':
pre_task(emu);
break;
case 'Y':
pre_type(emu);
break;
case 'S':
pre_sched(emu);
break;
case 'U':
pre_ss(emu, ST_NOSV_SCHED_SUBMITTING);
break;
case 'M':
pre_mem(emu);
break;
case 'H':
pre_thread_type(emu);
break;
case 'A':
pre_api(emu);
break;
default:
break;
}
@ -470,17 +534,14 @@ void
hook_end_nosv(struct ovni_emu *emu)
{
/* Emit types for all channel types and processes */
for(enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++)
{
for (enum chan_type ct = 0; ct < CHAN_MAXTYPE; ct++) {
struct pcf_file *pcf = &emu->pcf[ct];
int typeid = chan_to_prvtype[CHAN_NOSV_TYPE];
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
for(size_t i = 0; i < emu->trace.nlooms; i++)
{
for (size_t i = 0; i < emu->trace.nlooms; i++) {
struct ovni_loom *loom = &emu->trace.loom[i];
for(size_t j = 0; j < loom->nprocs; j++)
{
for (size_t j = 0; j < loom->nprocs; j++) {
struct ovni_eproc *proc = &loom->proc[j];
task_create_pcf_types(pcftype, proc->nosv_task_info.types);
}

View File

@ -3,10 +3,10 @@
#include "uthash.h"
#include "ovni.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
/* --------------------------- init ------------------------------- */
@ -26,8 +26,7 @@ hook_init_openmp(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
uth = &emu->th_chan;
@ -36,8 +35,7 @@ hook_init_openmp(struct ovni_emu *emu)
}
/* Init the channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -57,8 +55,7 @@ pre_mode(struct ovni_emu *emu, int st)
th = emu->cur_thread;
chan = &th->chan[CHAN_OPENMP_MODE];
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan, st);
break;
@ -83,10 +80,13 @@ hook_pre_openmp(struct ovni_emu *emu)
die("hook_pre_openmp: current thread %d not active\n",
emu->cur_thread->tid);
switch(emu->cur_ev->header.category)
{
case 'T': pre_mode(emu, ST_OPENMP_TASK); break;
case 'P': pre_mode(emu, ST_OPENMP_PARALLEL); break;
switch (emu->cur_ev->header.category) {
case 'T':
pre_mode(emu, ST_OPENMP_TASK);
break;
case 'P':
pre_mode(emu, ST_OPENMP_PARALLEL);
break;
default:
break;
}

View File

@ -1,10 +1,10 @@
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#include "ovni.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
#include "utlist.h"
/* The emulator ovni module provides the execution model by tracking the thread
@ -28,8 +28,7 @@ hook_init_ovni(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the ovni channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
uth = &emu->th_chan;
@ -42,8 +41,7 @@ hook_init_ovni(struct ovni_emu *emu)
}
/* Init the ovni channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -66,8 +64,7 @@ chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
if (th == NULL)
die("chan_tracking_update: thread is NULL");
switch (chan->track)
{
switch (chan->track) {
case CHAN_TRACK_TH_RUNNING:
enabled = th->is_running;
break;
@ -110,7 +107,9 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
th->is_active = (state == TH_ST_RUNNING
|| state == TH_ST_COOLING
|| state == TH_ST_WARMING) ? 1 : 0;
|| state == TH_ST_WARMING)
? 1
: 0;
chan_set(&th->chan[CHAN_OVNI_STATE], th->state);
@ -129,15 +128,12 @@ cpu_update_th_stats(struct ovni_cpu *cpu)
DL_FOREACH(cpu->thread, th)
{
if(th->state == TH_ST_RUNNING)
{
if (th->state == TH_ST_RUNNING) {
th_running = th;
running++;
th_active = th;
active++;
}
else if(th->state == TH_ST_COOLING || th->state == TH_ST_WARMING)
{
} else if (th->state == TH_ST_COOLING || th->state == TH_ST_WARMING) {
th_active = th;
active++;
}
@ -202,8 +198,7 @@ static void
cpu_add_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
{
/* Found, abort */
if(emu_cpu_find_thread(cpu, thread) != NULL)
{
if (emu_cpu_find_thread(cpu, thread) != NULL) {
err("The thread %d is already assigned to %s\n",
thread->tid, cpu->name);
abort();
@ -223,8 +218,7 @@ cpu_remove_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
p = emu_cpu_find_thread(cpu, thread);
/* Not found, abort */
if(p == NULL)
{
if (p == NULL) {
err("cannot remove missing thread %d from cpu %s\n",
thread->tid, cpu->name);
abort();
@ -241,7 +235,6 @@ cpu_migrate_thread(struct ovni_cpu *cpu,
struct ovni_ethread *thread,
struct ovni_cpu *newcpu)
{
cpu_remove_thread(cpu, thread);
cpu_add_thread(newcpu, thread);
}
@ -408,8 +401,7 @@ pre_thread(struct ovni_emu *emu)
th = emu->cur_thread;
ev = emu->cur_ev;
switch(ev->header.value)
{
switch (ev->header.value) {
case 'C': /* create */
dbg("thread %d creates a new thread at cpu=%d with args=%x %x\n",
th->tid,
@ -418,12 +410,24 @@ pre_thread(struct ovni_emu *emu)
ev->payload.u32[2]);
break;
case 'x': pre_thread_execute(emu, th); break;
case 'e': pre_thread_end(th); break;
case 'p': pre_thread_pause(th); break;
case 'r': pre_thread_resume(th); break;
case 'c': pre_thread_cool(th); break;
case 'w': pre_thread_warm(th); break;
case 'x':
pre_thread_execute(emu, th);
break;
case 'e':
pre_thread_end(th);
break;
case 'p':
pre_thread_pause(th);
break;
case 'r':
pre_thread_resume(th);
break;
case 'c':
pre_thread_cool(th);
break;
case 'w':
pre_thread_warm(th);
break;
default:
err("unknown thread event value %c\n",
ev->header.value);
@ -477,14 +481,12 @@ pre_affinity_remote(struct ovni_emu *emu)
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
* not found in the current one */
loom = emu->cur_loom;
for(i=0; i<loom->nprocs; i++)
{
for (i = 0; i < loom->nprocs; i++) {
proc = &loom->proc[i];
/* Skip the current process */
@ -497,8 +499,7 @@ pre_affinity_remote(struct ovni_emu *emu)
break;
}
if(remote_th == NULL)
{
if (remote_th == NULL) {
err("thread tid %d not found: cannot set affinity remotely\n",
tid);
abort();
@ -533,10 +534,13 @@ static void
pre_affinity(struct ovni_emu *emu)
{
// emu_emit(emu);
switch(emu->cur_ev->header.value)
{
case 's': pre_affinity_set(emu); break;
case 'r': pre_affinity_remote(emu); break;
switch (emu->cur_ev->header.value) {
case 's':
pre_affinity_set(emu);
break;
case 'r':
pre_affinity_remote(emu);
break;
default:
dbg("unknown affinity event value %c\n",
emu->cur_ev->header.value);
@ -554,17 +558,14 @@ pre_burst(struct ovni_emu *emu)
th = emu->cur_thread;
if(th->nbursts >= MAX_BURSTS)
{
if (th->nbursts >= MAX_BURSTS) {
err("too many bursts: ignored\n");
return;
}
th->burst_time[th->nbursts] = emu->delta_time;
if(th->nbursts > 0)
{
dt = th->burst_time[th->nbursts] -
th->burst_time[th->nbursts - 1];
if (th->nbursts > 0) {
dt = th->burst_time[th->nbursts] - th->burst_time[th->nbursts - 1];
dbg("burst delta time %ld ns\n", dt);
}
@ -581,8 +582,7 @@ pre_flush(struct ovni_emu *emu)
th = emu->cur_thread;
chan_th = &th->chan[CHAN_OVNI_FLUSH];
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case '[':
chan_push(chan_th, ST_OVNI_FLUSHING);
break;
@ -604,12 +604,19 @@ hook_pre_ovni(struct ovni_emu *emu)
if (emu->cur_ev->header.model != 'O')
return;
switch(emu->cur_ev->header.category)
{
case 'H': pre_thread(emu); break;
case 'A': pre_affinity(emu); break;
case 'B': pre_burst(emu); break;
case 'F': pre_flush(emu); break;
switch (emu->cur_ev->header.category) {
case 'H':
pre_thread(emu);
break;
case 'A':
pre_affinity(emu);
break;
case 'B':
pre_burst(emu);
break;
case 'F':
pre_flush(emu);
break;
default:
dbg("unknown ovni event category %c\n",
emu->cur_ev->header.category);

View File

@ -3,10 +3,10 @@
#include "uthash.h"
#include "ovni.h"
#include "emu.h"
#include "prv.h"
#include "chan.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
/* --------------------------- init ------------------------------- */
@ -26,8 +26,7 @@ hook_init_tampi(struct ovni_emu *emu)
prv_cpu = emu->prv_cpu;
/* Init the channels in all threads */
for(i=0; i<emu->total_nthreads; i++)
{
for (i = 0; i < emu->total_nthreads; i++) {
th = emu->global_thread[i];
row = th->gindex + 1;
uth = &emu->th_chan;
@ -36,8 +35,7 @@ hook_init_tampi(struct ovni_emu *emu)
}
/* Init the channels in all cpus */
for(i=0; i<emu->total_ncpus; i++)
{
for (i = 0; i < emu->total_ncpus; i++) {
cpu = emu->global_cpu[i];
row = cpu->gindex + 1;
ucpu = &emu->cpu_chan;
@ -55,8 +53,7 @@ pre_tampi_mode(struct ovni_emu *emu, int state)
th = emu->cur_thread;
switch(emu->cur_ev->header.value)
{
switch (emu->cur_ev->header.value) {
case '[':
chan_push(&th->chan[CHAN_TAMPI_MODE], state);
break;
@ -76,14 +73,25 @@ hook_pre_tampi(struct ovni_emu *emu)
edie(emu, "hook_pre_tampi: unexpected event with model %c\n",
emu->cur_ev->header.model);
switch(emu->cur_ev->header.category)
{
case 'S': pre_tampi_mode(emu, ST_TAMPI_SEND); break;
case 'R': pre_tampi_mode(emu, ST_TAMPI_RECV); break;
case 's': pre_tampi_mode(emu, ST_TAMPI_ISEND); break;
case 'r': pre_tampi_mode(emu, ST_TAMPI_IRECV); break;
case 'V': pre_tampi_mode(emu, ST_TAMPI_WAIT); break;
case 'W': pre_tampi_mode(emu, ST_TAMPI_WAITALL); break;
switch (emu->cur_ev->header.category) {
case 'S':
pre_tampi_mode(emu, ST_TAMPI_SEND);
break;
case 'R':
pre_tampi_mode(emu, ST_TAMPI_RECV);
break;
case 's':
pre_tampi_mode(emu, ST_TAMPI_ISEND);
break;
case 'r':
pre_tampi_mode(emu, ST_TAMPI_IRECV);
break;
case 'V':
pre_tampi_mode(emu, ST_TAMPI_WAIT);
break;
case 'W':
pre_tampi_mode(emu, ST_TAMPI_WAITALL);
break;
default:
break;
}

View File

@ -4,11 +4,11 @@
#include "uthash.h"
#include "utlist.h"
#include "ovni.h"
#include "chan.h"
#include "emu.h"
#include "emu_task.h"
#include "ovni.h"
#include "prv.h"
#include "chan.h"
struct task *
task_find(struct task *tasks, uint32_t task_id)
@ -230,11 +230,9 @@ 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 (tt = types; tt != NULL; tt = tt->hh.next) {
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
* no collision occurred */
if (strcmp(pcfvalue->label, tt->label) != 0)

8
heap.h
View File

@ -7,8 +7,8 @@
#ifndef HEAP_H
#define HEAP_H
#include <stddef.h>
#include "common.h"
#include <stddef.h>
typedef struct heap_node {
struct heap_node *parent;
@ -25,7 +25,11 @@ typedef struct head_head {
((type *) (((char *) head) - offsetof(type, name)))
#define heap_swap(a, b) \
do { heap_node_t *aux = (a); (a) = (b); (b) = aux; } while(0)
do { \
heap_node_t *aux = (a); \
(a) = (b); \
(b) = aux; \
} while (0)
/* heap_node_compare_t - comparison function.
* The comparison function cmp(a, b) shall return an integer:

76
ovni.c
View File

@ -6,7 +6,6 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/mman.h>
@ -14,10 +13,10 @@
#include <time.h>
#include <unistd.h>
#include "ovni.h"
#include "common.h"
#include "parson.h"
#include "compat.h"
#include "ovni.h"
#include "parson.h"
/* Data per process */
struct ovni_rproc rproc = {0};
@ -93,8 +92,7 @@ ovni_add_cpu(int index, int phyid)
/* Find the CPU array and create it if needed */
JSON_Array *cpuarray = json_object_dotget_array(meta, "cpus");
if(cpuarray == NULL)
{
if (cpuarray == NULL) {
JSON_Value *value = json_value_init_array();
if (value == NULL)
die("ovni_add_cpu: json_value_init_array() failed\n");
@ -123,8 +121,7 @@ ovni_add_cpu(int index, int phyid)
if (json_array_append_value(cpuarray, valcpu) != 0)
die("ovni_add_cpu: json_array_append_value() failed\n");
if(first_time)
{
if (first_time) {
JSON_Value *value = json_array_get_wrapping_value(cpuarray);
if (value == NULL)
die("ovni_add_cpu: json_array_get_wrapping_value() failed\n");
@ -206,14 +203,11 @@ create_proc_dir(const char *loom, int pid)
{
char *tmpdir = getenv("OVNI_TMPDIR");
if(tmpdir != NULL)
{
if (tmpdir != NULL) {
rproc.move_to_final = 1;
mkdir_proc(rproc.procdir, tmpdir, loom, pid);
mkdir_proc(rproc.procdir_final, OVNI_TRACEDIR, loom, pid);
}
else
{
} else {
rproc.move_to_final = 0;
mkdir_proc(rproc.procdir, OVNI_TRACEDIR, loom, pid);
}
@ -253,16 +247,14 @@ move_thread_to_final(const char *src, const char *dst)
FILE *infile = fopen(src, "r");
if(infile == NULL)
{
if (infile == NULL) {
err("fopen(%s) failed: %s\n", src, strerror(errno));
return -1;
}
FILE *outfile = fopen(dst, "w");
if(outfile == NULL)
{
if (outfile == NULL) {
err("fopen(%s) failed: %s\n", src, strerror(errno));
return -1;
}
@ -273,8 +265,7 @@ move_thread_to_final(const char *src, const char *dst)
fclose(outfile);
fclose(infile);
if(remove(src) != 0)
{
if (remove(src) != 0) {
err("remove(%s) failed: %s\n", src, strerror(errno));
return -1;
}
@ -291,22 +282,20 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
char thread_final[PATH_MAX];
int err = 0;
if((dir = opendir(procdir)) == NULL)
{
if ((dir = opendir(procdir)) == NULL) {
err("opendir %s failed: %s\n", procdir, strerror(errno));
return;
}
const char *prefix = "thread.";
while((dirent = readdir(dir)) != NULL)
{
while ((dirent = readdir(dir)) != NULL) {
/* It should only contain thread.* directories, skip others */
if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
continue;
if (snprintf(thread, PATH_MAX, "%s/%s", procdir,
dirent->d_name) >= PATH_MAX)
{
dirent->d_name)
>= PATH_MAX) {
err("snprintf: path too large: %s/%s\n", procdir,
dirent->d_name);
err = 1;
@ -314,8 +303,8 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
}
if (snprintf(thread_final, PATH_MAX, "%s/%s", procdir_final,
dirent->d_name) >= PATH_MAX)
{
dirent->d_name)
>= PATH_MAX) {
err("snprintf: path too large: %s/%s\n", procdir_final,
dirent->d_name);
err = 1;
@ -328,8 +317,7 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
closedir(dir);
if(rmdir(procdir) != 0)
{
if (rmdir(procdir) != 0) {
err("rmdir(%s) failed: %s\n", procdir, strerror(errno));
err = 1;
}
@ -349,13 +337,10 @@ ovni_proc_fini(void)
rproc.ready = 0;
if(rproc.move_to_final)
{
if (rproc.move_to_final) {
proc_metadata_store(rproc.meta, rproc.procdir_final);
move_procdir_to_final(rproc.procdir, rproc.procdir_final);
}
else
{
} else {
proc_metadata_store(rproc.meta, rproc.procdir);
}
}
@ -363,8 +348,7 @@ ovni_proc_fini(void)
static void
write_evbuf(uint8_t *buf, size_t size)
{
do
{
do {
ssize_t written = write(rthread.streamfd, buf, size);
if (written < 0)
@ -399,8 +383,7 @@ write_stream_header(void)
void
ovni_thread_init(pid_t tid)
{
if(rthread.ready)
{
if (rthread.ready) {
err("warning: thread %d already initialized, ignored\n", tid);
return;
}
@ -442,13 +425,14 @@ ovni_thread_isready(void)
}
#ifdef USE_TSC
static inline
uint64_t clock_tsc_now(void)
static inline uint64_t
clock_tsc_now(void)
{
uint32_t lo, hi;
/* RDTSC copies contents of 64-bit TSC into EDX:EAX */
__asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));
__asm__ volatile("rdtsc"
: "=a"(lo), "=d"(hi));
return (uint64_t) hi << 32 | lo;
}
#endif
@ -609,8 +593,7 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
die("ovni_ev_add_jumbo: event too large\n");
/* Check if the event fits or flush first otherwise */
if(rthread.evlen + totalsize >= OVNI_MAX_EV_BUF)
{
if (rthread.evlen + totalsize >= OVNI_MAX_EV_BUF) {
/* Measure the flush times */
t0 = ovni_clock_now();
flush_evbuf();
@ -627,8 +610,7 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
memcpy(&rthread.evbuf[rthread.evlen], buf, bufsize);
rthread.evlen += bufsize;
if(flushed)
{
if (flushed) {
/* Emit the flush events *after* the user event */
add_flush_events(t0, t1);
}
@ -643,8 +625,7 @@ ovni_ev_add(struct ovni_ev *ev)
int size = ovni_ev_size(ev);
/* Check if the event fits or flush first otherwise */
if(rthread.evlen + size >= OVNI_MAX_EV_BUF)
{
if (rthread.evlen + size >= OVNI_MAX_EV_BUF) {
/* Measure the flush times */
t0 = ovni_clock_now();
flush_evbuf();
@ -655,8 +636,7 @@ ovni_ev_add(struct ovni_ev *ev)
memcpy(&rthread.evbuf[rthread.evlen], ev, size);
rthread.evlen += size;
if(flushed)
{
if (flushed) {
/* Emit the flush events *after* the user event */
add_flush_events(t0, t1);
}

7
ovni.h
View File

@ -8,13 +8,13 @@
extern "C" {
#endif
#include <stdio.h>
#include <limits.h>
#include <linux/limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <sys/types.h>
#include <limits.h>
/* Hardcode the JSON_Value to avoid a dependency with janson */
typedef struct json_value_t JSON_Value;
@ -43,7 +43,6 @@ struct __attribute__((__packed__)) ovni_jumbo_payload {
};
union __attribute__((__packed__)) ovni_ev_payload {
int8_t i8[16];
int16_t i16[8];
int32_t i32[4];

View File

@ -1,15 +1,15 @@
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <linux/limits.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <stdatomic.h>
#include <dirent.h>
#include "ovni.h"
#include "trace.h"
@ -47,30 +47,26 @@ dump_events(struct ovni_trace *trace)
struct ovni_stream *stream;
/* Load events */
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
ovni_load_next_event(stream);
}
lastclock = 0;
while(1)
{
while (1) {
f = -1;
minclock = 0;
/* Select next event based on the clock */
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
if (!stream->active)
continue;
ev = stream->cur_ev;
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
{
if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
f = i;
minclock = ovni_ev_get_clock(ev);
}
@ -83,8 +79,7 @@ dump_events(struct ovni_trace *trace)
stream = &trace->stream[f];
if(lastclock >= ovni_ev_get_clock(stream->cur_ev))
{
if (lastclock >= ovni_ev_get_clock(stream->cur_ev)) {
fprintf(stderr, "warning: backwards jump in time\n");
}
@ -100,23 +95,21 @@ dump_events(struct ovni_trace *trace)
/* Unset the index */
f = -1;
minclock = 0;
}
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
char *tracedir;
struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
if(trace == NULL)
{
if (trace == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}
if(argc != 2)
{
if (argc != 2) {
fprintf(stderr, "missing tracedir\n");
exit(EXIT_FAILURE);
}

View File

@ -60,18 +60,15 @@ static double
get_time(clockid_t clock, int use_ns)
{
struct timespec tv;
if(clock_gettime(clock, &tv) != 0)
{
if (clock_gettime(clock, &tv) != 0) {
perror("clock_gettime failed");
exit(EXIT_FAILURE);
}
if (use_ns)
return (double)(tv.tv_sec) * 1.0e9 +
(double)tv.tv_nsec;
return (double) (tv.tv_sec) * 1.0e9 + (double) tv.tv_nsec;
return (double)(tv.tv_sec) +
(double)tv.tv_nsec * 1.0e-9;
return (double) (tv.tv_sec) + (double) tv.tv_nsec * 1.0e-9;
}
static int
@ -105,13 +102,10 @@ try_mkdir(const char *path, mode_t mode)
{
struct stat st;
if(stat(path, &st) != 0)
{
if (stat(path, &st) != 0) {
/* Directory does not exist */
return mkdir(path, mode);
}
else if(!S_ISDIR(st.st_mode))
{
} else if (!S_ISDIR(st.st_mode)) {
errno = ENOTDIR;
return -1;
}
@ -183,8 +177,7 @@ parse_options(struct options *options, int argc, char *argv[])
}
}
if (optind < argc)
{
if (optind < argc) {
fprintf(stderr, "error: unexpected extra arguments\n");
exit(EXIT_FAILURE);
}
@ -200,8 +193,7 @@ get_clock_samples(struct offset *offset, int nsamples)
offset->nsamples = nsamples;
for(i=0; i<nsamples; i++)
{
for (i = 0; i < nsamples; i++) {
MPI_Barrier(MPI_COMM_WORLD);
offset->clock_sample[i] = get_time(CLOCK_MONOTONIC, 1);
}
@ -218,8 +210,7 @@ fill_offset(struct offset *offset, int nsamples)
MPI_Comm_rank(MPI_COMM_WORLD, &offset->rank);
/* Fill the host name */
if(gethostname(offset->hostname, OVNI_MAX_HOSTNAME) != 0)
{
if (gethostname(offset->hostname, OVNI_MAX_HOSTNAME) != 0) {
perror("gethostname");
exit(EXIT_FAILURE);
}
@ -241,17 +232,14 @@ offset_compute_delta(struct offset *ref, struct offset *cur, int nsamples, int v
delta = malloc(sizeof(double) * nsamples);
if(delta == NULL)
{
if (delta == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
for(i=0; i<nsamples; i++)
{
for (i = 0; i < nsamples; 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",
cur->rank, i, delta[i],
ref->clock_sample[i],
@ -269,8 +257,7 @@ offset_compute_delta(struct offset *ref, struct offset *cur, int nsamples, int v
cur->delta_mean /= nsamples;
for (cur->delta_var = 0, 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_std = sqrt(cur->delta_var);
@ -307,12 +294,10 @@ build_offset_table(int nsamples, int rank, int verbose)
void *sendbuf;
/* The rank 0 must build the table */
if(rank == 0)
{
if (rank == 0) {
table = malloc(sizeof(*table));
if(table == NULL)
{
if (table == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
@ -321,17 +306,14 @@ build_offset_table(int nsamples, int rank, int verbose)
table->_offset = calloc(table->nprocs, offset_size(nsamples));
if(table->_offset == NULL)
{
if (table->_offset == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
table->offset = malloc(sizeof(struct offset *) *
table->nprocs);
table->offset = malloc(sizeof(struct offset *) * table->nprocs);
if(table->offset == NULL)
{
if (table->offset == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
@ -340,14 +322,11 @@ build_offset_table(int nsamples, int rank, int verbose)
table->offset[i] = table_get_offset(table, i, nsamples);
offset = table->offset[0];
}
else
{
} else {
/* Otherwise just allocate one offset */
offset = calloc(1, offset_size(nsamples));
if(offset == NULL)
{
if (offset == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
@ -366,10 +345,8 @@ build_offset_table(int nsamples, int rank, int verbose)
0, MPI_COMM_WORLD);
/* Finish the offsets by computing the deltas on rank 0 */
if(rank == 0)
{
for(i=0; i<table->nprocs; i++)
{
if (rank == 0) {
for (i = 0; i < table->nprocs; i++) {
offset_compute_delta(offset, table->offset[i],
nsamples, verbose);
}
@ -390,8 +367,7 @@ print_drift_header(FILE *out, struct offset_table *table)
fprintf(out, "%-20s", "wallclock");
for(i=0; i<table->nprocs; i++)
{
for (i = 0; i < table->nprocs; i++) {
// sprintf(buf, "rank%d", i);
fprintf(out, " %-20s", table->offset[i]->hostname);
}
@ -421,8 +397,7 @@ print_table_detailed(FILE *out, struct offset_table *table)
fprintf(out, "%-10s %-20s %-20s %-20s %-20s\n",
"rank", "hostname", "offset_median", "offset_mean", "offset_std");
for(i=0; i<table->nprocs; i++)
{
for (i = 0; i < table->nprocs; i++) {
offset = table->offset[i];
fprintf(out, "%-10d %-20s %-20ld %-20f %-20f\n",
i, offset->hostname, offset->offset,
@ -440,39 +415,31 @@ do_work(struct options *options, int rank)
drift_mode = options->ndrift_samples > 1 ? 1 : 0;
if(rank == 0)
{
if(mkpath(options->outpath, 0755) != 0)
{
if (rank == 0) {
if (mkpath(options->outpath, 0755) != 0) {
fprintf(stderr, "mkpath(%s) failed: %s\n",
options->outpath, strerror(errno));
exit(EXIT_FAILURE);
}
out = fopen(options->outpath, "w");
if(out == NULL)
{
if (out == NULL) {
fprintf(stderr, "fopen(%s) failed: %s\n",
options->outpath, strerror(errno));
exit(EXIT_FAILURE);
}
}
for(i=0; i<options->ndrift_samples; i++)
{
for (i = 0; i < options->ndrift_samples; i++) {
table = build_offset_table(options->nsamples, rank, options->verbose);
if(rank == 0)
{
if(drift_mode)
{
if (rank == 0) {
if (drift_mode) {
if (i == 0)
print_drift_header(out, table);
print_drift_row(out, table);
}
else
{
} else {
print_table_detailed(out, table);
}

802
parson.c

File diff suppressed because it is too large Load Diff

View File

@ -27,8 +27,7 @@
#define parson_parson_h
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <stddef.h> /* size_t */

21
pcf.c
View File

@ -2,12 +2,12 @@
* SPDX-License-Identifier: GPL-3.0-or-later */
#include "pcf.h"
#include "prv.h"
#include "emu.h"
#include "prv.h"
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
const char *pcf_def_header =
"DEFAULT_OPTIONS\n"
@ -61,8 +61,7 @@ const uint32_t pcf_def_palette[] = {
GREEN,
YELLOW, ORANGE, PURPLE, CYAN, MAGENTA, LIME, PINK,
TEAL, GREY, LAVENDER, BROWN, BEIGE, MAROON, MINT,
OLIVE, APRICOT, NAVY, DEEPBLUE
};
OLIVE, APRICOT, NAVY, DEEPBLUE};
const uint32_t *pcf_palette = pcf_def_palette;
const int pcf_palette_len = ARRAY_LEN(pcf_def_palette);
@ -260,7 +259,11 @@ char *pcf_chan_name[CHAN_MAX] = {
[CHAN_KERNEL_CS] = "Context switches",
};
enum pcf_suffix { NONE = 0, CUR_TH, RUN_TH, ACT_TH, SUFFIX_MAX };
enum pcf_suffix { NONE = 0,
CUR_TH,
RUN_TH,
ACT_TH,
SUFFIX_MAX };
char *pcf_suffix_name[SUFFIX_MAX] = {
[NONE] = "",
@ -323,8 +326,7 @@ write_colors(FILE *f, const uint32_t *palette, int n)
fprintf(f, "\n\n");
fprintf(f, "STATES_COLOR\n");
for(i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
decompose_rgb(palette[i], &r, &g, &b);
fprintf(f, "%-3d {%3d, %3d, %3d}\n", i, r, g, b);
}
@ -398,8 +400,7 @@ pcf_open(struct pcf_file *pcf, char *path, int chantype)
pcf->f = fopen(path, "w");
pcf->chantype = chantype;
if(pcf->f == NULL)
{
if (pcf->f == NULL) {
die("cannot open PCF file '%s': %s\n",
path, strerror(errno));
}

2
pcf.h
View File

@ -4,8 +4,8 @@
#ifndef OVNI_PCF_H
#define OVNI_PCF_H
#include <stdio.h>
#include "uthash.h"
#include <stdio.h>
#define MAX_PCF_LABEL 512

2
prv.c
View File

@ -3,8 +3,8 @@
#include <stdio.h>
#include "ovni.h"
#include "emu.h"
#include "ovni.h"
#include "prv.h"
void

4
prv.h
View File

@ -4,9 +4,9 @@
#ifndef OVNI_PRV_H
#define OVNI_PRV_H
#include <stdint.h>
#include "ovni.h"
#include "emu.h"
#include "ovni.h"
#include <stdint.h>
void
prv_ev(FILE *f, int row, int64_t time, int type, int val);

106
sort.c
View File

@ -27,9 +27,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include "emu.h"
#include "ovni.h"
#include "trace.h"
#include "emu.h"
struct ring {
ssize_t head;
@ -54,7 +54,8 @@ struct sortplan {
int fd;
};
enum operation_mode { SORT, CHECK };
enum operation_mode { SORT,
CHECK };
static char *tracedir = NULL;
static enum operation_mode operation_mode = SORT;
@ -92,10 +93,8 @@ find_destination(struct ring *r, uint64_t clock)
start = r->tail - 1 >= 0 ? r->tail - 1 : r->size - 1;
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)
{
if(r->ev[i]->header.clock < clock)
{
for (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);
return i;
@ -111,17 +110,13 @@ find_destination(struct ring *r, uint64_t clock)
static int
starts_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 == '[';
}
static int
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
@ -179,19 +174,15 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
p = src;
q = srcbad;
while(1)
{
while (1) {
ep = (struct ovni_ev *) p;
eq = (struct ovni_ev *) q;
if(p < srcbad && ep->header.clock < eq->header.clock)
{
if (p < srcbad && ep->header.clock < eq->header.clock) {
ev = ep;
evsize = ovni_ev_size(ev);
p += evsize;
}
else
{
} else {
ev = eq;
evsize = ovni_ev_size(ev);
q += evsize;
@ -243,8 +234,7 @@ execute_sort_plan(struct sortplan *sp)
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)
{
if ((i0 = find_destination(sp->r, sp->bad0->header.clock)) < 0) {
err("cannot find destination for region starting at clock %ld\n",
sp->bad0->header.clock);
@ -299,39 +289,28 @@ stream_winsort(struct ovni_stream *stream, struct ring *r)
size_t empty_regions = 0;
size_t updated = 0;
while(stream->active)
{
while (stream->active) {
ovni_load_next_event(stream);
ev = stream->cur_ev;
if(st == 'S' && starts_unsorted_region(ev))
{
if (st == 'S' && starts_unsorted_region(ev)) {
st = 'U';
}
else if(st == 'U')
{
} else if (st == 'U') {
/* Ensure that we have at least one unsorted
* event inside the section */
if(ends_unsorted_region(ev))
{
if (ends_unsorted_region(ev)) {
empty_regions++;
st = 'S';
}
else
{
} else {
st = 'X';
sp.bad0 = ev;
}
}
else if(st == 'X')
{
if(ends_unsorted_region(ev))
{
} else if (st == 'X') {
if (ends_unsorted_region(ev)) {
updated = 1;
sp.next = ev;
dbg("executing sort plan for stream tid=%d\n", stream->tid);
if(execute_sort_plan(&sp) < 0)
{
if (execute_sort_plan(&sp) < 0) {
err("sort failed for stream tid=%d\n",
stream->tid);
return -1;
@ -370,14 +349,12 @@ stream_check(struct ovni_stream *stream)
uint64_t last_clock = ev->header.clock;
int ret = 0;
while(stream->active)
{
while (stream->active) {
ovni_load_next_event(stream);
ev = stream->cur_ev;
uint64_t cur_clock = ovni_ev_get_clock(ev);
if(cur_clock < last_clock)
{
if (cur_clock < last_clock) {
err("backwards jump in time %ld -> %ld for stream tid=%d\n",
last_clock, cur_clock, stream->tid);
ret = -1;
@ -403,24 +380,18 @@ process_trace(struct ovni_trace *trace)
if (ring.ev == NULL)
die("malloc failed: %s\n", strerror(errno));
for(i=0; i<trace->nstreams; i++)
{
for (i = 0; i < trace->nstreams; i++) {
stream = &trace->stream[i];
if(operation_mode == SORT)
{
if (operation_mode == SORT) {
dbg("sorting stream tid=%d\n", stream->tid);
if(stream_winsort(stream, &ring) != 0)
{
if (stream_winsort(stream, &ring) != 0) {
err("sort stream tid=%d failed\n", stream->tid);
/* When sorting, return at the first
* attempt */
return -1;
}
}
else
{
if(stream_check(stream) != 0)
{
} else {
if (stream_check(stream) != 0) {
err("stream tid=%d is not sorted\n", stream->tid);
/* When checking, report all errors and
* then fail */
@ -431,14 +402,10 @@ process_trace(struct ovni_trace *trace)
free(ring.ev);
if(operation_mode == CHECK)
{
if(ret == 0)
{
if (operation_mode == CHECK) {
if (ret == 0) {
err("all streams sorted\n");
}
else
{
} else {
err("streams NOT sorted\n");
}
}
@ -476,10 +443,8 @@ parse_args(int argc, char *argv[])
{
int opt;
while((opt = getopt(argc, argv, "c")) != -1)
{
switch(opt)
{
while ((opt = getopt(argc, argv, "c")) != -1) {
switch (opt) {
case 'c':
operation_mode = CHECK;
break;
@ -488,8 +453,7 @@ parse_args(int argc, char *argv[])
}
}
if(optind >= argc)
{
if (optind >= argc) {
err("missing tracedir\n");
usage(argc, argv);
}
@ -497,7 +461,8 @@ parse_args(int argc, char *argv[])
tracedir = argv[optind];
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int ret = 0;
struct ovni_trace *trace;
@ -506,8 +471,7 @@ int main(int argc, char *argv[])
trace = calloc(1, sizeof(struct ovni_trace));
if(trace == NULL)
{
if (trace == NULL) {
perror("calloc");
exit(EXIT_FAILURE);
}

View File

@ -14,16 +14,14 @@ main(void)
instr_nanos6_type_create(typeid);
/* Create and run the tasks, one nested into another */
for(int i = 0; i < ntasks; i++)
{
for (int i = 0; i < ntasks; i++) {
instr_nanos6_handle_task_enter();
instr_nanos6_task_create_and_execute(i + 1, typeid);
usleep(500);
}
/* End the tasks in the opposite order */
for(int i = ntasks - 1; i >= 0; i--)
{
for (int i = ntasks - 1; i >= 0; i--) {
instr_nanos6_task_end(i + 1);
instr_nanos6_task_body_exit();
instr_nanos6_handle_task_exit();

View File

@ -17,8 +17,7 @@ main(void)
for (int i = 0; i < ntypes; i++)
instr_nanos6_type_create(i + 1);
for(int i = 0; i < ntasks; i++)
{
for (int i = 0; i < ntasks; i++) {
instr_nanos6_task_create_and_execute(i + 1, (i % ntypes) + 1);
usleep(500);
instr_nanos6_task_end(i + 1);

View File

@ -33,4 +33,3 @@ main(void)
return 0;
}

View File

@ -27,4 +27,3 @@ main(void)
return 0;
}

View File

@ -17,8 +17,7 @@ main(void)
for (int i = 0; i < ntypes; i++)
instr_nosv_type_create(i + 1);
for(int i=0; i<ntasks; i++)
{
for (int i = 0; i < ntasks; i++) {
instr_nosv_task_create(i + 1, (i % ntypes) + 1);
instr_nosv_task_execute(i + 1);
usleep(500);
@ -29,4 +28,3 @@ main(void)
return 0;
}

View File

@ -4,25 +4,24 @@
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <stdint.h>
#include <limits.h>
#include <linux/limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/limits.h>
#include <limits.h>
#include <unistd.h>
#include "ovni.h"
#include "compat.h"
#include "ovni.h"
static inline void
init(void)
{
char hostname[HOST_NAME_MAX];
if(gethostname(hostname, HOST_NAME_MAX) != 0)
{
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
perror("gethostname failed");
exit(EXIT_FAILURE);
}
@ -32,7 +31,8 @@ init(void)
ovni_add_cpu(0, 0);
}
static void emit(uint8_t *buf, size_t size)
static void
emit(uint8_t *buf, size_t size)
{
struct ovni_ev ev = {0};
ovni_ev_set_mcv(&ev, "O$$");
@ -42,13 +42,13 @@ static void emit(uint8_t *buf, size_t size)
#define NRUNS 50
int main(void)
int
main(void)
{
size_t payload_size;
uint8_t *payload_buf;
if(setenv("OVNI_TMPDIR", "/dev/shm/ovni-flush-overhead", 1) != 0)
{
if (setenv("OVNI_TMPDIR", "/dev/shm/ovni-flush-overhead", 1) != 0) {
perror("setenv failed");
exit(EXIT_FAILURE);
}
@ -59,21 +59,18 @@ int main(void)
payload_size = 1024 * 1024;
payload_buf = calloc(1, payload_size);
if(!payload_buf)
{
if (!payload_buf) {
perror("calloc failed");
exit(EXIT_FAILURE);
}
double *times = calloc(sizeof(double), NRUNS);
if(times == NULL)
{
if (times == NULL) {
perror("calloc failed");
exit(EXIT_FAILURE);
}
for(int i=0; i < NRUNS; i++)
{
for (int i = 0; i < NRUNS; i++) {
emit(payload_buf, payload_size);
double t0 = (double) ovni_clock_now();
ovni_flush();

View File

@ -4,25 +4,24 @@
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <stdint.h>
#include <limits.h>
#include <linux/limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/limits.h>
#include <limits.h>
#include <unistd.h>
#include "ovni.h"
#include "compat.h"
#include "ovni.h"
static inline void
init(void)
{
char hostname[HOST_NAME_MAX];
if(gethostname(hostname, HOST_NAME_MAX) != 0)
{
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
perror("gethostname failed");
exit(EXIT_FAILURE);
}
@ -32,7 +31,8 @@ init(void)
ovni_add_cpu(0, 0);
}
static void emit(uint8_t *buf, size_t size)
static void
emit(uint8_t *buf, size_t size)
{
struct ovni_ev ev = {0};
ovni_ev_set_mcv(&ev, "O$$");
@ -40,7 +40,8 @@ static void emit(uint8_t *buf, size_t size)
ovni_ev_jumbo_emit(&ev, buf, size);
}
int main(void)
int
main(void)
{
size_t payload_size;
uint8_t *payload_buf;
@ -50,8 +51,7 @@ int main(void)
payload_size = (size_t) (0.9 * (double) OVNI_MAX_EV_BUF);
payload_buf = calloc(1, payload_size);
if(!payload_buf)
{
if (!payload_buf) {
perror("calloc failed");
exit(EXIT_FAILURE);
}

View File

@ -3,8 +3,8 @@
#define _GNU_SOURCE
#include "ovni.h"
#include "compat.h"
#include "ovni.h"
#include <assert.h>
#include <inttypes.h>
@ -15,7 +15,8 @@
#include <time.h>
#include <unistd.h>
static void fail(const char *msg)
static void
fail(const char *msg)
{
fprintf(stderr, "%s\n", msg);
abort();
@ -35,7 +36,8 @@ static void fail(const char *msg)
INSTR_3ARG(instr_thread_execute, "OHx", int32_t, cpu, int32_t, creator_tid, uint64_t, tag)
static inline void instr_thread_end(void)
static inline void
instr_thread_end(void)
{
struct ovni_ev ev = {0};
@ -47,7 +49,8 @@ static inline void instr_thread_end(void)
ovni_flush();
}
static inline void instr_start(int rank, int nranks)
static inline void
instr_start(int rank, int nranks)
{
char hostname[HOST_NAME_MAX];
@ -61,8 +64,7 @@ static inline void instr_start(int rank, int nranks)
ovni_thread_init(gettid());
/* Only the rank 0 inform about all CPUs */
if(rank == 0)
{
if (rank == 0) {
/* Fake nranks cpus */
for (int i = 0; i < nranks; i++)
ovni_add_cpu(i, i);
@ -76,7 +78,8 @@ static inline void instr_start(int rank, int nranks)
instr_thread_execute(curcpu, -1, 0);
}
static inline void instr_end(void)
static inline void
instr_end(void)
{
instr_thread_end();
ovni_thread_free();
@ -132,7 +135,8 @@ task(int32_t id, uint32_t typeid, int us)
ovni_ev_emit(&ev);
}
int main(void)
int
main(void)
{
int rank = atoi(getenv("OVNI_RANK"));
int nranks = atoi(getenv("OVNI_NRANKS"));
@ -150,4 +154,3 @@ int main(void)
return 0;
}

View File

@ -3,8 +3,8 @@
#define _GNU_SOURCE
#include "ovni.h"
#include "compat.h"
#include "ovni.h"
#include <assert.h>
#include <inttypes.h>
@ -16,7 +16,8 @@
#include <time.h>
#include <unistd.h>
static void fail(const char *msg)
static void
fail(const char *msg)
{
fprintf(stderr, "%s\n", msg);
abort();
@ -36,7 +37,8 @@ static void fail(const char *msg)
INSTR_3ARG(instr_thread_execute, "OHx", int32_t, cpu, int32_t, creator_tid, uint64_t, tag)
static inline void instr_thread_end(void)
static inline void
instr_thread_end(void)
{
struct ovni_ev ev = {0};
@ -48,7 +50,8 @@ static inline void instr_thread_end(void)
ovni_flush();
}
static inline void instr_start(int rank)
static inline void
instr_start(int rank)
{
cpu_set_t mask;
char hostname[HOST_NAME_MAX];
@ -65,12 +68,9 @@ static inline void instr_start(int rank)
ovni_thread_init(gettid());
/* Only the rank 0 inform about all CPUs */
if(rank == 0)
{
for(i=0; i < CPU_SETSIZE; i++)
{
if(CPU_ISSET(i, &mask))
{
if (rank == 0) {
for (i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &mask)) {
last_phy = i;
if (rank == 0)
@ -90,14 +90,16 @@ static inline void instr_start(int rank)
instr_thread_execute(curcpu, -1, 0);
}
static inline void instr_end(void)
static inline void
instr_end(void)
{
instr_thread_end();
ovni_thread_free();
ovni_proc_fini();
}
int main(void)
int
main(void)
{
int rank = atoi(getenv("OVNI_RANK"));
// int nranks = atoi(getenv("OVNI_NRANKS"));
@ -110,4 +112,3 @@ int main(void)
return 0;
}

View File

@ -4,7 +4,8 @@
#define _GNU_SOURCE
#include <unistd.h>
int main(void)
int
main(void)
{
#pragma oss task if (0)
{

View File

@ -1,7 +1,8 @@
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
int main(void)
int
main(void)
{
#pragma oss task
{

View File

@ -40,11 +40,11 @@ do_run(void)
do_task(t);
/* Wait for all tasks to fill the handle */
while (atomic_load(&nhandles) < ntasks);
while (atomic_load(&nhandles) < ntasks)
;
/* Is ok if we call unblock before the block happens */
for(int t = 0; t < ntasks; t++)
{
for (int t = 0; t < ntasks; t++) {
if (handle[t] == NULL)
abort();
@ -54,7 +54,8 @@ do_run(void)
#pragma oss taskwait
}
static int get_ncpus(void)
static int
get_ncpus(void)
{
return (int) nanos6_get_num_cpus();
}
@ -66,8 +67,7 @@ main(void)
handle = calloc(ntasks, sizeof(void *));
if(handle == NULL)
{
if (handle == NULL) {
perror("calloc failed");
return -1;
}

View File

@ -1,14 +1,13 @@
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
int main(void)
{
for(int i = 0; i < 5000; i++)
int
main(void)
{
for (int i = 0; i < 5000; i++) {
#pragma oss task
{
for(volatile long j = 0; j < 10000L; j++)
{
for (volatile long j = 0; j < 10000L; j++) {
}
}
}

View File

@ -1,7 +1,8 @@
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
int main(void)
int
main(void)
{
#pragma oss task
{

View File

@ -4,7 +4,8 @@
#define _GNU_SOURCE
#include <unistd.h>
int main(void)
int
main(void)
{
#pragma oss task for
for (int i = 0; i < 1024; i++)

View File

@ -3,18 +3,20 @@
#define _DEFAULT_SOURCE
#include <unistd.h>
#include <nosv.h>
#include <unistd.h>
#include "common.h"
int main(void)
int
main(void)
{
nosv_init();
nosv_task_type_t type;
if (nosv_type_init(&type, NULL, NULL, NULL, "adopted", NULL,
NULL, NOSV_TYPE_INIT_EXTERNAL) != 0)
NULL, NOSV_TYPE_INIT_EXTERNAL)
!= 0)
die("nosv_type_init failed\n");
nosv_task_t task;

212
trace.c
View File

@ -6,20 +6,19 @@
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <linux/limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdatomic.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
static int
find_dir_prefix_str(const char *dirname, const char *prefix, const char **str)
@ -66,8 +65,7 @@ count_dir_prefix(DIR *dir, const char *prefix)
struct dirent *dirent;
size_t n = 0;
while((dirent = readdir(dir)) != NULL)
{
while ((dirent = readdir(dir)) != NULL) {
if (find_dir_prefix_str(dirent->d_name, prefix, NULL) != 0)
continue;
@ -88,8 +86,7 @@ load_thread(struct ovni_ethread *thread, struct ovni_eproc *proc, int index, int
thread->state = TH_ST_UNKNOWN;
thread->proc = proc;
if(strlen(filepath) >= PATH_MAX)
{
if (strlen(filepath) >= PATH_MAX) {
err("filepath too large: %s\n", filepath);
return -1;
}
@ -116,13 +113,10 @@ load_proc_metadata(struct ovni_eproc *proc, int *rank_enabled)
JSON_Value *rank_val = json_object_get_value(meta, "rank");
if(rank_val != NULL)
{
if (rank_val != NULL) {
proc->rank = (int) json_number(rank_val);
*rank_enabled = 1;
}
else
{
} else {
proc->rank = -1;
}
}
@ -135,36 +129,31 @@ check_metadata_version(struct ovni_eproc *proc)
die("check_metadata_version: json_value_get_object() failed\n");
JSON_Value *version_val = json_object_get_value(meta, "version");
if(version_val == NULL)
{
if (version_val == NULL) {
die("process %d is missing attribute \"version\" in metadata\n",
proc->pid);
}
int version = (int) json_number(version_val);
if(version != OVNI_METADATA_VERSION)
{
if (version != OVNI_METADATA_VERSION) {
die("pid %d: metadata version mismatch %d (expected %d)\n",
proc->pid, version,
OVNI_METADATA_VERSION);
}
JSON_Value *mversion_val = json_object_get_value(meta, "model_version");
if(mversion_val == NULL)
{
if (mversion_val == NULL) {
die("process %d is missing attribute \"model_version\" in metadata\n",
proc->pid);
}
const char *mversion = json_string(mversion_val);
if(strcmp(mversion, OVNI_MODEL_VERSION) != 0)
{
if (strcmp(mversion, OVNI_MODEL_VERSION) != 0) {
die("pid %d: metadata model version mismatch '%s' (expected '%s')\n",
proc->pid, mversion,
OVNI_MODEL_VERSION);
}
}
@ -197,16 +186,13 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
proc->gindex = total_procs++;
proc->loom = loom;
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);
abort();
}
proc->meta = json_parse_file_with_comments(path);
if(proc->meta == NULL)
{
if (proc->meta == NULL) {
err("error loading metadata from %s\n", path);
return -1;
}
@ -216,8 +202,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);
if((dir = opendir(procdir)) == NULL)
{
if ((dir = opendir(procdir)) == NULL) {
fprintf(stderr, "opendir %s failed: %s\n",
procdir, strerror(errno));
return -1;
@ -225,8 +210,7 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
proc->nthreads = count_dir_prefix(dir, "thread");
if(proc->nthreads <= 0)
{
if (proc->nthreads <= 0) {
err("cannot find any thread for process %d\n",
proc->pid);
return -1;
@ -234,28 +218,24 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
proc->thread = calloc(proc->nthreads, sizeof(struct ovni_ethread));
if(proc->thread == NULL)
{
if (proc->thread == NULL) {
perror("calloc failed");
return -1;
}
int *tids;
if((tids = calloc(proc->nthreads, sizeof(int))) == NULL)
{
if ((tids = calloc(proc->nthreads, sizeof(int))) == NULL) {
perror("calloc failed\n");
return -1;
}
rewinddir(dir);
for(size_t i = 0; i < proc->nthreads; )
{
for (size_t i = 0; i < proc->nthreads;) {
dirent = readdir(dir);
if(dirent == NULL)
{
if (dirent == NULL) {
err("inconsistent: readdir returned NULL\n");
return -1;
}
@ -271,13 +251,10 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
/* Sort threads by ascending TID */
qsort(tids, proc->nthreads, sizeof(int), compare_int);
for(size_t i = 0; i < proc->nthreads; i++)
{
for (size_t i = 0; i < proc->nthreads; i++) {
int tid = tids[i];
if(snprintf(path, PATH_MAX, "%s/thread.%d", procdir, tid) >=
PATH_MAX)
{
if (snprintf(path, PATH_MAX, "%s/thread.%d", procdir, tid) >= PATH_MAX) {
err("snprintf: path too large: %s\n", procdir);
abort();
}
@ -302,8 +279,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
DIR *dir;
struct dirent *dirent;
if((dir = opendir(loomdir)) == NULL)
{
if ((dir = opendir(loomdir)) == NULL) {
fprintf(stderr, "opendir %s failed: %s\n",
loomdir, strerror(errno));
return -1;
@ -312,8 +288,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
loom->rank_enabled = 0;
loom->nprocs = count_dir_prefix(dir, "proc");
if(loom->nprocs <= 0)
{
if (loom->nprocs <= 0) {
err("cannot find any process directory in loom %s\n",
loom->hostname);
return -1;
@ -321,8 +296,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
loom->proc = calloc(loom->nprocs, sizeof(struct ovni_eproc));
if(loom->proc == NULL)
{
if (loom->proc == NULL) {
perror("calloc failed");
return -1;
}
@ -330,15 +304,13 @@ load_loom(struct ovni_loom *loom, char *loomdir)
rewinddir(dir);
i = 0;
while((dirent = readdir(dir)) != NULL)
{
while ((dirent = readdir(dir)) != NULL) {
if (find_dir_prefix_int(dirent->d_name, "proc", &pid) != 0)
continue;
sprintf(path, "%s/%s", loomdir, dirent->d_name);
if(i >= loom->nprocs)
{
if (i >= loom->nprocs) {
err("more process than expected\n");
abort();
}
@ -347,11 +319,9 @@ load_loom(struct ovni_loom *loom, char *loomdir)
return -1;
i++;
}
if(i != loom->nprocs)
{
if (i != loom->nprocs) {
err("unexpected number of processes\n");
abort();
}
@ -359,13 +329,10 @@ load_loom(struct ovni_loom *loom, char *loomdir)
closedir(dir);
/* Ensure all process have the rank, if enabled in any */
if(loom->rank_enabled)
{
for(i = 0; i < loom->nprocs; i++)
{
if (loom->rank_enabled) {
for (i = 0; i < loom->nprocs; i++) {
struct ovni_eproc *proc = &loom->proc[i];
if(proc->rank < 0)
{
if (proc->rank < 0) {
die("process %d is missing the rank\n",
proc->pid);
}
@ -388,8 +355,7 @@ loom_to_host(const char *loom_name, char *host, int n)
{
int i;
for(i = 0; i < n; i++)
{
for (i = 0; i < n; i++) {
/* Copy until dot or end */
if (loom_name[i] != '.' && loom_name[i] != '\0')
host[i] = loom_name[i];
@ -408,24 +374,21 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
{
DIR *dir;
if((dir = opendir(tracedir)) == NULL)
{
if ((dir = opendir(tracedir)) == NULL) {
err("opendir %s failed: %s\n", tracedir, strerror(errno));
return -1;
}
trace->nlooms = count_dir_prefix(dir, "loom");
if(trace->nlooms == 0)
{
if (trace->nlooms == 0) {
err("cannot find any loom in %s\n", tracedir);
return -1;
}
trace->loom = calloc(trace->nlooms, sizeof(struct ovni_loom));
if(trace->loom == NULL)
{
if (trace->loom == NULL) {
perror("calloc failed\n");
return -1;
}
@ -435,25 +398,21 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
size_t l = 0;
struct dirent *dirent;
while((dirent = readdir(dir)) != NULL)
{
while ((dirent = readdir(dir)) != NULL) {
struct ovni_loom *loom = &trace->loom[l];
const char *loom_name;
if(find_dir_prefix_str(dirent->d_name, "loom", &loom_name) != 0)
{
if (find_dir_prefix_str(dirent->d_name, "loom", &loom_name) != 0) {
/* Ignore other files in tracedir */
continue;
}
if(l >= trace->nlooms)
{
if (l >= trace->nlooms) {
err("extra loom detected\n");
return -1;
}
/* Copy the complete loom directory name to looms */
if(snprintf(loom->dname, PATH_MAX, "%s", dirent->d_name) >= PATH_MAX)
{
if (snprintf(loom->dname, PATH_MAX, "%s", dirent->d_name) >= PATH_MAX) {
err("error: loom name %s too long\n", dirent->d_name);
return -1;
}
@ -467,13 +426,11 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
qsort(trace->loom, trace->nlooms, sizeof(struct ovni_loom),
compare_looms);
for(size_t i = 0; i < trace->nlooms; i++)
{
for (size_t i = 0; i < trace->nlooms; i++) {
struct ovni_loom *loom = &trace->loom[i];
const char *name = NULL;
if(find_dir_prefix_str(loom->dname, "loom", &name) != 0)
{
if (find_dir_prefix_str(loom->dname, "loom", &name) != 0) {
err("error: mismatch for loom %s\n", loom->dname);
return -1;
}
@ -481,8 +438,8 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
loom_to_host(name, loom->hostname, sizeof(loom->hostname));
if (snprintf(loom->path, PATH_MAX, "%s/%s",
tracedir, loom->dname) >= PATH_MAX)
{
tracedir, loom->dname)
>= PATH_MAX) {
err("error: loom path %s/%s too long\n",
tracedir, loom->dname);
return -1;
@ -500,8 +457,7 @@ check_stream_header(struct ovni_stream *stream)
{
int ret = 0;
if(stream->size < sizeof(struct ovni_stream_header))
{
if (stream->size < sizeof(struct ovni_stream_header)) {
err("stream %d: incomplete stream header\n",
stream->tid);
return -1;
@ -510,8 +466,7 @@ check_stream_header(struct ovni_stream *stream)
struct ovni_stream_header *h =
(struct ovni_stream_header *) stream->buf;
if(memcmp(h->magic, OVNI_STREAM_MAGIC, 4) != 0)
{
if (memcmp(h->magic, OVNI_STREAM_MAGIC, 4) != 0) {
char magic[5];
memcpy(magic, h->magic, 4);
magic[4] = '\0';
@ -520,8 +475,7 @@ check_stream_header(struct ovni_stream *stream)
ret = -1;
}
if(h->version != OVNI_STREAM_VERSION)
{
if (h->version != OVNI_STREAM_VERSION) {
err("stream %d: stream version mismatch %u (expected %u)\n",
stream->tid, h->version, OVNI_STREAM_VERSION);
ret = -1;
@ -534,15 +488,13 @@ static int
load_stream_fd(struct ovni_stream *stream, int fd)
{
struct stat st;
if(fstat(fd, &st) < 0)
{
if (fstat(fd, &st) < 0) {
perror("fstat failed");
return -1;
}
/* Error because it doesn't have the header */
if(st.st_size == 0)
{
if (st.st_size == 0) {
err("stream %d is empty\n", stream->tid);
return -1;
}
@ -550,8 +502,7 @@ load_stream_fd(struct ovni_stream *stream, int fd)
int prot = PROT_READ | PROT_WRITE;
stream->buf = mmap(NULL, st.st_size, prot, MAP_PRIVATE, fd, 0);
if(stream->buf == MAP_FAILED)
{
if (stream->buf == MAP_FAILED) {
perror("mmap failed");
return -1;
}
@ -566,8 +517,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
{
int fd;
if((fd = open(thread->tracefile, O_RDWR)) == -1)
{
if ((fd = open(thread->tracefile, O_RDWR)) == -1) {
perror("open failed");
return -1;
}
@ -575,8 +525,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
if (load_stream_fd(stream, fd) != 0)
return -1;
if(check_stream_header(stream) != 0)
{
if (check_stream_header(stream) != 0) {
err("stream %d: bad header\n", stream->tid);
return -1;
}
@ -589,8 +538,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
stream->active = 1;
/* No need to keep the fd open */
if(close(fd))
{
if (close(fd)) {
perror("close failed");
return -1;
}
@ -610,14 +558,11 @@ ovni_load_streams(struct ovni_trace *trace)
trace->nstreams = 0;
for(i=0; i<trace->nlooms; i++)
{
for (i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
for(k=0; k<proc->nthreads; k++)
{
for (k = 0; k < proc->nthreads; k++) {
trace->nstreams++;
}
}
@ -625,22 +570,18 @@ ovni_load_streams(struct ovni_trace *trace)
trace->stream = calloc(trace->nstreams, sizeof(struct ovni_stream));
if(trace->stream == NULL)
{
if (trace->stream == NULL) {
perror("calloc failed");
return -1;
}
err("loaded %ld streams\n", trace->nstreams);
for(s=0, i=0; i<trace->nlooms; i++)
{
for (s = 0, i = 0; i < trace->nlooms; i++) {
loom = &trace->loom[i];
for(j=0; j<loom->nprocs; j++)
{
for (j = 0; j < loom->nprocs; j++) {
proc = &loom->proc[j];
for(k=0; k<proc->nthreads; k++)
{
for (k = 0; k < proc->nthreads; k++) {
thread = &proc->thread[k];
stream = &trace->stream[s++];
@ -652,12 +593,10 @@ ovni_load_streams(struct ovni_trace *trace)
stream->offset = 0;
stream->cur_ev = NULL;
if(load_stream_buf(stream, thread) != 0)
{
if (load_stream_buf(stream, thread) != 0) {
err("load_stream_buf failed\n");
return -1;
}
}
}
}
@ -668,8 +607,7 @@ ovni_load_streams(struct ovni_trace *trace)
void
ovni_free_streams(struct ovni_trace *trace)
{
for(size_t i = 0; i < trace->nstreams; i++)
{
for (size_t i = 0; i < trace->nstreams; i++) {
struct ovni_stream *stream = &trace->stream[i];
if (munmap(stream->buf, stream->size) != 0)
die("munmap stream failed: %s\n", strerror(errno));
@ -683,10 +621,8 @@ 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 (i = 0; i < trace->nlooms; i++) {
for (j = 0; j < trace->loom[i].nprocs; j++) {
free(trace->loom[i].proc[j].thread);
}
@ -699,8 +635,7 @@ ovni_free_trace(struct ovni_trace *trace)
int
ovni_load_next_event(struct ovni_stream *stream)
{
if(stream->active == 0)
{
if (stream->active == 0) {
dbg("stream is inactive, cannot load more events\n");
return -1;
}
@ -714,8 +649,7 @@ ovni_load_next_event(struct ovni_stream *stream)
die("ovni_load_next_event: stream offset exceeds size\n");
/* We have reached the end */
if(stream->offset == stream->size)
{
if (stream->offset == stream->size) {
stream->active = 0;
stream->cur_ev = NULL;
dbg("stream %d runs out of events\n", stream->tid);

View File

@ -4,8 +4,8 @@
#ifndef OVNI_TRACE_H
#define OVNI_TRACE_H
#include "ovni.h"
#include "emu.h"
#include "ovni.h"
int ovni_load_next_event(struct ovni_stream *stream);

161
uthash.h
View File

@ -26,9 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define UTHASH_VERSION 2.1.0
#include <string.h> /* memcmp, memset, strlen */
#include <stddef.h> /* ptrdiff_t */
#include <stdlib.h> /* exit */
#include <string.h> /* memcmp, memset, strlen */
/* These macros use decltype or the earlier __typeof GNU extension.
As decltype is only available in newer compilers (VS2010 or gcc 4.3+
@ -118,10 +118,15 @@ typedef unsigned char uint8_t;
/* malloc failures can be recovered from */
#ifndef uthash_nonfatal_oom
#define uthash_nonfatal_oom(obj) do {} while (0) /* non-fatal OOM error */
#define uthash_nonfatal_oom(obj) \
do { \
} while (0) /* non-fatal OOM error */
#endif
#define HASH_RECORD_OOM(oomed) do { (oomed) = 1; } while (0)
#define HASH_RECORD_OOM(oomed) \
do { \
(oomed) = 1; \
} while (0)
#define IF_HASH_NONFATAL_OOM(x) x
#else
@ -243,8 +248,7 @@ do {
uthash_free((head)->hh.tbl->buckets, \
HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \
uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \
} \
) \
}) \
} \
} \
} while (0)
@ -519,7 +523,11 @@ do {
* This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
*/
#ifdef HASH_DEBUG
#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0)
#define HASH_OOPS(...) \
do { \
fprintf(stderr, __VA_ARGS__); \
exit(-1); \
} while (0)
#define HASH_FSCK(hh, head, where) \
do { \
struct UT_hash_handle *_thh; \
@ -645,15 +653,33 @@ do {
#define HASH_JEN_MIX(a, b, c) \
do { \
a -= b; a -= c; a ^= ( c >> 13 ); \
b -= c; b -= a; b ^= ( a << 8 ); \
c -= a; c -= b; c ^= ( b >> 13 ); \
a -= b; a -= c; a ^= ( c >> 12 ); \
b -= c; b -= a; b ^= ( a << 16 ); \
c -= a; c -= b; c ^= ( b >> 5 ); \
a -= b; a -= c; a ^= ( c >> 3 ); \
b -= c; b -= a; b ^= ( a << 10 ); \
c -= a; c -= b; c ^= ( b >> 15 ); \
a -= b; \
a -= c; \
a ^= (c >> 13); \
b -= c; \
b -= a; \
b ^= (a << 8); \
c -= a; \
c -= b; \
c ^= (b >> 13); \
a -= b; \
a -= c; \
a ^= (c >> 12); \
b -= c; \
b -= a; \
b ^= (a << 16); \
c -= a; \
c -= b; \
c ^= (b >> 5); \
a -= b; \
a -= c; \
a ^= (c >> 3); \
b -= c; \
b -= a; \
b ^= (a << 10); \
c -= a; \
c -= b; \
c ^= (b >> 15); \
} while (0)
#define HASH_JEN(key, keylen, hashv) \
@ -681,17 +707,28 @@ do {
} \
hashv += (unsigned) (keylen); \
switch (_hj_k) { \
case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); /* FALLTHROUGH */ \
case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); /* FALLTHROUGH */ \
case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); /* FALLTHROUGH */ \
case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); /* FALLTHROUGH */ \
case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); /* FALLTHROUGH */ \
case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); /* FALLTHROUGH */ \
case 5: _hj_j += _hj_key[4]; /* FALLTHROUGH */ \
case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); /* FALLTHROUGH */ \
case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); /* FALLTHROUGH */ \
case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); /* FALLTHROUGH */ \
case 1: _hj_i += _hj_key[0]; \
case 11: \
hashv += ((unsigned) _hj_key[10] << 24); /* FALLTHROUGH */ \
case 10: \
hashv += ((unsigned) _hj_key[9] << 16); /* FALLTHROUGH */ \
case 9: \
hashv += ((unsigned) _hj_key[8] << 8); /* FALLTHROUGH */ \
case 8: \
_hj_j += ((unsigned) _hj_key[7] << 24); /* FALLTHROUGH */ \
case 7: \
_hj_j += ((unsigned) _hj_key[6] << 16); /* FALLTHROUGH */ \
case 6: \
_hj_j += ((unsigned) _hj_key[5] << 8); /* FALLTHROUGH */ \
case 5: \
_hj_j += _hj_key[4]; /* FALLTHROUGH */ \
case 4: \
_hj_i += ((unsigned) _hj_key[3] << 24); /* FALLTHROUGH */ \
case 3: \
_hj_i += ((unsigned) _hj_key[2] << 16); /* FALLTHROUGH */ \
case 2: \
_hj_i += ((unsigned) _hj_key[1] << 8); /* FALLTHROUGH */ \
case 1: \
_hj_i += _hj_key[0]; \
} \
HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
} while (0)
@ -727,16 +764,19 @@ do {
\
/* Handle end cases */ \
switch (_sfh_rem) { \
case 3: hashv += get16bits (_sfh_key); \
case 3: \
hashv += get16bits(_sfh_key); \
hashv ^= hashv << 16; \
hashv ^= (uint32_t) (_sfh_key[sizeof(uint16_t)]) << 18; \
hashv += hashv >> 11; \
break; \
case 2: hashv += get16bits (_sfh_key); \
case 2: \
hashv += get16bits(_sfh_key); \
hashv ^= hashv << 11; \
hashv += hashv >> 17; \
break; \
case 1: hashv += *_sfh_key; \
case 1: \
hashv += *_sfh_key; \
hashv ^= hashv << 10; \
hashv += hashv >> 1; \
} \
@ -777,10 +817,7 @@ do {
#define MUR_TWO_TWO(p) ((((*WP(p)) & 0xffff0000) >> 16) | (((*(WP(p) + 1)) & 0x0000ffff) << 16))
#define MUR_ONE_THREE(p) ((((*WP(p)) & 0xff000000) >> 24) | (((*(WP(p) + 1)) & 0x00ffffff) << 8))
#endif
#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \
(MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \
(MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \
MUR_ONE_THREE(p))))
#define MUR_GETBLOCK(p, i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : MUR_ONE_THREE(p))))
#endif
#define MUR_ROTL32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
#define MUR_FMIX(_h) \
@ -816,10 +853,14 @@ do { \
_mur_tail = (const uint8_t *) (_mur_data + (_mur_nblocks * 4)); \
_mur_k1 = 0; \
switch ((keylen) &3U) { \
case 0: break; \
case 3: _mur_k1 ^= (uint32_t)_mur_tail[2] << 16; /* FALLTHROUGH */ \
case 2: _mur_k1 ^= (uint32_t)_mur_tail[1] << 8; /* FALLTHROUGH */ \
case 1: _mur_k1 ^= (uint32_t)_mur_tail[0]; \
case 0: \
break; \
case 3: \
_mur_k1 ^= (uint32_t) _mur_tail[2] << 16; /* FALLTHROUGH */ \
case 2: \
_mur_k1 ^= (uint32_t) _mur_tail[1] << 8; /* FALLTHROUGH */ \
case 1: \
_mur_k1 ^= (uint32_t) _mur_tail[0]; \
_mur_k1 *= _mur_c1; \
_mur_k1 = MUR_ROTL32(_mur_k1, 15); \
_mur_k1 *= _mur_c2; \
@ -870,8 +911,7 @@ do {
IF_HASH_NONFATAL_OOM( \
if (oomed) { \
HASH_DEL_IN_BKT(head, addhh); \
} \
) \
}) \
} \
} while (0)
@ -934,8 +974,7 @@ do {
uthash_bzero(_he_new_buckets, \
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
(tbl)->ideal_chain_maxlen = \
((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \
((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \
((tbl)->num_items >> ((tbl)->log2_num_buckets + 1U)) + ((((tbl)->num_items & (((tbl)->num_buckets * 2U) - 1U)) != 0U) ? 1U : 0U); \
(tbl)->nonideal_items = 0; \
for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) { \
_he_thh = (tbl)->buckets[_he_bkt_i].hh_head; \
@ -962,8 +1001,7 @@ do {
(tbl)->num_buckets *= 2U; \
(tbl)->log2_num_buckets++; \
(tbl)->buckets = _he_new_buckets; \
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? \
((tbl)->ineff_expands+1U) : 0U; \
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) : 0U; \
if ((tbl)->ineff_expands > 1U) { \
(tbl)->noexpand = 1; \
uthash_noexpand_fyi(tbl); \
@ -997,8 +1035,7 @@ do {
_hs_psize = 0; \
for (_hs_i = 0; _hs_i < _hs_insize; ++_hs_i) { \
_hs_psize++; \
_hs_q = ((_hs_q->next != NULL) ? \
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
if (_hs_q == NULL) { \
break; \
} \
@ -1007,41 +1044,35 @@ do {
while ((_hs_psize != 0U) || ((_hs_qsize != 0U) && (_hs_q != NULL))) { \
if (_hs_psize == 0U) { \
_hs_e = _hs_q; \
_hs_q = ((_hs_q->next != NULL) ? \
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
_hs_qsize--; \
} else if ((_hs_qsize == 0U) || (_hs_q == NULL)) { \
_hs_e = _hs_p; \
if (_hs_p != NULL) { \
_hs_p = ((_hs_p->next != NULL) ? \
HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
_hs_p = ((_hs_p->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
} \
_hs_psize--; \
} else if ((cmpfcn( \
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)) \
)) <= 0) { \
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)))) \
<= 0) { \
_hs_e = _hs_p; \
if (_hs_p != NULL) { \
_hs_p = ((_hs_p->next != NULL) ? \
HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
_hs_p = ((_hs_p->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
} \
_hs_psize--; \
} else { \
_hs_e = _hs_q; \
_hs_q = ((_hs_q->next != NULL) ? \
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
_hs_qsize--; \
} \
if (_hs_tail != NULL) { \
_hs_tail->next = ((_hs_e != NULL) ? \
ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL); \
_hs_tail->next = ((_hs_e != NULL) ? ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL); \
} else { \
_hs_list = _hs_e; \
} \
if (_hs_e != NULL) { \
_hs_e->prev = ((_hs_tail != NULL) ? \
ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL); \
_hs_e->prev = ((_hs_tail != NULL) ? ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL); \
} \
_hs_tail = _hs_e; \
} \
@ -1097,8 +1128,7 @@ do {
uthash_nonfatal_oom(_elt); \
(dst) = NULL; \
continue; \
} \
) \
}) \
} else { \
_dst_hh->tbl = (dst)->hh_dst.tbl; \
} \
@ -1112,8 +1142,7 @@ do {
_dst_hh->tbl = NULL; \
uthash_nonfatal_oom(_elt); \
continue; \
} \
) \
}) \
HASH_BLOOM_ADD(_dst_hh->tbl, _dst_hh->hashv); \
_last_elt = _elt; \
_last_elt_hh = _dst_hh; \
@ -1137,10 +1166,8 @@ do {
#define HASH_OVERHEAD(hh, head) \
(((head) != NULL) ? ( \
(size_t)(((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \
((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + \
sizeof(UT_hash_table) + \
(HASH_BLOOM_BYTELEN))) : 0U)
(size_t) (((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + sizeof(UT_hash_table) + (HASH_BLOOM_BYTELEN))) \
: 0U)
#ifdef NO_DECLTYPE
#define HASH_ITER(hh, head, el, tmp) \

335
utlist.h
View File

@ -81,13 +81,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef NO_DECLTYPE
#define IF_NO_DECLTYPE(x) x
#define LDECLTYPE(x) char *
#define UTLIST_SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
#define UTLIST_SV(elt, list) \
_tmp = (char *) (list); \
{ \
char **_alias = (char **) &(list); \
*_alias = (elt); \
}
#define UTLIST_NEXT(elt, list, next) ((char *) ((list)->next))
#define UTLIST_NEXTASGN(elt,list,to,next) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
#define UTLIST_NEXTASGN(elt, list, to, next) \
{ \
char **_alias = (char **) &((list)->next); \
*_alias = (char *) (to); \
}
/* #define UTLIST_PREV(elt,list,prev) ((char*)((list)->prev)) */
#define UTLIST_PREVASGN(elt,list,to,prev) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
#define UTLIST_RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
#define UTLIST_CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
#define UTLIST_PREVASGN(elt, list, to, prev) \
{ \
char **_alias = (char **) &((list)->prev); \
*_alias = (char *) (to); \
}
#define UTLIST_RS(list) \
{ \
char **_alias = (char **) &(list); \
*_alias = _tmp; \
}
#define UTLIST_CASTASGN(a, b) \
{ \
char **_alias = (char **) &(a); \
*_alias = (char *) (b); \
}
#else
#define IF_NO_DECLTYPE(x)
#define UTLIST_SV(elt, list)
@ -108,10 +129,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define LL_SORT2(list, cmp, next) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) \
_ls_p; \
LDECLTYPE(list) \
_ls_q; \
LDECLTYPE(list) \
_ls_e; \
LDECLTYPE(list) \
_ls_tail; \
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
@ -128,26 +153,47 @@ do {
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
if (!_ls_q) break; \
UTLIST_SV(_ls_q, list); \
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
if (!_ls_q) \
break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
} else if (cmp(_ls_p, _ls_q) <= 0) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
} else { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
} \
if (_ls_tail) { \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, _ls_e, next); \
UTLIST_RS(list); \
} else { \
UTLIST_CASTASGN(list, _ls_e); \
} \
@ -156,7 +202,9 @@ do {
_ls_p = _ls_q; \
} \
if (_ls_tail) { \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,NULL,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, NULL, next); \
UTLIST_RS(list); \
} \
if (_ls_nmerges <= 1) { \
_ls_looping = 0; \
@ -172,10 +220,14 @@ do {
#define DL_SORT2(list, cmp, prev, next) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) \
_ls_p; \
LDECLTYPE(list) \
_ls_q; \
LDECLTYPE(list) \
_ls_e; \
LDECLTYPE(list) \
_ls_tail; \
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
@ -192,36 +244,61 @@ do {
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
if (!_ls_q) break; \
UTLIST_SV(_ls_q, list); \
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
if (!_ls_q) \
break; \
} \
_ls_qsize = _ls_insize; \
while ((_ls_psize > 0) || ((_ls_qsize > 0) && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
} else if ((_ls_qsize == 0) || (!_ls_q)) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
} else if (cmp(_ls_p, _ls_q) <= 0) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
} else { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
} \
if (_ls_tail) { \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, _ls_e, next); \
UTLIST_RS(list); \
} else { \
UTLIST_CASTASGN(list, _ls_e); \
} \
UTLIST_SV(_ls_e,list); UTLIST_PREVASGN(_ls_e,list,_ls_tail,prev); UTLIST_RS(list); \
UTLIST_SV(_ls_e, list); \
UTLIST_PREVASGN(_ls_e, list, _ls_tail, prev); \
UTLIST_RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
UTLIST_CASTASGN((list)->prev, _ls_tail); \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,NULL,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, NULL, next); \
UTLIST_RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping = 0; \
} \
@ -235,12 +312,18 @@ do {
#define CDL_SORT2(list, cmp, prev, next) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
LDECLTYPE(list) \
_ls_p; \
LDECLTYPE(list) \
_ls_q; \
LDECLTYPE(list) \
_ls_e; \
LDECLTYPE(list) \
_ls_tail; \
LDECLTYPE(list) \
_ls_oldhead; \
LDECLTYPE(list) \
_tmp; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
@ -264,40 +347,71 @@ do {
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
} \
UTLIST_RS(list); \
if (!_ls_q) break; \
if (!_ls_q) \
break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
if (_ls_q == _ls_oldhead) { \
_ls_q = NULL; \
} \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
if (_ls_p == _ls_oldhead) { \
_ls_p = NULL; \
} \
} else if (cmp(_ls_p, _ls_q) <= 0) { \
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
_ls_e = _ls_p; \
UTLIST_SV(_ls_p, list); \
_ls_p = \
UTLIST_NEXT(_ls_p, list, next); \
UTLIST_RS(list); \
_ls_psize--; \
if (_ls_p == _ls_oldhead) { \
_ls_p = NULL; \
} \
} else { \
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
_ls_e = _ls_q; \
UTLIST_SV(_ls_q, list); \
_ls_q = \
UTLIST_NEXT(_ls_q, list, next); \
UTLIST_RS(list); \
_ls_qsize--; \
if (_ls_q == _ls_oldhead) { \
_ls_q = NULL; \
} \
} \
if (_ls_tail) { \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, _ls_e, next); \
UTLIST_RS(list); \
} else { \
UTLIST_CASTASGN(list, _ls_e); \
} \
UTLIST_SV(_ls_e,list); UTLIST_PREVASGN(_ls_e,list,_ls_tail,prev); UTLIST_RS(list); \
UTLIST_SV(_ls_e, list); \
UTLIST_PREVASGN(_ls_e, list, _ls_tail, prev); \
UTLIST_RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
UTLIST_CASTASGN((list)->prev, _ls_tail); \
UTLIST_CASTASGN(_tmp, list); \
UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_tmp,next); UTLIST_RS(list); \
UTLIST_SV(_ls_tail, list); \
UTLIST_NEXTASGN(_ls_tail, list, _tmp, next); \
UTLIST_RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping = 0; \
} \
@ -323,10 +437,13 @@ do {
#define LL_CONCAT2(head1, head2, next) \
do { \
LDECLTYPE(head1) _tmp; \
LDECLTYPE(head1) \
_tmp; \
if (head1) { \
_tmp = (head1); \
while (_tmp->next) { _tmp = _tmp->next; } \
while (_tmp->next) { \
_tmp = _tmp->next; \
} \
_tmp->next = (head2); \
} else { \
(head1) = (head2); \
@ -338,11 +455,14 @@ do {
#define LL_APPEND2(head, add, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
(add)->next = NULL; \
if (head) { \
_tmp = (head); \
while (_tmp->next) { _tmp = _tmp->next; } \
while (_tmp->next) { \
_tmp = _tmp->next; \
} \
_tmp->next = (add); \
} else { \
(head) = (add); \
@ -354,7 +474,8 @@ do {
#define LL_INSERT_INORDER2(head, add, cmp, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
if (head) { \
LL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
LL_APPEND_ELEM2(head, _tmp, add, next); \
@ -385,7 +506,8 @@ do {
#define LL_DELETE2(head, del, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
if ((head) == (del)) { \
(head) = (head)->next; \
} else { \
@ -400,12 +522,15 @@ do {
} while (0)
#define LL_COUNT(head, el, counter) \
LL_COUNT2(head,el,counter,next) \
LL_COUNT2(head, el, counter, next)
#define LL_COUNT2(head, el, counter, next) \
do { \
(counter) = 0; \
LL_FOREACH2(head,el,next) { ++(counter); } \
LL_FOREACH2(head, el, next) \
{ \
++(counter); \
} \
} while (0)
#define LL_FOREACH(head, el) \
@ -425,8 +550,10 @@ do {
#define LL_SEARCH_SCALAR2(head, out, field, val, next) \
do { \
LL_FOREACH2(head,out,next) { \
if ((out)->field == (val)) break; \
LL_FOREACH2(head, out, next) \
{ \
if ((out)->field == (val)) \
break; \
} \
} while (0)
@ -435,14 +562,17 @@ do {
#define LL_SEARCH2(head, out, elt, cmp, next) \
do { \
LL_FOREACH2(head,out,next) { \
if ((cmp(out,elt))==0) break; \
LL_FOREACH2(head, out, next) \
{ \
if ((cmp(out, elt)) == 0) \
break; \
} \
} while (0)
#define LL_REPLACE_ELEM2(head, el, add, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
(add)->next = (el)->next; \
if ((head) == (el)) { \
(head) = (add); \
@ -463,7 +593,8 @@ do {
#define LL_PREPEND_ELEM2(head, el, add, next) \
do { \
if (el) { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
(add)->next = (el); \
if ((head) == (el)) { \
(head) = (add); \
@ -479,7 +610,7 @@ do {
} else { \
LL_APPEND2(head, add, next); \
} \
} while (0) \
} while (0)
#define LL_PREPEND_ELEM(head, el, add) \
LL_PREPEND_ELEM2(head, el, add, next)
@ -492,7 +623,7 @@ do {
} else { \
LL_PREPEND2(head, add, next); \
} \
} while (0) \
} while (0)
#define LL_APPEND_ELEM(head, el, add) \
LL_APPEND_ELEM2(head, el, add, next)
@ -506,7 +637,9 @@ do {
char *_tmp; \
if (head1) { \
_tmp = (char *) (head1); \
while ((head1)->next) { (head1) = (head1)->next; } \
while ((head1)->next) { \
(head1) = (head1)->next; \
} \
(head1)->next = (head2); \
UTLIST_RS(head1); \
} else { \
@ -519,7 +652,9 @@ do {
do { \
if (head) { \
(add)->next = head; /* use add->next as a temp variable */ \
while ((add)->next->next) { (add)->next = (add)->next->next; } \
while ((add)->next->next) { \
(add)->next = (add)->next->next; \
} \
(add)->next->next = (add); \
} else { \
(head) = (add); \
@ -597,7 +732,7 @@ do {
} else { \
LL_APPEND2(head, add, next); \
} \
} while (0) \
} while (0)
#endif /* NO_DECLTYPE */
@ -641,7 +776,8 @@ do {
#define DL_INSERT_INORDER2(head, add, cmp, prev, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
if (head) { \
DL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
DL_APPEND_ELEM2(head, _tmp, add, prev, next); \
@ -673,7 +809,8 @@ do {
#define DL_CONCAT2(head1, head2, prev, next) \
do { \
LDECLTYPE(head1) _tmp; \
LDECLTYPE(head1) \
_tmp; \
if (head2) { \
if (head1) { \
UTLIST_CASTASGN(_tmp, (head2)->prev); \
@ -707,12 +844,15 @@ do {
} while (0)
#define DL_COUNT(head, el, counter) \
DL_COUNT2(head,el,counter,next) \
DL_COUNT2(head, el, counter, next)
#define DL_COUNT2(head, el, counter, next) \
do { \
(counter) = 0; \
DL_FOREACH2(head,el,next) { ++(counter); } \
DL_FOREACH2(head, el, next) \
{ \
++(counter); \
} \
} while (0)
#define DL_FOREACH(head, el) \
@ -774,7 +914,7 @@ do {
} else { \
DL_APPEND2(head, add, prev, next); \
} \
} while (0) \
} while (0)
#define DL_PREPEND_ELEM(head, el, add) \
DL_PREPEND_ELEM2(head, el, add, prev, next)
@ -793,7 +933,7 @@ do {
} else { \
DL_PREPEND2(head, add, prev, next); \
} \
} while (0) \
} while (0)
#define DL_APPEND_ELEM(head, el, add) \
DL_APPEND_ELEM2(head, el, add, prev, next)
@ -873,7 +1013,8 @@ do {
#define CDL_INSERT_INORDER2(head, add, cmp, prev, next) \
do { \
LDECLTYPE(head) _tmp; \
LDECLTYPE(head) \
_tmp; \
if (head) { \
CDL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
CDL_APPEND_ELEM2(head, _tmp, add, prev, next); \
@ -910,17 +1051,21 @@ do {
} else { \
(del)->next->prev = (del)->prev; \
(del)->prev->next = (del)->next; \
if ((del) == (head)) (head)=(del)->next; \
if ((del) == (head)) \
(head) = (del)->next; \
} \
} while (0)
#define CDL_COUNT(head, el, counter) \
CDL_COUNT2(head,el,counter,next) \
CDL_COUNT2(head, el, counter, next)
#define CDL_COUNT2(head, el, counter, next) \
do { \
(counter) = 0; \
CDL_FOREACH2(head,el,next) { ++(counter); } \
CDL_FOREACH2(head, el, next) \
{ \
++(counter); \
} \
} while (0)
#define CDL_FOREACH(head, el) \
@ -942,8 +1087,10 @@ do {
#define CDL_SEARCH_SCALAR2(head, out, field, val, next) \
do { \
CDL_FOREACH2(head,out,next) { \
if ((out)->field == (val)) break; \
CDL_FOREACH2(head, out, next) \
{ \
if ((out)->field == (val)) \
break; \
} \
} while (0)
@ -952,8 +1099,10 @@ do {
#define CDL_SEARCH2(head, out, elt, cmp, next) \
do { \
CDL_FOREACH2(head,out,next) { \
if ((cmp(out,elt))==0) break; \
CDL_FOREACH2(head, out, next) \
{ \
if ((cmp(out, elt)) == 0) \
break; \
} \
} while (0)