From 080898363b7bd7b17848d39ba85e69bd1de89e92 Mon Sep 17 00:00:00 2001 From: David Alvarez Date: Thu, 7 Jul 2022 16:31:15 +0200 Subject: [PATCH] Add Nanos6 tests --- test/CMakeLists.txt | 6 ++ test/common.h | 89 ++++++++++++++++++++ test/nanos6-blocking.c | 47 +++++++++++ test/nanos6-nested-tasks-bad.c | 37 +++++++++ test/nanos6-nested-tasks.c | 47 +++++++++++ test/nanos6-subsystems.c | 89 ++++++++++++++++++++ test/nanos6-task-types.c | 48 +++++++++++ test/nanos6.h | 146 +++++++++++++++++++++++++++++++++ test/nosv-nested-tasks.c | 4 +- 9 files changed, 511 insertions(+), 2 deletions(-) create mode 100644 test/common.h create mode 100644 test/nanos6-blocking.c create mode 100644 test/nanos6-nested-tasks-bad.c create mode 100644 test/nanos6-nested-tasks.c create mode 100644 test/nanos6-subsystems.c create mode 100644 test/nanos6-task-types.c create mode 100644 test/nanos6.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4223d51..1e7bcc6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,6 +33,12 @@ ovni_test(NAME nosv-nested-tasks-bad ovni_test(NAME nosv-task-types MP) ovni_test(NAME nosv-pause MP) +ovni_test(NAME nanos6-nested-tasks) +ovni_test(NAME nanos6-nested-tasks-bad) +ovni_test(NAME nanos6-task-types MP) +ovni_test(NAME nanos6-blocking MP) +ovni_test(NAME nanos6-subsystems MP) + if(BUILD_RT_TESTING) add_subdirectory(rt) endif() diff --git a/test/common.h b/test/common.h new file mode 100644 index 0000000..8dd274c --- /dev/null +++ b/test/common.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 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 . + */ + +#ifndef OVNI_TEST_COMMON_H +#define OVNI_TEST_COMMON_H + +#include "../common.h" +#include "ovni.h" + +#include +#include +#include +#include +#include +#include +#include + +#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_mcv(&ev, mcv); \ + ovni_ev_emit(&ev); \ + } + +#define INSTR_1ARG(name, mcv, ta, a) \ + static inline void name(ta a) \ + { \ + struct ovni_ev ev = {0}; \ + ovni_ev_set_clock(&ev, ovni_clock_now()); \ + ovni_ev_set_mcv(&ev, mcv); \ + ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \ + ovni_ev_emit(&ev); \ + } + +#define INSTR_2ARG(name, mcv, ta, a, tb, b) \ + static inline void name(ta a, tb b) \ + { \ + struct ovni_ev ev = {0}; \ + ovni_ev_set_clock(&ev, ovni_clock_now()); \ + ovni_ev_set_mcv(&ev, mcv); \ + ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \ + ovni_payload_add(&ev, (uint8_t *) &b, sizeof(b)); \ + ovni_ev_emit(&ev); \ + } + +#define INSTR_3ARG(name, mcv, ta, a, tb, b, tc, c) \ + static inline void name(ta a, tb b, tc c) \ + { \ + struct ovni_ev ev = {0}; \ + 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)); \ + ovni_ev_emit(&ev); \ + } + +INSTR_3ARG(instr_thread_execute, "OHx", int32_t, cpu, int32_t, creator_tid, uint64_t, tag) + +static inline void +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_emit(&ev); + + /* Flush the events to disk before killing the thread */ + ovni_flush(); +} + +#endif /* OVNI_TEST_COMMON_H */ diff --git a/test/nanos6-blocking.c b/test/nanos6-blocking.c new file mode 100644 index 0000000..8bf25b4 --- /dev/null +++ b/test/nanos6-blocking.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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 _GNU_SOURCE + +#include "test/common.h" +#include "test/nanos6.h" + +int +main(void) +{ + int rank = atoi(getenv("OVNI_RANK")); + int nranks = atoi(getenv("OVNI_NRANKS")); + instr_start(rank, nranks); + + int us = 500; + uint32_t typeid = 1; + + type_create(typeid); + + task_begin(1, typeid); + usleep(us); + block_enter(1); + usleep(us); + block_exit(1); + usleep(us); + task_end(1); + + instr_end(); + + return 0; +} + diff --git a/test/nanos6-nested-tasks-bad.c b/test/nanos6-nested-tasks-bad.c new file mode 100644 index 0000000..563ce78 --- /dev/null +++ b/test/nanos6-nested-tasks-bad.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 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 _GNU_SOURCE + +#include "test/common.h" +#include "test/nanos6.h" + +int +main(void) +{ + instr_start(0, 1); + + /* Create two nested tasks with the same task_id: this should + * fail */ + task_begin(1, 500); + task_begin(1, 500); + + instr_end(); + + return 0; +} + diff --git a/test/nanos6-nested-tasks.c b/test/nanos6-nested-tasks.c new file mode 100644 index 0000000..59b3bd7 --- /dev/null +++ b/test/nanos6-nested-tasks.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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 _GNU_SOURCE + +#include "test/common.h" +#include "test/nanos6.h" + +int +main(void) +{ + instr_start(0, 1); + + int ntasks = 100; + uint32_t typeid = 1; + + type_create(typeid); + + /* Create and run the tasks, one nested into another */ + for(int i = 0; i < ntasks; i++) + { + task_begin(i + 1, typeid); + usleep(500); + } + + /* End the tasks in the opposite order */ + for(int i = ntasks - 1; i >= 0; i--) + task_end(i + 1); + + instr_end(); + + return 0; +} diff --git a/test/nanos6-subsystems.c b/test/nanos6-subsystems.c new file mode 100644 index 0000000..d44ed39 --- /dev/null +++ b/test/nanos6-subsystems.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 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 _GNU_SOURCE + +#include "test/common.h" +#include "test/nanos6.h" + +int +main(void) +{ + int rank = atoi(getenv("OVNI_RANK")); + int nranks = atoi(getenv("OVNI_NRANKS")); + instr_start(rank, nranks); + + int us = 500; + + int32_t typeid = 1; + int32_t taskid = 1; + + type_create(typeid); + task_begin(taskid, typeid); + + sched_receive_task(); + usleep(us); + sched_assign_task(); + usleep(us); + sched_self_assign_task(); + usleep(us); + sched_hungry(); + usleep(us); + sched_fill(); + usleep(us); + sched_server_enter(); + usleep(us); + sched_server_exit(); + usleep(us); + sched_submit_enter(); + usleep(us); + sched_submit_exit(); + usleep(us); + enter_submit_task(); + usleep(us); + exit_submit_task(); + usleep(us); + block_enter(taskid); + usleep(us); + block_exit(taskid); + usleep(us); + waitfor_enter(taskid); + usleep(us); + waitfor_exit(taskid); + usleep(us); + register_accesses_enter(); + usleep(us); + register_accesses_exit(); + usleep(us); + unregister_accesses_enter(); + usleep(us); + unregister_accesses_exit(); + usleep(us); + task_wait_enter(taskid); + usleep(us); + task_wait_exit(taskid); + usleep(us); + spawn_function_enter(); + usleep(us); + spawn_function_exit(); + usleep(us); + + instr_end(); + + return 0; +} + diff --git a/test/nanos6-task-types.c b/test/nanos6-task-types.c new file mode 100644 index 0000000..0854ab1 --- /dev/null +++ b/test/nanos6-task-types.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 _GNU_SOURCE + +#include "test/common.h" +#include "test/nanos6.h" + +int +main(void) +{ + int rank = atoi(getenv("OVNI_RANK")); + int nranks = atoi(getenv("OVNI_NRANKS")); + + instr_start(rank, nranks); + + int ntasks = 100; + int ntypes = 10; + + for(int i = 0; i < ntypes; i++) + type_create(i + 1); + + for(int i = 0; i < ntasks; i++) + { + task_begin(i + 1, (i % ntypes) + 1); + usleep(500); + task_end(i + 1); + } + + instr_end(); + + return 0; +} + diff --git a/test/nanos6.h b/test/nanos6.h new file mode 100644 index 0000000..69fe003 --- /dev/null +++ b/test/nanos6.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 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 . + */ + +#ifndef OVNI_TEST_NANOS6_H +#define OVNI_TEST_NANOS6_H + +#include "test/common.h" +#include "compat.h" + +static inline void +instr_start(int rank, int nranks) +{ + char hostname[HOST_NAME_MAX]; + char rankname[HOST_NAME_MAX + 64]; + + if(gethostname(hostname, HOST_NAME_MAX) != 0) + die("gethostname failed"); + + sprintf(rankname, "%s.%d", hostname, rank); + + ovni_proc_init(1, rankname, getpid()); + ovni_proc_set_rank(rank, nranks); + ovni_thread_init(gettid()); + + /* All ranks inform CPUs */ + for(int i=0; i < nranks; i++) + ovni_add_cpu(i, i); + + int curcpu = rank; + + dbg("thread %d has cpu %d (ncpus=%d)\n", + gettid(), curcpu, nranks); + + instr_thread_execute(curcpu, -1, 0); +} + +static inline void +instr_end(void) +{ + instr_thread_end(); + ovni_thread_free(); + ovni_proc_fini(); +} + +static inline void +type_create(int32_t typeid) +{ + struct ovni_ev ev = {0}; + + ovni_ev_set_mcv(&ev, "6Yc"); + ovni_ev_set_clock(&ev, ovni_clock_now()); + + char buf[256]; + char *p = buf; + + size_t nbytes = 0; + memcpy(buf, &typeid, sizeof(typeid)); + p += sizeof(typeid); + nbytes += sizeof(typeid); + sprintf(p, "testtype%d", typeid); + nbytes += strlen(p) + 1; + + ovni_ev_jumbo_emit(&ev, (uint8_t *) buf, nbytes); +} + +INSTR_2ARG(task_create, "6Tc", int32_t, id, uint32_t, typeid) +INSTR_0ARG(task_create_end, "6TC") +INSTR_1ARG(task_execute, "6Tx", int32_t, id) + +static inline void +task_begin(int32_t id, uint32_t typeid) +{ + task_create(id, typeid); + task_create_end(); + task_execute(id); +} + +INSTR_2ARG(task_block, "6Tb", int32_t, id, int32_t, reason) +INSTR_2ARG(task_unblock, "6Tu", int32_t, id, int32_t, reason) + +static inline void block_enter(int32_t id) +{ + task_block(id, 0); +} + +static inline void block_exit(int32_t id) +{ + task_unblock(id, 0); +} + +static inline void task_wait_enter(int32_t id) +{ + task_block(id, 1); +} + +static inline void task_wait_exit(int32_t id) +{ + task_unblock(id, 1); +} + +static inline void waitfor_enter(int32_t id) +{ + task_block(id, 2); +} + +static inline void waitfor_exit(int32_t id) +{ + task_unblock(id, 2); +} + +INSTR_1ARG(task_end, "6Te", int32_t, id) + +INSTR_0ARG(sched_receive_task, "6Sr") +INSTR_0ARG(sched_assign_task, "6Ss") +INSTR_0ARG(sched_self_assign_task, "6S@") +INSTR_0ARG(sched_hungry, "6Sh") +INSTR_0ARG(sched_fill, "6Sf") +INSTR_0ARG(sched_server_enter, "6S[") +INSTR_0ARG(sched_server_exit, "6S]") +INSTR_0ARG(sched_submit_enter, "6Su") +INSTR_0ARG(sched_submit_exit, "6SU") +INSTR_0ARG(enter_submit_task, "6U[") +INSTR_0ARG(exit_submit_task, "6U]") +INSTR_0ARG(register_accesses_enter, "6Dr") +INSTR_0ARG(register_accesses_exit, "6DR") +INSTR_0ARG(unregister_accesses_enter, "6Du") +INSTR_0ARG(unregister_accesses_exit, "6DU") +INSTR_0ARG(exit_create_task, "6TC") +INSTR_0ARG(spawn_function_enter, "6Hs") +INSTR_0ARG(spawn_function_exit, "6HS") + +#endif /* OVNI_TEST_NANOS6_H */ diff --git a/test/nosv-nested-tasks.c b/test/nosv-nested-tasks.c index 7a24315..6f7a79d 100644 --- a/test/nosv-nested-tasks.c +++ b/test/nosv-nested-tasks.c @@ -175,11 +175,11 @@ main(void) type_create(typeid); /* Create and run the tasks, one nested into another */ - for(int i=0; i=0; i--) + for(int i = ntasks - 1; i >= 0; i--) task_end(i + 1); instr_end();