From 8ed906348868e9b79ce0da261c44ff43a46958fe Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 1 Feb 2023 12:33:19 +0100 Subject: [PATCH] Remove emu prefix from trace and stream --- src/emu/CMakeLists.txt | 4 +-- src/emu/emu.c | 2 +- src/emu/emu.h | 6 ++-- src/emu/emu_player.c | 30 ++++++++--------- src/emu/emu_player.h | 8 ++--- src/emu/{emu_stream.c => stream.c} | 50 ++++++++++++++-------------- src/emu/{emu_stream.h => stream.h} | 26 +++++++-------- src/emu/system.c | 18 +++++----- src/emu/system.h | 10 +++--- src/emu/{emu_trace.c => trace.c} | 18 +++++----- src/emu/{emu_trace.h => trace.h} | 8 ++--- test/unit/CMakeLists.txt | 4 +-- test/unit/emu_trace.c | 14 -------- test/unit/{emu_stream.c => stream.c} | 12 +++---- test/unit/trace.c | 14 ++++++++ 15 files changed, 112 insertions(+), 112 deletions(-) rename src/emu/{emu_stream.c => stream.c} (72%) rename src/emu/{emu_stream.h => stream.h} (50%) rename src/emu/{emu_trace.c => trace.c} (79%) rename src/emu/{emu_trace.h => trace.h} (64%) delete mode 100644 test/unit/emu_trace.c rename test/unit/{emu_stream.c => stream.c} (83%) create mode 100644 test/unit/trace.c diff --git a/src/emu/CMakeLists.txt b/src/emu/CMakeLists.txt index 4d29016..bd289e6 100644 --- a/src/emu/CMakeLists.txt +++ b/src/emu/CMakeLists.txt @@ -19,8 +19,8 @@ add_library(emu STATIC emu_ev.c emu_model.c emu_player.c - emu_stream.c - emu_trace.c + stream.c + trace.c loom.c metadata.c mux.c diff --git a/src/emu/emu.c b/src/emu/emu.c index 1dc5fd2..c7b6acb 100644 --- a/src/emu/emu.c +++ b/src/emu/emu.c @@ -18,7 +18,7 @@ emu_init(struct emu *emu, int argc, char *argv[]) emu_args_init(&emu->args, argc, argv); /* Load the streams into the trace */ - if (emu_trace_load(&emu->trace, emu->args.tracedir) != 0) { + if (trace_load(&emu->trace, emu->args.tracedir) != 0) { err("cannot load trace '%s'\n", emu->args.tracedir); return -1; } diff --git a/src/emu/emu.h b/src/emu/emu.h index ab2b24c..d800b2b 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -5,7 +5,7 @@ #define EMU_H #include "bay.h" -#include "emu_trace.h" +#include "trace.h" #include "emu_args.h" #include "system.h" #include "emu_player.h" @@ -22,14 +22,14 @@ struct emu { struct bay bay; struct emu_args args; - struct emu_trace trace; + struct trace trace; struct system system; struct emu_player player; struct emu_model model; struct recorder recorder; /* Quick access */ - struct emu_stream *stream; + struct stream *stream; struct emu_ev *ev; struct thread *thread; struct proc *proc; diff --git a/src/emu/emu_player.c b/src/emu/emu_player.c index 5b46164..1eb6da7 100644 --- a/src/emu/emu_player.c +++ b/src/emu/emu_player.c @@ -15,13 +15,13 @@ static inline int stream_cmp(heap_node_t *a, heap_node_t *b) { - struct emu_stream *sa, *sb; + struct stream *sa, *sb; - sa = heap_elem(a, struct emu_stream, hh); - sb = heap_elem(b, struct emu_stream, hh); + sa = heap_elem(a, struct stream, hh); + sb = heap_elem(b, struct stream, hh); - int64_t ca = emu_stream_lastclock(sa); - int64_t cb = emu_stream_lastclock(sb); + int64_t ca = stream_lastclock(sa); + int64_t cb = stream_lastclock(sb); /* Return the opposite, so we have min-heap */ if (ca < cb) @@ -33,12 +33,12 @@ stream_cmp(heap_node_t *a, heap_node_t *b) } static int -step_stream(struct emu_player *player, struct emu_stream *stream) +step_stream(struct emu_player *player, struct stream *stream) { if (!stream->active) return +1; - int ret = emu_stream_step(stream); + int ret = stream_step(stream); if (ret < 0) { err("step_stream: cannot step stream '%s'\n", @@ -54,7 +54,7 @@ step_stream(struct emu_player *player, struct emu_stream *stream) } int -emu_player_init(struct emu_player *player, struct emu_trace *trace) +emu_player_init(struct emu_player *player, struct trace *trace) { memset(player, 0, sizeof(struct emu_player)); @@ -64,7 +64,7 @@ emu_player_init(struct emu_player *player, struct emu_trace *trace) player->stream = NULL; /* Load initial streams and events */ - struct emu_stream *stream; + struct stream *stream; DL_FOREACH(trace->streams, stream) { int ret = step_stream(player, stream); if (ret > 0) { @@ -80,7 +80,7 @@ emu_player_init(struct emu_player *player, struct emu_trace *trace) } static int -update_clocks(struct emu_player *player, struct emu_stream *stream) +update_clocks(struct emu_player *player, struct stream *stream) { /* This can happen if two events are not ordered in the stream, but the * emulator picks other events in the middle. Example: @@ -95,7 +95,7 @@ update_clocks(struct emu_player *player, struct emu_stream *stream) * 12 * ... * */ - int64_t sclock = emu_stream_lastclock(stream); + int64_t sclock = stream_lastclock(stream); if (player->first_event) { player->first_event = 0; @@ -133,7 +133,7 @@ emu_player_step(struct emu_player *player) if (node == NULL) return +1; - struct emu_stream *stream = heap_elem(node, struct emu_stream, hh); + struct stream *stream = heap_elem(node, struct stream, hh); if (stream == NULL) { err("emu_player_step: heap_elem() returned NULL\n"); @@ -147,8 +147,8 @@ emu_player_step(struct emu_player *player) player->stream = stream; - struct ovni_ev *oev = emu_stream_ev(stream); - int64_t sclock = emu_stream_evclock(stream, oev); + struct ovni_ev *oev = stream_ev(stream); + int64_t sclock = stream_evclock(stream, oev); emu_ev(&player->ev, oev, sclock, player->deltaclock); return 0; @@ -160,7 +160,7 @@ emu_player_ev(struct emu_player *player) return &player->ev; } -struct emu_stream * +struct stream * emu_player_stream(struct emu_player *player) { return player->stream; diff --git a/src/emu/emu_player.h b/src/emu/emu_player.h index 5d98525..bd9c3cf 100644 --- a/src/emu/emu_player.h +++ b/src/emu/emu_player.h @@ -4,7 +4,7 @@ #ifndef EMU_PLAYER_H #define EMU_PLAYER_H -#include "emu_trace.h" +#include "trace.h" #include "emu_ev.h" #include @@ -15,13 +15,13 @@ struct emu_player { int64_t lastclock; int64_t deltaclock; int first_event; - struct emu_stream *stream; + struct stream *stream; struct emu_ev ev; }; -int emu_player_init(struct emu_player *player, struct emu_trace *trace); +int emu_player_init(struct emu_player *player, struct trace *trace); int emu_player_step(struct emu_player *player); struct emu_ev *emu_player_ev(struct emu_player *player); -struct emu_stream *emu_player_stream(struct emu_player *player); +struct stream *emu_player_stream(struct emu_player *player); #endif /* EMU_PLAYER_H */ diff --git a/src/emu/emu_stream.c b/src/emu/stream.c similarity index 72% rename from src/emu/emu_stream.c rename to src/emu/stream.c index 9c1f1dd..075aa52 100644 --- a/src/emu/emu_stream.c +++ b/src/emu/stream.c @@ -1,7 +1,7 @@ /* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ -#include "emu_stream.h" +#include "stream.h" #include "ovni.h" #include @@ -10,7 +10,7 @@ #include static int -check_stream_header(struct emu_stream *stream) +check_stream_header(struct stream *stream) { int ret = 0; @@ -42,7 +42,7 @@ check_stream_header(struct emu_stream *stream) } static int -load_stream_fd(struct emu_stream *stream, int fd) +load_stream_fd(struct stream *stream, int fd) { struct stat st; if (fstat(fd, &st) < 0) { @@ -70,35 +70,35 @@ load_stream_fd(struct emu_stream *stream, int fd) } int -emu_stream_load(struct emu_stream *stream, const char *tracedir, const char *relpath) +stream_load(struct stream *stream, const char *tracedir, const char *relpath) { int fd; if (snprintf(stream->path, PATH_MAX, "%s/%s", tracedir, relpath) >= PATH_MAX) { - err("emu_stream_load: path too long: %s/%s\n", tracedir, relpath); + err("stream_load: path too long: %s/%s\n", tracedir, relpath); return -1; } if (snprintf(stream->relpath, PATH_MAX, "%s", relpath) >= PATH_MAX) { - err("emu_stream_load: path too long: %s\n", relpath); + err("stream_load: path too long: %s\n", relpath); return -1; } - dbg("emu_stream_load: loading %s\n", stream->relpath); + dbg("stream_load: loading %s\n", stream->relpath); if ((fd = open(stream->path, O_RDWR)) == -1) { - err("emu_stream_load: open failed: %s\n", stream->path); + err("stream_load: open failed: %s\n", stream->path); return -1; } if (load_stream_fd(stream, fd) != 0) { - err("emu_stream_load: load_stream_fd failed for stream '%s'\n", + err("stream_load: load_stream_fd failed for stream '%s'\n", stream->path); return -1; } if (check_stream_header(stream) != 0) { - err("emu_stream_load: stream '%s' has bad header\n", + err("stream_load: stream '%s' has bad header\n", stream->path); return -1; } @@ -112,7 +112,7 @@ emu_stream_load(struct emu_stream *stream, const char *tracedir, const char *rel err("warning: stream '%s' has zero events\n", stream->relpath); stream->active = 0; } else { - err("emu_stream_load: impossible, offset %ld bigger than size %ld\n", + err("stream_load: impossible, offset %ld bigger than size %ld\n", stream->offset, stream->size); return -1; } @@ -127,28 +127,28 @@ emu_stream_load(struct emu_stream *stream, const char *tracedir, const char *rel } void -emu_stream_data_set(struct emu_stream *stream, void *data) +stream_data_set(struct stream *stream, void *data) { stream->data = data; } void * -emu_stream_data_get(struct emu_stream *stream) +stream_data_get(struct stream *stream) { return stream->data; } int -emu_stream_clkoff_set(struct emu_stream *stream, int64_t clkoff) +stream_clkoff_set(struct stream *stream, int64_t clkoff) { if (stream->cur_ev) { - die("emu_stream_clkoff_set: cannot set clokoff in started stream '%s'\n", + die("stream_clkoff_set: cannot set clokoff in started stream '%s'\n", stream->relpath); return -1; } if (stream->clock_offset != 0) { - err("emu_stream_clkoff_set: stream '%s' already has a clock offset\n", + err("stream_clkoff_set: stream '%s' already has a clock offset\n", stream->relpath); return -1; } @@ -159,28 +159,28 @@ emu_stream_clkoff_set(struct emu_stream *stream, int64_t clkoff) } struct ovni_ev * -emu_stream_ev(struct emu_stream *stream) +stream_ev(struct stream *stream) { return stream->cur_ev; } int64_t -emu_stream_evclock(struct emu_stream *stream, struct ovni_ev *ev) +stream_evclock(struct stream *stream, struct ovni_ev *ev) { return (int64_t) ovni_ev_get_clock(ev) + stream->clock_offset; } int64_t -emu_stream_lastclock(struct emu_stream *stream) +stream_lastclock(struct stream *stream) { return stream->lastclock; } int -emu_stream_step(struct emu_stream *stream) +stream_step(struct stream *stream) { if (!stream->active) { - err("emu_stream_step: stream is inactive, cannot step\n"); + err("stream_step: stream is inactive, cannot step\n"); return -1; } @@ -190,7 +190,7 @@ emu_stream_step(struct emu_stream *stream) /* It cannot pass the size, otherwise we are reading garbage */ if (stream->offset > stream->size) { - err("emu_stream_step: stream offset %ld exceeds size %ld\n", + err("stream_step: stream offset %ld exceeds size %ld\n", stream->offset, stream->size); return -1; } @@ -207,13 +207,13 @@ emu_stream_step(struct emu_stream *stream) /* Ensure the event fits */ if (stream->offset + ovni_ev_size(stream->cur_ev) > stream->size) { - err("emu_stream_step: stream '%s' ends with incomplete event\n", + err("stream_step: stream '%s' ends with incomplete event\n", stream->relpath); return -1; } /* Ensure the clock grows monotonically */ - int64_t clock = emu_stream_evclock(stream, stream->cur_ev); + int64_t clock = stream_evclock(stream, stream->cur_ev); if (clock < stream->lastclock) { err("clock goes backwards %ld -> %ld in stream '%s' at offset %ld\n", stream->lastclock, @@ -228,7 +228,7 @@ emu_stream_step(struct emu_stream *stream) } double -emu_stream_progress(struct emu_stream *stream) +stream_progress(struct stream *stream) { if (stream->usize == 0) return 1.0; diff --git a/src/emu/emu_stream.h b/src/emu/stream.h similarity index 50% rename from src/emu/emu_stream.h rename to src/emu/stream.h index d05eead..4a0a7da 100644 --- a/src/emu/emu_stream.h +++ b/src/emu/stream.h @@ -9,9 +9,9 @@ #include #include -struct emu_stream; +struct stream; -struct emu_stream { +struct stream { char path[PATH_MAX]; char relpath[PATH_MAX]; /* To tracedir */ @@ -28,26 +28,26 @@ struct emu_stream { int64_t clock_offset; heap_node_t hh; - struct emu_stream *next; - struct emu_stream *prev; + struct stream *next; + struct stream *prev; struct ovni_ev *cur_ev; void *data; /* To hold system details */ }; -int emu_stream_load(struct emu_stream *stream, +int stream_load(struct stream *stream, const char *tracedir, const char *relpath); -int emu_stream_clkoff_set(struct emu_stream *stream, int64_t clock_offset); +int stream_clkoff_set(struct stream *stream, int64_t clock_offset); -double emu_stream_progress(struct emu_stream *stream); -int emu_stream_step(struct emu_stream *stream); -struct ovni_ev *emu_stream_ev(struct emu_stream *stream); -int64_t emu_stream_evclock(struct emu_stream *stream, struct ovni_ev *ev); -int64_t emu_stream_lastclock(struct emu_stream *stream); +double stream_progress(struct stream *stream); +int stream_step(struct stream *stream); +struct ovni_ev *stream_ev(struct stream *stream); +int64_t stream_evclock(struct stream *stream, struct ovni_ev *ev); +int64_t stream_lastclock(struct stream *stream); -void emu_stream_data_set(struct emu_stream *stream, void *data); -void *emu_stream_data_get(struct emu_stream *stream); +void stream_data_set(struct stream *stream, void *data); +void *stream_data_get(struct stream *stream); #endif /* EMU_STREAM_H */ diff --git a/src/emu/system.c b/src/emu/system.c index 6ca8394..b7746f3 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -137,7 +137,7 @@ create_loom(struct system *sys, const char *relpath) } static int -create_system(struct system *sys, struct emu_trace *trace) +create_system(struct system *sys, struct trace *trace) { const char *dir = trace->tracedir; @@ -149,7 +149,7 @@ create_system(struct system *sys, struct emu_trace *trace) } size_t i = 0; - for (struct emu_stream *s = trace->streams; s ; s = s->next) { + for (struct stream *s = trace->streams; s ; s = s->next) { if (!loom_matches(s->relpath)) { err("warning: ignoring unknown stream %s", s->relpath); continue; @@ -180,7 +180,7 @@ create_system(struct system *sys, struct emu_trace *trace) lpt->proc = proc; lpt->thread = thread; - emu_stream_data_set(s, lpt); + stream_data_set(s, lpt); } return 0; @@ -396,7 +396,7 @@ parse_clkoff_entry(struct loom *looms, struct clkoff_entry *entry) } static int -init_offsets(struct system *sys, struct emu_trace *trace) +init_offsets(struct system *sys, struct trace *trace) { struct clkoff *table = &sys->clkoff; int n = clkoff_count(table); @@ -419,7 +419,7 @@ init_offsets(struct system *sys, struct emu_trace *trace) } } - for (struct emu_stream *s = trace->streams; s; s = s->next) { + for (struct stream *s = trace->streams; s; s = s->next) { struct lpt *lpt = system_get_lpt(s); if (lpt == NULL) { err("cannot get stream lpt"); @@ -427,7 +427,7 @@ init_offsets(struct system *sys, struct emu_trace *trace) } int64_t offset = lpt->loom->clock_offset; - if (emu_stream_clkoff_set(s, offset) != 0) { + if (stream_clkoff_set(s, offset) != 0) { err("cannot set clock offset"); return -1; } @@ -471,7 +471,7 @@ init_end_system(struct system *sys) } int -system_init(struct system *sys, struct emu_args *args, struct emu_trace *trace) +system_init(struct system *sys, struct emu_args *args, struct trace *trace) { memset(sys, 0, sizeof(struct system)); sys->args = args; @@ -522,9 +522,9 @@ system_init(struct system *sys, struct emu_args *args, struct emu_trace *trace) } struct lpt * -system_get_lpt(struct emu_stream *stream) +system_get_lpt(struct stream *stream) { - struct lpt *lpt = emu_stream_data_get(stream); + struct lpt *lpt = stream_data_get(stream); if (lpt->stream != stream) die("inconsistent stream in lpt map"); diff --git a/src/emu/system.h b/src/emu/system.h index 61171f6..9234160 100644 --- a/src/emu/system.h +++ b/src/emu/system.h @@ -5,8 +5,8 @@ #define EMU_SYSTEM_H #include "emu_args.h" -#include "emu_trace.h" -#include "emu_stream.h" +#include "trace.h" +#include "stream.h" #include "loom.h" #include "proc.h" #include "thread.h" @@ -17,7 +17,7 @@ /* Map from stream to lpt */ struct lpt { - struct emu_stream *stream; /* Redundancy */ + struct stream *stream; /* Redundancy */ struct loom *loom; struct proc *proc; struct thread *thread; @@ -43,9 +43,9 @@ struct system { //struct model_ctx ctx; }; -int system_init(struct system *sys, struct emu_args *args, struct emu_trace *trace); +int system_init(struct system *sys, struct emu_args *args, struct trace *trace); int system_connect(struct system *sys, struct bay *bay, struct recorder *rec); -struct lpt *system_get_lpt(struct emu_stream *stream); +struct lpt *system_get_lpt(struct stream *stream); //struct emu_cpu *system_find_cpu(struct emu_loom *loom, int cpuid); //int model_ctx_set(struct model_ctx *ctx, int model, void *data); //int model_ctx_get(struct model_ctx *ctx, int model, void *data); diff --git a/src/emu/emu_trace.c b/src/emu/trace.c similarity index 79% rename from src/emu/emu_trace.c rename to src/emu/trace.c index ed8abbf..4826a93 100644 --- a/src/emu/emu_trace.c +++ b/src/emu/trace.c @@ -3,7 +3,7 @@ #define _XOPEN_SOURCE 500 -#include "emu_trace.h" +#include "trace.h" #include "utlist.h" #include #include @@ -11,19 +11,19 @@ /* See the nftw(3) manual to see why we need a global variable here: * https://pubs.opengroup.org/onlinepubs/9699919799/functions/nftw.html */ -static struct emu_trace *cur_trace = NULL; +static struct trace *cur_trace = NULL; static void -add_stream(struct emu_trace *trace, struct emu_stream *stream) +add_stream(struct trace *trace, struct stream *stream) { DL_APPEND(trace->streams, stream); trace->nstreams++; } static int -load_stream(struct emu_trace *trace, const char *path) +load_stream(struct trace *trace, const char *path) { - struct emu_stream *stream = calloc(1, sizeof(struct emu_stream)); + struct stream *stream = calloc(1, sizeof(struct stream)); if (stream == NULL) { perror("calloc failed"); @@ -36,7 +36,7 @@ load_stream(struct emu_trace *trace, const char *path) /* Skip begin slashes */ while (relpath[0] == '/') relpath++; - if (emu_stream_load(stream, trace->tracedir, relpath) != 0) { + if (stream_load(stream, trace->tracedir, relpath) != 0) { err("load_stream: emu_steam_load failed\n"); return -1; } @@ -82,15 +82,15 @@ cb_nftw(const char *fpath, const struct stat *sb, } static int -cmp_streams(struct emu_stream *a, struct emu_stream *b) +cmp_streams(struct stream *a, struct stream *b) { return strcmp(a->relpath, b->relpath); } int -emu_trace_load(struct emu_trace *trace, const char *tracedir) +trace_load(struct trace *trace, const char *tracedir) { - memset(trace, 0, sizeof(struct emu_trace)); + memset(trace, 0, sizeof(struct trace)); cur_trace = trace; diff --git a/src/emu/emu_trace.h b/src/emu/trace.h similarity index 64% rename from src/emu/emu_trace.h rename to src/emu/trace.h index 1b0dcd6..a314739 100644 --- a/src/emu/emu_trace.h +++ b/src/emu/trace.h @@ -4,17 +4,17 @@ #ifndef EMU_TRACE_H #define EMU_TRACE_H -#include "emu_stream.h" +#include "stream.h" #include -struct emu_trace { +struct trace { char tracedir[PATH_MAX]; long nstreams; - struct emu_stream *streams; + struct stream *streams; }; -int emu_trace_load(struct emu_trace *trace, const char *tracedir); +int trace_load(struct trace *trace, const char *tracedir); #endif /* EMU_TRACE_H */ diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 4b33178..938d8a1 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,10 +15,10 @@ unit_test(mux.c) unit_test(value.c) unit_test(prv.c) #unit_test(ovni_model.c) -unit_test(emu_trace.c) +unit_test(trace.c) unit_test(emu.c) unit_test(clkoff.c) -unit_test(emu_stream.c) +unit_test(stream.c) unit_test(loom.c) unit_test(thread.c) unit_test(proc.c) diff --git a/test/unit/emu_trace.c b/test/unit/emu_trace.c deleted file mode 100644 index 99586f3..0000000 --- a/test/unit/emu_trace.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "emu/emu_trace.h" -#include "common.h" - -int main(void) -{ - char *tracedir = "/home/ram/bsc/ovni/traces/test/ovni"; - - struct emu_trace trace; - - if (emu_trace_load(&trace, tracedir) != 0) - die("emu_trace_load failed\n"); - - return 0; -} diff --git a/test/unit/emu_stream.c b/test/unit/stream.c similarity index 83% rename from test/unit/emu_stream.c rename to test/unit/stream.c index 2a3b28b..a91c7a4 100644 --- a/test/unit/emu_stream.c +++ b/test/unit/stream.c @@ -24,10 +24,10 @@ test_ok(char *fname) fclose(f); - struct emu_stream stream; + struct stream stream; const char *relpath = &fname[5]; - if (emu_stream_load(&stream, "/tmp", relpath) != 0) - die("emu_stream_load failed"); + if (stream_load(&stream, "/tmp", relpath) != 0) + die("stream_load failed"); if (stream.active) die("stream is active\n"); @@ -51,10 +51,10 @@ test_bad(char *fname) fclose(f); - struct emu_stream stream; + struct stream stream; const char *relpath = &fname[5]; - if (emu_stream_load(&stream, "/tmp", relpath) == 0) - die("emu_stream_load didn't fail"); + if (stream_load(&stream, "/tmp", relpath) == 0) + die("stream_load didn't fail"); } int main(void) diff --git a/test/unit/trace.c b/test/unit/trace.c new file mode 100644 index 0000000..3e4e879 --- /dev/null +++ b/test/unit/trace.c @@ -0,0 +1,14 @@ +#include "emu/trace.h" +#include "common.h" + +int main(void) +{ + char *tracedir = "/home/ram/bsc/ovni/traces/test/ovni"; + + struct trace trace; + + if (trace_load(&trace, tracedir) != 0) + die("trace_load failed\n"); + + return 0; +}