diff --git a/test/emu/instr.c b/test/emu/instr.c new file mode 100644 index 0000000..079b777 --- /dev/null +++ b/test/emu/instr.c @@ -0,0 +1,24 @@ +/* Copyright (c) 2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include "instr.h" + +int first_clock_set = 0; +int64_t first_clock; /* First clock */ +int64_t last_clock; /* Clock from the last event */ + +int64_t get_clock(void) +{ + last_clock = ovni_clock_now(); + if (first_clock_set == 0) { + first_clock = last_clock; + first_clock_set = 1; + } + + return last_clock; +} + +int64_t get_delta(void) +{ + return last_clock - first_clock; +} diff --git a/test/emu/instr.h b/test/emu/instr.h index 3241df0..a4db867 100644 --- a/test/emu/instr.h +++ b/test/emu/instr.h @@ -18,11 +18,18 @@ #include #include +extern int first_clock_set; +extern int64_t first_clock; +extern int64_t last_clock; + +int64_t get_clock(void); +int64_t get_delta(void); + #define INSTR_0ARG(name, mcv) \ static inline void name(void) \ { \ struct ovni_ev ev = {0}; \ - ovni_ev_set_clock(&ev, ovni_clock_now()); \ + ovni_ev_set_clock(&ev, get_clock()); \ ovni_ev_set_mcv(&ev, mcv); \ ovni_ev_emit(&ev); \ } @@ -31,7 +38,7 @@ static inline void name(ta a) \ { \ struct ovni_ev ev = {0}; \ - ovni_ev_set_clock(&ev, ovni_clock_now()); \ + ovni_ev_set_clock(&ev, get_clock()); \ ovni_ev_set_mcv(&ev, mcv); \ ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \ ovni_ev_emit(&ev); \ @@ -41,7 +48,7 @@ static inline void name(ta a, tb b) \ { \ struct ovni_ev ev = {0}; \ - ovni_ev_set_clock(&ev, ovni_clock_now()); \ + ovni_ev_set_clock(&ev, get_clock()); \ ovni_ev_set_mcv(&ev, mcv); \ ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \ ovni_payload_add(&ev, (uint8_t *) &b, sizeof(b)); \ @@ -52,8 +59,8 @@ static inline void name(ta a, tb b, tc c) \ { \ struct ovni_ev ev = {0}; \ + ovni_ev_set_clock(&ev, get_clock()); \ ovni_ev_set_mcv(&ev, mcv); \ - ovni_ev_set_clock(&ev, ovni_clock_now()); \ ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \ ovni_payload_add(&ev, (uint8_t *) &b, sizeof(b)); \ ovni_payload_add(&ev, (uint8_t *) &c, sizeof(c)); \ @@ -68,7 +75,7 @@ instr_thread_end(void) struct ovni_ev ev = {0}; ovni_ev_set_mcv(&ev, "OHe"); - ovni_ev_set_clock(&ev, ovni_clock_now()); + ovni_ev_set_clock(&ev, get_clock()); ovni_ev_emit(&ev); /* Flush the events to disk before killing the thread */ diff --git a/test/emu/nanos6/instr_nanos6.h b/test/emu/nanos6/instr_nanos6.h index 48ac859..6cd4824 100644 --- a/test/emu/nanos6/instr_nanos6.h +++ b/test/emu/nanos6/instr_nanos6.h @@ -13,7 +13,7 @@ instr_nanos6_type_create(int32_t typeid) struct ovni_ev ev = {0}; ovni_ev_set_mcv(&ev, "6Yc"); - ovni_ev_set_clock(&ev, ovni_clock_now()); + ovni_ev_set_clock(&ev, get_clock()); char buf[256]; char *p = buf; diff --git a/test/emu/nosv/instr_nosv.h b/test/emu/nosv/instr_nosv.h index ea0c187..d20aa4c 100644 --- a/test/emu/nosv/instr_nosv.h +++ b/test/emu/nosv/instr_nosv.h @@ -12,7 +12,7 @@ instr_nosv_type_create(int32_t typeid) struct ovni_ev ev = {0}; ovni_ev_set_mcv(&ev, "VYc"); - ovni_ev_set_clock(&ev, ovni_clock_now()); + ovni_ev_set_clock(&ev, get_clock()); char buf[256]; char *p = buf; diff --git a/test/macros.cmake b/test/macros.cmake index fb0e4a3..15d8fa9 100644 --- a/test/macros.cmake +++ b/test/macros.cmake @@ -104,11 +104,17 @@ function(ovni_test source) include_directories( "${CMAKE_SOURCE_DIR}/src/include" + "${CMAKE_SOURCE_DIR}/src/emu" "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/include" ) - add_executable("${OVNI_TEST_NAME}" "${OVNI_TEST_SOURCE}") - target_link_libraries("${OVNI_TEST_NAME}" PRIVATE ovni) + + add_executable("${OVNI_TEST_NAME}" + "${OVNI_TEST_SOURCE}" + "${CMAKE_SOURCE_DIR}/test/emu/instr.c" + ) + + target_link_libraries("${OVNI_TEST_NAME}" PRIVATE ovni emu) set(driver "${OVNI_TEST_SOURCE_DIR}/ovni-driver.sh")