From 09e11b28a44111079882c94ad756ade32f38be2c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 13 Sep 2022 15:36:55 +0200 Subject: [PATCH] Add nanos6 as library and sched-add test --- nix/rt.nix | 1 + test/rt/nanos6/CMakeLists.txt | 7 ++++ test/rt/nanos6/sched-add.c | 77 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 test/rt/nanos6/sched-add.c diff --git a/nix/rt.nix b/nix/rt.nix index c14240a..f7c1ab5 100644 --- a/nix/rt.nix +++ b/nix/rt.nix @@ -82,6 +82,7 @@ let buildInputs = old.buildInputs ++ [ pkgs.gdb last.nosv + last.nanos6 pkgs.strace ]; cmakeFlags = old.cmakeFlags ++ [ "-DENABLE_TEST_RT=ON" ]; diff --git a/test/rt/nanos6/CMakeLists.txt b/test/rt/nanos6/CMakeLists.txt index 01eb5aa..8443f60 100644 --- a/test/rt/nanos6/CMakeLists.txt +++ b/test/rt/nanos6/CMakeLists.txt @@ -1,7 +1,13 @@ +find_library(nanos6 libnanos6) +find_path(NANOS6_INCLUDE_DIR nanos6.h) + function(nanos6_rt_test) ovni_test(${ARGN}) target_compile_options("${OVNI_TEST_NAME}" PUBLIC "-fompss-2") target_link_options("${OVNI_TEST_NAME}" PUBLIC "-fompss-2") + target_link_libraries("${OVNI_TEST_NAME}" nanos6) + target_include_directories("${OVNI_TEST_NAME}" + PUBLIC ${NANOS6_INCLUDE_DIR}) set_property(TEST "${OVNI_TEST_NAME}" APPEND PROPERTY ENVIRONMENT "NANOS6_CONFIG=${OVNI_TEST_SOURCE_DIR}/rt/nanos6/nanos6.toml") endfunction() @@ -9,3 +15,4 @@ endfunction() nanos6_rt_test(simple-task.c) nanos6_rt_test(nested-task.c) nanos6_rt_test(several-tasks.c) +nanos6_rt_test(sched-add.c) diff --git a/test/rt/nanos6/sched-add.c b/test/rt/nanos6/sched-add.c new file mode 100644 index 0000000..9fef44f --- /dev/null +++ b/test/rt/nanos6/sched-add.c @@ -0,0 +1,77 @@ +/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#define _POSIX_C_SOURCE 2 + +#include +#include +#include +#include +#include +#include +#include +#include + +static int ncpus = -1; +static long nruns = 3L; +static long ntasks = 10000L; + +static atomic_int wait = 0; +static void **handle; + +#pragma oss task +static void +do_task(int t) +{ + if(atomic_load(&wait)) + { + handle[t] = nanos6_get_current_blocking_context(); + nanos6_block_current_task(handle[t]); + } +} + +static void +do_run(void) +{ + memset(handle, 0, ntasks * sizeof(void *)); + atomic_fetch_add(&wait, 1); + + for(int t = 0; t < ntasks; t++) + do_task(t); + + atomic_fetch_sub(&wait, 1); + + for(int t = 0; t < ntasks; t++) + { + if (handle[t]) { + nanos6_unblock_task(handle[t]); + } + } + + #pragma oss taskwait +} + +static int get_ncpus(void) +{ + return (int) nanos6_get_num_cpus(); +} + +int +main(void) +{ + ncpus = get_ncpus(); + + handle = calloc(ntasks, sizeof(void *)); + + if(handle == NULL) + { + perror("calloc failed"); + return -1; + } + + printf("%s,%s,%s,%s\n", "run", "ntasks", "time", "time_per_task_per_cpu"); + for(int run = 0; run < nruns; run++) + do_run(); + + return 0; +}