diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cae75e1..eb654ba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,6 +21,11 @@ target_link_libraries(flush ovni) add_test(NAME flush COMMAND "${OVNI_TEST_DIR}/driver.sh" flush) set_tests_properties(flush PROPERTIES RUN_SERIAL TRUE) +add_executable(flush-overhead flush-overhead.c) +target_link_libraries(flush-overhead ovni) +add_test(NAME flush-overhead COMMAND "${OVNI_TEST_DIR}/driver.sh" flush-overhead) +set_tests_properties(flush-overhead PROPERTIES RUN_SERIAL TRUE) + add_executable(mp-simple mp-simple.c) target_link_libraries(mp-simple ovni) add_test(NAME mp-simple COMMAND "${OVNI_TEST_DIR}/mp-driver.sh" mp-simple) diff --git a/test/flush-overhead.c b/test/flush-overhead.c new file mode 100644 index 0000000..9fac9b2 --- /dev/null +++ b/test/flush-overhead.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define _POSIX_C_SOURCE 200112L +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ovni.h" +#include "compat.h" + +static inline void +init(void) +{ + char hostname[HOST_NAME_MAX]; + + if(gethostname(hostname, HOST_NAME_MAX) != 0) + { + perror("gethostname failed"); + exit(EXIT_FAILURE); + } + + ovni_proc_init(0, hostname, getpid()); + ovni_thread_init(gettid()); + ovni_add_cpu(0, 0); +} + +static void emit(uint8_t *buf, size_t size) +{ + struct ovni_ev ev = {0}; + ovni_ev_set_mcv(&ev, "O$$"); + ovni_ev_set_clock(&ev, ovni_clock_now()); + ovni_ev_jumbo_emit(&ev, buf, size); +} + +#define NRUNS 50 + +int main(void) +{ + size_t payload_size; + uint8_t *payload_buf; + + if(setenv("OVNI_TMPDIR", "/dev/shm/ovni-flush-overhead", 1) != 0) + { + perror("setenv failed"); + exit(EXIT_FAILURE); + } + + init(); + + payload_size = (size_t) (0.5 * (double) OVNI_MAX_EV_BUF); + payload_buf = calloc(1, payload_size); + + if(!payload_buf) + { + perror("calloc failed"); + exit(EXIT_FAILURE); + } + + double *times = calloc(sizeof(double), NRUNS); + if(times == NULL) + { + perror("calloc failed"); + exit(EXIT_FAILURE); + } + + for(int i=0; i < NRUNS; i++) + { + emit(payload_buf, payload_size); + double t0 = (double) ovni_clock_now(); + ovni_flush(); + double t1 = (double) ovni_clock_now(); + + times[i] = (t1 - t0) * 1e-6; /* to milliseconds */ + } + + double mean = 0.0; + for(int i=0; i < NRUNS; i++) + mean += times[i]; + mean /= (double) NRUNS; + + fprintf(stderr, "mean %f ms\n", mean); + + if (mean > 1.0) { + fprintf(stderr, "too much time: %f ms\n", mean); + exit(EXIT_FAILURE); + } + + ovni_proc_fini(); + + free(payload_buf); + free(times); + + return 0; +}