diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0521a69..2bfb091 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Consistency check for events emitted when the kernel has removed the thread
from the CPU.
+- 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}.
## [1.8.0] - 2024-03-18
diff --git a/cfg/cpu/nosv/subsystem.cfg b/cfg/cpu/nosv/subsystem.cfg
index 5dc6fc5..09757c7 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: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},{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 427dc7c..ccc5157 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: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},{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 6ac7a7f..e366b3b 100644
--- a/doc/user/emulation/events.md
+++ b/doc/user/emulation/events.md
@@ -615,7 +615,7 @@ List of events for the model *tampi* with identifier **`T`** at version `1.0.0`:
## Model nosv
-List of events for the model *nosv* with identifier **`V`** at version `2.0.0`:
+List of events for the model *nosv* with identifier **`V`** at version `2.1.0`:
VTc(u32 taskid, u32 typeid)
- creates task %{taskid} with type %{typeid}
@@ -693,6 +693,18 @@ List of events for the model *nosv* with identifier **`V`** at version `2.0.0`:
- enters nosv_detach()
VAE
- leaves nosv_detach()
+VAl
+- enters nosv_mutex_lock()
+VAL
+- leaves nosv_mutex_lock()
+VAt
+- enters nosv_mutex_trylock()
+VAT
+- leaves nosv_mutex_trylock()
+VAu
+- enters nosv_mutex_unlock()
+VAU
+- leaves nosv_mutex_unlock()
VHa
- enters nosv_attach()
VHA
diff --git a/doc/user/emulation/versions.md b/doc/user/emulation/versions.md
index a9b7d7c..ed5a84d 100644
--- a/doc/user/emulation/versions.md
+++ b/doc/user/emulation/versions.md
@@ -39,6 +39,8 @@ Track changes in emulator model versions.
## nOS-V
+- nosv 2.1.0
+ - Add support for `nosv_mutex_lock`, `nosv_mutex_trylock` and `nosv_mutex_unlock` events VA{lLtTuU}.
- 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 fc9ccba..e50b694 100644
--- a/src/emu/nosv/event.c
+++ b/src/emu/nosv/event.c
@@ -59,6 +59,12 @@ static const int ss_table[256][256][3] = {
['A'] = { CHSS, POP, ST_API_ATTACH },
['e'] = { CHSS, PUSH, ST_API_DETACH },
['E'] = { CHSS, POP, ST_API_DETACH },
+ ['l'] = { CHSS, PUSH, ST_API_MUTEX_LOCK },
+ ['L'] = { CHSS, POP, ST_API_MUTEX_LOCK },
+ ['t'] = { CHSS, PUSH, ST_API_MUTEX_TRYLOCK },
+ ['T'] = { CHSS, POP, ST_API_MUTEX_TRYLOCK },
+ ['u'] = { CHSS, PUSH, ST_API_MUTEX_UNLOCK },
+ ['U'] = { CHSS, POP, ST_API_MUTEX_UNLOCK },
},
/* 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 01f523a..cb50a63 100644
--- a/src/emu/nosv/nosv_priv.h
+++ b/src/emu/nosv/nosv_priv.h
@@ -37,6 +37,9 @@ enum nosv_ss_values {
ST_API_SCHEDPOINT,
ST_API_ATTACH,
ST_API_DETACH,
+ ST_API_MUTEX_LOCK,
+ ST_API_MUTEX_TRYLOCK,
+ ST_API_MUTEX_UNLOCK,
ST_WORKER,
ST_DELEGATE,
diff --git a/src/emu/nosv/setup.c b/src/emu/nosv/setup.c
index 36464da..68d6680 100644
--- a/src/emu/nosv/setup.c
+++ b/src/emu/nosv/setup.c
@@ -60,6 +60,9 @@ static struct ev_decl model_evlist[] = {
PAIR_E("VAc", "VAC", "nosv_schedpoint()")
PAIR_E("VAa", "VAA", "nosv_attach()")
PAIR_E("VAe", "VAE", "nosv_detach()")
+ PAIR_E("VAl", "VAL", "nosv_mutex_lock()")
+ PAIR_E("VAt", "VAT", "nosv_mutex_trylock()")
+ PAIR_E("VAu", "VAU", "nosv_mutex_unlock()")
/* FIXME: VHA and VHa are not subsystems */
{ "VHa", "enters nosv_attach()" },
@@ -73,7 +76,7 @@ static struct ev_decl model_evlist[] = {
struct model_spec model_nosv = {
.name = model_name,
- .version = "2.0.0",
+ .version = "2.1.0",
.evlist = model_evlist,
.model = model_id,
.create = model_nosv_create,
@@ -144,6 +147,9 @@ static const struct pcf_value_label nosv_ss_values[] = {
{ ST_API_SCHEDPOINT, "API: Scheduling point" },
{ ST_API_ATTACH, "API: Attach" },
{ ST_API_DETACH, "API: Detach" },
+ { ST_API_MUTEX_LOCK, "API: Mutex lock" },
+ { ST_API_MUTEX_TRYLOCK,"API: Mutex trylock" },
+ { ST_API_MUTEX_UNLOCK, "API: Mutex unlock" },
{ 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 9bef0db..2a22872 100644
--- a/test/emu/nosv/CMakeLists.txt
+++ b/test/emu/nosv/CMakeLists.txt
@@ -20,6 +20,7 @@ test_emu(require-missing.c
REGEX "all .* models are enabled")
test_emu(parallel-tasks.c)
test_emu(nest-to-parallel.c)
+test_emu(mutex.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/instr_nosv.h b/test/emu/nosv/instr_nosv.h
index 8463c54..f96c6ae 100644
--- a/test/emu/nosv/instr_nosv.h
+++ b/test/emu/nosv/instr_nosv.h
@@ -50,6 +50,12 @@ 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_mutex_lock_enter, "VAl")
+INSTR_0ARG(instr_nosv_mutex_lock_exit, "VAL")
+INSTR_0ARG(instr_nosv_mutex_trylock_enter, "VAt")
+INSTR_0ARG(instr_nosv_mutex_trylock_exit, "VAT")
+INSTR_0ARG(instr_nosv_mutex_unlock_enter, "VAu")
+INSTR_0ARG(instr_nosv_mutex_unlock_exit, "VAU")
INSTR_0ARG(instr_nosv_attached, "VHa") /* deprecated */
INSTR_0ARG(instr_nosv_detached, "VHA") /* deprecated */
diff --git a/test/emu/nosv/mutex.c b/test/emu/nosv/mutex.c
new file mode 100644
index 0000000..dd60bdb
--- /dev/null
+++ b/test/emu/nosv/mutex.c
@@ -0,0 +1,32 @@
+/* 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_mutex_lock(), nosv_mutex_trylock() and nosv_mutex_unlock() API
+ * events, introduced in the nOS-V model 2.1.0 */
+
+int
+main(void)
+{
+ instr_start(0, 1);
+ instr_nosv_init();
+
+ instr_nosv_mutex_lock_enter();
+ sleep_us(100);
+ instr_nosv_mutex_lock_exit();
+
+ instr_nosv_mutex_trylock_enter();
+ sleep_us(100);
+ instr_nosv_mutex_trylock_exit();
+
+ instr_nosv_mutex_unlock_enter();
+ sleep_us(100);
+ instr_nosv_mutex_unlock_exit();
+
+ instr_end();
+
+ return 0;
+}
diff --git a/test/rt/nosv/CMakeLists.txt b/test/rt/nosv/CMakeLists.txt
index b1bd5a1..ab4325a 100644
--- a/test/rt/nosv/CMakeLists.txt
+++ b/test/rt/nosv/CMakeLists.txt
@@ -42,6 +42,7 @@ nosv_test(several-tasks.c SORT)
nosv_test(init-nested.c SORT)
nosv_test(parallel-tasks.c SORT)
nosv_test(inline.c SORT)
+nosv_test(mutex.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/mutex.c b/test/rt/nosv/mutex.c
new file mode 100644
index 0000000..4dc873c
--- /dev/null
+++ b/test/rt/nosv/mutex.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC)
+ * SPDX-License-Identifier: GPL-3.0-or-later */
+
+#include
+#include
+
+#include "common.h"
+#include "compat.h"
+
+int
+main(void)
+{
+ nosv_task_t task;
+ nosv_mutex_t mutex;
+
+ if (nosv_init() != 0)
+ die("nosv_init failed");
+
+ if (nosv_attach(&task, NULL, "attached-task", 0) != 0)
+ die("nosv_attach failed");
+
+
+ if (nosv_mutex_init(&mutex, NOSV_MUTEX_NONE) != 0)
+ die("nosv_mutex_init failed");
+
+ if (nosv_mutex_lock(mutex) != 0)
+ die("nosv_mutex_lock failed");
+
+ if (nosv_mutex_trylock(mutex) != NOSV_ERR_BUSY)
+ die("nosv_mutex_trylock failed");
+
+ if (nosv_mutex_unlock(mutex) != 0)
+ die("nosv_mutex_unlock failed");
+
+ if (nosv_mutex_destroy(mutex) != 0)
+ die("nosv_mutex_destroy failed");
+
+
+ if (nosv_detach(0) != 0)
+ die("nosv_detach failed");
+
+ if (nosv_shutdown() != 0)
+ die("nosv_shutdown failed");
+
+ return 0;
+}