Follow K&R coding style using clang-format
This commit is contained in:
parent
baefb2b01c
commit
177429fabc
31
.clang-format
Normal file
31
.clang-format
Normal 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
53
chan.c
@ -103,8 +103,7 @@ chan_dump_update_list(struct ovni_chan *chan)
|
|||||||
|
|
||||||
dbg("update list for chan %d at %p:\n",
|
dbg("update list for chan %d at %p:\n",
|
||||||
chan->id, (void *) chan);
|
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);
|
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);
|
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);
|
err("chan_enable: chan already in enabled=%d\n", enabled);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -126,12 +124,9 @@ chan_enable(struct ovni_chan *chan, int enabled)
|
|||||||
chan->t = *chan->clock;
|
chan->t = *chan->clock;
|
||||||
|
|
||||||
/* Only append if not dirty */
|
/* Only append if not dirty */
|
||||||
if(!chan->dirty)
|
if (!chan->dirty) {
|
||||||
{
|
|
||||||
mark_dirty(chan, CHAN_DIRTY_ACTIVE);
|
mark_dirty(chan, CHAN_DIRTY_ACTIVE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dbg("already dirty chan %d: skip update list\n",
|
dbg("already dirty chan %d: skip update list\n",
|
||||||
chan->id);
|
chan->id);
|
||||||
chan_dump_update_list(chan);
|
chan_dump_update_list(chan);
|
||||||
@ -169,8 +164,7 @@ chan_set(struct ovni_chan *chan, int st)
|
|||||||
* used by the tracking channels */
|
* used by the tracking channels */
|
||||||
if (chan->dirty != CHAN_DIRTY_ACTIVE
|
if (chan->dirty != CHAN_DIRTY_ACTIVE
|
||||||
&& chan->lastst >= 0
|
&& chan->lastst >= 0
|
||||||
&& chan->lastst == st)
|
&& chan->lastst == st) {
|
||||||
{
|
|
||||||
err("chan_set id=%d cannot emit the state %d twice\n",
|
err("chan_set id=%d cannot emit the state %d twice\n",
|
||||||
chan->id, st);
|
chan->id, st);
|
||||||
abort();
|
abort();
|
||||||
@ -183,12 +177,9 @@ chan_set(struct ovni_chan *chan, int st)
|
|||||||
chan->t = *chan->clock;
|
chan->t = *chan->clock;
|
||||||
|
|
||||||
/* Only append if not dirty */
|
/* Only append if not dirty */
|
||||||
if(!chan->dirty)
|
if (!chan->dirty) {
|
||||||
{
|
|
||||||
mark_dirty(chan, CHAN_DIRTY_VALUE);
|
mark_dirty(chan, CHAN_DIRTY_VALUE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dbg("already dirty chan %d: skip update list\n",
|
dbg("already dirty chan %d: skip update list\n",
|
||||||
chan->id);
|
chan->id);
|
||||||
chan_dump_update_list(chan);
|
chan_dump_update_list(chan);
|
||||||
@ -203,8 +194,7 @@ chan_push(struct ovni_chan *chan, int st)
|
|||||||
if (!chan->enabled)
|
if (!chan->enabled)
|
||||||
die("chan_push: chan %d not enabled\n", chan->id);
|
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);
|
err("chan_push: cannot push a non-positive state %d\n", st);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -213,15 +203,13 @@ chan_push(struct ovni_chan *chan, int st)
|
|||||||
if (chan->dirty != CHAN_CLEAN)
|
if (chan->dirty != CHAN_CLEAN)
|
||||||
die("chan_push: chan %d not clean", chan->id);
|
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",
|
err("chan_push id=%d cannot emit the state %d twice\n",
|
||||||
chan->id, st);
|
chan->id, st);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chan->n >= MAX_CHAN_STACK)
|
if (chan->n >= MAX_CHAN_STACK) {
|
||||||
{
|
|
||||||
err("chan_push: channel stack full\n");
|
err("chan_push: channel stack full\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -246,16 +234,14 @@ chan_pop(struct ovni_chan *chan, int expected_st)
|
|||||||
if (chan->dirty != CHAN_CLEAN)
|
if (chan->dirty != CHAN_CLEAN)
|
||||||
die("chan_pop: chan %d not clean", chan->id);
|
die("chan_pop: chan %d not clean", chan->id);
|
||||||
|
|
||||||
if(chan->n <= 0)
|
if (chan->n <= 0) {
|
||||||
{
|
|
||||||
err("chan_pop: channel empty\n");
|
err("chan_pop: channel empty\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
st = chan->stack[chan->n - 1];
|
st = chan->stack[chan->n - 1];
|
||||||
|
|
||||||
if(expected_st >= 0 && st != expected_st)
|
if (expected_st >= 0 && st != expected_st) {
|
||||||
{
|
|
||||||
err("chan_pop: unexpected channel state %d (expected %d)\n",
|
err("chan_pop: unexpected channel state %d (expected %d)\n",
|
||||||
st, expected_st);
|
st, expected_st);
|
||||||
abort();
|
abort();
|
||||||
@ -267,14 +253,12 @@ chan_pop(struct ovni_chan *chan, int expected_st)
|
|||||||
st = chan_get_st(chan);
|
st = chan_get_st(chan);
|
||||||
|
|
||||||
/* A st == 0 can be obtained when returning to the initial state */
|
/* 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);
|
err("chan_pop: obtained negative state %d from the stack\n", st);
|
||||||
abort();
|
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",
|
err("chan_pop id=%d cannot emit the state %d twice\n",
|
||||||
chan->id, st);
|
chan->id, st);
|
||||||
abort();
|
abort();
|
||||||
@ -338,15 +322,13 @@ emit(struct ovni_chan *chan, int64_t t, int state)
|
|||||||
* consecutive ovni events?) */
|
* consecutive ovni events?) */
|
||||||
if (chan->lastst != -1
|
if (chan->lastst != -1
|
||||||
&& chan->dirty == CHAN_DIRTY_VALUE
|
&& chan->dirty == CHAN_DIRTY_VALUE
|
||||||
&& chan->lastst == state)
|
&& chan->lastst == state) {
|
||||||
{
|
|
||||||
/* TODO: Print the raw clock of the offending event */
|
/* TODO: Print the raw clock of the offending event */
|
||||||
die("emit: chan %d cannot emit the same state %d twice\n",
|
die("emit: chan %d cannot emit the same state %d twice\n",
|
||||||
chan->id, state);
|
chan->id, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chan->lastst != state)
|
if (chan->lastst != state) {
|
||||||
{
|
|
||||||
prv_ev(chan->prv, chan->row, t, chan->type, state);
|
prv_ev(chan->prv, chan->row, t, chan->type, state);
|
||||||
|
|
||||||
chan->lastst = state;
|
chan->lastst = state;
|
||||||
@ -393,8 +375,7 @@ chan_emit(struct ovni_chan *chan)
|
|||||||
dbg("chan_emit chan %d\n", chan->id);
|
dbg("chan_emit chan %d\n", chan->id);
|
||||||
|
|
||||||
/* Emit badst if disabled */
|
/* Emit badst if disabled */
|
||||||
if(chan->enabled == 0)
|
if (chan->enabled == 0) {
|
||||||
{
|
|
||||||
/* No punctual events allowed when disabled */
|
/* No punctual events allowed when disabled */
|
||||||
if (chan->ev != -1)
|
if (chan->ev != -1)
|
||||||
die("chan_emit: no punctual event allowed when disabled\n");
|
die("chan_emit: no punctual event allowed when disabled\n");
|
||||||
|
3
compat.h
3
compat.h
@ -11,7 +11,8 @@
|
|||||||
/* Define gettid for older glibc versions (below 2.30) */
|
/* Define gettid for older glibc versions (below 2.30) */
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__)
|
||||||
#if !__GLIBC_PREREQ(2, 30)
|
#if !__GLIBC_PREREQ(2, 30)
|
||||||
static inline pid_t gettid(void)
|
static inline pid_t
|
||||||
|
gettid(void)
|
||||||
{
|
{
|
||||||
return (pid_t) syscall(SYS_gettid);
|
return (pid_t) syscall(SYS_gettid);
|
||||||
}
|
}
|
||||||
|
49
dump.c
49
dump.c
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdatomic.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "emu.h"
|
||||||
#include "ovni.h"
|
#include "ovni.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "emu.h"
|
|
||||||
|
|
||||||
int filter_tid = -1;
|
int filter_tid = -1;
|
||||||
char *tracedir;
|
char *tracedir;
|
||||||
@ -59,8 +59,7 @@ emit(struct ovni_stream *stream, struct ovni_ev *ev)
|
|||||||
ev->header.value);
|
ev->header.value);
|
||||||
|
|
||||||
payloadsize = ovni_payload_size(ev);
|
payloadsize = ovni_payload_size(ev);
|
||||||
if(payloadsize > 0)
|
if (payloadsize > 0) {
|
||||||
{
|
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for (i = 0; i < payloadsize; i++)
|
for (i = 0; i < payloadsize; i++)
|
||||||
printf(":%02x", ev->payload.u8[i]);
|
printf(":%02x", ev->payload.u8[i]);
|
||||||
@ -81,8 +80,7 @@ dump_events(struct ovni_trace *trace)
|
|||||||
struct ovni_stream *stream;
|
struct ovni_stream *stream;
|
||||||
|
|
||||||
/* Load events */
|
/* Load events */
|
||||||
for(i=0; i<trace->nstreams; i++)
|
for (i = 0; i < trace->nstreams; i++) {
|
||||||
{
|
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
|
|
||||||
/* It can be inactive if it has been disabled by the
|
/* It can be inactive if it has been disabled by the
|
||||||
@ -93,22 +91,19 @@ dump_events(struct ovni_trace *trace)
|
|||||||
|
|
||||||
lastclock = 0;
|
lastclock = 0;
|
||||||
|
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
f = -1;
|
f = -1;
|
||||||
minclock = 0;
|
minclock = 0;
|
||||||
|
|
||||||
/* Select next event based on the clock */
|
/* 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];
|
stream = &trace->stream[i];
|
||||||
|
|
||||||
if (!stream->active)
|
if (!stream->active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ev = stream->cur_ev;
|
ev = stream->cur_ev;
|
||||||
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
|
if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
|
||||||
{
|
|
||||||
f = i;
|
f = i;
|
||||||
minclock = ovni_ev_get_clock(ev);
|
minclock = ovni_ev_get_clock(ev);
|
||||||
}
|
}
|
||||||
@ -121,8 +116,7 @@ dump_events(struct ovni_trace *trace)
|
|||||||
|
|
||||||
stream = &trace->stream[f];
|
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",
|
fprintf(stdout, "warning: backwards jump in time %lu -> %lu\n",
|
||||||
lastclock, ovni_ev_get_clock(stream->cur_ev));
|
lastclock, ovni_ev_get_clock(stream->cur_ev));
|
||||||
}
|
}
|
||||||
@ -138,7 +132,6 @@ dump_events(struct ovni_trace *trace)
|
|||||||
/* Unset the index */
|
/* Unset the index */
|
||||||
f = -1;
|
f = -1;
|
||||||
minclock = 0;
|
minclock = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,10 +159,8 @@ parse_args(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "t:")) != -1)
|
while ((opt = getopt(argc, argv, "t:")) != -1) {
|
||||||
{
|
switch (opt) {
|
||||||
switch(opt)
|
|
||||||
{
|
|
||||||
case 't':
|
case 't':
|
||||||
filter_tid = atoi(optarg);
|
filter_tid = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
@ -178,8 +169,7 @@ parse_args(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(optind >= argc)
|
if (optind >= argc) {
|
||||||
{
|
|
||||||
err("missing tracedir\n");
|
err("missing tracedir\n");
|
||||||
usage(argc, argv);
|
usage(argc, argv);
|
||||||
}
|
}
|
||||||
@ -187,7 +177,8 @@ parse_args(int argc, char *argv[])
|
|||||||
tracedir = argv[optind];
|
tracedir = argv[optind];
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
parse_args(argc, argv);
|
parse_args(argc, argv);
|
||||||
|
|
||||||
@ -199,10 +190,8 @@ int main(int argc, char *argv[])
|
|||||||
if (ovni_load_streams(trace))
|
if (ovni_load_streams(trace))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if(filter_tid != -1)
|
if (filter_tid != -1) {
|
||||||
{
|
for (size_t i = 0; i < trace->nstreams; i++) {
|
||||||
for(size_t i=0; i<trace->nstreams; i++)
|
|
||||||
{
|
|
||||||
struct ovni_stream *stream;
|
struct ovni_stream *stream;
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
if (stream->tid != filter_tid)
|
if (stream->tid != filter_tid)
|
||||||
|
249
emu.c
249
emu.c
@ -3,25 +3,25 @@
|
|||||||
|
|
||||||
#define _POSIX_C_SOURCE 200112L
|
#define _POSIX_C_SOURCE 200112L
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdatomic.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdatomic.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.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 "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "pcf.h"
|
||||||
|
#include "prv.h"
|
||||||
|
#include "trace.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
/* Obtains the corrected clock of the given event */
|
/* 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);
|
ev->header.model, ev->header.category, ev->header.value, clock, delta);
|
||||||
|
|
||||||
payloadsize = ovni_payload_size(ev);
|
payloadsize = ovni_payload_size(ev);
|
||||||
for(i=0; i<payloadsize; i++)
|
for (i = 0; i < payloadsize; i++) {
|
||||||
{
|
|
||||||
dbg("%d ", ev->payload.u8[i]);
|
dbg("%d ", ev->payload.u8[i]);
|
||||||
}
|
}
|
||||||
dbg("\n");
|
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;
|
int th_enabled, cpu_enabled, st;
|
||||||
struct ovni_chan *th_chan;
|
struct ovni_chan *th_chan;
|
||||||
|
|
||||||
switch (cpu_chan->track)
|
switch (cpu_chan->track) {
|
||||||
{
|
|
||||||
case CHAN_TRACK_TH_RUNNING:
|
case CHAN_TRACK_TH_RUNNING:
|
||||||
cpu_enabled = th->is_running;
|
cpu_enabled = th->is_running;
|
||||||
break;
|
break;
|
||||||
@ -95,30 +93,23 @@ cpu_update_tracking_chan(struct ovni_chan *cpu_chan, struct ovni_ethread *th)
|
|||||||
chan_enable(cpu_chan, cpu_enabled);
|
chan_enable(cpu_chan, cpu_enabled);
|
||||||
|
|
||||||
/* Copy the state from the thread channel if needed */
|
/* Copy the state from the thread channel if needed */
|
||||||
if(th_enabled && cpu_enabled)
|
if (th_enabled && cpu_enabled) {
|
||||||
{
|
|
||||||
/* Both enabled: simply follow the same value */
|
/* Both enabled: simply follow the same value */
|
||||||
st = chan_get_st(th_chan);
|
st = chan_get_st(th_chan);
|
||||||
if (chan_get_st(cpu_chan) != st)
|
if (chan_get_st(cpu_chan) != st)
|
||||||
chan_set(cpu_chan, st);
|
chan_set(cpu_chan, st);
|
||||||
}
|
} else if (th_enabled && !cpu_enabled) {
|
||||||
else if(th_enabled && !cpu_enabled)
|
|
||||||
{
|
|
||||||
/* Only thread enabled: disable CPU */
|
/* Only thread enabled: disable CPU */
|
||||||
if (chan_is_enabled(cpu_chan))
|
if (chan_is_enabled(cpu_chan))
|
||||||
chan_disable(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 */
|
/* Only CPU enabled: is this possible? Set to bad */
|
||||||
chan_set(cpu_chan, ST_BAD);
|
chan_set(cpu_chan, ST_BAD);
|
||||||
err("warning: cpu %s chan %d enabled but tracked thread %d chan disabled\n",
|
err("warning: cpu %s chan %d enabled but tracked thread %d chan disabled\n",
|
||||||
cpu_chan->cpu->name,
|
cpu_chan->cpu->name,
|
||||||
cpu_chan->id,
|
cpu_chan->id,
|
||||||
th->tid);
|
th->tid);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Both disabled: disable CPU channel if needed */
|
/* Both disabled: disable CPU channel if needed */
|
||||||
if (chan_is_enabled(cpu_chan))
|
if (chan_is_enabled(cpu_chan))
|
||||||
chan_disable(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,
|
cpu_chan->cpu->name, cpu_chan->id,
|
||||||
chan_is_enabled(cpu_chan),
|
chan_is_enabled(cpu_chan),
|
||||||
chan_get_st(cpu_chan));
|
chan_get_st(cpu_chan));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -139,8 +129,7 @@ emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan)
|
|||||||
|
|
||||||
/* Determine the source of tracking */
|
/* Determine the source of tracking */
|
||||||
|
|
||||||
switch (cpu_chan->track)
|
switch (cpu_chan->track) {
|
||||||
{
|
|
||||||
case CHAN_TRACK_TH_RUNNING:
|
case CHAN_TRACK_TH_RUNNING:
|
||||||
count = cpu->nrunning_threads;
|
count = cpu->nrunning_threads;
|
||||||
th = cpu->th_running;
|
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 */
|
/* Based on how many threads, determine the state */
|
||||||
if(count == 0)
|
if (count == 0) {
|
||||||
{
|
|
||||||
/* The channel can be already disabled (migration of paused
|
/* The channel can be already disabled (migration of paused
|
||||||
* thread) so only disable it if needed. */
|
* thread) so only disable it if needed. */
|
||||||
if (chan_is_enabled(cpu_chan))
|
if (chan_is_enabled(cpu_chan))
|
||||||
chan_disable(cpu_chan);
|
chan_disable(cpu_chan);
|
||||||
}
|
} else if (count == 1) {
|
||||||
else if(count == 1)
|
|
||||||
{
|
|
||||||
if (th == NULL)
|
if (th == NULL)
|
||||||
die("emu_cpu_update_chan: tracking thread is NULL\n");
|
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);
|
th->tid, cpu_chan->id);
|
||||||
|
|
||||||
cpu_update_tracking_chan(cpu_chan, th);
|
cpu_update_tracking_chan(cpu_chan, th);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* More than one thread: enable the channel and set it to a
|
/* More than one thread: enable the channel and set it to a
|
||||||
* error value */
|
* error value */
|
||||||
if (!chan_is_enabled(cpu_chan))
|
if (!chan_is_enabled(cpu_chan))
|
||||||
@ -266,15 +250,28 @@ hook_end(struct ovni_emu *emu)
|
|||||||
static void
|
static void
|
||||||
hook_pre(struct ovni_emu *emu)
|
hook_pre(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
switch(emu->cur_ev->header.model)
|
switch (emu->cur_ev->header.model) {
|
||||||
{
|
case 'O':
|
||||||
case 'O': hook_pre_ovni(emu); break;
|
hook_pre_ovni(emu);
|
||||||
case 'V': hook_pre_nosv(emu); break;
|
break;
|
||||||
case 'T': hook_pre_tampi(emu); break;
|
case 'V':
|
||||||
case 'M': hook_pre_openmp(emu); break;
|
hook_pre_nosv(emu);
|
||||||
case 'D': hook_pre_nodes(emu); break;
|
break;
|
||||||
case 'K': hook_pre_kernel(emu); break;
|
case 'T':
|
||||||
case '6': hook_pre_nanos6(emu); break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -283,8 +280,7 @@ hook_pre(struct ovni_emu *emu)
|
|||||||
static void
|
static void
|
||||||
hook_post(struct ovni_emu *emu)
|
hook_post(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
switch(emu->cur_ev->header.model)
|
switch (emu->cur_ev->header.model) {
|
||||||
{
|
|
||||||
default:
|
default:
|
||||||
// dbg("unknown model %c\n", emu->cur_ev->model);
|
// dbg("unknown model %c\n", emu->cur_ev->model);
|
||||||
break;
|
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
|
* 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;
|
struct ovni_stream *sa, *sb;
|
||||||
|
|
||||||
@ -346,8 +343,7 @@ print_progress(struct ovni_emu *emu)
|
|||||||
|
|
||||||
written = cpu_written + th_written;
|
written = cpu_written + th_written;
|
||||||
|
|
||||||
progress = ((double) emu->global_offset) /
|
progress = ((double) emu->global_offset) / ((double) emu->global_size);
|
||||||
((double) emu->global_size);
|
|
||||||
|
|
||||||
time_now = get_time();
|
time_now = get_time();
|
||||||
time_elapsed = time_now - emu->start_emulation_time;
|
time_elapsed = time_now - emu->start_emulation_time;
|
||||||
@ -423,8 +419,7 @@ next_event(struct ovni_emu *emu)
|
|||||||
* 12
|
* 12
|
||||||
* ...
|
* ...
|
||||||
* */
|
* */
|
||||||
if(emu->lastclock > stream->lastclock)
|
if (emu->lastclock > stream->lastclock) {
|
||||||
{
|
|
||||||
err("warning: backwards jump in time %lu -> %lu for tid %d\n",
|
err("warning: backwards jump in time %lu -> %lu for tid %d\n",
|
||||||
emu->lastclock, stream->lastclock, stream->tid);
|
emu->lastclock, stream->lastclock, stream->tid);
|
||||||
|
|
||||||
@ -434,8 +429,7 @@ next_event(struct ovni_emu *emu)
|
|||||||
|
|
||||||
emu->lastclock = stream->lastclock;
|
emu->lastclock = stream->lastclock;
|
||||||
|
|
||||||
if(!done_first)
|
if (!done_first) {
|
||||||
{
|
|
||||||
done_first = 1;
|
done_first = 1;
|
||||||
emu->firstclock = emu->lastclock;
|
emu->firstclock = emu->lastclock;
|
||||||
}
|
}
|
||||||
@ -459,13 +453,11 @@ emu_load_first_events(struct ovni_emu *emu)
|
|||||||
|
|
||||||
/* Load initial streams and events */
|
/* Load initial streams and events */
|
||||||
trace = &emu->trace;
|
trace = &emu->trace;
|
||||||
for(i=0; i<trace->nstreams; i++)
|
for (i = 0; i < trace->nstreams; i++) {
|
||||||
{
|
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
emu->global_size += stream->size;
|
emu->global_size += stream->size;
|
||||||
|
|
||||||
if(emu_step_stream(emu, stream) < 0)
|
if (emu_step_stream(emu, stream) < 0) {
|
||||||
{
|
|
||||||
err("warning: empty stream for tid %d\n", stream->tid);
|
err("warning: empty stream for tid %d\n", stream->tid);
|
||||||
|
|
||||||
if (emu->enable_linter)
|
if (emu->enable_linter)
|
||||||
@ -494,8 +486,7 @@ emulate(struct ovni_emu *emu)
|
|||||||
emit_channels(emu);
|
emit_channels(emu);
|
||||||
|
|
||||||
/* Then process all events */
|
/* Then process all events */
|
||||||
for(i=0; next_event(emu) == 0; i++)
|
for (i = 0; next_event(emu) == 0; i++) {
|
||||||
{
|
|
||||||
print_cur_ev(emu);
|
print_cur_ev(emu);
|
||||||
|
|
||||||
hook_pre(emu);
|
hook_pre(emu);
|
||||||
@ -505,8 +496,7 @@ emulate(struct ovni_emu *emu)
|
|||||||
|
|
||||||
hook_post(emu);
|
hook_post(emu);
|
||||||
|
|
||||||
if(i >= 50000)
|
if (i >= 50000) {
|
||||||
{
|
|
||||||
print_progress(emu);
|
print_progress(emu);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
@ -527,8 +517,7 @@ emu_get_thread(struct ovni_eproc *proc, int tid)
|
|||||||
size_t i;
|
size_t i;
|
||||||
struct ovni_ethread *thread;
|
struct ovni_ethread *thread;
|
||||||
|
|
||||||
for(i=0; i<proc->nthreads; i++)
|
for (i = 0; i < proc->nthreads; i++) {
|
||||||
{
|
|
||||||
thread = &proc->thread[i];
|
thread = &proc->thread[i];
|
||||||
if (thread->tid == tid)
|
if (thread->tid == tid)
|
||||||
return thread;
|
return thread;
|
||||||
@ -595,8 +584,7 @@ proc_load_cpus(struct ovni_emu *emu, struct ovni_loom *loom,
|
|||||||
if (loom->cpu == NULL)
|
if (loom->cpu == NULL)
|
||||||
die("calloc failed: %s\n", strerror(errno));
|
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);
|
JSON_Object *cpu = json_array_get_object(cpuarray, i);
|
||||||
|
|
||||||
if (cpu == NULL)
|
if (cpu == NULL)
|
||||||
@ -638,15 +626,13 @@ load_metadata(struct ovni_emu *emu)
|
|||||||
|
|
||||||
trace = &emu->trace;
|
trace = &emu->trace;
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
|
||||||
loom = &trace->loom[i];
|
loom = &trace->loom[i];
|
||||||
loom->offset_ncpus = emu->total_ncpus;
|
loom->offset_ncpus = emu->total_ncpus;
|
||||||
|
|
||||||
struct ovni_eproc *metadata_proc = NULL;
|
struct ovni_eproc *metadata_proc = NULL;
|
||||||
|
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
|
|
||||||
if (proc_load_cpus(emu, loom, proc, metadata_proc) < 0)
|
if (proc_load_cpus(emu, loom, proc, metadata_proc) < 0)
|
||||||
@ -679,11 +665,9 @@ destroy_metadata(struct ovni_emu *emu)
|
|||||||
|
|
||||||
trace = &emu->trace;
|
trace = &emu->trace;
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
|
||||||
loom = &trace->loom[i];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
|
|
||||||
if (proc->meta == NULL)
|
if (proc->meta == NULL)
|
||||||
@ -707,8 +691,7 @@ open_prvs(struct ovni_emu *emu, char *tracedir)
|
|||||||
|
|
||||||
emu->prv_thread = fopen(path, "w");
|
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,
|
err("error opening thread PRV file %s: %s\n", path,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -718,8 +701,7 @@ open_prvs(struct ovni_emu *emu, char *tracedir)
|
|||||||
|
|
||||||
emu->prv_cpu = fopen(path, "w");
|
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,
|
err("error opening cpu PRV file %s: %s\n", path,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -788,10 +770,8 @@ parse_args(struct ovni_emu *emu, int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "c:l")) != -1)
|
while ((opt = getopt(argc, argv, "c:l")) != -1) {
|
||||||
{
|
switch (opt) {
|
||||||
switch(opt)
|
|
||||||
{
|
|
||||||
case 'c':
|
case 'c':
|
||||||
emu->clock_offset_file = optarg;
|
emu->clock_offset_file = optarg;
|
||||||
break;
|
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");
|
err("missing tracedir\n");
|
||||||
usage(argc, argv);
|
usage(argc, argv);
|
||||||
}
|
}
|
||||||
@ -817,8 +796,7 @@ set_clock_offsets(struct ovni_emu *emu, const char *host, size_t offset)
|
|||||||
{
|
{
|
||||||
size_t matches = 0;
|
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];
|
struct ovni_loom *loom = &emu->trace.loom[i];
|
||||||
|
|
||||||
/* Match the hostname exactly */
|
/* Match the hostname exactly */
|
||||||
@ -849,53 +827,44 @@ load_clock_offsets(struct ovni_emu *emu)
|
|||||||
struct ovni_trace *trace;
|
struct ovni_trace *trace;
|
||||||
struct ovni_stream *stream;
|
struct ovni_stream *stream;
|
||||||
|
|
||||||
if(emu->clock_offset_file != NULL)
|
if (emu->clock_offset_file != NULL) {
|
||||||
{
|
|
||||||
f = fopen(emu->clock_offset_file, "r");
|
f = fopen(emu->clock_offset_file, "r");
|
||||||
|
|
||||||
/* If provided by the user, it must exist */
|
/* If provided by the user, it must exist */
|
||||||
if(f == NULL)
|
if (f == NULL) {
|
||||||
{
|
|
||||||
err("error opening clock offset file %s: %s\n",
|
err("error opening clock offset file %s: %s\n",
|
||||||
emu->clock_offset_file,
|
emu->clock_offset_file,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
if (snprintf(path, PATH_MAX, "%s/clock-offsets.txt",
|
if (snprintf(path, PATH_MAX, "%s/clock-offsets.txt",
|
||||||
emu->tracedir) >= PATH_MAX)
|
emu->tracedir)
|
||||||
{
|
>= PATH_MAX) {
|
||||||
die("clock offset path too long\n");
|
die("clock offset path too long\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fopen(path, "r");
|
f = fopen(path, "r");
|
||||||
|
|
||||||
if(f == NULL)
|
if (f == NULL) {
|
||||||
{
|
|
||||||
/* May not exist, but is fine */
|
/* May not exist, but is fine */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore header line */
|
/* Ignore header line */
|
||||||
if(fgets(buf, 1024, f) == NULL)
|
if (fgets(buf, 1024, f) == NULL) {
|
||||||
{
|
|
||||||
perror("fgets failed");
|
perror("fgets failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ret = fscanf(f, "%d %s %lf %lf %lf", &rank, host, &offset, &mean, &std);
|
ret = fscanf(f, "%d %s %lf %lf %lf", &rank, host, &offset, &mean, &std);
|
||||||
|
|
||||||
if(ret == EOF)
|
if (ret == EOF) {
|
||||||
{
|
if (errno != 0) {
|
||||||
if(errno != 0)
|
|
||||||
{
|
|
||||||
perror("fscanf failed");
|
perror("fscanf failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -903,8 +872,7 @@ load_clock_offsets(struct ovni_emu *emu)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 5)
|
if (ret != 5) {
|
||||||
{
|
|
||||||
err("fscanf read %d instead of 5 fields in %s\n",
|
err("fscanf read %d instead of 5 fields in %s\n",
|
||||||
ret, emu->clock_offset_file);
|
ret, emu->clock_offset_file);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -917,8 +885,7 @@ load_clock_offsets(struct ovni_emu *emu)
|
|||||||
|
|
||||||
trace = &emu->trace;
|
trace = &emu->trace;
|
||||||
|
|
||||||
for(i=0; i<trace->nstreams; i++)
|
for (i = 0; i < trace->nstreams; i++) {
|
||||||
{
|
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
loom = stream->loom;
|
loom = stream->loom;
|
||||||
stream->clock_offset = loom->clock_offset;
|
stream->clock_offset = loom->clock_offset;
|
||||||
@ -941,8 +908,7 @@ write_row_cpu(struct ovni_emu *emu)
|
|||||||
|
|
||||||
f = fopen(path, "w");
|
f = fopen(path, "w");
|
||||||
|
|
||||||
if(f == NULL)
|
if (f == NULL) {
|
||||||
{
|
|
||||||
perror("cannot open row file");
|
perror("cannot open row file");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -953,8 +919,7 @@ write_row_cpu(struct ovni_emu *emu)
|
|||||||
|
|
||||||
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_ncpus);
|
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_ncpus);
|
||||||
|
|
||||||
for(i=0; i<emu->total_ncpus; i++)
|
for (i = 0; i < emu->total_ncpus; i++) {
|
||||||
{
|
|
||||||
cpu = emu->global_cpu[i];
|
cpu = emu->global_cpu[i];
|
||||||
fprintf(f, "%s\n", cpu->name);
|
fprintf(f, "%s\n", cpu->name);
|
||||||
}
|
}
|
||||||
@ -974,8 +939,7 @@ write_row_thread(struct ovni_emu *emu)
|
|||||||
|
|
||||||
f = fopen(path, "w");
|
f = fopen(path, "w");
|
||||||
|
|
||||||
if(f == NULL)
|
if (f == NULL) {
|
||||||
{
|
|
||||||
perror("cannot open row file");
|
perror("cannot open row file");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -986,8 +950,7 @@ write_row_thread(struct ovni_emu *emu)
|
|||||||
|
|
||||||
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_nthreads);
|
fprintf(f, "LEVEL THREAD SIZE %ld\n", emu->total_nthreads);
|
||||||
|
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
fprintf(f, "THREAD %d.%d\n", th->proc->appid, th->tid);
|
fprintf(f, "THREAD %d.%d\n", th->proc->appid, th->tid);
|
||||||
}
|
}
|
||||||
@ -1009,15 +972,12 @@ init_threads(struct ovni_emu *emu)
|
|||||||
|
|
||||||
trace = &emu->trace;
|
trace = &emu->trace;
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
|
||||||
loom = &trace->loom[i];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
emu->total_nprocs++;
|
emu->total_nprocs++;
|
||||||
for(k=0; k<proc->nthreads; k++)
|
for (k = 0; k < proc->nthreads; k++) {
|
||||||
{
|
|
||||||
thread = &proc->thread[k];
|
thread = &proc->thread[k];
|
||||||
emu->total_nthreads++;
|
emu->total_nthreads++;
|
||||||
}
|
}
|
||||||
@ -1027,20 +987,16 @@ init_threads(struct ovni_emu *emu)
|
|||||||
emu->global_thread = calloc(emu->total_nthreads,
|
emu->global_thread = calloc(emu->total_nthreads,
|
||||||
sizeof(*emu->global_thread));
|
sizeof(*emu->global_thread));
|
||||||
|
|
||||||
if(emu->global_thread == NULL)
|
if (emu->global_thread == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
exit(EXIT_FAILURE);
|
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];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
for(k=0; k<proc->nthreads; k++)
|
for (k = 0; k < proc->nthreads; k++) {
|
||||||
{
|
|
||||||
thread = &proc->thread[k];
|
thread = &proc->thread[k];
|
||||||
|
|
||||||
emu->global_thread[gi++] = thread;
|
emu->global_thread[gi++] = thread;
|
||||||
@ -1062,23 +1018,20 @@ init_cpus(struct ovni_emu *emu)
|
|||||||
emu->global_cpu = calloc(emu->total_ncpus,
|
emu->global_cpu = calloc(emu->total_ncpus,
|
||||||
sizeof(*emu->global_cpu));
|
sizeof(*emu->global_cpu));
|
||||||
|
|
||||||
if(emu->global_cpu == NULL)
|
if (emu->global_cpu == NULL) {
|
||||||
{
|
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
|
||||||
loom = &trace->loom[i];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->ncpus; j++)
|
for (j = 0; j < loom->ncpus; j++) {
|
||||||
{
|
|
||||||
cpu = &loom->cpu[j];
|
cpu = &loom->cpu[j];
|
||||||
emu->global_cpu[cpu->gindex] = cpu;
|
emu->global_cpu[cpu->gindex] = cpu;
|
||||||
|
|
||||||
if (snprintf(cpu->name, MAX_CPU_NAME, "CPU %ld.%ld",
|
if (snprintf(cpu->name, MAX_CPU_NAME, "CPU %ld.%ld",
|
||||||
i, j) >= MAX_CPU_NAME)
|
i, j)
|
||||||
{
|
>= MAX_CPU_NAME) {
|
||||||
err("error cpu %ld.%ld name too long\n", i, j);
|
err("error cpu %ld.%ld name too long\n", i, j);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -1087,8 +1040,8 @@ init_cpus(struct ovni_emu *emu)
|
|||||||
|
|
||||||
emu->global_cpu[loom->vcpu.gindex] = &loom->vcpu;
|
emu->global_cpu[loom->vcpu.gindex] = &loom->vcpu;
|
||||||
if (snprintf(loom->vcpu.name, MAX_CPU_NAME, "CPU %ld.*",
|
if (snprintf(loom->vcpu.name, MAX_CPU_NAME, "CPU %ld.*",
|
||||||
i) >= MAX_CPU_NAME)
|
i)
|
||||||
{
|
>= MAX_CPU_NAME) {
|
||||||
err("error cpu %ld.* name too long\n", i);
|
err("error cpu %ld.* name too long\n", i);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -1107,8 +1060,7 @@ create_pcf_cpus(struct ovni_emu *emu)
|
|||||||
if (type == NULL)
|
if (type == NULL)
|
||||||
die("cannot find PCF type for CHAN_OVNI_CPU\n");
|
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;
|
int value = i + 1;
|
||||||
char *label = emu->global_cpu[i]->name;
|
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);
|
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");
|
err("error loading ovni trace\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ovni_load_streams(&emu->trace))
|
if (ovni_load_streams(&emu->trace)) {
|
||||||
{
|
|
||||||
err("error loading streams\n");
|
err("error loading streams\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -1225,8 +1175,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
emu = malloc(sizeof(struct ovni_emu));
|
emu = malloc(sizeof(struct ovni_emu));
|
||||||
|
|
||||||
if(emu == NULL)
|
if (emu == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
6
emu.h
6
emu.h
@ -7,11 +7,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "ovni.h"
|
|
||||||
#include "uthash.h"
|
|
||||||
#include "parson.h"
|
|
||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "parson.h"
|
||||||
#include "pcf.h"
|
#include "pcf.h"
|
||||||
|
#include "uthash.h"
|
||||||
|
|
||||||
/* Emulated thread runtime status */
|
/* Emulated thread runtime status */
|
||||||
enum ethread_state {
|
enum ethread_state {
|
||||||
|
20
emu_kernel.c
20
emu_kernel.c
@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "trace.h"
|
|
||||||
#include "emu.h"
|
|
||||||
#include "prv.h"
|
|
||||||
#include "chan.h"
|
#include "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "prv.h"
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
/* --------------------------- init ------------------------------- */
|
/* --------------------------- init ------------------------------- */
|
||||||
|
|
||||||
@ -27,8 +27,7 @@ hook_init_kernel(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
uth = &emu->th_chan;
|
uth = &emu->th_chan;
|
||||||
@ -37,8 +36,7 @@ hook_init_kernel(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the channels in all cpus */
|
/* 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];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -58,8 +56,7 @@ context_switch(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan = &th->chan[CHAN_KERNEL_CS];
|
chan = &th->chan[CHAN_KERNEL_CS];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case 'O':
|
case 'O':
|
||||||
chan_push(chan, ST_KERNEL_CSOUT);
|
chan_push(chan, ST_KERNEL_CSOUT);
|
||||||
break;
|
break;
|
||||||
@ -79,8 +76,7 @@ hook_pre_kernel(struct ovni_emu *emu)
|
|||||||
edie(emu, "hook_pre_kernel: unexpected event with model %c\n",
|
edie(emu, "hook_pre_kernel: unexpected event with model %c\n",
|
||||||
emu->cur_ev->header.model);
|
emu->cur_ev->header.model);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
|
||||||
case 'C':
|
case 'C':
|
||||||
context_switch(emu);
|
context_switch(emu);
|
||||||
break;
|
break;
|
||||||
|
333
emu_nanos6.c
333
emu_nanos6.c
@ -4,11 +4,11 @@
|
|||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
#include "chan.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "emu_task.h"
|
#include "emu_task.h"
|
||||||
|
#include "ovni.h"
|
||||||
#include "prv.h"
|
#include "prv.h"
|
||||||
#include "chan.h"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hook_init_nanos6(struct ovni_emu *emu)
|
hook_init_nanos6(struct ovni_emu *emu)
|
||||||
@ -25,8 +25,7 @@ hook_init_nanos6(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(size_t i=0; i<emu->total_nthreads; i++)
|
for (size_t i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
|
|
||||||
@ -40,8 +39,7 @@ hook_init_nanos6(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the Nanos6 channels in all cpus */
|
/* Init the Nanos6 channels in all cpus */
|
||||||
for(size_t i=0; i<emu->total_ncpus; i++)
|
for (size_t i = 0; i < emu->total_ncpus; i++) {
|
||||||
{
|
|
||||||
cpu = emu->global_cpu[i];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -54,8 +52,7 @@ hook_init_nanos6(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init task stack */
|
/* Init task stack */
|
||||||
for(size_t i=0; i<emu->total_nthreads; i++)
|
for (size_t i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
th->nanos6_task_stack.thread = th;
|
th->nanos6_task_stack.thread = th;
|
||||||
}
|
}
|
||||||
@ -153,12 +150,19 @@ update_task_state(struct ovni_emu *emu)
|
|||||||
if (task == NULL)
|
if (task == NULL)
|
||||||
edie(emu, "cannot find task with id %u\n", task_id);
|
edie(emu, "cannot find task with id %u\n", task_id);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'x':
|
||||||
case 'x': task_execute(emu, stack, task); break;
|
task_execute(emu, stack, task);
|
||||||
case 'e': task_end(emu, stack, task); break;
|
break;
|
||||||
case 'p': task_pause(emu, stack, task); break;
|
case 'e':
|
||||||
case 'r': task_resume(emu, stack, task); break;
|
task_end(emu, stack, task);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
task_pause(emu, stack, task);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
task_resume(emu, stack, task);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
edie(emu, "unexpected Nanos6 task event\n");
|
edie(emu, "unexpected Nanos6 task event\n");
|
||||||
}
|
}
|
||||||
@ -186,8 +190,7 @@ static void
|
|||||||
update_task_channels(struct ovni_emu *emu,
|
update_task_channels(struct ovni_emu *emu,
|
||||||
char tr, struct task *prev, struct task *next)
|
char tr, struct task *prev, struct task *next)
|
||||||
{
|
{
|
||||||
switch(tr)
|
switch (tr) {
|
||||||
{
|
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'r':
|
case 'r':
|
||||||
chan_task_running(emu, next);
|
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
|
/* If a task has just entered the running state, it must show
|
||||||
* the running task body subsystem */
|
* the running task body subsystem */
|
||||||
if(tr == 'x' || tr == 'X')
|
if (tr == 'x' || tr == 'X') {
|
||||||
{
|
|
||||||
if (next->state != TASK_ST_RUNNING)
|
if (next->state != TASK_ST_RUNNING)
|
||||||
edie(emu, "a Nanos6 task starts running but not in the running state\n");
|
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
|
static void
|
||||||
pre_task(struct ovni_emu *emu)
|
pre_task(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case 'c':
|
case 'c':
|
||||||
create_task(emu);
|
create_task(emu);
|
||||||
break;
|
break;
|
||||||
@ -316,12 +317,19 @@ pre_deps(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'r':
|
||||||
case 'r': chan_push(chan_th, ST_NANOS6_DEP_REG); break;
|
chan_push(chan_th, ST_NANOS6_DEP_REG);
|
||||||
case 'R': chan_pop (chan_th, ST_NANOS6_DEP_REG); break;
|
break;
|
||||||
case 'u': chan_push(chan_th, ST_NANOS6_DEP_UNREG); break;
|
case 'R':
|
||||||
case 'U': chan_pop (chan_th, ST_NANOS6_DEP_UNREG); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 dependency event\n");
|
edie(emu, "unknown Nanos6 dependency event\n");
|
||||||
}
|
}
|
||||||
@ -336,16 +344,31 @@ pre_blocking(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'b':
|
||||||
case 'b': chan_push(chan_th, ST_NANOS6_BLK_BLOCKING); break;
|
chan_push(chan_th, ST_NANOS6_BLK_BLOCKING);
|
||||||
case 'B': chan_pop (chan_th, ST_NANOS6_BLK_BLOCKING); break;
|
break;
|
||||||
case 'u': chan_push(chan_th, ST_NANOS6_BLK_UNBLOCKING); break;
|
case 'B':
|
||||||
case 'U': chan_pop (chan_th, ST_NANOS6_BLK_UNBLOCKING); break;
|
chan_pop(chan_th, ST_NANOS6_BLK_BLOCKING);
|
||||||
case 'w': chan_push(chan_th, ST_NANOS6_BLK_TASKWAIT); break;
|
break;
|
||||||
case 'W': chan_pop (chan_th, ST_NANOS6_BLK_TASKWAIT); break;
|
case 'u':
|
||||||
case 'f': chan_push(chan_th, ST_NANOS6_BLK_WAITFOR); break;
|
chan_push(chan_th, ST_NANOS6_BLK_UNBLOCKING);
|
||||||
case 'F': chan_pop (chan_th, ST_NANOS6_BLK_WAITFOR); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 blocking event\n");
|
edie(emu, "unknown Nanos6 blocking event\n");
|
||||||
}
|
}
|
||||||
@ -360,21 +383,46 @@ pre_worker(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case '[':
|
||||||
case '[': chan_push(chan_th, ST_NANOS6_WORKER_LOOP); break;
|
chan_push(chan_th, ST_NANOS6_WORKER_LOOP);
|
||||||
case ']': chan_pop (chan_th, ST_NANOS6_WORKER_LOOP); break;
|
break;
|
||||||
case 't': chan_push(chan_th, ST_NANOS6_HANDLING_TASK); break;
|
case ']':
|
||||||
case 'T': chan_pop (chan_th, ST_NANOS6_HANDLING_TASK); break;
|
chan_pop(chan_th, ST_NANOS6_WORKER_LOOP);
|
||||||
case 'w': chan_push(chan_th, ST_NANOS6_SWITCH_TO); break;
|
break;
|
||||||
case 'W': chan_pop (chan_th, ST_NANOS6_SWITCH_TO); break;
|
case 't':
|
||||||
case 'm': chan_push(chan_th, ST_NANOS6_MIGRATE); break;
|
chan_push(chan_th, ST_NANOS6_HANDLING_TASK);
|
||||||
case 'M': chan_pop (chan_th, ST_NANOS6_MIGRATE); break;
|
break;
|
||||||
case 's': chan_push(chan_th, ST_NANOS6_SUSPEND); break;
|
case 'T':
|
||||||
case 'S': chan_pop (chan_th, ST_NANOS6_SUSPEND); break;
|
chan_pop(chan_th, ST_NANOS6_HANDLING_TASK);
|
||||||
case 'r': chan_push(chan_th, ST_NANOS6_RESUME); break;
|
break;
|
||||||
case 'R': chan_pop (chan_th, ST_NANOS6_RESUME); break;
|
case 'w':
|
||||||
case '*': chan_ev (chan_th, EV_NANOS6_SIGNAL); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 worker event\n");
|
edie(emu, "unknown Nanos6 worker event\n");
|
||||||
}
|
}
|
||||||
@ -389,12 +437,19 @@ pre_memory(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'a':
|
||||||
case 'a': chan_push(chan_th, ST_NANOS6_ALLOCATING); break;
|
chan_push(chan_th, ST_NANOS6_ALLOCATING);
|
||||||
case 'A': chan_pop (chan_th, ST_NANOS6_ALLOCATING); break;
|
break;
|
||||||
case 'f': chan_push(chan_th, ST_NANOS6_FREEING); break;
|
case 'A':
|
||||||
case 'F': chan_pop (chan_th, ST_NANOS6_FREEING); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 memory event\n");
|
edie(emu, "unknown Nanos6 memory event\n");
|
||||||
}
|
}
|
||||||
@ -409,17 +464,34 @@ pre_sched(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case '[':
|
||||||
case '[': chan_push(chan_th, ST_NANOS6_SCHED_SERVING); break;
|
chan_push(chan_th, ST_NANOS6_SCHED_SERVING);
|
||||||
case ']': chan_pop (chan_th, ST_NANOS6_SCHED_SERVING); break;
|
break;
|
||||||
case 'a': chan_push(chan_th, ST_NANOS6_SCHED_ADDING); break;
|
case ']':
|
||||||
case 'A': chan_pop (chan_th, ST_NANOS6_SCHED_ADDING); break;
|
chan_pop(chan_th, ST_NANOS6_SCHED_SERVING);
|
||||||
case 'p': chan_push(chan_th, ST_NANOS6_SCHED_PROCESSING); break;
|
break;
|
||||||
case 'P': chan_pop (chan_th, ST_NANOS6_SCHED_PROCESSING); break;
|
case 'a':
|
||||||
case '@': chan_ev (chan_th, EV_NANOS6_SCHED_SELF); break;
|
chan_push(chan_th, ST_NANOS6_SCHED_ADDING);
|
||||||
case 'r': chan_ev (chan_th, EV_NANOS6_SCHED_RECV); break;
|
break;
|
||||||
case 's': chan_ev (chan_th, EV_NANOS6_SCHED_SEND); 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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 scheduler event\n");
|
edie(emu, "unknown Nanos6 scheduler event\n");
|
||||||
}
|
}
|
||||||
@ -434,16 +506,31 @@ pre_thread(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NANOS6_THREAD];
|
chan_th = &th->chan[CHAN_NANOS6_THREAD];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'e':
|
||||||
case 'e': chan_push(chan_th, ST_NANOS6_TH_EXTERNAL); break;
|
chan_push(chan_th, ST_NANOS6_TH_EXTERNAL);
|
||||||
case 'E': chan_pop (chan_th, ST_NANOS6_TH_EXTERNAL); break;
|
break;
|
||||||
case 'w': chan_push(chan_th, ST_NANOS6_TH_WORKER); break;
|
case 'E':
|
||||||
case 'W': chan_pop (chan_th, ST_NANOS6_TH_WORKER); break;
|
chan_pop(chan_th, ST_NANOS6_TH_EXTERNAL);
|
||||||
case 'l': chan_push(chan_th, ST_NANOS6_TH_LEADER); break;
|
break;
|
||||||
case 'L': chan_pop (chan_th, ST_NANOS6_TH_LEADER); break;
|
case 'w':
|
||||||
case 'm': chan_push(chan_th, ST_NANOS6_TH_MAIN); break;
|
chan_push(chan_th, ST_NANOS6_TH_WORKER);
|
||||||
case 'M': chan_pop (chan_th, ST_NANOS6_TH_MAIN); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 thread type event\n");
|
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);
|
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 '[':
|
||||||
case '[': chan_push(chan_th, st); break;
|
chan_push(chan_th, st);
|
||||||
case ']': chan_pop(chan_th, st); break;
|
break;
|
||||||
|
case ']':
|
||||||
|
chan_pop(chan_th, st);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
|
edie(emu, "unexpected value '%c' (expecting '[' or ']')\n",
|
||||||
emu->cur_ev->header.value);
|
emu->cur_ev->header.value);
|
||||||
@ -479,8 +569,7 @@ check_affinity(struct ovni_emu *emu)
|
|||||||
if (!cpu || cpu->virtual)
|
if (!cpu || cpu->virtual)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(cpu->nrunning_threads > 1)
|
if (cpu->nrunning_threads > 1) {
|
||||||
{
|
|
||||||
eerr(emu, "cpu %s has more than one thread running\n", cpu->name);
|
eerr(emu, "cpu %s has more than one thread running\n", cpu->name);
|
||||||
|
|
||||||
/* Only abort in linter mode so we can still see the
|
/* 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);
|
emu->cur_thread->tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'T':
|
||||||
case 'T': pre_task(emu); break;
|
pre_task(emu);
|
||||||
case 'C': pre_ss(emu, ST_NANOS6_TASK_CREATING); break;
|
break;
|
||||||
case 'Y': pre_type(emu); break;
|
case 'C':
|
||||||
case 'S': pre_sched(emu); break;
|
pre_ss(emu, ST_NANOS6_TASK_CREATING);
|
||||||
case 'U': pre_ss(emu, ST_NANOS6_TASK_SUBMIT); break;
|
break;
|
||||||
case 'F': pre_ss(emu, ST_NANOS6_TASK_SPAWNING); break;
|
case 'Y':
|
||||||
case 'O': pre_ss(emu, ST_NANOS6_TASK_FOR); break;
|
pre_type(emu);
|
||||||
case 't': pre_ss(emu, ST_NANOS6_TASK_BODY); break;
|
break;
|
||||||
case 'H': pre_thread(emu); break;
|
case 'S':
|
||||||
case 'D': pre_deps(emu); break;
|
pre_sched(emu);
|
||||||
case 'B': pre_blocking(emu); break;
|
break;
|
||||||
case 'W': pre_worker(emu); break;
|
case 'U':
|
||||||
case 'M': pre_memory(emu); break;
|
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:
|
default:
|
||||||
edie(emu, "unknown Nanos6 event category\n");
|
edie(emu, "unknown Nanos6 event category\n");
|
||||||
}
|
}
|
||||||
@ -528,20 +642,16 @@ static void
|
|||||||
end_lint(struct ovni_emu *emu)
|
end_lint(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
/* Ensure we run out of subsystem states */
|
/* 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_ethread *th = emu->global_thread[i];
|
||||||
struct ovni_chan *ch = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
struct ovni_chan *ch = &th->chan[CHAN_NANOS6_SUBSYSTEM];
|
||||||
if(ch->n != 1)
|
if (ch->n != 1) {
|
||||||
{
|
|
||||||
int top = ch->stack[ch->n - 1];
|
int top = ch->stack[ch->n - 1];
|
||||||
|
|
||||||
struct pcf_value_label *pv;
|
struct pcf_value_label *pv;
|
||||||
char *name = "(unknown)";
|
char *name = "(unknown)";
|
||||||
for(pv = &nanos6_ss_values[0]; pv->label; pv++)
|
for (pv = &nanos6_ss_values[0]; pv->label; pv++) {
|
||||||
{
|
if (pv->value == top) {
|
||||||
if(pv->value == top)
|
|
||||||
{
|
|
||||||
name = pv->label;
|
name = pv->label;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -557,17 +667,14 @@ void
|
|||||||
hook_end_nanos6(struct ovni_emu *emu)
|
hook_end_nanos6(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
/* Emit types for all channel types and processes */
|
/* 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];
|
struct pcf_file *pcf = &emu->pcf[ct];
|
||||||
int typeid = chan_to_prvtype[CHAN_NANOS6_TYPE];
|
int typeid = chan_to_prvtype[CHAN_NANOS6_TYPE];
|
||||||
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
|
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];
|
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];
|
struct ovni_eproc *proc = &loom->proc[j];
|
||||||
task_create_pcf_types(pcftype, proc->nanos6_task_info.types);
|
task_create_pcf_types(pcftype, proc->nanos6_task_info.types);
|
||||||
}
|
}
|
||||||
|
50
emu_nodes.c
50
emu_nodes.c
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
|
||||||
#include "prv.h"
|
|
||||||
#include "chan.h"
|
#include "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "prv.h"
|
||||||
|
|
||||||
/* --------------------------- init ------------------------------- */
|
/* --------------------------- init ------------------------------- */
|
||||||
|
|
||||||
@ -26,8 +26,7 @@ hook_init_nodes(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
uth = &emu->th_chan;
|
uth = &emu->th_chan;
|
||||||
@ -36,8 +35,7 @@ hook_init_nodes(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the channels in all cpus */
|
/* 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];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -57,8 +55,7 @@ pre_subsystem(struct ovni_emu *emu, int st)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan = &th->chan[CHAN_NODES_SUBSYSTEM];
|
chan = &th->chan[CHAN_NODES_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case '[':
|
case '[':
|
||||||
chan_push(chan, st);
|
chan_push(chan, st);
|
||||||
break;
|
break;
|
||||||
@ -82,16 +79,31 @@ hook_pre_nodes(struct ovni_emu *emu)
|
|||||||
edie(emu, "hook_pre_nodes: current thread %d not running\n",
|
edie(emu, "hook_pre_nodes: current thread %d not running\n",
|
||||||
emu->cur_thread->tid);
|
emu->cur_thread->tid);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'R':
|
||||||
case 'R': pre_subsystem(emu, ST_NODES_REGISTER); break;
|
pre_subsystem(emu, ST_NODES_REGISTER);
|
||||||
case 'U': pre_subsystem(emu, ST_NODES_UNREGISTER); break;
|
break;
|
||||||
case 'W': pre_subsystem(emu, ST_NODES_IF0_WAIT); break;
|
case 'U':
|
||||||
case 'I': pre_subsystem(emu, ST_NODES_IF0_INLINE); break;
|
pre_subsystem(emu, ST_NODES_UNREGISTER);
|
||||||
case 'T': pre_subsystem(emu, ST_NODES_TASKWAIT); break;
|
break;
|
||||||
case 'C': pre_subsystem(emu, ST_NODES_CREATE); break;
|
case 'W':
|
||||||
case 'S': pre_subsystem(emu, ST_NODES_SUBMIT); break;
|
pre_subsystem(emu, ST_NODES_IF0_WAIT);
|
||||||
case 'P': pre_subsystem(emu, ST_NODES_SPAWN); break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
209
emu_nosv.c
209
emu_nosv.c
@ -4,11 +4,11 @@
|
|||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
#include "chan.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "emu_task.h"
|
#include "emu_task.h"
|
||||||
|
#include "ovni.h"
|
||||||
#include "prv.h"
|
#include "prv.h"
|
||||||
#include "chan.h"
|
|
||||||
|
|
||||||
/* --------------------------- init ------------------------------- */
|
/* --------------------------- init ------------------------------- */
|
||||||
|
|
||||||
@ -28,8 +28,7 @@ hook_init_nosv(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
|
|
||||||
@ -48,8 +47,7 @@ hook_init_nosv(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the nosv channels in all cpus */
|
/* Init the nosv channels in all cpus */
|
||||||
for(i=0; i<emu->total_ncpus; i++)
|
for (i = 0; i < emu->total_ncpus; i++) {
|
||||||
{
|
|
||||||
cpu = emu->global_cpu[i];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -62,8 +60,7 @@ hook_init_nosv(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init task stack */
|
/* 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 = emu->global_thread[i];
|
||||||
th->nosv_task_stack.thread = th;
|
th->nosv_task_stack.thread = th;
|
||||||
}
|
}
|
||||||
@ -167,12 +164,19 @@ update_task_state(struct ovni_emu *emu)
|
|||||||
if (task == NULL)
|
if (task == NULL)
|
||||||
edie(emu, "cannot find task with id %u\n", task_id);
|
edie(emu, "cannot find task with id %u\n", task_id);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'x':
|
||||||
case 'x': task_execute(emu, stack, task); break;
|
task_execute(emu, stack, task);
|
||||||
case 'e': task_end(emu, stack, task); break;
|
break;
|
||||||
case 'p': task_pause(emu, stack, task); break;
|
case 'e':
|
||||||
case 'r': task_resume(emu, stack, task); break;
|
task_end(emu, stack, task);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
task_pause(emu, stack, task);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
task_resume(emu, stack, task);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
edie(emu, "unexpected Nanos6 task event value %c\n",
|
edie(emu, "unexpected Nanos6 task event value %c\n",
|
||||||
emu->cur_ev->header.value);
|
emu->cur_ev->header.value);
|
||||||
@ -201,15 +205,26 @@ static void
|
|||||||
update_task_channels(struct ovni_emu *emu,
|
update_task_channels(struct ovni_emu *emu,
|
||||||
char tr, struct task *prev, struct task *next)
|
char tr, struct task *prev, struct task *next)
|
||||||
{
|
{
|
||||||
switch(tr)
|
switch (tr) {
|
||||||
{
|
case 'x':
|
||||||
case 'x': chan_task_running(emu, next); break;
|
chan_task_running(emu, next);
|
||||||
case 'r': chan_task_running(emu, next); break;
|
break;
|
||||||
case 'e': chan_task_stopped(emu); break;
|
case 'r':
|
||||||
case 'p': chan_task_stopped(emu); break;
|
chan_task_running(emu, next);
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
chan_task_stopped(emu);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
chan_task_stopped(emu);
|
||||||
|
break;
|
||||||
/* Additional nested transitions */
|
/* Additional nested transitions */
|
||||||
case 'X': chan_task_switch(emu, prev, next); break;
|
case 'X':
|
||||||
case 'E': chan_task_switch(emu, prev, next); break;
|
chan_task_switch(emu, prev, next);
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
chan_task_switch(emu, prev, next);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
edie(emu, "unexpected transition value %c\n", tr);
|
edie(emu, "unexpected transition value %c\n", tr);
|
||||||
}
|
}
|
||||||
@ -253,8 +268,7 @@ create_task(struct ovni_emu *emu)
|
|||||||
static void
|
static void
|
||||||
pre_task(struct ovni_emu *emu)
|
pre_task(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case 'c':
|
case 'c':
|
||||||
create_task(emu);
|
create_task(emu);
|
||||||
break;
|
break;
|
||||||
@ -300,8 +314,7 @@ pre_sched(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case 'h':
|
case 'h':
|
||||||
chan_push(chan_th, ST_NOSV_SCHED_HUNGRY);
|
chan_push(chan_th, ST_NOSV_SCHED_HUNGRY);
|
||||||
break;
|
break;
|
||||||
@ -337,19 +350,39 @@ pre_api(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 's':
|
||||||
case 's': chan_push(chan_th, ST_NOSV_API_SUBMIT); break;
|
chan_push(chan_th, ST_NOSV_API_SUBMIT);
|
||||||
case 'S': chan_pop (chan_th, ST_NOSV_API_SUBMIT); break;
|
break;
|
||||||
case 'p': chan_push(chan_th, ST_NOSV_API_PAUSE); break;
|
case 'S':
|
||||||
case 'P': chan_pop (chan_th, ST_NOSV_API_PAUSE); break;
|
chan_pop(chan_th, ST_NOSV_API_SUBMIT);
|
||||||
case 'y': chan_push(chan_th, ST_NOSV_API_YIELD); break;
|
break;
|
||||||
case 'Y': chan_pop (chan_th, ST_NOSV_API_YIELD); break;
|
case 'p':
|
||||||
case 'w': chan_push(chan_th, ST_NOSV_API_WAITFOR); break;
|
chan_push(chan_th, ST_NOSV_API_PAUSE);
|
||||||
case 'W': chan_pop (chan_th, ST_NOSV_API_WAITFOR); break;
|
break;
|
||||||
case 'c': chan_push(chan_th, ST_NOSV_API_SCHEDPOINT); break;
|
case 'P':
|
||||||
case 'C': chan_pop (chan_th, ST_NOSV_API_SCHEDPOINT); break;
|
chan_pop(chan_th, ST_NOSV_API_PAUSE);
|
||||||
default: break;
|
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;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'a':
|
||||||
case 'a': chan_push(chan_th, ST_NOSV_MEM_ALLOCATING); break;
|
chan_push(chan_th, ST_NOSV_MEM_ALLOCATING);
|
||||||
case 'A': chan_pop (chan_th, ST_NOSV_MEM_ALLOCATING); break;
|
break;
|
||||||
case 'f': chan_push(chan_th, ST_NOSV_MEM_FREEING); break;
|
case 'A':
|
||||||
case 'F': chan_pop (chan_th, ST_NOSV_MEM_FREEING); break;
|
chan_pop(chan_th, ST_NOSV_MEM_ALLOCATING);
|
||||||
default: break;
|
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;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
chan_th = &th->chan[CHAN_NOSV_SUBSYSTEM];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 'a':
|
||||||
case 'a': chan_push(chan_th, ST_NOSV_ATTACH); break;
|
chan_push(chan_th, ST_NOSV_ATTACH);
|
||||||
case 'A': chan_pop (chan_th, ST_NOSV_ATTACH); break;
|
break;
|
||||||
case 'w': chan_push(chan_th, ST_NOSV_WORKER); break;
|
case 'A':
|
||||||
case 'W': chan_pop (chan_th, ST_NOSV_WORKER); break;
|
chan_pop(chan_th, ST_NOSV_ATTACH);
|
||||||
case 'd': chan_push(chan_th, ST_NOSV_DELEGATE); break;
|
break;
|
||||||
case 'D': chan_pop (chan_th, ST_NOSV_DELEGATE); break;
|
case 'w':
|
||||||
default: break;
|
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);
|
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 '[':
|
case '[':
|
||||||
chan_push(chan_th, st);
|
chan_push(chan_th, st);
|
||||||
break;
|
break;
|
||||||
@ -431,8 +483,7 @@ check_affinity(struct ovni_emu *emu)
|
|||||||
if (th->state != TH_ST_RUNNING)
|
if (th->state != TH_ST_RUNNING)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(cpu->nrunning_threads > 1)
|
if (cpu->nrunning_threads > 1) {
|
||||||
{
|
|
||||||
edie(emu, "cpu %s has more than one thread running\n",
|
edie(emu, "cpu %s has more than one thread running\n",
|
||||||
cpu->name);
|
cpu->name);
|
||||||
}
|
}
|
||||||
@ -449,15 +500,28 @@ hook_pre_nosv(struct ovni_emu *emu)
|
|||||||
edie(emu, "hook_pre_nosv: current thread %d not active\n",
|
edie(emu, "hook_pre_nosv: current thread %d not active\n",
|
||||||
emu->cur_thread->tid);
|
emu->cur_thread->tid);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'T':
|
||||||
case 'T': pre_task(emu); break;
|
pre_task(emu);
|
||||||
case 'Y': pre_type(emu); break;
|
break;
|
||||||
case 'S': pre_sched(emu); break;
|
case 'Y':
|
||||||
case 'U': pre_ss(emu, ST_NOSV_SCHED_SUBMITTING); break;
|
pre_type(emu);
|
||||||
case 'M': pre_mem(emu); break;
|
break;
|
||||||
case 'H': pre_thread_type(emu); break;
|
case 'S':
|
||||||
case 'A': pre_api(emu); break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -470,17 +534,14 @@ void
|
|||||||
hook_end_nosv(struct ovni_emu *emu)
|
hook_end_nosv(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
/* Emit types for all channel types and processes */
|
/* 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];
|
struct pcf_file *pcf = &emu->pcf[ct];
|
||||||
int typeid = chan_to_prvtype[CHAN_NOSV_TYPE];
|
int typeid = chan_to_prvtype[CHAN_NOSV_TYPE];
|
||||||
struct pcf_type *pcftype = pcf_find_type(pcf, typeid);
|
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];
|
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];
|
struct ovni_eproc *proc = &loom->proc[j];
|
||||||
task_create_pcf_types(pcftype, proc->nosv_task_info.types);
|
task_create_pcf_types(pcftype, proc->nosv_task_info.types);
|
||||||
}
|
}
|
||||||
|
26
emu_openmp.c
26
emu_openmp.c
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
|
||||||
#include "prv.h"
|
|
||||||
#include "chan.h"
|
#include "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "prv.h"
|
||||||
|
|
||||||
/* --------------------------- init ------------------------------- */
|
/* --------------------------- init ------------------------------- */
|
||||||
|
|
||||||
@ -26,8 +26,7 @@ hook_init_openmp(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
uth = &emu->th_chan;
|
uth = &emu->th_chan;
|
||||||
@ -36,8 +35,7 @@ hook_init_openmp(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the channels in all cpus */
|
/* 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];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -57,8 +55,7 @@ pre_mode(struct ovni_emu *emu, int st)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan = &th->chan[CHAN_OPENMP_MODE];
|
chan = &th->chan[CHAN_OPENMP_MODE];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case '[':
|
case '[':
|
||||||
chan_push(chan, st);
|
chan_push(chan, st);
|
||||||
break;
|
break;
|
||||||
@ -83,10 +80,13 @@ hook_pre_openmp(struct ovni_emu *emu)
|
|||||||
die("hook_pre_openmp: current thread %d not active\n",
|
die("hook_pre_openmp: current thread %d not active\n",
|
||||||
emu->cur_thread->tid);
|
emu->cur_thread->tid);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'T':
|
||||||
case 'T': pre_mode(emu, ST_OPENMP_TASK); break;
|
pre_mode(emu, ST_OPENMP_TASK);
|
||||||
case 'P': pre_mode(emu, ST_OPENMP_PARALLEL); break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
pre_mode(emu, ST_OPENMP_PARALLEL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
111
emu_ovni.c
111
emu_ovni.c
@ -1,10 +1,10 @@
|
|||||||
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
|
||||||
#include "prv.h"
|
|
||||||
#include "chan.h"
|
#include "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "prv.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
/* The emulator ovni module provides the execution model by tracking the thread
|
/* 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;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the ovni channels in all threads */
|
/* Init the ovni channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
uth = &emu->th_chan;
|
uth = &emu->th_chan;
|
||||||
@ -42,8 +41,7 @@ hook_init_ovni(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the ovni channels in all cpus */
|
/* Init the ovni channels in all cpus */
|
||||||
for(i=0; i<emu->total_ncpus; i++)
|
for (i = 0; i < emu->total_ncpus; i++) {
|
||||||
{
|
|
||||||
cpu = emu->global_cpu[i];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -66,8 +64,7 @@ chan_tracking_update(struct ovni_chan *chan, struct ovni_ethread *th)
|
|||||||
if (th == NULL)
|
if (th == NULL)
|
||||||
die("chan_tracking_update: thread is NULL");
|
die("chan_tracking_update: thread is NULL");
|
||||||
|
|
||||||
switch (chan->track)
|
switch (chan->track) {
|
||||||
{
|
|
||||||
case CHAN_TRACK_TH_RUNNING:
|
case CHAN_TRACK_TH_RUNNING:
|
||||||
enabled = th->is_running;
|
enabled = th->is_running;
|
||||||
break;
|
break;
|
||||||
@ -110,7 +107,9 @@ thread_set_state(struct ovni_ethread *th, enum ethread_state state)
|
|||||||
|
|
||||||
th->is_active = (state == TH_ST_RUNNING
|
th->is_active = (state == TH_ST_RUNNING
|
||||||
|| state == TH_ST_COOLING
|
|| 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);
|
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)
|
DL_FOREACH(cpu->thread, th)
|
||||||
{
|
{
|
||||||
if(th->state == TH_ST_RUNNING)
|
if (th->state == TH_ST_RUNNING) {
|
||||||
{
|
|
||||||
th_running = th;
|
th_running = th;
|
||||||
running++;
|
running++;
|
||||||
th_active = th;
|
th_active = th;
|
||||||
active++;
|
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;
|
th_active = th;
|
||||||
active++;
|
active++;
|
||||||
}
|
}
|
||||||
@ -202,8 +198,7 @@ static void
|
|||||||
cpu_add_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
|
cpu_add_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
|
||||||
{
|
{
|
||||||
/* Found, abort */
|
/* 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",
|
err("The thread %d is already assigned to %s\n",
|
||||||
thread->tid, cpu->name);
|
thread->tid, cpu->name);
|
||||||
abort();
|
abort();
|
||||||
@ -223,8 +218,7 @@ cpu_remove_thread(struct ovni_cpu *cpu, struct ovni_ethread *thread)
|
|||||||
p = emu_cpu_find_thread(cpu, thread);
|
p = emu_cpu_find_thread(cpu, thread);
|
||||||
|
|
||||||
/* Not found, abort */
|
/* Not found, abort */
|
||||||
if(p == NULL)
|
if (p == NULL) {
|
||||||
{
|
|
||||||
err("cannot remove missing thread %d from cpu %s\n",
|
err("cannot remove missing thread %d from cpu %s\n",
|
||||||
thread->tid, cpu->name);
|
thread->tid, cpu->name);
|
||||||
abort();
|
abort();
|
||||||
@ -241,7 +235,6 @@ cpu_migrate_thread(struct ovni_cpu *cpu,
|
|||||||
struct ovni_ethread *thread,
|
struct ovni_ethread *thread,
|
||||||
struct ovni_cpu *newcpu)
|
struct ovni_cpu *newcpu)
|
||||||
{
|
{
|
||||||
|
|
||||||
cpu_remove_thread(cpu, thread);
|
cpu_remove_thread(cpu, thread);
|
||||||
cpu_add_thread(newcpu, thread);
|
cpu_add_thread(newcpu, thread);
|
||||||
}
|
}
|
||||||
@ -408,8 +401,7 @@ pre_thread(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
ev = emu->cur_ev;
|
ev = emu->cur_ev;
|
||||||
|
|
||||||
switch(ev->header.value)
|
switch (ev->header.value) {
|
||||||
{
|
|
||||||
case 'C': /* create */
|
case 'C': /* create */
|
||||||
dbg("thread %d creates a new thread at cpu=%d with args=%x %x\n",
|
dbg("thread %d creates a new thread at cpu=%d with args=%x %x\n",
|
||||||
th->tid,
|
th->tid,
|
||||||
@ -418,12 +410,24 @@ pre_thread(struct ovni_emu *emu)
|
|||||||
ev->payload.u32[2]);
|
ev->payload.u32[2]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'x': pre_thread_execute(emu, th); break;
|
case 'x':
|
||||||
case 'e': pre_thread_end(th); break;
|
pre_thread_execute(emu, th);
|
||||||
case 'p': pre_thread_pause(th); break;
|
break;
|
||||||
case 'r': pre_thread_resume(th); break;
|
case 'e':
|
||||||
case 'c': pre_thread_cool(th); break;
|
pre_thread_end(th);
|
||||||
case 'w': pre_thread_warm(th); break;
|
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:
|
default:
|
||||||
err("unknown thread event value %c\n",
|
err("unknown thread event value %c\n",
|
||||||
ev->header.value);
|
ev->header.value);
|
||||||
@ -477,14 +481,12 @@ pre_affinity_remote(struct ovni_emu *emu)
|
|||||||
|
|
||||||
remote_th = emu_get_thread(emu->cur_proc, tid);
|
remote_th = emu_get_thread(emu->cur_proc, tid);
|
||||||
|
|
||||||
if(remote_th == NULL)
|
if (remote_th == NULL) {
|
||||||
{
|
|
||||||
/* Search the thread in other processes of the loom if
|
/* Search the thread in other processes of the loom if
|
||||||
* not found in the current one */
|
* not found in the current one */
|
||||||
loom = emu->cur_loom;
|
loom = emu->cur_loom;
|
||||||
|
|
||||||
for(i=0; i<loom->nprocs; i++)
|
for (i = 0; i < loom->nprocs; i++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[i];
|
proc = &loom->proc[i];
|
||||||
|
|
||||||
/* Skip the current process */
|
/* Skip the current process */
|
||||||
@ -497,8 +499,7 @@ pre_affinity_remote(struct ovni_emu *emu)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(remote_th == NULL)
|
if (remote_th == NULL) {
|
||||||
{
|
|
||||||
err("thread tid %d not found: cannot set affinity remotely\n",
|
err("thread tid %d not found: cannot set affinity remotely\n",
|
||||||
tid);
|
tid);
|
||||||
abort();
|
abort();
|
||||||
@ -533,10 +534,13 @@ static void
|
|||||||
pre_affinity(struct ovni_emu *emu)
|
pre_affinity(struct ovni_emu *emu)
|
||||||
{
|
{
|
||||||
// emu_emit(emu);
|
// emu_emit(emu);
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
case 's':
|
||||||
case 's': pre_affinity_set(emu); break;
|
pre_affinity_set(emu);
|
||||||
case 'r': pre_affinity_remote(emu); break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
pre_affinity_remote(emu);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbg("unknown affinity event value %c\n",
|
dbg("unknown affinity event value %c\n",
|
||||||
emu->cur_ev->header.value);
|
emu->cur_ev->header.value);
|
||||||
@ -554,17 +558,14 @@ pre_burst(struct ovni_emu *emu)
|
|||||||
|
|
||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
|
|
||||||
if(th->nbursts >= MAX_BURSTS)
|
if (th->nbursts >= MAX_BURSTS) {
|
||||||
{
|
|
||||||
err("too many bursts: ignored\n");
|
err("too many bursts: ignored\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
th->burst_time[th->nbursts] = emu->delta_time;
|
th->burst_time[th->nbursts] = emu->delta_time;
|
||||||
if(th->nbursts > 0)
|
if (th->nbursts > 0) {
|
||||||
{
|
dt = th->burst_time[th->nbursts] - th->burst_time[th->nbursts - 1];
|
||||||
dt = th->burst_time[th->nbursts] -
|
|
||||||
th->burst_time[th->nbursts - 1];
|
|
||||||
|
|
||||||
dbg("burst delta time %ld ns\n", dt);
|
dbg("burst delta time %ld ns\n", dt);
|
||||||
}
|
}
|
||||||
@ -581,8 +582,7 @@ pre_flush(struct ovni_emu *emu)
|
|||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
chan_th = &th->chan[CHAN_OVNI_FLUSH];
|
chan_th = &th->chan[CHAN_OVNI_FLUSH];
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case '[':
|
case '[':
|
||||||
chan_push(chan_th, ST_OVNI_FLUSHING);
|
chan_push(chan_th, ST_OVNI_FLUSHING);
|
||||||
break;
|
break;
|
||||||
@ -604,12 +604,19 @@ hook_pre_ovni(struct ovni_emu *emu)
|
|||||||
if (emu->cur_ev->header.model != 'O')
|
if (emu->cur_ev->header.model != 'O')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'H':
|
||||||
case 'H': pre_thread(emu); break;
|
pre_thread(emu);
|
||||||
case 'A': pre_affinity(emu); break;
|
break;
|
||||||
case 'B': pre_burst(emu); break;
|
case 'A':
|
||||||
case 'F': pre_flush(emu); break;
|
pre_affinity(emu);
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
pre_burst(emu);
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
pre_flush(emu);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbg("unknown ovni event category %c\n",
|
dbg("unknown ovni event category %c\n",
|
||||||
emu->cur_ev->header.category);
|
emu->cur_ev->header.category);
|
||||||
|
42
emu_tampi.c
42
emu_tampi.c
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
|
||||||
#include "prv.h"
|
|
||||||
#include "chan.h"
|
#include "chan.h"
|
||||||
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "prv.h"
|
||||||
|
|
||||||
/* --------------------------- init ------------------------------- */
|
/* --------------------------- init ------------------------------- */
|
||||||
|
|
||||||
@ -26,8 +26,7 @@ hook_init_tampi(struct ovni_emu *emu)
|
|||||||
prv_cpu = emu->prv_cpu;
|
prv_cpu = emu->prv_cpu;
|
||||||
|
|
||||||
/* Init the channels in all threads */
|
/* Init the channels in all threads */
|
||||||
for(i=0; i<emu->total_nthreads; i++)
|
for (i = 0; i < emu->total_nthreads; i++) {
|
||||||
{
|
|
||||||
th = emu->global_thread[i];
|
th = emu->global_thread[i];
|
||||||
row = th->gindex + 1;
|
row = th->gindex + 1;
|
||||||
uth = &emu->th_chan;
|
uth = &emu->th_chan;
|
||||||
@ -36,8 +35,7 @@ hook_init_tampi(struct ovni_emu *emu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Init the channels in all cpus */
|
/* 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];
|
cpu = emu->global_cpu[i];
|
||||||
row = cpu->gindex + 1;
|
row = cpu->gindex + 1;
|
||||||
ucpu = &emu->cpu_chan;
|
ucpu = &emu->cpu_chan;
|
||||||
@ -55,8 +53,7 @@ pre_tampi_mode(struct ovni_emu *emu, int state)
|
|||||||
|
|
||||||
th = emu->cur_thread;
|
th = emu->cur_thread;
|
||||||
|
|
||||||
switch(emu->cur_ev->header.value)
|
switch (emu->cur_ev->header.value) {
|
||||||
{
|
|
||||||
case '[':
|
case '[':
|
||||||
chan_push(&th->chan[CHAN_TAMPI_MODE], state);
|
chan_push(&th->chan[CHAN_TAMPI_MODE], state);
|
||||||
break;
|
break;
|
||||||
@ -76,14 +73,25 @@ hook_pre_tampi(struct ovni_emu *emu)
|
|||||||
edie(emu, "hook_pre_tampi: unexpected event with model %c\n",
|
edie(emu, "hook_pre_tampi: unexpected event with model %c\n",
|
||||||
emu->cur_ev->header.model);
|
emu->cur_ev->header.model);
|
||||||
|
|
||||||
switch(emu->cur_ev->header.category)
|
switch (emu->cur_ev->header.category) {
|
||||||
{
|
case 'S':
|
||||||
case 'S': pre_tampi_mode(emu, ST_TAMPI_SEND); break;
|
pre_tampi_mode(emu, ST_TAMPI_SEND);
|
||||||
case 'R': pre_tampi_mode(emu, ST_TAMPI_RECV); break;
|
break;
|
||||||
case 's': pre_tampi_mode(emu, ST_TAMPI_ISEND); break;
|
case 'R':
|
||||||
case 'r': pre_tampi_mode(emu, ST_TAMPI_IRECV); break;
|
pre_tampi_mode(emu, ST_TAMPI_RECV);
|
||||||
case 'V': pre_tampi_mode(emu, ST_TAMPI_WAIT); break;
|
break;
|
||||||
case 'W': pre_tampi_mode(emu, ST_TAMPI_WAITALL); 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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
10
emu_task.c
10
emu_task.c
@ -4,11 +4,11 @@
|
|||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
#include "ovni.h"
|
#include "chan.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "emu_task.h"
|
#include "emu_task.h"
|
||||||
|
#include "ovni.h"
|
||||||
#include "prv.h"
|
#include "prv.h"
|
||||||
#include "chan.h"
|
|
||||||
|
|
||||||
struct task *
|
struct task *
|
||||||
task_find(struct task *tasks, uint32_t task_id)
|
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 */
|
/* Emit types for all task types */
|
||||||
struct task_type *tt;
|
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);
|
struct pcf_value *pcfvalue = pcf_find_value(pcftype, tt->gid);
|
||||||
if(pcfvalue != NULL)
|
if (pcfvalue != NULL) {
|
||||||
{
|
|
||||||
/* Ensure the label is the same, so we know that
|
/* Ensure the label is the same, so we know that
|
||||||
* no collision occurred */
|
* no collision occurred */
|
||||||
if (strcmp(pcfvalue->label, tt->label) != 0)
|
if (strcmp(pcfvalue->label, tt->label) != 0)
|
||||||
|
8
heap.h
8
heap.h
@ -7,8 +7,8 @@
|
|||||||
#ifndef HEAP_H
|
#ifndef HEAP_H
|
||||||
#define HEAP_H
|
#define HEAP_H
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct heap_node {
|
typedef struct heap_node {
|
||||||
struct heap_node *parent;
|
struct heap_node *parent;
|
||||||
@ -25,7 +25,11 @@ typedef struct head_head {
|
|||||||
((type *) (((char *) head) - offsetof(type, name)))
|
((type *) (((char *) head) - offsetof(type, name)))
|
||||||
|
|
||||||
#define heap_swap(a, b) \
|
#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.
|
/* heap_node_compare_t - comparison function.
|
||||||
* The comparison function cmp(a, b) shall return an integer:
|
* The comparison function cmp(a, b) shall return an integer:
|
||||||
|
76
ovni.c
76
ovni.c
@ -6,7 +6,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@ -14,10 +13,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "parson.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include "parson.h"
|
||||||
|
|
||||||
/* Data per process */
|
/* Data per process */
|
||||||
struct ovni_rproc rproc = {0};
|
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 */
|
/* Find the CPU array and create it if needed */
|
||||||
JSON_Array *cpuarray = json_object_dotget_array(meta, "cpus");
|
JSON_Array *cpuarray = json_object_dotget_array(meta, "cpus");
|
||||||
|
|
||||||
if(cpuarray == NULL)
|
if (cpuarray == NULL) {
|
||||||
{
|
|
||||||
JSON_Value *value = json_value_init_array();
|
JSON_Value *value = json_value_init_array();
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
die("ovni_add_cpu: json_value_init_array() failed\n");
|
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)
|
if (json_array_append_value(cpuarray, valcpu) != 0)
|
||||||
die("ovni_add_cpu: json_array_append_value() failed\n");
|
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);
|
JSON_Value *value = json_array_get_wrapping_value(cpuarray);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
die("ovni_add_cpu: json_array_get_wrapping_value() failed\n");
|
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");
|
char *tmpdir = getenv("OVNI_TMPDIR");
|
||||||
|
|
||||||
if(tmpdir != NULL)
|
if (tmpdir != NULL) {
|
||||||
{
|
|
||||||
rproc.move_to_final = 1;
|
rproc.move_to_final = 1;
|
||||||
mkdir_proc(rproc.procdir, tmpdir, loom, pid);
|
mkdir_proc(rproc.procdir, tmpdir, loom, pid);
|
||||||
mkdir_proc(rproc.procdir_final, OVNI_TRACEDIR, loom, pid);
|
mkdir_proc(rproc.procdir_final, OVNI_TRACEDIR, loom, pid);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
rproc.move_to_final = 0;
|
rproc.move_to_final = 0;
|
||||||
mkdir_proc(rproc.procdir, OVNI_TRACEDIR, loom, pid);
|
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");
|
FILE *infile = fopen(src, "r");
|
||||||
|
|
||||||
if(infile == NULL)
|
if (infile == NULL) {
|
||||||
{
|
|
||||||
err("fopen(%s) failed: %s\n", src, strerror(errno));
|
err("fopen(%s) failed: %s\n", src, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *outfile = fopen(dst, "w");
|
FILE *outfile = fopen(dst, "w");
|
||||||
|
|
||||||
if(outfile == NULL)
|
if (outfile == NULL) {
|
||||||
{
|
|
||||||
err("fopen(%s) failed: %s\n", src, strerror(errno));
|
err("fopen(%s) failed: %s\n", src, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -273,8 +265,7 @@ move_thread_to_final(const char *src, const char *dst)
|
|||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
|
||||||
if(remove(src) != 0)
|
if (remove(src) != 0) {
|
||||||
{
|
|
||||||
err("remove(%s) failed: %s\n", src, strerror(errno));
|
err("remove(%s) failed: %s\n", src, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -291,22 +282,20 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
|
|||||||
char thread_final[PATH_MAX];
|
char thread_final[PATH_MAX];
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if((dir = opendir(procdir)) == NULL)
|
if ((dir = opendir(procdir)) == NULL) {
|
||||||
{
|
|
||||||
err("opendir %s failed: %s\n", procdir, strerror(errno));
|
err("opendir %s failed: %s\n", procdir, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *prefix = "thread.";
|
const char *prefix = "thread.";
|
||||||
while((dirent = readdir(dir)) != NULL)
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
{
|
|
||||||
/* It should only contain thread.* directories, skip others */
|
/* It should only contain thread.* directories, skip others */
|
||||||
if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
|
if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (snprintf(thread, PATH_MAX, "%s/%s", procdir,
|
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,
|
err("snprintf: path too large: %s/%s\n", procdir,
|
||||||
dirent->d_name);
|
dirent->d_name);
|
||||||
err = 1;
|
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,
|
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,
|
err("snprintf: path too large: %s/%s\n", procdir_final,
|
||||||
dirent->d_name);
|
dirent->d_name);
|
||||||
err = 1;
|
err = 1;
|
||||||
@ -328,8 +317,7 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
|
|||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
if(rmdir(procdir) != 0)
|
if (rmdir(procdir) != 0) {
|
||||||
{
|
|
||||||
err("rmdir(%s) failed: %s\n", procdir, strerror(errno));
|
err("rmdir(%s) failed: %s\n", procdir, strerror(errno));
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
@ -349,13 +337,10 @@ ovni_proc_fini(void)
|
|||||||
rproc.ready = 0;
|
rproc.ready = 0;
|
||||||
|
|
||||||
|
|
||||||
if(rproc.move_to_final)
|
if (rproc.move_to_final) {
|
||||||
{
|
|
||||||
proc_metadata_store(rproc.meta, rproc.procdir_final);
|
proc_metadata_store(rproc.meta, rproc.procdir_final);
|
||||||
move_procdir_to_final(rproc.procdir, rproc.procdir_final);
|
move_procdir_to_final(rproc.procdir, rproc.procdir_final);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
proc_metadata_store(rproc.meta, rproc.procdir);
|
proc_metadata_store(rproc.meta, rproc.procdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,8 +348,7 @@ ovni_proc_fini(void)
|
|||||||
static void
|
static void
|
||||||
write_evbuf(uint8_t *buf, size_t size)
|
write_evbuf(uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
ssize_t written = write(rthread.streamfd, buf, size);
|
ssize_t written = write(rthread.streamfd, buf, size);
|
||||||
|
|
||||||
if (written < 0)
|
if (written < 0)
|
||||||
@ -399,8 +383,7 @@ write_stream_header(void)
|
|||||||
void
|
void
|
||||||
ovni_thread_init(pid_t tid)
|
ovni_thread_init(pid_t tid)
|
||||||
{
|
{
|
||||||
if(rthread.ready)
|
if (rthread.ready) {
|
||||||
{
|
|
||||||
err("warning: thread %d already initialized, ignored\n", tid);
|
err("warning: thread %d already initialized, ignored\n", tid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -442,13 +425,14 @@ ovni_thread_isready(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_TSC
|
#ifdef USE_TSC
|
||||||
static inline
|
static inline uint64_t
|
||||||
uint64_t clock_tsc_now(void)
|
clock_tsc_now(void)
|
||||||
{
|
{
|
||||||
uint32_t lo, hi;
|
uint32_t lo, hi;
|
||||||
|
|
||||||
/* RDTSC copies contents of 64-bit TSC into EDX:EAX */
|
/* 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;
|
return (uint64_t) hi << 32 | lo;
|
||||||
}
|
}
|
||||||
#endif
|
#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");
|
die("ovni_ev_add_jumbo: event too large\n");
|
||||||
|
|
||||||
/* Check if the event fits or flush first otherwise */
|
/* 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 */
|
/* Measure the flush times */
|
||||||
t0 = ovni_clock_now();
|
t0 = ovni_clock_now();
|
||||||
flush_evbuf();
|
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);
|
memcpy(&rthread.evbuf[rthread.evlen], buf, bufsize);
|
||||||
rthread.evlen += bufsize;
|
rthread.evlen += bufsize;
|
||||||
|
|
||||||
if(flushed)
|
if (flushed) {
|
||||||
{
|
|
||||||
/* Emit the flush events *after* the user event */
|
/* Emit the flush events *after* the user event */
|
||||||
add_flush_events(t0, t1);
|
add_flush_events(t0, t1);
|
||||||
}
|
}
|
||||||
@ -643,8 +625,7 @@ ovni_ev_add(struct ovni_ev *ev)
|
|||||||
int size = ovni_ev_size(ev);
|
int size = ovni_ev_size(ev);
|
||||||
|
|
||||||
/* Check if the event fits or flush first otherwise */
|
/* 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 */
|
/* Measure the flush times */
|
||||||
t0 = ovni_clock_now();
|
t0 = ovni_clock_now();
|
||||||
flush_evbuf();
|
flush_evbuf();
|
||||||
@ -655,8 +636,7 @@ ovni_ev_add(struct ovni_ev *ev)
|
|||||||
memcpy(&rthread.evbuf[rthread.evlen], ev, size);
|
memcpy(&rthread.evbuf[rthread.evlen], ev, size);
|
||||||
rthread.evlen += size;
|
rthread.evlen += size;
|
||||||
|
|
||||||
if(flushed)
|
if (flushed) {
|
||||||
{
|
|
||||||
/* Emit the flush events *after* the user event */
|
/* Emit the flush events *after* the user event */
|
||||||
add_flush_events(t0, t1);
|
add_flush_events(t0, t1);
|
||||||
}
|
}
|
||||||
|
7
ovni.h
7
ovni.h
@ -8,13 +8,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <limits.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
/* Hardcode the JSON_Value to avoid a dependency with janson */
|
/* Hardcode the JSON_Value to avoid a dependency with janson */
|
||||||
typedef struct json_value_t JSON_Value;
|
typedef struct json_value_t JSON_Value;
|
||||||
@ -43,7 +43,6 @@ struct __attribute__((__packed__)) ovni_jumbo_payload {
|
|||||||
};
|
};
|
||||||
|
|
||||||
union __attribute__((__packed__)) ovni_ev_payload {
|
union __attribute__((__packed__)) ovni_ev_payload {
|
||||||
|
|
||||||
int8_t i8[16];
|
int8_t i8[16];
|
||||||
int16_t i16[8];
|
int16_t i16[8];
|
||||||
int32_t i32[4];
|
int32_t i32[4];
|
||||||
|
35
ovni2prv.c
35
ovni2prv.c
@ -1,15 +1,15 @@
|
|||||||
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
/* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* 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 <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdatomic.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include "ovni.h"
|
#include "ovni.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
@ -47,30 +47,26 @@ dump_events(struct ovni_trace *trace)
|
|||||||
struct ovni_stream *stream;
|
struct ovni_stream *stream;
|
||||||
|
|
||||||
/* Load events */
|
/* Load events */
|
||||||
for(i=0; i<trace->nstreams; i++)
|
for (i = 0; i < trace->nstreams; i++) {
|
||||||
{
|
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
ovni_load_next_event(stream);
|
ovni_load_next_event(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastclock = 0;
|
lastclock = 0;
|
||||||
|
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
f = -1;
|
f = -1;
|
||||||
minclock = 0;
|
minclock = 0;
|
||||||
|
|
||||||
/* Select next event based on the clock */
|
/* 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];
|
stream = &trace->stream[i];
|
||||||
|
|
||||||
if (!stream->active)
|
if (!stream->active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ev = stream->cur_ev;
|
ev = stream->cur_ev;
|
||||||
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
|
if (f < 0 || ovni_ev_get_clock(ev) < minclock) {
|
||||||
{
|
|
||||||
f = i;
|
f = i;
|
||||||
minclock = ovni_ev_get_clock(ev);
|
minclock = ovni_ev_get_clock(ev);
|
||||||
}
|
}
|
||||||
@ -83,8 +79,7 @@ dump_events(struct ovni_trace *trace)
|
|||||||
|
|
||||||
stream = &trace->stream[f];
|
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");
|
fprintf(stderr, "warning: backwards jump in time\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,23 +95,21 @@ dump_events(struct ovni_trace *trace)
|
|||||||
/* Unset the index */
|
/* Unset the index */
|
||||||
f = -1;
|
f = -1;
|
||||||
minclock = 0;
|
minclock = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *tracedir;
|
char *tracedir;
|
||||||
struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
|
struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace));
|
||||||
|
|
||||||
if(trace == NULL)
|
if (trace == NULL) {
|
||||||
{
|
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc != 2)
|
if (argc != 2) {
|
||||||
{
|
|
||||||
fprintf(stderr, "missing tracedir\n");
|
fprintf(stderr, "missing tracedir\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
93
ovnisync.c
93
ovnisync.c
@ -60,18 +60,15 @@ static double
|
|||||||
get_time(clockid_t clock, int use_ns)
|
get_time(clockid_t clock, int use_ns)
|
||||||
{
|
{
|
||||||
struct timespec tv;
|
struct timespec tv;
|
||||||
if(clock_gettime(clock, &tv) != 0)
|
if (clock_gettime(clock, &tv) != 0) {
|
||||||
{
|
|
||||||
perror("clock_gettime failed");
|
perror("clock_gettime failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_ns)
|
if (use_ns)
|
||||||
return (double)(tv.tv_sec) * 1.0e9 +
|
return (double) (tv.tv_sec) * 1.0e9 + (double) tv.tv_nsec;
|
||||||
(double)tv.tv_nsec;
|
|
||||||
|
|
||||||
return (double)(tv.tv_sec) +
|
return (double) (tv.tv_sec) + (double) tv.tv_nsec * 1.0e-9;
|
||||||
(double)tv.tv_nsec * 1.0e-9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -105,13 +102,10 @@ try_mkdir(const char *path, mode_t mode)
|
|||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if(stat(path, &st) != 0)
|
if (stat(path, &st) != 0) {
|
||||||
{
|
|
||||||
/* Directory does not exist */
|
/* Directory does not exist */
|
||||||
return mkdir(path, mode);
|
return mkdir(path, mode);
|
||||||
}
|
} else if (!S_ISDIR(st.st_mode)) {
|
||||||
else if(!S_ISDIR(st.st_mode))
|
|
||||||
{
|
|
||||||
errno = ENOTDIR;
|
errno = ENOTDIR;
|
||||||
return -1;
|
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");
|
fprintf(stderr, "error: unexpected extra arguments\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -200,8 +193,7 @@ get_clock_samples(struct offset *offset, int nsamples)
|
|||||||
|
|
||||||
offset->nsamples = nsamples;
|
offset->nsamples = nsamples;
|
||||||
|
|
||||||
for(i=0; i<nsamples; i++)
|
for (i = 0; i < nsamples; i++) {
|
||||||
{
|
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
offset->clock_sample[i] = get_time(CLOCK_MONOTONIC, 1);
|
offset->clock_sample[i] = get_time(CLOCK_MONOTONIC, 1);
|
||||||
}
|
}
|
||||||
@ -218,8 +210,7 @@ fill_offset(struct offset *offset, int nsamples)
|
|||||||
MPI_Comm_rank(MPI_COMM_WORLD, &offset->rank);
|
MPI_Comm_rank(MPI_COMM_WORLD, &offset->rank);
|
||||||
|
|
||||||
/* Fill the host name */
|
/* Fill the host name */
|
||||||
if(gethostname(offset->hostname, OVNI_MAX_HOSTNAME) != 0)
|
if (gethostname(offset->hostname, OVNI_MAX_HOSTNAME) != 0) {
|
||||||
{
|
|
||||||
perror("gethostname");
|
perror("gethostname");
|
||||||
exit(EXIT_FAILURE);
|
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);
|
delta = malloc(sizeof(double) * nsamples);
|
||||||
|
|
||||||
if(delta == NULL)
|
if (delta == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i<nsamples; i++)
|
for (i = 0; i < nsamples; i++) {
|
||||||
{
|
|
||||||
delta[i] = ref->clock_sample[i] - cur->clock_sample[i];
|
delta[i] = ref->clock_sample[i] - cur->clock_sample[i];
|
||||||
if(verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
printf("rank=%d sample=%d delta=%f ref=%f cur=%f\n",
|
printf("rank=%d sample=%d delta=%f ref=%f cur=%f\n",
|
||||||
cur->rank, i, delta[i],
|
cur->rank, i, delta[i],
|
||||||
ref->clock_sample[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;
|
cur->delta_mean /= nsamples;
|
||||||
|
|
||||||
for (cur->delta_var = 0, i = 0; i < nsamples; i++)
|
for (cur->delta_var = 0, i = 0; i < nsamples; i++)
|
||||||
cur->delta_var += (delta[i] - cur->delta_mean) *
|
cur->delta_var += (delta[i] - cur->delta_mean) * (delta[i] - cur->delta_mean);
|
||||||
(delta[i] - cur->delta_mean);
|
|
||||||
|
|
||||||
cur->delta_var /= (double) (nsamples - 1);
|
cur->delta_var /= (double) (nsamples - 1);
|
||||||
cur->delta_std = sqrt(cur->delta_var);
|
cur->delta_std = sqrt(cur->delta_var);
|
||||||
@ -307,12 +294,10 @@ build_offset_table(int nsamples, int rank, int verbose)
|
|||||||
void *sendbuf;
|
void *sendbuf;
|
||||||
|
|
||||||
/* The rank 0 must build the table */
|
/* The rank 0 must build the table */
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
|
||||||
table = malloc(sizeof(*table));
|
table = malloc(sizeof(*table));
|
||||||
|
|
||||||
if(table == NULL)
|
if (table == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -321,17 +306,14 @@ build_offset_table(int nsamples, int rank, int verbose)
|
|||||||
|
|
||||||
table->_offset = calloc(table->nprocs, offset_size(nsamples));
|
table->_offset = calloc(table->nprocs, offset_size(nsamples));
|
||||||
|
|
||||||
if(table->_offset == NULL)
|
if (table->_offset == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
table->offset = malloc(sizeof(struct offset *) *
|
table->offset = malloc(sizeof(struct offset *) * table->nprocs);
|
||||||
table->nprocs);
|
|
||||||
|
|
||||||
if(table->offset == NULL)
|
if (table->offset == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(EXIT_FAILURE);
|
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);
|
table->offset[i] = table_get_offset(table, i, nsamples);
|
||||||
|
|
||||||
offset = table->offset[0];
|
offset = table->offset[0];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Otherwise just allocate one offset */
|
/* Otherwise just allocate one offset */
|
||||||
offset = calloc(1, offset_size(nsamples));
|
offset = calloc(1, offset_size(nsamples));
|
||||||
|
|
||||||
if(offset == NULL)
|
if (offset == NULL) {
|
||||||
{
|
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -366,10 +345,8 @@ build_offset_table(int nsamples, int rank, int verbose)
|
|||||||
0, MPI_COMM_WORLD);
|
0, MPI_COMM_WORLD);
|
||||||
|
|
||||||
/* Finish the offsets by computing the deltas on rank 0 */
|
/* Finish the offsets by computing the deltas on rank 0 */
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
for (i = 0; i < table->nprocs; i++) {
|
||||||
for(i=0; i<table->nprocs; i++)
|
|
||||||
{
|
|
||||||
offset_compute_delta(offset, table->offset[i],
|
offset_compute_delta(offset, table->offset[i],
|
||||||
nsamples, verbose);
|
nsamples, verbose);
|
||||||
}
|
}
|
||||||
@ -390,8 +367,7 @@ print_drift_header(FILE *out, struct offset_table *table)
|
|||||||
|
|
||||||
fprintf(out, "%-20s", "wallclock");
|
fprintf(out, "%-20s", "wallclock");
|
||||||
|
|
||||||
for(i=0; i<table->nprocs; i++)
|
for (i = 0; i < table->nprocs; i++) {
|
||||||
{
|
|
||||||
// sprintf(buf, "rank%d", i);
|
// sprintf(buf, "rank%d", i);
|
||||||
fprintf(out, " %-20s", table->offset[i]->hostname);
|
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",
|
fprintf(out, "%-10s %-20s %-20s %-20s %-20s\n",
|
||||||
"rank", "hostname", "offset_median", "offset_mean", "offset_std");
|
"rank", "hostname", "offset_median", "offset_mean", "offset_std");
|
||||||
|
|
||||||
for(i=0; i<table->nprocs; i++)
|
for (i = 0; i < table->nprocs; i++) {
|
||||||
{
|
|
||||||
offset = table->offset[i];
|
offset = table->offset[i];
|
||||||
fprintf(out, "%-10d %-20s %-20ld %-20f %-20f\n",
|
fprintf(out, "%-10d %-20s %-20ld %-20f %-20f\n",
|
||||||
i, offset->hostname, offset->offset,
|
i, offset->hostname, offset->offset,
|
||||||
@ -440,39 +415,31 @@ do_work(struct options *options, int rank)
|
|||||||
|
|
||||||
drift_mode = options->ndrift_samples > 1 ? 1 : 0;
|
drift_mode = options->ndrift_samples > 1 ? 1 : 0;
|
||||||
|
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
if (mkpath(options->outpath, 0755) != 0) {
|
||||||
if(mkpath(options->outpath, 0755) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "mkpath(%s) failed: %s\n",
|
fprintf(stderr, "mkpath(%s) failed: %s\n",
|
||||||
options->outpath, strerror(errno));
|
options->outpath, strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(options->outpath, "w");
|
out = fopen(options->outpath, "w");
|
||||||
if(out == NULL)
|
if (out == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "fopen(%s) failed: %s\n",
|
fprintf(stderr, "fopen(%s) failed: %s\n",
|
||||||
options->outpath, strerror(errno));
|
options->outpath, strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
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);
|
table = build_offset_table(options->nsamples, rank, options->verbose);
|
||||||
|
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
if (drift_mode) {
|
||||||
if(drift_mode)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
print_drift_header(out, table);
|
print_drift_header(out, table);
|
||||||
|
|
||||||
print_drift_row(out, table);
|
print_drift_row(out, table);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print_table_detailed(out, table);
|
print_table_detailed(out, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
parson.h
3
parson.h
@ -27,8 +27,7 @@
|
|||||||
#define parson_parson_h
|
#define parson_parson_h
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
|
21
pcf.c
21
pcf.c
@ -2,12 +2,12 @@
|
|||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
#include "pcf.h"
|
#include "pcf.h"
|
||||||
#include "prv.h"
|
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
|
#include "prv.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
const char *pcf_def_header =
|
const char *pcf_def_header =
|
||||||
"DEFAULT_OPTIONS\n"
|
"DEFAULT_OPTIONS\n"
|
||||||
@ -61,8 +61,7 @@ const uint32_t pcf_def_palette[] = {
|
|||||||
GREEN,
|
GREEN,
|
||||||
YELLOW, ORANGE, PURPLE, CYAN, MAGENTA, LIME, PINK,
|
YELLOW, ORANGE, PURPLE, CYAN, MAGENTA, LIME, PINK,
|
||||||
TEAL, GREY, LAVENDER, BROWN, BEIGE, MAROON, MINT,
|
TEAL, GREY, LAVENDER, BROWN, BEIGE, MAROON, MINT,
|
||||||
OLIVE, APRICOT, NAVY, DEEPBLUE
|
OLIVE, APRICOT, NAVY, DEEPBLUE};
|
||||||
};
|
|
||||||
|
|
||||||
const uint32_t *pcf_palette = pcf_def_palette;
|
const uint32_t *pcf_palette = pcf_def_palette;
|
||||||
const int pcf_palette_len = ARRAY_LEN(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",
|
[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] = {
|
char *pcf_suffix_name[SUFFIX_MAX] = {
|
||||||
[NONE] = "",
|
[NONE] = "",
|
||||||
@ -323,8 +326,7 @@ write_colors(FILE *f, const uint32_t *palette, int n)
|
|||||||
fprintf(f, "\n\n");
|
fprintf(f, "\n\n");
|
||||||
fprintf(f, "STATES_COLOR\n");
|
fprintf(f, "STATES_COLOR\n");
|
||||||
|
|
||||||
for(i=0; i<n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
decompose_rgb(palette[i], &r, &g, &b);
|
decompose_rgb(palette[i], &r, &g, &b);
|
||||||
fprintf(f, "%-3d {%3d, %3d, %3d}\n", i, r, g, b);
|
fprintf(f, "%-3d {%3d, %3d, %3d}\n", i, r, g, b);
|
||||||
}
|
}
|
||||||
@ -398,8 +400,7 @@ pcf_open(struct pcf_file *pcf, char *path, int chantype)
|
|||||||
pcf->f = fopen(path, "w");
|
pcf->f = fopen(path, "w");
|
||||||
pcf->chantype = chantype;
|
pcf->chantype = chantype;
|
||||||
|
|
||||||
if(pcf->f == NULL)
|
if (pcf->f == NULL) {
|
||||||
{
|
|
||||||
die("cannot open PCF file '%s': %s\n",
|
die("cannot open PCF file '%s': %s\n",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
2
pcf.h
2
pcf.h
@ -4,8 +4,8 @@
|
|||||||
#ifndef OVNI_PCF_H
|
#ifndef OVNI_PCF_H
|
||||||
#define OVNI_PCF_H
|
#define OVNI_PCF_H
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAX_PCF_LABEL 512
|
#define MAX_PCF_LABEL 512
|
||||||
|
|
||||||
|
2
prv.c
2
prv.c
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
#include "prv.h"
|
#include "prv.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
4
prv.h
4
prv.h
@ -4,9 +4,9 @@
|
|||||||
#ifndef OVNI_PRV_H
|
#ifndef OVNI_PRV_H
|
||||||
#define OVNI_PRV_H
|
#define OVNI_PRV_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
prv_ev(FILE *f, int row, int64_t time, int type, int val);
|
prv_ev(FILE *f, int row, int64_t time, int type, int val);
|
||||||
|
106
sort.c
106
sort.c
@ -27,9 +27,9 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "emu.h"
|
||||||
#include "ovni.h"
|
#include "ovni.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "emu.h"
|
|
||||||
|
|
||||||
struct ring {
|
struct ring {
|
||||||
ssize_t head;
|
ssize_t head;
|
||||||
@ -54,7 +54,8 @@ struct sortplan {
|
|||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum operation_mode { SORT, CHECK };
|
enum operation_mode { SORT,
|
||||||
|
CHECK };
|
||||||
|
|
||||||
static char *tracedir = NULL;
|
static char *tracedir = NULL;
|
||||||
static enum operation_mode operation_mode = SORT;
|
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;
|
start = r->tail - 1 >= 0 ? r->tail - 1 : r->size - 1;
|
||||||
end = r->head - 1 >= 0 ? r->head - 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)
|
for (i = start; i != end; i = i - 1 < 0 ? r->size - 1 : i - 1) {
|
||||||
{
|
if (r->ev[i]->header.clock < clock) {
|
||||||
if(r->ev[i]->header.clock < clock)
|
|
||||||
{
|
|
||||||
dbg("found suitable position %ld events backwards\n",
|
dbg("found suitable position %ld events backwards\n",
|
||||||
nback);
|
nback);
|
||||||
return i;
|
return i;
|
||||||
@ -111,17 +110,13 @@ find_destination(struct ring *r, uint64_t clock)
|
|||||||
static int
|
static int
|
||||||
starts_unsorted_region(struct ovni_ev *ev)
|
starts_unsorted_region(struct ovni_ev *ev)
|
||||||
{
|
{
|
||||||
return ev->header.model == 'O' &&
|
return ev->header.model == 'O' && ev->header.category == 'U' && ev->header.value == '[';
|
||||||
ev->header.category == 'U' &&
|
|
||||||
ev->header.value == '[';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ends_unsorted_region(struct ovni_ev *ev)
|
ends_unsorted_region(struct ovni_ev *ev)
|
||||||
{
|
{
|
||||||
return ev->header.model == 'O' &&
|
return ev->header.model == 'O' && ev->header.category == 'U' && ev->header.value == ']';
|
||||||
ev->header.category == 'U' &&
|
|
||||||
ev->header.value == ']';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -179,19 +174,15 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
|
|||||||
p = src;
|
p = src;
|
||||||
q = srcbad;
|
q = srcbad;
|
||||||
|
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
ep = (struct ovni_ev *) p;
|
ep = (struct ovni_ev *) p;
|
||||||
eq = (struct ovni_ev *) q;
|
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;
|
ev = ep;
|
||||||
evsize = ovni_ev_size(ev);
|
evsize = ovni_ev_size(ev);
|
||||||
p += evsize;
|
p += evsize;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ev = eq;
|
ev = eq;
|
||||||
evsize = ovni_ev_size(ev);
|
evsize = ovni_ev_size(ev);
|
||||||
q += evsize;
|
q += evsize;
|
||||||
@ -243,8 +234,7 @@ execute_sort_plan(struct sortplan *sp)
|
|||||||
dbg("attempt to sort: start clock %ld\n", sp->bad0->header.clock);
|
dbg("attempt to sort: start clock %ld\n", sp->bad0->header.clock);
|
||||||
|
|
||||||
/* Cannot sort in one pass; just fail for now */
|
/* Cannot sort in one pass; just fail for now */
|
||||||
if((i0 = find_destination(sp->r, sp->bad0->header.clock)) < 0)
|
if ((i0 = find_destination(sp->r, sp->bad0->header.clock)) < 0) {
|
||||||
{
|
|
||||||
err("cannot find destination for region starting at clock %ld\n",
|
err("cannot find destination for region starting at clock %ld\n",
|
||||||
sp->bad0->header.clock);
|
sp->bad0->header.clock);
|
||||||
|
|
||||||
@ -299,39 +289,28 @@ stream_winsort(struct ovni_stream *stream, struct ring *r)
|
|||||||
size_t empty_regions = 0;
|
size_t empty_regions = 0;
|
||||||
size_t updated = 0;
|
size_t updated = 0;
|
||||||
|
|
||||||
while(stream->active)
|
while (stream->active) {
|
||||||
{
|
|
||||||
ovni_load_next_event(stream);
|
ovni_load_next_event(stream);
|
||||||
ev = stream->cur_ev;
|
ev = stream->cur_ev;
|
||||||
|
|
||||||
if(st == 'S' && starts_unsorted_region(ev))
|
if (st == 'S' && starts_unsorted_region(ev)) {
|
||||||
{
|
|
||||||
st = 'U';
|
st = 'U';
|
||||||
}
|
} else if (st == 'U') {
|
||||||
else if(st == 'U')
|
|
||||||
{
|
|
||||||
/* Ensure that we have at least one unsorted
|
/* Ensure that we have at least one unsorted
|
||||||
* event inside the section */
|
* event inside the section */
|
||||||
if(ends_unsorted_region(ev))
|
if (ends_unsorted_region(ev)) {
|
||||||
{
|
|
||||||
empty_regions++;
|
empty_regions++;
|
||||||
st = 'S';
|
st = 'S';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
st = 'X';
|
st = 'X';
|
||||||
sp.bad0 = ev;
|
sp.bad0 = ev;
|
||||||
}
|
}
|
||||||
}
|
} else if (st == 'X') {
|
||||||
else if(st == 'X')
|
if (ends_unsorted_region(ev)) {
|
||||||
{
|
|
||||||
if(ends_unsorted_region(ev))
|
|
||||||
{
|
|
||||||
updated = 1;
|
updated = 1;
|
||||||
sp.next = ev;
|
sp.next = ev;
|
||||||
dbg("executing sort plan for stream tid=%d\n", stream->tid);
|
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",
|
err("sort failed for stream tid=%d\n",
|
||||||
stream->tid);
|
stream->tid);
|
||||||
return -1;
|
return -1;
|
||||||
@ -370,14 +349,12 @@ stream_check(struct ovni_stream *stream)
|
|||||||
uint64_t last_clock = ev->header.clock;
|
uint64_t last_clock = ev->header.clock;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
while(stream->active)
|
while (stream->active) {
|
||||||
{
|
|
||||||
ovni_load_next_event(stream);
|
ovni_load_next_event(stream);
|
||||||
ev = stream->cur_ev;
|
ev = stream->cur_ev;
|
||||||
uint64_t cur_clock = ovni_ev_get_clock(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",
|
err("backwards jump in time %ld -> %ld for stream tid=%d\n",
|
||||||
last_clock, cur_clock, stream->tid);
|
last_clock, cur_clock, stream->tid);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -403,24 +380,18 @@ process_trace(struct ovni_trace *trace)
|
|||||||
if (ring.ev == NULL)
|
if (ring.ev == NULL)
|
||||||
die("malloc failed: %s\n", strerror(errno));
|
die("malloc failed: %s\n", strerror(errno));
|
||||||
|
|
||||||
for(i=0; i<trace->nstreams; i++)
|
for (i = 0; i < trace->nstreams; i++) {
|
||||||
{
|
|
||||||
stream = &trace->stream[i];
|
stream = &trace->stream[i];
|
||||||
if(operation_mode == SORT)
|
if (operation_mode == SORT) {
|
||||||
{
|
|
||||||
dbg("sorting stream tid=%d\n", stream->tid);
|
dbg("sorting stream tid=%d\n", stream->tid);
|
||||||
if(stream_winsort(stream, &ring) != 0)
|
if (stream_winsort(stream, &ring) != 0) {
|
||||||
{
|
|
||||||
err("sort stream tid=%d failed\n", stream->tid);
|
err("sort stream tid=%d failed\n", stream->tid);
|
||||||
/* When sorting, return at the first
|
/* When sorting, return at the first
|
||||||
* attempt */
|
* attempt */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (stream_check(stream) != 0) {
|
||||||
{
|
|
||||||
if(stream_check(stream) != 0)
|
|
||||||
{
|
|
||||||
err("stream tid=%d is not sorted\n", stream->tid);
|
err("stream tid=%d is not sorted\n", stream->tid);
|
||||||
/* When checking, report all errors and
|
/* When checking, report all errors and
|
||||||
* then fail */
|
* then fail */
|
||||||
@ -431,14 +402,10 @@ process_trace(struct ovni_trace *trace)
|
|||||||
|
|
||||||
free(ring.ev);
|
free(ring.ev);
|
||||||
|
|
||||||
if(operation_mode == CHECK)
|
if (operation_mode == CHECK) {
|
||||||
{
|
if (ret == 0) {
|
||||||
if(ret == 0)
|
|
||||||
{
|
|
||||||
err("all streams sorted\n");
|
err("all streams sorted\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
err("streams NOT sorted\n");
|
err("streams NOT sorted\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -476,10 +443,8 @@ parse_args(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "c")) != -1)
|
while ((opt = getopt(argc, argv, "c")) != -1) {
|
||||||
{
|
switch (opt) {
|
||||||
switch(opt)
|
|
||||||
{
|
|
||||||
case 'c':
|
case 'c':
|
||||||
operation_mode = CHECK;
|
operation_mode = CHECK;
|
||||||
break;
|
break;
|
||||||
@ -488,8 +453,7 @@ parse_args(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(optind >= argc)
|
if (optind >= argc) {
|
||||||
{
|
|
||||||
err("missing tracedir\n");
|
err("missing tracedir\n");
|
||||||
usage(argc, argv);
|
usage(argc, argv);
|
||||||
}
|
}
|
||||||
@ -497,7 +461,8 @@ parse_args(int argc, char *argv[])
|
|||||||
tracedir = argv[optind];
|
tracedir = argv[optind];
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct ovni_trace *trace;
|
struct ovni_trace *trace;
|
||||||
@ -506,8 +471,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
trace = calloc(1, sizeof(struct ovni_trace));
|
trace = calloc(1, sizeof(struct ovni_trace));
|
||||||
|
|
||||||
if(trace == NULL)
|
if (trace == NULL) {
|
||||||
{
|
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,14 @@ main(void)
|
|||||||
instr_nanos6_type_create(typeid);
|
instr_nanos6_type_create(typeid);
|
||||||
|
|
||||||
/* Create and run the tasks, one nested into another */
|
/* 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_handle_task_enter();
|
||||||
instr_nanos6_task_create_and_execute(i + 1, typeid);
|
instr_nanos6_task_create_and_execute(i + 1, typeid);
|
||||||
usleep(500);
|
usleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End the tasks in the opposite order */
|
/* 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_end(i + 1);
|
||||||
instr_nanos6_task_body_exit();
|
instr_nanos6_task_body_exit();
|
||||||
instr_nanos6_handle_task_exit();
|
instr_nanos6_handle_task_exit();
|
||||||
|
@ -17,8 +17,7 @@ main(void)
|
|||||||
for (int i = 0; i < ntypes; i++)
|
for (int i = 0; i < ntypes; i++)
|
||||||
instr_nanos6_type_create(i + 1);
|
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);
|
instr_nanos6_task_create_and_execute(i + 1, (i % ntypes) + 1);
|
||||||
usleep(500);
|
usleep(500);
|
||||||
instr_nanos6_task_end(i + 1);
|
instr_nanos6_task_end(i + 1);
|
||||||
|
@ -33,4 +33,3 @@ main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,4 +27,3 @@ main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ main(void)
|
|||||||
for (int i = 0; i < ntypes; i++)
|
for (int i = 0; i < ntypes; i++)
|
||||||
instr_nosv_type_create(i + 1);
|
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_create(i + 1, (i % ntypes) + 1);
|
||||||
instr_nosv_task_execute(i + 1);
|
instr_nosv_task_execute(i + 1);
|
||||||
usleep(500);
|
usleep(500);
|
||||||
@ -29,4 +28,3 @@ main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,25 +4,24 @@
|
|||||||
#define _POSIX_C_SOURCE 200112L
|
#define _POSIX_C_SOURCE 200112L
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <limits.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <linux/limits.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
init(void)
|
init(void)
|
||||||
{
|
{
|
||||||
char hostname[HOST_NAME_MAX];
|
char hostname[HOST_NAME_MAX];
|
||||||
|
|
||||||
if(gethostname(hostname, HOST_NAME_MAX) != 0)
|
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
|
||||||
{
|
|
||||||
perror("gethostname failed");
|
perror("gethostname failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -32,7 +31,8 @@ init(void)
|
|||||||
ovni_add_cpu(0, 0);
|
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};
|
struct ovni_ev ev = {0};
|
||||||
ovni_ev_set_mcv(&ev, "O$$");
|
ovni_ev_set_mcv(&ev, "O$$");
|
||||||
@ -42,13 +42,13 @@ static void emit(uint8_t *buf, size_t size)
|
|||||||
|
|
||||||
#define NRUNS 50
|
#define NRUNS 50
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
size_t payload_size;
|
size_t payload_size;
|
||||||
uint8_t *payload_buf;
|
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");
|
perror("setenv failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -59,21 +59,18 @@ int main(void)
|
|||||||
payload_size = 1024 * 1024;
|
payload_size = 1024 * 1024;
|
||||||
payload_buf = calloc(1, payload_size);
|
payload_buf = calloc(1, payload_size);
|
||||||
|
|
||||||
if(!payload_buf)
|
if (!payload_buf) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
double *times = calloc(sizeof(double), NRUNS);
|
double *times = calloc(sizeof(double), NRUNS);
|
||||||
if(times == NULL)
|
if (times == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i < NRUNS; i++)
|
for (int i = 0; i < NRUNS; i++) {
|
||||||
{
|
|
||||||
emit(payload_buf, payload_size);
|
emit(payload_buf, payload_size);
|
||||||
double t0 = (double) ovni_clock_now();
|
double t0 = (double) ovni_clock_now();
|
||||||
ovni_flush();
|
ovni_flush();
|
||||||
|
@ -4,25 +4,24 @@
|
|||||||
#define _POSIX_C_SOURCE 200112L
|
#define _POSIX_C_SOURCE 200112L
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <limits.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <linux/limits.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
init(void)
|
init(void)
|
||||||
{
|
{
|
||||||
char hostname[HOST_NAME_MAX];
|
char hostname[HOST_NAME_MAX];
|
||||||
|
|
||||||
if(gethostname(hostname, HOST_NAME_MAX) != 0)
|
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
|
||||||
{
|
|
||||||
perror("gethostname failed");
|
perror("gethostname failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -32,7 +31,8 @@ init(void)
|
|||||||
ovni_add_cpu(0, 0);
|
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};
|
struct ovni_ev ev = {0};
|
||||||
ovni_ev_set_mcv(&ev, "O$$");
|
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);
|
ovni_ev_jumbo_emit(&ev, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
size_t payload_size;
|
size_t payload_size;
|
||||||
uint8_t *payload_buf;
|
uint8_t *payload_buf;
|
||||||
@ -50,8 +51,7 @@ int main(void)
|
|||||||
payload_size = (size_t) (0.9 * (double) OVNI_MAX_EV_BUF);
|
payload_size = (size_t) (0.9 * (double) OVNI_MAX_EV_BUF);
|
||||||
payload_buf = calloc(1, payload_size);
|
payload_buf = calloc(1, payload_size);
|
||||||
|
|
||||||
if(!payload_buf)
|
if (!payload_buf) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -15,7 +15,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static void fail(const char *msg)
|
static void
|
||||||
|
fail(const char *msg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
abort();
|
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)
|
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};
|
struct ovni_ev ev = {0};
|
||||||
|
|
||||||
@ -47,7 +49,8 @@ static inline void instr_thread_end(void)
|
|||||||
ovni_flush();
|
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];
|
char hostname[HOST_NAME_MAX];
|
||||||
|
|
||||||
@ -61,8 +64,7 @@ static inline void instr_start(int rank, int nranks)
|
|||||||
ovni_thread_init(gettid());
|
ovni_thread_init(gettid());
|
||||||
|
|
||||||
/* Only the rank 0 inform about all CPUs */
|
/* Only the rank 0 inform about all CPUs */
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
|
||||||
/* Fake nranks cpus */
|
/* Fake nranks cpus */
|
||||||
for (int i = 0; i < nranks; i++)
|
for (int i = 0; i < nranks; i++)
|
||||||
ovni_add_cpu(i, 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);
|
instr_thread_execute(curcpu, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void instr_end(void)
|
static inline void
|
||||||
|
instr_end(void)
|
||||||
{
|
{
|
||||||
instr_thread_end();
|
instr_thread_end();
|
||||||
ovni_thread_free();
|
ovni_thread_free();
|
||||||
@ -132,7 +135,8 @@ task(int32_t id, uint32_t typeid, int us)
|
|||||||
ovni_ev_emit(&ev);
|
ovni_ev_emit(&ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
int rank = atoi(getenv("OVNI_RANK"));
|
int rank = atoi(getenv("OVNI_RANK"));
|
||||||
int nranks = atoi(getenv("OVNI_NRANKS"));
|
int nranks = atoi(getenv("OVNI_NRANKS"));
|
||||||
@ -150,4 +154,3 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -16,7 +16,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static void fail(const char *msg)
|
static void
|
||||||
|
fail(const char *msg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
abort();
|
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)
|
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};
|
struct ovni_ev ev = {0};
|
||||||
|
|
||||||
@ -48,7 +50,8 @@ static inline void instr_thread_end(void)
|
|||||||
ovni_flush();
|
ovni_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void instr_start(int rank)
|
static inline void
|
||||||
|
instr_start(int rank)
|
||||||
{
|
{
|
||||||
cpu_set_t mask;
|
cpu_set_t mask;
|
||||||
char hostname[HOST_NAME_MAX];
|
char hostname[HOST_NAME_MAX];
|
||||||
@ -65,12 +68,9 @@ static inline void instr_start(int rank)
|
|||||||
ovni_thread_init(gettid());
|
ovni_thread_init(gettid());
|
||||||
|
|
||||||
/* Only the rank 0 inform about all CPUs */
|
/* Only the rank 0 inform about all CPUs */
|
||||||
if(rank == 0)
|
if (rank == 0) {
|
||||||
{
|
for (i = 0; i < CPU_SETSIZE; i++) {
|
||||||
for(i=0; i < CPU_SETSIZE; i++)
|
if (CPU_ISSET(i, &mask)) {
|
||||||
{
|
|
||||||
if(CPU_ISSET(i, &mask))
|
|
||||||
{
|
|
||||||
last_phy = i;
|
last_phy = i;
|
||||||
|
|
||||||
if (rank == 0)
|
if (rank == 0)
|
||||||
@ -90,14 +90,16 @@ static inline void instr_start(int rank)
|
|||||||
instr_thread_execute(curcpu, -1, 0);
|
instr_thread_execute(curcpu, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void instr_end(void)
|
static inline void
|
||||||
|
instr_end(void)
|
||||||
{
|
{
|
||||||
instr_thread_end();
|
instr_thread_end();
|
||||||
ovni_thread_free();
|
ovni_thread_free();
|
||||||
ovni_proc_fini();
|
ovni_proc_fini();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
int rank = atoi(getenv("OVNI_RANK"));
|
int rank = atoi(getenv("OVNI_RANK"));
|
||||||
// int nranks = atoi(getenv("OVNI_NRANKS"));
|
// int nranks = atoi(getenv("OVNI_NRANKS"));
|
||||||
@ -110,4 +112,3 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
#pragma oss task if (0)
|
#pragma oss task if (0)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
#pragma oss task
|
#pragma oss task
|
||||||
{
|
{
|
||||||
|
@ -40,11 +40,11 @@ do_run(void)
|
|||||||
do_task(t);
|
do_task(t);
|
||||||
|
|
||||||
/* Wait for all tasks to fill the handle */
|
/* 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 */
|
/* 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)
|
if (handle[t] == NULL)
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
@ -54,7 +54,8 @@ do_run(void)
|
|||||||
#pragma oss taskwait
|
#pragma oss taskwait
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_ncpus(void)
|
static int
|
||||||
|
get_ncpus(void)
|
||||||
{
|
{
|
||||||
return (int) nanos6_get_num_cpus();
|
return (int) nanos6_get_num_cpus();
|
||||||
}
|
}
|
||||||
@ -66,8 +67,7 @@ main(void)
|
|||||||
|
|
||||||
handle = calloc(ntasks, sizeof(void *));
|
handle = calloc(ntasks, sizeof(void *));
|
||||||
|
|
||||||
if(handle == NULL)
|
if (handle == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
{
|
main(void)
|
||||||
for(int i = 0; i < 5000; i++)
|
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < 5000; i++) {
|
||||||
#pragma oss task
|
#pragma oss task
|
||||||
{
|
{
|
||||||
for(volatile long j = 0; j < 10000L; j++)
|
for (volatile long j = 0; j < 10000L; j++) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
#pragma oss task
|
#pragma oss task
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
#pragma oss task for
|
#pragma oss task for
|
||||||
for (int i = 0; i < 1024; i++)
|
for (int i = 0; i < 1024; i++)
|
||||||
|
@ -3,18 +3,20 @@
|
|||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <nosv.h>
|
#include <nosv.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main(void)
|
||||||
{
|
{
|
||||||
nosv_init();
|
nosv_init();
|
||||||
|
|
||||||
nosv_task_type_t type;
|
nosv_task_type_t type;
|
||||||
if (nosv_type_init(&type, NULL, NULL, NULL, "adopted", NULL,
|
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");
|
die("nosv_type_init failed\n");
|
||||||
|
|
||||||
nosv_task_t task;
|
nosv_task_t task;
|
||||||
|
212
trace.c
212
trace.c
@ -6,20 +6,19 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#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 <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
|
static int
|
||||||
find_dir_prefix_str(const char *dirname, const char *prefix, const char **str)
|
find_dir_prefix_str(const char *dirname, const char *prefix, const char **str)
|
||||||
@ -66,8 +65,7 @@ count_dir_prefix(DIR *dir, const char *prefix)
|
|||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
size_t n = 0;
|
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)
|
if (find_dir_prefix_str(dirent->d_name, prefix, NULL) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -88,8 +86,7 @@ load_thread(struct ovni_ethread *thread, struct ovni_eproc *proc, int index, int
|
|||||||
thread->state = TH_ST_UNKNOWN;
|
thread->state = TH_ST_UNKNOWN;
|
||||||
thread->proc = proc;
|
thread->proc = proc;
|
||||||
|
|
||||||
if(strlen(filepath) >= PATH_MAX)
|
if (strlen(filepath) >= PATH_MAX) {
|
||||||
{
|
|
||||||
err("filepath too large: %s\n", filepath);
|
err("filepath too large: %s\n", filepath);
|
||||||
return -1;
|
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");
|
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);
|
proc->rank = (int) json_number(rank_val);
|
||||||
*rank_enabled = 1;
|
*rank_enabled = 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
proc->rank = -1;
|
proc->rank = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,36 +129,31 @@ check_metadata_version(struct ovni_eproc *proc)
|
|||||||
die("check_metadata_version: json_value_get_object() failed\n");
|
die("check_metadata_version: json_value_get_object() failed\n");
|
||||||
|
|
||||||
JSON_Value *version_val = json_object_get_value(meta, "version");
|
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",
|
die("process %d is missing attribute \"version\" in metadata\n",
|
||||||
proc->pid);
|
proc->pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int version = (int) json_number(version_val);
|
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",
|
die("pid %d: metadata version mismatch %d (expected %d)\n",
|
||||||
proc->pid, version,
|
proc->pid, version,
|
||||||
OVNI_METADATA_VERSION);
|
OVNI_METADATA_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_Value *mversion_val = json_object_get_value(meta, "model_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",
|
die("process %d is missing attribute \"model_version\" in metadata\n",
|
||||||
proc->pid);
|
proc->pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mversion = json_string(mversion_val);
|
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",
|
die("pid %d: metadata model version mismatch '%s' (expected '%s')\n",
|
||||||
proc->pid, mversion,
|
proc->pid, mversion,
|
||||||
OVNI_MODEL_VERSION);
|
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->gindex = total_procs++;
|
||||||
proc->loom = loom;
|
proc->loom = loom;
|
||||||
|
|
||||||
if(snprintf(path, PATH_MAX, "%s/%s", procdir, "metadata.json") >=
|
if (snprintf(path, PATH_MAX, "%s/%s", procdir, "metadata.json") >= PATH_MAX) {
|
||||||
PATH_MAX)
|
|
||||||
{
|
|
||||||
err("snprintf: path too large: %s\n", procdir);
|
err("snprintf: path too large: %s\n", procdir);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
proc->meta = json_parse_file_with_comments(path);
|
proc->meta = json_parse_file_with_comments(path);
|
||||||
if(proc->meta == NULL)
|
if (proc->meta == NULL) {
|
||||||
{
|
|
||||||
err("error loading metadata from %s\n", path);
|
err("error loading metadata from %s\n", path);
|
||||||
return -1;
|
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 */
|
/* The appid is populated from the metadata */
|
||||||
load_proc_metadata(proc, &loom->rank_enabled);
|
load_proc_metadata(proc, &loom->rank_enabled);
|
||||||
|
|
||||||
if((dir = opendir(procdir)) == NULL)
|
if ((dir = opendir(procdir)) == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "opendir %s failed: %s\n",
|
fprintf(stderr, "opendir %s failed: %s\n",
|
||||||
procdir, strerror(errno));
|
procdir, strerror(errno));
|
||||||
return -1;
|
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");
|
proc->nthreads = count_dir_prefix(dir, "thread");
|
||||||
|
|
||||||
if(proc->nthreads <= 0)
|
if (proc->nthreads <= 0) {
|
||||||
{
|
|
||||||
err("cannot find any thread for process %d\n",
|
err("cannot find any thread for process %d\n",
|
||||||
proc->pid);
|
proc->pid);
|
||||||
return -1;
|
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));
|
proc->thread = calloc(proc->nthreads, sizeof(struct ovni_ethread));
|
||||||
|
|
||||||
if(proc->thread == NULL)
|
if (proc->thread == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int *tids;
|
int *tids;
|
||||||
|
|
||||||
if((tids = calloc(proc->nthreads, sizeof(int))) == NULL)
|
if ((tids = calloc(proc->nthreads, sizeof(int))) == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed\n");
|
perror("calloc failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
|
|
||||||
for(size_t i = 0; i < proc->nthreads; )
|
for (size_t i = 0; i < proc->nthreads;) {
|
||||||
{
|
|
||||||
dirent = readdir(dir);
|
dirent = readdir(dir);
|
||||||
|
|
||||||
if(dirent == NULL)
|
if (dirent == NULL) {
|
||||||
{
|
|
||||||
err("inconsistent: readdir returned NULL\n");
|
err("inconsistent: readdir returned NULL\n");
|
||||||
return -1;
|
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 */
|
/* Sort threads by ascending TID */
|
||||||
qsort(tids, proc->nthreads, sizeof(int), compare_int);
|
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];
|
int tid = tids[i];
|
||||||
|
|
||||||
if(snprintf(path, PATH_MAX, "%s/thread.%d", procdir, tid) >=
|
if (snprintf(path, PATH_MAX, "%s/thread.%d", procdir, tid) >= PATH_MAX) {
|
||||||
PATH_MAX)
|
|
||||||
{
|
|
||||||
err("snprintf: path too large: %s\n", procdir);
|
err("snprintf: path too large: %s\n", procdir);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -302,8 +279,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
|
|
||||||
if((dir = opendir(loomdir)) == NULL)
|
if ((dir = opendir(loomdir)) == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "opendir %s failed: %s\n",
|
fprintf(stderr, "opendir %s failed: %s\n",
|
||||||
loomdir, strerror(errno));
|
loomdir, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -312,8 +288,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
loom->rank_enabled = 0;
|
loom->rank_enabled = 0;
|
||||||
loom->nprocs = count_dir_prefix(dir, "proc");
|
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",
|
err("cannot find any process directory in loom %s\n",
|
||||||
loom->hostname);
|
loom->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
@ -321,8 +296,7 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
|
|
||||||
loom->proc = calloc(loom->nprocs, sizeof(struct ovni_eproc));
|
loom->proc = calloc(loom->nprocs, sizeof(struct ovni_eproc));
|
||||||
|
|
||||||
if(loom->proc == NULL)
|
if (loom->proc == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -330,15 +304,13 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while((dirent = readdir(dir)) != NULL)
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
{
|
|
||||||
if (find_dir_prefix_int(dirent->d_name, "proc", &pid) != 0)
|
if (find_dir_prefix_int(dirent->d_name, "proc", &pid) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sprintf(path, "%s/%s", loomdir, dirent->d_name);
|
sprintf(path, "%s/%s", loomdir, dirent->d_name);
|
||||||
|
|
||||||
if(i >= loom->nprocs)
|
if (i >= loom->nprocs) {
|
||||||
{
|
|
||||||
err("more process than expected\n");
|
err("more process than expected\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -347,11 +319,9 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i != loom->nprocs)
|
if (i != loom->nprocs) {
|
||||||
{
|
|
||||||
err("unexpected number of processes\n");
|
err("unexpected number of processes\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -359,13 +329,10 @@ load_loom(struct ovni_loom *loom, char *loomdir)
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
/* Ensure all process have the rank, if enabled in any */
|
/* Ensure all process have the rank, if enabled in any */
|
||||||
if(loom->rank_enabled)
|
if (loom->rank_enabled) {
|
||||||
{
|
for (i = 0; i < loom->nprocs; i++) {
|
||||||
for(i = 0; i < loom->nprocs; i++)
|
|
||||||
{
|
|
||||||
struct ovni_eproc *proc = &loom->proc[i];
|
struct ovni_eproc *proc = &loom->proc[i];
|
||||||
if(proc->rank < 0)
|
if (proc->rank < 0) {
|
||||||
{
|
|
||||||
die("process %d is missing the rank\n",
|
die("process %d is missing the rank\n",
|
||||||
proc->pid);
|
proc->pid);
|
||||||
}
|
}
|
||||||
@ -388,8 +355,7 @@ loom_to_host(const char *loom_name, char *host, int n)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
/* Copy until dot or end */
|
/* Copy until dot or end */
|
||||||
if (loom_name[i] != '.' && loom_name[i] != '\0')
|
if (loom_name[i] != '.' && loom_name[i] != '\0')
|
||||||
host[i] = loom_name[i];
|
host[i] = loom_name[i];
|
||||||
@ -408,24 +374,21 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
|
|||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
if((dir = opendir(tracedir)) == NULL)
|
if ((dir = opendir(tracedir)) == NULL) {
|
||||||
{
|
|
||||||
err("opendir %s failed: %s\n", tracedir, strerror(errno));
|
err("opendir %s failed: %s\n", tracedir, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace->nlooms = count_dir_prefix(dir, "loom");
|
trace->nlooms = count_dir_prefix(dir, "loom");
|
||||||
|
|
||||||
if(trace->nlooms == 0)
|
if (trace->nlooms == 0) {
|
||||||
{
|
|
||||||
err("cannot find any loom in %s\n", tracedir);
|
err("cannot find any loom in %s\n", tracedir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace->loom = calloc(trace->nlooms, sizeof(struct ovni_loom));
|
trace->loom = calloc(trace->nlooms, sizeof(struct ovni_loom));
|
||||||
|
|
||||||
if(trace->loom == NULL)
|
if (trace->loom == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed\n");
|
perror("calloc failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -435,25 +398,21 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
|
|||||||
size_t l = 0;
|
size_t l = 0;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
|
|
||||||
while((dirent = readdir(dir)) != NULL)
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
{
|
|
||||||
struct ovni_loom *loom = &trace->loom[l];
|
struct ovni_loom *loom = &trace->loom[l];
|
||||||
const char *loom_name;
|
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 */
|
/* Ignore other files in tracedir */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(l >= trace->nlooms)
|
if (l >= trace->nlooms) {
|
||||||
{
|
|
||||||
err("extra loom detected\n");
|
err("extra loom detected\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the complete loom directory name to looms */
|
/* 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);
|
err("error: loom name %s too long\n", dirent->d_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -467,13 +426,11 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
|
|||||||
qsort(trace->loom, trace->nlooms, sizeof(struct ovni_loom),
|
qsort(trace->loom, trace->nlooms, sizeof(struct ovni_loom),
|
||||||
compare_looms);
|
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];
|
struct ovni_loom *loom = &trace->loom[i];
|
||||||
const char *name = NULL;
|
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);
|
err("error: mismatch for loom %s\n", loom->dname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -481,8 +438,8 @@ ovni_load_trace(struct ovni_trace *trace, char *tracedir)
|
|||||||
loom_to_host(name, loom->hostname, sizeof(loom->hostname));
|
loom_to_host(name, loom->hostname, sizeof(loom->hostname));
|
||||||
|
|
||||||
if (snprintf(loom->path, PATH_MAX, "%s/%s",
|
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",
|
err("error: loom path %s/%s too long\n",
|
||||||
tracedir, loom->dname);
|
tracedir, loom->dname);
|
||||||
return -1;
|
return -1;
|
||||||
@ -500,8 +457,7 @@ check_stream_header(struct ovni_stream *stream)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
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",
|
err("stream %d: incomplete stream header\n",
|
||||||
stream->tid);
|
stream->tid);
|
||||||
return -1;
|
return -1;
|
||||||
@ -510,8 +466,7 @@ check_stream_header(struct ovni_stream *stream)
|
|||||||
struct ovni_stream_header *h =
|
struct ovni_stream_header *h =
|
||||||
(struct ovni_stream_header *) stream->buf;
|
(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];
|
char magic[5];
|
||||||
memcpy(magic, h->magic, 4);
|
memcpy(magic, h->magic, 4);
|
||||||
magic[4] = '\0';
|
magic[4] = '\0';
|
||||||
@ -520,8 +475,7 @@ check_stream_header(struct ovni_stream *stream)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(h->version != OVNI_STREAM_VERSION)
|
if (h->version != OVNI_STREAM_VERSION) {
|
||||||
{
|
|
||||||
err("stream %d: stream version mismatch %u (expected %u)\n",
|
err("stream %d: stream version mismatch %u (expected %u)\n",
|
||||||
stream->tid, h->version, OVNI_STREAM_VERSION);
|
stream->tid, h->version, OVNI_STREAM_VERSION);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -534,15 +488,13 @@ static int
|
|||||||
load_stream_fd(struct ovni_stream *stream, int fd)
|
load_stream_fd(struct ovni_stream *stream, int fd)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(fstat(fd, &st) < 0)
|
if (fstat(fd, &st) < 0) {
|
||||||
{
|
|
||||||
perror("fstat failed");
|
perror("fstat failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Error because it doesn't have the header */
|
/* 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);
|
err("stream %d is empty\n", stream->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -550,8 +502,7 @@ load_stream_fd(struct ovni_stream *stream, int fd)
|
|||||||
int prot = PROT_READ | PROT_WRITE;
|
int prot = PROT_READ | PROT_WRITE;
|
||||||
stream->buf = mmap(NULL, st.st_size, prot, MAP_PRIVATE, fd, 0);
|
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");
|
perror("mmap failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -566,8 +517,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if((fd = open(thread->tracefile, O_RDWR)) == -1)
|
if ((fd = open(thread->tracefile, O_RDWR)) == -1) {
|
||||||
{
|
|
||||||
perror("open failed");
|
perror("open failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -575,8 +525,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
|
|||||||
if (load_stream_fd(stream, fd) != 0)
|
if (load_stream_fd(stream, fd) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(check_stream_header(stream) != 0)
|
if (check_stream_header(stream) != 0) {
|
||||||
{
|
|
||||||
err("stream %d: bad header\n", stream->tid);
|
err("stream %d: bad header\n", stream->tid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -589,8 +538,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
|
|||||||
stream->active = 1;
|
stream->active = 1;
|
||||||
|
|
||||||
/* No need to keep the fd open */
|
/* No need to keep the fd open */
|
||||||
if(close(fd))
|
if (close(fd)) {
|
||||||
{
|
|
||||||
perror("close failed");
|
perror("close failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -610,14 +558,11 @@ ovni_load_streams(struct ovni_trace *trace)
|
|||||||
|
|
||||||
trace->nstreams = 0;
|
trace->nstreams = 0;
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
|
||||||
loom = &trace->loom[i];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
for(k=0; k<proc->nthreads; k++)
|
for (k = 0; k < proc->nthreads; k++) {
|
||||||
{
|
|
||||||
trace->nstreams++;
|
trace->nstreams++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -625,22 +570,18 @@ ovni_load_streams(struct ovni_trace *trace)
|
|||||||
|
|
||||||
trace->stream = calloc(trace->nstreams, sizeof(struct ovni_stream));
|
trace->stream = calloc(trace->nstreams, sizeof(struct ovni_stream));
|
||||||
|
|
||||||
if(trace->stream == NULL)
|
if (trace->stream == NULL) {
|
||||||
{
|
|
||||||
perror("calloc failed");
|
perror("calloc failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err("loaded %ld streams\n", trace->nstreams);
|
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];
|
loom = &trace->loom[i];
|
||||||
for(j=0; j<loom->nprocs; j++)
|
for (j = 0; j < loom->nprocs; j++) {
|
||||||
{
|
|
||||||
proc = &loom->proc[j];
|
proc = &loom->proc[j];
|
||||||
for(k=0; k<proc->nthreads; k++)
|
for (k = 0; k < proc->nthreads; k++) {
|
||||||
{
|
|
||||||
thread = &proc->thread[k];
|
thread = &proc->thread[k];
|
||||||
stream = &trace->stream[s++];
|
stream = &trace->stream[s++];
|
||||||
|
|
||||||
@ -652,12 +593,10 @@ ovni_load_streams(struct ovni_trace *trace)
|
|||||||
stream->offset = 0;
|
stream->offset = 0;
|
||||||
stream->cur_ev = NULL;
|
stream->cur_ev = NULL;
|
||||||
|
|
||||||
if(load_stream_buf(stream, thread) != 0)
|
if (load_stream_buf(stream, thread) != 0) {
|
||||||
{
|
|
||||||
err("load_stream_buf failed\n");
|
err("load_stream_buf failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -668,8 +607,7 @@ ovni_load_streams(struct ovni_trace *trace)
|
|||||||
void
|
void
|
||||||
ovni_free_streams(struct ovni_trace *trace)
|
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];
|
struct ovni_stream *stream = &trace->stream[i];
|
||||||
if (munmap(stream->buf, stream->size) != 0)
|
if (munmap(stream->buf, stream->size) != 0)
|
||||||
die("munmap stream failed: %s\n", strerror(errno));
|
die("munmap stream failed: %s\n", strerror(errno));
|
||||||
@ -683,10 +621,8 @@ ovni_free_trace(struct ovni_trace *trace)
|
|||||||
{
|
{
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for(i=0; i<trace->nlooms; i++)
|
for (i = 0; i < trace->nlooms; i++) {
|
||||||
{
|
for (j = 0; j < trace->loom[i].nprocs; j++) {
|
||||||
for(j=0; j<trace->loom[i].nprocs; j++)
|
|
||||||
{
|
|
||||||
free(trace->loom[i].proc[j].thread);
|
free(trace->loom[i].proc[j].thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,8 +635,7 @@ ovni_free_trace(struct ovni_trace *trace)
|
|||||||
int
|
int
|
||||||
ovni_load_next_event(struct ovni_stream *stream)
|
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");
|
dbg("stream is inactive, cannot load more events\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -714,8 +649,7 @@ ovni_load_next_event(struct ovni_stream *stream)
|
|||||||
die("ovni_load_next_event: stream offset exceeds size\n");
|
die("ovni_load_next_event: stream offset exceeds size\n");
|
||||||
|
|
||||||
/* We have reached the end */
|
/* We have reached the end */
|
||||||
if(stream->offset == stream->size)
|
if (stream->offset == stream->size) {
|
||||||
{
|
|
||||||
stream->active = 0;
|
stream->active = 0;
|
||||||
stream->cur_ev = NULL;
|
stream->cur_ev = NULL;
|
||||||
dbg("stream %d runs out of events\n", stream->tid);
|
dbg("stream %d runs out of events\n", stream->tid);
|
||||||
|
2
trace.h
2
trace.h
@ -4,8 +4,8 @@
|
|||||||
#ifndef OVNI_TRACE_H
|
#ifndef OVNI_TRACE_H
|
||||||
#define OVNI_TRACE_H
|
#define OVNI_TRACE_H
|
||||||
|
|
||||||
#include "ovni.h"
|
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
|
#include "ovni.h"
|
||||||
|
|
||||||
int ovni_load_next_event(struct ovni_stream *stream);
|
int ovni_load_next_event(struct ovni_stream *stream);
|
||||||
|
|
||||||
|
161
uthash.h
161
uthash.h
@ -26,9 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#define UTHASH_VERSION 2.1.0
|
#define UTHASH_VERSION 2.1.0
|
||||||
|
|
||||||
#include <string.h> /* memcmp, memset, strlen */
|
|
||||||
#include <stddef.h> /* ptrdiff_t */
|
#include <stddef.h> /* ptrdiff_t */
|
||||||
#include <stdlib.h> /* exit */
|
#include <stdlib.h> /* exit */
|
||||||
|
#include <string.h> /* memcmp, memset, strlen */
|
||||||
|
|
||||||
/* These macros use decltype or the earlier __typeof GNU extension.
|
/* These macros use decltype or the earlier __typeof GNU extension.
|
||||||
As decltype is only available in newer compilers (VS2010 or gcc 4.3+
|
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 */
|
/* malloc failures can be recovered from */
|
||||||
|
|
||||||
#ifndef uthash_nonfatal_oom
|
#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
|
#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
|
#define IF_HASH_NONFATAL_OOM(x) x
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -243,8 +248,7 @@ do {
|
|||||||
uthash_free((head)->hh.tbl->buckets, \
|
uthash_free((head)->hh.tbl->buckets, \
|
||||||
HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \
|
HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \
|
||||||
uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \
|
uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \
|
||||||
} \
|
}) \
|
||||||
) \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -519,7 +523,11 @@ do {
|
|||||||
* This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
|
* This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
|
||||||
*/
|
*/
|
||||||
#ifdef HASH_DEBUG
|
#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) \
|
#define HASH_FSCK(hh, head, where) \
|
||||||
do { \
|
do { \
|
||||||
struct UT_hash_handle *_thh; \
|
struct UT_hash_handle *_thh; \
|
||||||
@ -645,15 +653,33 @@ do {
|
|||||||
|
|
||||||
#define HASH_JEN_MIX(a, b, c) \
|
#define HASH_JEN_MIX(a, b, c) \
|
||||||
do { \
|
do { \
|
||||||
a -= b; a -= c; a ^= ( c >> 13 ); \
|
a -= b; \
|
||||||
b -= c; b -= a; b ^= ( a << 8 ); \
|
a -= c; \
|
||||||
c -= a; c -= b; c ^= ( b >> 13 ); \
|
a ^= (c >> 13); \
|
||||||
a -= b; a -= c; a ^= ( c >> 12 ); \
|
b -= c; \
|
||||||
b -= c; b -= a; b ^= ( a << 16 ); \
|
b -= a; \
|
||||||
c -= a; c -= b; c ^= ( b >> 5 ); \
|
b ^= (a << 8); \
|
||||||
a -= b; a -= c; a ^= ( c >> 3 ); \
|
c -= a; \
|
||||||
b -= c; b -= a; b ^= ( a << 10 ); \
|
c -= b; \
|
||||||
c -= a; c -= b; c ^= ( b >> 15 ); \
|
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)
|
} while (0)
|
||||||
|
|
||||||
#define HASH_JEN(key, keylen, hashv) \
|
#define HASH_JEN(key, keylen, hashv) \
|
||||||
@ -681,17 +707,28 @@ do {
|
|||||||
} \
|
} \
|
||||||
hashv += (unsigned) (keylen); \
|
hashv += (unsigned) (keylen); \
|
||||||
switch (_hj_k) { \
|
switch (_hj_k) { \
|
||||||
case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); /* FALLTHROUGH */ \
|
case 11: \
|
||||||
case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); /* FALLTHROUGH */ \
|
hashv += ((unsigned) _hj_key[10] << 24); /* FALLTHROUGH */ \
|
||||||
case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); /* FALLTHROUGH */ \
|
case 10: \
|
||||||
case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); /* FALLTHROUGH */ \
|
hashv += ((unsigned) _hj_key[9] << 16); /* FALLTHROUGH */ \
|
||||||
case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); /* FALLTHROUGH */ \
|
case 9: \
|
||||||
case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); /* FALLTHROUGH */ \
|
hashv += ((unsigned) _hj_key[8] << 8); /* FALLTHROUGH */ \
|
||||||
case 5: _hj_j += _hj_key[4]; /* FALLTHROUGH */ \
|
case 8: \
|
||||||
case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); /* FALLTHROUGH */ \
|
_hj_j += ((unsigned) _hj_key[7] << 24); /* FALLTHROUGH */ \
|
||||||
case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); /* FALLTHROUGH */ \
|
case 7: \
|
||||||
case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); /* FALLTHROUGH */ \
|
_hj_j += ((unsigned) _hj_key[6] << 16); /* FALLTHROUGH */ \
|
||||||
case 1: _hj_i += _hj_key[0]; \
|
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); \
|
HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -727,16 +764,19 @@ do {
|
|||||||
\
|
\
|
||||||
/* Handle end cases */ \
|
/* Handle end cases */ \
|
||||||
switch (_sfh_rem) { \
|
switch (_sfh_rem) { \
|
||||||
case 3: hashv += get16bits (_sfh_key); \
|
case 3: \
|
||||||
|
hashv += get16bits(_sfh_key); \
|
||||||
hashv ^= hashv << 16; \
|
hashv ^= hashv << 16; \
|
||||||
hashv ^= (uint32_t) (_sfh_key[sizeof(uint16_t)]) << 18; \
|
hashv ^= (uint32_t) (_sfh_key[sizeof(uint16_t)]) << 18; \
|
||||||
hashv += hashv >> 11; \
|
hashv += hashv >> 11; \
|
||||||
break; \
|
break; \
|
||||||
case 2: hashv += get16bits (_sfh_key); \
|
case 2: \
|
||||||
|
hashv += get16bits(_sfh_key); \
|
||||||
hashv ^= hashv << 11; \
|
hashv ^= hashv << 11; \
|
||||||
hashv += hashv >> 17; \
|
hashv += hashv >> 17; \
|
||||||
break; \
|
break; \
|
||||||
case 1: hashv += *_sfh_key; \
|
case 1: \
|
||||||
|
hashv += *_sfh_key; \
|
||||||
hashv ^= hashv << 10; \
|
hashv ^= hashv << 10; \
|
||||||
hashv += hashv >> 1; \
|
hashv += hashv >> 1; \
|
||||||
} \
|
} \
|
||||||
@ -777,10 +817,7 @@ do {
|
|||||||
#define MUR_TWO_TWO(p) ((((*WP(p)) & 0xffff0000) >> 16) | (((*(WP(p) + 1)) & 0x0000ffff) << 16))
|
#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))
|
#define MUR_ONE_THREE(p) ((((*WP(p)) & 0xff000000) >> 24) | (((*(WP(p) + 1)) & 0x00ffffff) << 8))
|
||||||
#endif
|
#endif
|
||||||
#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \
|
#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))))
|
||||||
(MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \
|
|
||||||
(MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \
|
|
||||||
MUR_ONE_THREE(p))))
|
|
||||||
#endif
|
#endif
|
||||||
#define MUR_ROTL32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
|
#define MUR_ROTL32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
|
||||||
#define MUR_FMIX(_h) \
|
#define MUR_FMIX(_h) \
|
||||||
@ -816,10 +853,14 @@ do { \
|
|||||||
_mur_tail = (const uint8_t *) (_mur_data + (_mur_nblocks * 4)); \
|
_mur_tail = (const uint8_t *) (_mur_data + (_mur_nblocks * 4)); \
|
||||||
_mur_k1 = 0; \
|
_mur_k1 = 0; \
|
||||||
switch ((keylen) &3U) { \
|
switch ((keylen) &3U) { \
|
||||||
case 0: break; \
|
case 0: \
|
||||||
case 3: _mur_k1 ^= (uint32_t)_mur_tail[2] << 16; /* FALLTHROUGH */ \
|
break; \
|
||||||
case 2: _mur_k1 ^= (uint32_t)_mur_tail[1] << 8; /* FALLTHROUGH */ \
|
case 3: \
|
||||||
case 1: _mur_k1 ^= (uint32_t)_mur_tail[0]; \
|
_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_c1; \
|
||||||
_mur_k1 = MUR_ROTL32(_mur_k1, 15); \
|
_mur_k1 = MUR_ROTL32(_mur_k1, 15); \
|
||||||
_mur_k1 *= _mur_c2; \
|
_mur_k1 *= _mur_c2; \
|
||||||
@ -870,8 +911,7 @@ do {
|
|||||||
IF_HASH_NONFATAL_OOM( \
|
IF_HASH_NONFATAL_OOM( \
|
||||||
if (oomed) { \
|
if (oomed) { \
|
||||||
HASH_DEL_IN_BKT(head, addhh); \
|
HASH_DEL_IN_BKT(head, addhh); \
|
||||||
} \
|
}) \
|
||||||
) \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -934,8 +974,7 @@ do {
|
|||||||
uthash_bzero(_he_new_buckets, \
|
uthash_bzero(_he_new_buckets, \
|
||||||
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
|
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
|
||||||
(tbl)->ideal_chain_maxlen = \
|
(tbl)->ideal_chain_maxlen = \
|
||||||
((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \
|
((tbl)->num_items >> ((tbl)->log2_num_buckets + 1U)) + ((((tbl)->num_items & (((tbl)->num_buckets * 2U) - 1U)) != 0U) ? 1U : 0U); \
|
||||||
((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \
|
|
||||||
(tbl)->nonideal_items = 0; \
|
(tbl)->nonideal_items = 0; \
|
||||||
for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) { \
|
for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) { \
|
||||||
_he_thh = (tbl)->buckets[_he_bkt_i].hh_head; \
|
_he_thh = (tbl)->buckets[_he_bkt_i].hh_head; \
|
||||||
@ -962,8 +1001,7 @@ do {
|
|||||||
(tbl)->num_buckets *= 2U; \
|
(tbl)->num_buckets *= 2U; \
|
||||||
(tbl)->log2_num_buckets++; \
|
(tbl)->log2_num_buckets++; \
|
||||||
(tbl)->buckets = _he_new_buckets; \
|
(tbl)->buckets = _he_new_buckets; \
|
||||||
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? \
|
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) : 0U; \
|
||||||
((tbl)->ineff_expands+1U) : 0U; \
|
|
||||||
if ((tbl)->ineff_expands > 1U) { \
|
if ((tbl)->ineff_expands > 1U) { \
|
||||||
(tbl)->noexpand = 1; \
|
(tbl)->noexpand = 1; \
|
||||||
uthash_noexpand_fyi(tbl); \
|
uthash_noexpand_fyi(tbl); \
|
||||||
@ -997,8 +1035,7 @@ do {
|
|||||||
_hs_psize = 0; \
|
_hs_psize = 0; \
|
||||||
for (_hs_i = 0; _hs_i < _hs_insize; ++_hs_i) { \
|
for (_hs_i = 0; _hs_i < _hs_insize; ++_hs_i) { \
|
||||||
_hs_psize++; \
|
_hs_psize++; \
|
||||||
_hs_q = ((_hs_q->next != NULL) ? \
|
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
||||||
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
|
||||||
if (_hs_q == NULL) { \
|
if (_hs_q == NULL) { \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
@ -1007,41 +1044,35 @@ do {
|
|||||||
while ((_hs_psize != 0U) || ((_hs_qsize != 0U) && (_hs_q != NULL))) { \
|
while ((_hs_psize != 0U) || ((_hs_qsize != 0U) && (_hs_q != NULL))) { \
|
||||||
if (_hs_psize == 0U) { \
|
if (_hs_psize == 0U) { \
|
||||||
_hs_e = _hs_q; \
|
_hs_e = _hs_q; \
|
||||||
_hs_q = ((_hs_q->next != NULL) ? \
|
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
||||||
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
|
||||||
_hs_qsize--; \
|
_hs_qsize--; \
|
||||||
} else if ((_hs_qsize == 0U) || (_hs_q == NULL)) { \
|
} else if ((_hs_qsize == 0U) || (_hs_q == NULL)) { \
|
||||||
_hs_e = _hs_p; \
|
_hs_e = _hs_p; \
|
||||||
if (_hs_p != NULL) { \
|
if (_hs_p != NULL) { \
|
||||||
_hs_p = ((_hs_p->next != NULL) ? \
|
_hs_p = ((_hs_p->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
|
||||||
HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
|
|
||||||
} \
|
} \
|
||||||
_hs_psize--; \
|
_hs_psize--; \
|
||||||
} else if ((cmpfcn( \
|
} else if ((cmpfcn( \
|
||||||
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \
|
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \
|
||||||
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)) \
|
DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)))) \
|
||||||
)) <= 0) { \
|
<= 0) { \
|
||||||
_hs_e = _hs_p; \
|
_hs_e = _hs_p; \
|
||||||
if (_hs_p != NULL) { \
|
if (_hs_p != NULL) { \
|
||||||
_hs_p = ((_hs_p->next != NULL) ? \
|
_hs_p = ((_hs_p->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
|
||||||
HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \
|
|
||||||
} \
|
} \
|
||||||
_hs_psize--; \
|
_hs_psize--; \
|
||||||
} else { \
|
} else { \
|
||||||
_hs_e = _hs_q; \
|
_hs_e = _hs_q; \
|
||||||
_hs_q = ((_hs_q->next != NULL) ? \
|
_hs_q = ((_hs_q->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
||||||
HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \
|
|
||||||
_hs_qsize--; \
|
_hs_qsize--; \
|
||||||
} \
|
} \
|
||||||
if (_hs_tail != NULL) { \
|
if (_hs_tail != NULL) { \
|
||||||
_hs_tail->next = ((_hs_e != NULL) ? \
|
_hs_tail->next = ((_hs_e != NULL) ? ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL); \
|
||||||
ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL); \
|
|
||||||
} else { \
|
} else { \
|
||||||
_hs_list = _hs_e; \
|
_hs_list = _hs_e; \
|
||||||
} \
|
} \
|
||||||
if (_hs_e != NULL) { \
|
if (_hs_e != NULL) { \
|
||||||
_hs_e->prev = ((_hs_tail != NULL) ? \
|
_hs_e->prev = ((_hs_tail != NULL) ? ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL); \
|
||||||
ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL); \
|
|
||||||
} \
|
} \
|
||||||
_hs_tail = _hs_e; \
|
_hs_tail = _hs_e; \
|
||||||
} \
|
} \
|
||||||
@ -1097,8 +1128,7 @@ do {
|
|||||||
uthash_nonfatal_oom(_elt); \
|
uthash_nonfatal_oom(_elt); \
|
||||||
(dst) = NULL; \
|
(dst) = NULL; \
|
||||||
continue; \
|
continue; \
|
||||||
} \
|
}) \
|
||||||
) \
|
|
||||||
} else { \
|
} else { \
|
||||||
_dst_hh->tbl = (dst)->hh_dst.tbl; \
|
_dst_hh->tbl = (dst)->hh_dst.tbl; \
|
||||||
} \
|
} \
|
||||||
@ -1112,8 +1142,7 @@ do {
|
|||||||
_dst_hh->tbl = NULL; \
|
_dst_hh->tbl = NULL; \
|
||||||
uthash_nonfatal_oom(_elt); \
|
uthash_nonfatal_oom(_elt); \
|
||||||
continue; \
|
continue; \
|
||||||
} \
|
}) \
|
||||||
) \
|
|
||||||
HASH_BLOOM_ADD(_dst_hh->tbl, _dst_hh->hashv); \
|
HASH_BLOOM_ADD(_dst_hh->tbl, _dst_hh->hashv); \
|
||||||
_last_elt = _elt; \
|
_last_elt = _elt; \
|
||||||
_last_elt_hh = _dst_hh; \
|
_last_elt_hh = _dst_hh; \
|
||||||
@ -1137,10 +1166,8 @@ do {
|
|||||||
|
|
||||||
#define HASH_OVERHEAD(hh, head) \
|
#define HASH_OVERHEAD(hh, head) \
|
||||||
(((head) != NULL) ? ( \
|
(((head) != NULL) ? ( \
|
||||||
(size_t)(((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \
|
(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))) \
|
||||||
((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + \
|
: 0U)
|
||||||
sizeof(UT_hash_table) + \
|
|
||||||
(HASH_BLOOM_BYTELEN))) : 0U)
|
|
||||||
|
|
||||||
#ifdef NO_DECLTYPE
|
#ifdef NO_DECLTYPE
|
||||||
#define HASH_ITER(hh, head, el, tmp) \
|
#define HASH_ITER(hh, head, el, tmp) \
|
||||||
|
335
utlist.h
335
utlist.h
@ -81,13 +81,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifdef NO_DECLTYPE
|
#ifdef NO_DECLTYPE
|
||||||
#define IF_NO_DECLTYPE(x) x
|
#define IF_NO_DECLTYPE(x) x
|
||||||
#define LDECLTYPE(x) char *
|
#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_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_PREV(elt,list,prev) ((char*)((list)->prev)) */
|
||||||
#define UTLIST_PREVASGN(elt,list,to,prev) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
|
#define UTLIST_PREVASGN(elt, list, to, prev) \
|
||||||
#define UTLIST_RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
|
{ \
|
||||||
#define UTLIST_CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
|
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
|
#else
|
||||||
#define IF_NO_DECLTYPE(x)
|
#define IF_NO_DECLTYPE(x)
|
||||||
#define UTLIST_SV(elt, list)
|
#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) \
|
#define LL_SORT2(list, cmp, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(list) _ls_p; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_q; \
|
_ls_p; \
|
||||||
LDECLTYPE(list) _ls_e; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_tail; \
|
_ls_q; \
|
||||||
|
LDECLTYPE(list) \
|
||||||
|
_ls_e; \
|
||||||
|
LDECLTYPE(list) \
|
||||||
|
_ls_tail; \
|
||||||
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
|
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
|
||||||
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
|
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
|
||||||
if (list) { \
|
if (list) { \
|
||||||
@ -128,26 +153,47 @@ do {
|
|||||||
_ls_psize = 0; \
|
_ls_psize = 0; \
|
||||||
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
|
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
|
||||||
_ls_psize++; \
|
_ls_psize++; \
|
||||||
UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
|
UTLIST_SV(_ls_q, list); \
|
||||||
if (!_ls_q) break; \
|
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
if (!_ls_q) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
_ls_qsize = _ls_insize; \
|
_ls_qsize = _ls_insize; \
|
||||||
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
|
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
|
||||||
if (_ls_psize == 0) { \
|
if (_ls_psize == 0) { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
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) { \
|
} else if (_ls_qsize == 0 || !_ls_q) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
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) { \
|
} else if (cmp(_ls_p, _ls_q) <= 0) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
UTLIST_SV(_ls_p, list); \
|
||||||
|
_ls_p = \
|
||||||
|
UTLIST_NEXT(_ls_p, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_psize--; \
|
||||||
} else { \
|
} else { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
UTLIST_SV(_ls_q, list); \
|
||||||
|
_ls_q = \
|
||||||
|
UTLIST_NEXT(_ls_q, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_qsize--; \
|
||||||
} \
|
} \
|
||||||
if (_ls_tail) { \
|
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 { \
|
} else { \
|
||||||
UTLIST_CASTASGN(list, _ls_e); \
|
UTLIST_CASTASGN(list, _ls_e); \
|
||||||
} \
|
} \
|
||||||
@ -156,7 +202,9 @@ do {
|
|||||||
_ls_p = _ls_q; \
|
_ls_p = _ls_q; \
|
||||||
} \
|
} \
|
||||||
if (_ls_tail) { \
|
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) { \
|
if (_ls_nmerges <= 1) { \
|
||||||
_ls_looping = 0; \
|
_ls_looping = 0; \
|
||||||
@ -172,10 +220,14 @@ do {
|
|||||||
|
|
||||||
#define DL_SORT2(list, cmp, prev, next) \
|
#define DL_SORT2(list, cmp, prev, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(list) _ls_p; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_q; \
|
_ls_p; \
|
||||||
LDECLTYPE(list) _ls_e; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_tail; \
|
_ls_q; \
|
||||||
|
LDECLTYPE(list) \
|
||||||
|
_ls_e; \
|
||||||
|
LDECLTYPE(list) \
|
||||||
|
_ls_tail; \
|
||||||
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
|
IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
|
||||||
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
|
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
|
||||||
if (list) { \
|
if (list) { \
|
||||||
@ -192,36 +244,61 @@ do {
|
|||||||
_ls_psize = 0; \
|
_ls_psize = 0; \
|
||||||
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
|
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
|
||||||
_ls_psize++; \
|
_ls_psize++; \
|
||||||
UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
|
UTLIST_SV(_ls_q, list); \
|
||||||
if (!_ls_q) break; \
|
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
if (!_ls_q) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
_ls_qsize = _ls_insize; \
|
_ls_qsize = _ls_insize; \
|
||||||
while ((_ls_psize > 0) || ((_ls_qsize > 0) && _ls_q)) { \
|
while ((_ls_psize > 0) || ((_ls_qsize > 0) && _ls_q)) { \
|
||||||
if (_ls_psize == 0) { \
|
if (_ls_psize == 0) { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
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)) { \
|
} else if ((_ls_qsize == 0) || (!_ls_q)) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
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) { \
|
} else if (cmp(_ls_p, _ls_q) <= 0) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
UTLIST_SV(_ls_p, list); \
|
||||||
|
_ls_p = \
|
||||||
|
UTLIST_NEXT(_ls_p, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_psize--; \
|
||||||
} else { \
|
} else { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
UTLIST_SV(_ls_q, list); \
|
||||||
|
_ls_q = \
|
||||||
|
UTLIST_NEXT(_ls_q, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_qsize--; \
|
||||||
} \
|
} \
|
||||||
if (_ls_tail) { \
|
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 { \
|
} else { \
|
||||||
UTLIST_CASTASGN(list, _ls_e); \
|
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_tail = _ls_e; \
|
||||||
} \
|
} \
|
||||||
_ls_p = _ls_q; \
|
_ls_p = _ls_q; \
|
||||||
} \
|
} \
|
||||||
UTLIST_CASTASGN((list)->prev, _ls_tail); \
|
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) { \
|
if (_ls_nmerges <= 1) { \
|
||||||
_ls_looping = 0; \
|
_ls_looping = 0; \
|
||||||
} \
|
} \
|
||||||
@ -235,12 +312,18 @@ do {
|
|||||||
|
|
||||||
#define CDL_SORT2(list, cmp, prev, next) \
|
#define CDL_SORT2(list, cmp, prev, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(list) _ls_p; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_q; \
|
_ls_p; \
|
||||||
LDECLTYPE(list) _ls_e; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _ls_tail; \
|
_ls_q; \
|
||||||
LDECLTYPE(list) _ls_oldhead; \
|
LDECLTYPE(list) \
|
||||||
LDECLTYPE(list) _tmp; \
|
_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; \
|
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
|
||||||
if (list) { \
|
if (list) { \
|
||||||
_ls_insize = 1; \
|
_ls_insize = 1; \
|
||||||
@ -264,40 +347,71 @@ do {
|
|||||||
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
|
_ls_q = UTLIST_NEXT(_ls_q, list, next); \
|
||||||
} \
|
} \
|
||||||
UTLIST_RS(list); \
|
UTLIST_RS(list); \
|
||||||
if (!_ls_q) break; \
|
if (!_ls_q) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
_ls_qsize = _ls_insize; \
|
_ls_qsize = _ls_insize; \
|
||||||
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
|
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
|
||||||
if (_ls_psize == 0) { \
|
if (_ls_psize == 0) { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
UTLIST_SV(_ls_q, list); \
|
||||||
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
|
_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) { \
|
} else if (_ls_qsize == 0 || !_ls_q) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
UTLIST_SV(_ls_p, list); \
|
||||||
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
|
_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) { \
|
} else if (cmp(_ls_p, _ls_q) <= 0) { \
|
||||||
_ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
|
_ls_e = _ls_p; \
|
||||||
UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
|
UTLIST_SV(_ls_p, list); \
|
||||||
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
|
_ls_p = \
|
||||||
|
UTLIST_NEXT(_ls_p, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_psize--; \
|
||||||
|
if (_ls_p == _ls_oldhead) { \
|
||||||
|
_ls_p = NULL; \
|
||||||
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
_ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
|
_ls_e = _ls_q; \
|
||||||
UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
|
UTLIST_SV(_ls_q, list); \
|
||||||
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
|
_ls_q = \
|
||||||
|
UTLIST_NEXT(_ls_q, list, next); \
|
||||||
|
UTLIST_RS(list); \
|
||||||
|
_ls_qsize--; \
|
||||||
|
if (_ls_q == _ls_oldhead) { \
|
||||||
|
_ls_q = NULL; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
if (_ls_tail) { \
|
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 { \
|
} else { \
|
||||||
UTLIST_CASTASGN(list, _ls_e); \
|
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_tail = _ls_e; \
|
||||||
} \
|
} \
|
||||||
_ls_p = _ls_q; \
|
_ls_p = _ls_q; \
|
||||||
} \
|
} \
|
||||||
UTLIST_CASTASGN((list)->prev, _ls_tail); \
|
UTLIST_CASTASGN((list)->prev, _ls_tail); \
|
||||||
UTLIST_CASTASGN(_tmp, list); \
|
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) { \
|
if (_ls_nmerges <= 1) { \
|
||||||
_ls_looping = 0; \
|
_ls_looping = 0; \
|
||||||
} \
|
} \
|
||||||
@ -323,10 +437,13 @@ do {
|
|||||||
|
|
||||||
#define LL_CONCAT2(head1, head2, next) \
|
#define LL_CONCAT2(head1, head2, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head1) _tmp; \
|
LDECLTYPE(head1) \
|
||||||
|
_tmp; \
|
||||||
if (head1) { \
|
if (head1) { \
|
||||||
_tmp = (head1); \
|
_tmp = (head1); \
|
||||||
while (_tmp->next) { _tmp = _tmp->next; } \
|
while (_tmp->next) { \
|
||||||
|
_tmp = _tmp->next; \
|
||||||
|
} \
|
||||||
_tmp->next = (head2); \
|
_tmp->next = (head2); \
|
||||||
} else { \
|
} else { \
|
||||||
(head1) = (head2); \
|
(head1) = (head2); \
|
||||||
@ -338,11 +455,14 @@ do {
|
|||||||
|
|
||||||
#define LL_APPEND2(head, add, next) \
|
#define LL_APPEND2(head, add, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
(add)->next = NULL; \
|
(add)->next = NULL; \
|
||||||
if (head) { \
|
if (head) { \
|
||||||
_tmp = (head); \
|
_tmp = (head); \
|
||||||
while (_tmp->next) { _tmp = _tmp->next; } \
|
while (_tmp->next) { \
|
||||||
|
_tmp = _tmp->next; \
|
||||||
|
} \
|
||||||
_tmp->next = (add); \
|
_tmp->next = (add); \
|
||||||
} else { \
|
} else { \
|
||||||
(head) = (add); \
|
(head) = (add); \
|
||||||
@ -354,7 +474,8 @@ do {
|
|||||||
|
|
||||||
#define LL_INSERT_INORDER2(head, add, cmp, next) \
|
#define LL_INSERT_INORDER2(head, add, cmp, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
if (head) { \
|
if (head) { \
|
||||||
LL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
LL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
||||||
LL_APPEND_ELEM2(head, _tmp, add, next); \
|
LL_APPEND_ELEM2(head, _tmp, add, next); \
|
||||||
@ -385,7 +506,8 @@ do {
|
|||||||
|
|
||||||
#define LL_DELETE2(head, del, next) \
|
#define LL_DELETE2(head, del, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
if ((head) == (del)) { \
|
if ((head) == (del)) { \
|
||||||
(head) = (head)->next; \
|
(head) = (head)->next; \
|
||||||
} else { \
|
} else { \
|
||||||
@ -400,12 +522,15 @@ do {
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LL_COUNT(head, el, counter) \
|
#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) \
|
#define LL_COUNT2(head, el, counter, next) \
|
||||||
do { \
|
do { \
|
||||||
(counter) = 0; \
|
(counter) = 0; \
|
||||||
LL_FOREACH2(head,el,next) { ++(counter); } \
|
LL_FOREACH2(head, el, next) \
|
||||||
|
{ \
|
||||||
|
++(counter); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LL_FOREACH(head, el) \
|
#define LL_FOREACH(head, el) \
|
||||||
@ -425,8 +550,10 @@ do {
|
|||||||
|
|
||||||
#define LL_SEARCH_SCALAR2(head, out, field, val, next) \
|
#define LL_SEARCH_SCALAR2(head, out, field, val, next) \
|
||||||
do { \
|
do { \
|
||||||
LL_FOREACH2(head,out,next) { \
|
LL_FOREACH2(head, out, next) \
|
||||||
if ((out)->field == (val)) break; \
|
{ \
|
||||||
|
if ((out)->field == (val)) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -435,14 +562,17 @@ do {
|
|||||||
|
|
||||||
#define LL_SEARCH2(head, out, elt, cmp, next) \
|
#define LL_SEARCH2(head, out, elt, cmp, next) \
|
||||||
do { \
|
do { \
|
||||||
LL_FOREACH2(head,out,next) { \
|
LL_FOREACH2(head, out, next) \
|
||||||
if ((cmp(out,elt))==0) break; \
|
{ \
|
||||||
|
if ((cmp(out, elt)) == 0) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LL_REPLACE_ELEM2(head, el, add, next) \
|
#define LL_REPLACE_ELEM2(head, el, add, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
(add)->next = (el)->next; \
|
(add)->next = (el)->next; \
|
||||||
if ((head) == (el)) { \
|
if ((head) == (el)) { \
|
||||||
(head) = (add); \
|
(head) = (add); \
|
||||||
@ -463,7 +593,8 @@ do {
|
|||||||
#define LL_PREPEND_ELEM2(head, el, add, next) \
|
#define LL_PREPEND_ELEM2(head, el, add, next) \
|
||||||
do { \
|
do { \
|
||||||
if (el) { \
|
if (el) { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
(add)->next = (el); \
|
(add)->next = (el); \
|
||||||
if ((head) == (el)) { \
|
if ((head) == (el)) { \
|
||||||
(head) = (add); \
|
(head) = (add); \
|
||||||
@ -479,7 +610,7 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
LL_APPEND2(head, add, next); \
|
LL_APPEND2(head, add, next); \
|
||||||
} \
|
} \
|
||||||
} while (0) \
|
} while (0)
|
||||||
|
|
||||||
#define LL_PREPEND_ELEM(head, el, add) \
|
#define LL_PREPEND_ELEM(head, el, add) \
|
||||||
LL_PREPEND_ELEM2(head, el, add, next)
|
LL_PREPEND_ELEM2(head, el, add, next)
|
||||||
@ -492,7 +623,7 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
LL_PREPEND2(head, add, next); \
|
LL_PREPEND2(head, add, next); \
|
||||||
} \
|
} \
|
||||||
} while (0) \
|
} while (0)
|
||||||
|
|
||||||
#define LL_APPEND_ELEM(head, el, add) \
|
#define LL_APPEND_ELEM(head, el, add) \
|
||||||
LL_APPEND_ELEM2(head, el, add, next)
|
LL_APPEND_ELEM2(head, el, add, next)
|
||||||
@ -506,7 +637,9 @@ do {
|
|||||||
char *_tmp; \
|
char *_tmp; \
|
||||||
if (head1) { \
|
if (head1) { \
|
||||||
_tmp = (char *) (head1); \
|
_tmp = (char *) (head1); \
|
||||||
while ((head1)->next) { (head1) = (head1)->next; } \
|
while ((head1)->next) { \
|
||||||
|
(head1) = (head1)->next; \
|
||||||
|
} \
|
||||||
(head1)->next = (head2); \
|
(head1)->next = (head2); \
|
||||||
UTLIST_RS(head1); \
|
UTLIST_RS(head1); \
|
||||||
} else { \
|
} else { \
|
||||||
@ -519,7 +652,9 @@ do {
|
|||||||
do { \
|
do { \
|
||||||
if (head) { \
|
if (head) { \
|
||||||
(add)->next = head; /* use add->next as a temp variable */ \
|
(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); \
|
(add)->next->next = (add); \
|
||||||
} else { \
|
} else { \
|
||||||
(head) = (add); \
|
(head) = (add); \
|
||||||
@ -597,7 +732,7 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
LL_APPEND2(head, add, next); \
|
LL_APPEND2(head, add, next); \
|
||||||
} \
|
} \
|
||||||
} while (0) \
|
} while (0)
|
||||||
|
|
||||||
#endif /* NO_DECLTYPE */
|
#endif /* NO_DECLTYPE */
|
||||||
|
|
||||||
@ -641,7 +776,8 @@ do {
|
|||||||
|
|
||||||
#define DL_INSERT_INORDER2(head, add, cmp, prev, next) \
|
#define DL_INSERT_INORDER2(head, add, cmp, prev, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
if (head) { \
|
if (head) { \
|
||||||
DL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
DL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
||||||
DL_APPEND_ELEM2(head, _tmp, add, prev, next); \
|
DL_APPEND_ELEM2(head, _tmp, add, prev, next); \
|
||||||
@ -673,7 +809,8 @@ do {
|
|||||||
|
|
||||||
#define DL_CONCAT2(head1, head2, prev, next) \
|
#define DL_CONCAT2(head1, head2, prev, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head1) _tmp; \
|
LDECLTYPE(head1) \
|
||||||
|
_tmp; \
|
||||||
if (head2) { \
|
if (head2) { \
|
||||||
if (head1) { \
|
if (head1) { \
|
||||||
UTLIST_CASTASGN(_tmp, (head2)->prev); \
|
UTLIST_CASTASGN(_tmp, (head2)->prev); \
|
||||||
@ -707,12 +844,15 @@ do {
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define DL_COUNT(head, el, counter) \
|
#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) \
|
#define DL_COUNT2(head, el, counter, next) \
|
||||||
do { \
|
do { \
|
||||||
(counter) = 0; \
|
(counter) = 0; \
|
||||||
DL_FOREACH2(head,el,next) { ++(counter); } \
|
DL_FOREACH2(head, el, next) \
|
||||||
|
{ \
|
||||||
|
++(counter); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define DL_FOREACH(head, el) \
|
#define DL_FOREACH(head, el) \
|
||||||
@ -774,7 +914,7 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
DL_APPEND2(head, add, prev, next); \
|
DL_APPEND2(head, add, prev, next); \
|
||||||
} \
|
} \
|
||||||
} while (0) \
|
} while (0)
|
||||||
|
|
||||||
#define DL_PREPEND_ELEM(head, el, add) \
|
#define DL_PREPEND_ELEM(head, el, add) \
|
||||||
DL_PREPEND_ELEM2(head, el, add, prev, next)
|
DL_PREPEND_ELEM2(head, el, add, prev, next)
|
||||||
@ -793,7 +933,7 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
DL_PREPEND2(head, add, prev, next); \
|
DL_PREPEND2(head, add, prev, next); \
|
||||||
} \
|
} \
|
||||||
} while (0) \
|
} while (0)
|
||||||
|
|
||||||
#define DL_APPEND_ELEM(head, el, add) \
|
#define DL_APPEND_ELEM(head, el, add) \
|
||||||
DL_APPEND_ELEM2(head, el, add, prev, next)
|
DL_APPEND_ELEM2(head, el, add, prev, next)
|
||||||
@ -873,7 +1013,8 @@ do {
|
|||||||
|
|
||||||
#define CDL_INSERT_INORDER2(head, add, cmp, prev, next) \
|
#define CDL_INSERT_INORDER2(head, add, cmp, prev, next) \
|
||||||
do { \
|
do { \
|
||||||
LDECLTYPE(head) _tmp; \
|
LDECLTYPE(head) \
|
||||||
|
_tmp; \
|
||||||
if (head) { \
|
if (head) { \
|
||||||
CDL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
CDL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
|
||||||
CDL_APPEND_ELEM2(head, _tmp, add, prev, next); \
|
CDL_APPEND_ELEM2(head, _tmp, add, prev, next); \
|
||||||
@ -910,17 +1051,21 @@ do {
|
|||||||
} else { \
|
} else { \
|
||||||
(del)->next->prev = (del)->prev; \
|
(del)->next->prev = (del)->prev; \
|
||||||
(del)->prev->next = (del)->next; \
|
(del)->prev->next = (del)->next; \
|
||||||
if ((del) == (head)) (head)=(del)->next; \
|
if ((del) == (head)) \
|
||||||
|
(head) = (del)->next; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CDL_COUNT(head, el, counter) \
|
#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) \
|
#define CDL_COUNT2(head, el, counter, next) \
|
||||||
do { \
|
do { \
|
||||||
(counter) = 0; \
|
(counter) = 0; \
|
||||||
CDL_FOREACH2(head,el,next) { ++(counter); } \
|
CDL_FOREACH2(head, el, next) \
|
||||||
|
{ \
|
||||||
|
++(counter); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CDL_FOREACH(head, el) \
|
#define CDL_FOREACH(head, el) \
|
||||||
@ -942,8 +1087,10 @@ do {
|
|||||||
|
|
||||||
#define CDL_SEARCH_SCALAR2(head, out, field, val, next) \
|
#define CDL_SEARCH_SCALAR2(head, out, field, val, next) \
|
||||||
do { \
|
do { \
|
||||||
CDL_FOREACH2(head,out,next) { \
|
CDL_FOREACH2(head, out, next) \
|
||||||
if ((out)->field == (val)) break; \
|
{ \
|
||||||
|
if ((out)->field == (val)) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -952,8 +1099,10 @@ do {
|
|||||||
|
|
||||||
#define CDL_SEARCH2(head, out, elt, cmp, next) \
|
#define CDL_SEARCH2(head, out, elt, cmp, next) \
|
||||||
do { \
|
do { \
|
||||||
CDL_FOREACH2(head,out,next) { \
|
CDL_FOREACH2(head, out, next) \
|
||||||
if ((cmp(out,elt))==0) break; \
|
{ \
|
||||||
|
if ((cmp(out, elt)) == 0) \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user