diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bfb091..178d5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The nOS-V model version is bumped to 2.1.0. - Add support for `nosv_mutex_lock`, `nosv_mutex_trylock` and `nosv_mutex_unlock` events VA{lLtTuU}. +- Add support for the `nosv_barrier_event` event VA{bB}. ## [1.8.0] - 2024-03-18 diff --git a/cfg/cpu/nosv/subsystem.cfg b/cfg/cpu/nosv/subsystem.cfg index 09757c7..5f282a5 100644 --- a/cfg/cpu/nosv/subsystem.cfg +++ b/cfg/cpu/nosv/subsystem.cfg @@ -17,7 +17,7 @@ window_comm_lines_enabled true window_flags_enabled false window_noncolor_mode true window_custom_color_enabled true -window_custom_color_palette {6.000000000000:94,0,0},{7.000000000000:153,114,0},{9.000000000000:124,213,228},{10.000000000000:242,239,141},{11.000000000000:0,70,0},{19.000000000000:195,96,151},{20.000000000000:255,162,255},{21.000000000000:203,255,3},{22.000000000000:7,255,12},{23.000000000000:21,224,189},{25.000000000000:0,99,162} +window_custom_color_palette {6.000000000000:94,0,0},{7.000000000000:153,114,0},{9.000000000000:124,213,228},{10.000000000000:242,239,141},{11.000000000000:0,70,0},{19.000000000000:195,96,151},{20.000000000000:255,162,255},{21.000000000000:203,255,3},{22.000000000000:7,255,12},{23.000000000000:21,224,189},{24.000000000000:255,103,0},{25.000000000000:0,99,162} window_logical_filtered true window_physical_filtered false window_comm_fromto true diff --git a/cfg/thread/nosv/subsystem.cfg b/cfg/thread/nosv/subsystem.cfg index ccc5157..0549f90 100644 --- a/cfg/thread/nosv/subsystem.cfg +++ b/cfg/thread/nosv/subsystem.cfg @@ -17,7 +17,7 @@ window_comm_lines_enabled true window_flags_enabled false window_noncolor_mode true window_custom_color_enabled true -window_custom_color_palette {6.000000000000:94,0,0},{7.000000000000:153,114,0},{9.000000000000:124,213,228},{10.000000000000:242,239,141},{11.000000000000:0,70,0},{19.000000000000:195,96,151},{20.000000000000:255,162,255},{21.000000000000:203,255,3},{22.000000000000:7,255,12},{23.000000000000:21,224,189},{25.000000000000:0,99,162} +window_custom_color_palette {6.000000000000:94,0,0},{7.000000000000:153,114,0},{9.000000000000:124,213,228},{10.000000000000:242,239,141},{11.000000000000:0,70,0},{19.000000000000:195,96,151},{20.000000000000:255,162,255},{21.000000000000:203,255,3},{22.000000000000:7,255,12},{23.000000000000:21,224,189},{24.000000000000:255,103,0},{25.000000000000:0,99,162} window_logical_filtered true window_physical_filtered false window_comm_fromto true diff --git a/doc/user/emulation/events.md b/doc/user/emulation/events.md index e366b3b..639b7ea 100644 --- a/doc/user/emulation/events.md +++ b/doc/user/emulation/events.md @@ -705,6 +705,10 @@ List of events for the model *nosv* with identifier **`V`** at version `2.1.0`:
enters nosv_mutex_unlock()
VAU
leaves nosv_mutex_unlock()
+
VAb
+
enters nosv_barrier_wait()
+
VAB
+
leaves nosv_barrier_wait()
VHa
enters nosv_attach()
VHA
diff --git a/doc/user/emulation/versions.md b/doc/user/emulation/versions.md index ed5a84d..affaefa 100644 --- a/doc/user/emulation/versions.md +++ b/doc/user/emulation/versions.md @@ -41,6 +41,7 @@ Track changes in emulator model versions. - nosv 2.1.0 - Add support for `nosv_mutex_lock`, `nosv_mutex_trylock` and `nosv_mutex_unlock` events VA{lLtTuU}. + - Add support for `nosv_barrier_wait` event VA{bB}. - nosv 2.0.0 - Add support for parallel tasks, adding a new `bodyid` argument in `VT*` events. - Remove support for old attach events `VH{aA}`. diff --git a/src/emu/nosv/event.c b/src/emu/nosv/event.c index e50b694..2d79466 100644 --- a/src/emu/nosv/event.c +++ b/src/emu/nosv/event.c @@ -65,6 +65,8 @@ static const int ss_table[256][256][3] = { ['T'] = { CHSS, POP, ST_API_MUTEX_TRYLOCK }, ['u'] = { CHSS, PUSH, ST_API_MUTEX_UNLOCK }, ['U'] = { CHSS, POP, ST_API_MUTEX_UNLOCK }, + ['b'] = { CHSS, PUSH, ST_API_BARRIER_WAIT }, + ['B'] = { CHSS, POP, ST_API_BARRIER_WAIT }, }, /* FIXME: Move thread type to another channel, like nanos6 */ ['H'] = { diff --git a/src/emu/nosv/nosv_priv.h b/src/emu/nosv/nosv_priv.h index cb50a63..67e7b23 100644 --- a/src/emu/nosv/nosv_priv.h +++ b/src/emu/nosv/nosv_priv.h @@ -40,6 +40,7 @@ enum nosv_ss_values { ST_API_MUTEX_LOCK, ST_API_MUTEX_TRYLOCK, ST_API_MUTEX_UNLOCK, + ST_API_BARRIER_WAIT, ST_WORKER, ST_DELEGATE, diff --git a/src/emu/nosv/setup.c b/src/emu/nosv/setup.c index 68d6680..fa9d908 100644 --- a/src/emu/nosv/setup.c +++ b/src/emu/nosv/setup.c @@ -63,6 +63,7 @@ static struct ev_decl model_evlist[] = { PAIR_E("VAl", "VAL", "nosv_mutex_lock()") PAIR_E("VAt", "VAT", "nosv_mutex_trylock()") PAIR_E("VAu", "VAU", "nosv_mutex_unlock()") + PAIR_E("VAb", "VAB", "nosv_barrier_wait()") /* FIXME: VHA and VHa are not subsystems */ { "VHa", "enters nosv_attach()" }, @@ -150,6 +151,7 @@ static const struct pcf_value_label nosv_ss_values[] = { { ST_API_MUTEX_LOCK, "API: Mutex lock" }, { ST_API_MUTEX_TRYLOCK,"API: Mutex trylock" }, { ST_API_MUTEX_UNLOCK, "API: Mutex unlock" }, + { ST_API_BARRIER_WAIT, "API: Barrier wait" }, { ST_WORKER, "Thread: Worker" }, { ST_DELEGATE, "Thread: Delegate" }, { EV_SCHED_SEND, "EV Scheduler: Send task" }, diff --git a/test/emu/nosv/CMakeLists.txt b/test/emu/nosv/CMakeLists.txt index 2a22872..a86d482 100644 --- a/test/emu/nosv/CMakeLists.txt +++ b/test/emu/nosv/CMakeLists.txt @@ -21,6 +21,7 @@ test_emu(require-missing.c test_emu(parallel-tasks.c) test_emu(nest-to-parallel.c) test_emu(mutex.c) +test_emu(barrier.c) test_emu(bad-nest-same-task.c SHOULD_FAIL REGEX "body_execute: refusing to run body(id=1,taskid=1) in Paused state, needs to resume intead") diff --git a/test/emu/nosv/barrier.c b/test/emu/nosv/barrier.c new file mode 100644 index 0000000..410dc55 --- /dev/null +++ b/test/emu/nosv/barrier.c @@ -0,0 +1,24 @@ +/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include "compat.h" +#include "instr.h" +#include "instr_nosv.h" + +/* Test the nosv_barrier_wait() API events, introduced in the nOS-V model 2.1.0 */ + +int +main(void) +{ + instr_start(0, 1); + instr_nosv_init(); + + instr_nosv_barrier_wait_enter(); + sleep_us(100); + instr_nosv_barrier_wait_exit(); + + instr_end(); + + return 0; +} + diff --git a/test/emu/nosv/instr_nosv.h b/test/emu/nosv/instr_nosv.h index f96c6ae..14724a3 100644 --- a/test/emu/nosv/instr_nosv.h +++ b/test/emu/nosv/instr_nosv.h @@ -50,6 +50,8 @@ INSTR_0ARG(instr_nosv_attach_enter, "VAa") INSTR_0ARG(instr_nosv_attach_exit, "VAA") INSTR_0ARG(instr_nosv_detach_enter, "VAe") INSTR_0ARG(instr_nosv_detach_exit, "VAE") +INSTR_0ARG(instr_nosv_barrier_wait_enter, "VAb") +INSTR_0ARG(instr_nosv_barrier_wait_exit, "VAB") INSTR_0ARG(instr_nosv_mutex_lock_enter, "VAl") INSTR_0ARG(instr_nosv_mutex_lock_exit, "VAL") INSTR_0ARG(instr_nosv_mutex_trylock_enter, "VAt") diff --git a/test/rt/nosv/CMakeLists.txt b/test/rt/nosv/CMakeLists.txt index ab4325a..db1850f 100644 --- a/test/rt/nosv/CMakeLists.txt +++ b/test/rt/nosv/CMakeLists.txt @@ -43,6 +43,7 @@ nosv_test(init-nested.c SORT) nosv_test(parallel-tasks.c SORT) nosv_test(inline.c SORT) nosv_test(mutex.c SORT) +nosv_test(barrier.c SORT) # Test multiple instrumentation levels nosv_test(several-tasks.c SORT NAME several-tasks-level-0 LEVEL 0) diff --git a/test/rt/nosv/barrier.c b/test/rt/nosv/barrier.c new file mode 100644 index 0000000..f53a290 --- /dev/null +++ b/test/rt/nosv/barrier.c @@ -0,0 +1,66 @@ +/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#define _DEFAULT_SOURCE + +#include +#include +#include +#include + +#include "common.h" +#include "compat.h" + +#define NTASKS 200 +atomic_int ncompleted = 0; + +nosv_task_t tasks[NTASKS]; +nosv_barrier_t barrier; + +static void +task_body(nosv_task_t task) +{ + UNUSED(task); + if (nosv_barrier_wait(barrier) != 0) + die("nosv_barrier_wait failed"); +} + +static void +task_done(nosv_task_t task) +{ + UNUSED(task); + atomic_fetch_add(&ncompleted, 1); +} + +int +main(void) +{ + nosv_init(); + + nosv_task_type_t task_type; + nosv_type_init(&task_type, task_body, NULL, task_done, "task", NULL, NULL, 0); + + if (nosv_barrier_init(&barrier, NOSV_BARRIER_NONE, NTASKS) != 0) + die("nosv_barrier_init failed"); + + for (int i = 0; i < NTASKS; i++) + nosv_create(&tasks[i], task_type, 0, 0); + + for (int i = 0; i < NTASKS; i++) + nosv_submit(tasks[i], 0); + + while (atomic_load(&ncompleted) != NTASKS) + sleep_us(1000); + + for (int i = 0; i < NTASKS; i++) + nosv_destroy(tasks[i], 0); + + if (nosv_barrier_destroy(barrier) != 0) + die("nosv_barrier_destroy failed"); + + nosv_type_destroy(task_type, 0); + + nosv_shutdown(); + + return 0; +}