From b265442b8c25519534bdc606cb0ec9cd93667058 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 20 Feb 2023 11:48:23 +0100 Subject: [PATCH] Mark select channel as dirty on mux_init() Ensures that the select callback will be called on the propagation phase, immediately setting the right output. Otherwise the mux won't be updated until the select channel sets a new value. --- src/emu/mux.c | 7 +++++++ test/emu/nanos6/CMakeLists.txt | 1 + test/emu/nanos6/delayed-connect-ss.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 test/emu/nanos6/delayed-connect-ss.c diff --git a/src/emu/mux.c b/src/emu/mux.c index 7735dc5..a182c77 100644 --- a/src/emu/mux.c +++ b/src/emu/mux.c @@ -192,6 +192,13 @@ mux_init(struct mux *mux, return -1; } + /* Mark the select channel as dirty, so it runs the select + * callback even if it doesn't have a new value */ + if (chan_dirty(select) != 0) { + err("chan_dirty failed"); + return -1; + } + return 0; } diff --git a/test/emu/nanos6/CMakeLists.txt b/test/emu/nanos6/CMakeLists.txt index 76d9851..4b39909 100644 --- a/test/emu/nanos6/CMakeLists.txt +++ b/test/emu/nanos6/CMakeLists.txt @@ -8,3 +8,4 @@ ovni_test(task-types.c MP) ovni_test(blocking.c MP) ovni_test(ss-mismatch.c SHOULD_FAIL REGEX "thread [0-9]\\+ ended with 1 stacked nanos6 subsystems") +ovni_test(delayed-connect-ss.c) diff --git a/test/emu/nanos6/delayed-connect-ss.c b/test/emu/nanos6/delayed-connect-ss.c new file mode 100644 index 0000000..8a75ec8 --- /dev/null +++ b/test/emu/nanos6/delayed-connect-ss.c @@ -0,0 +1,28 @@ +/* Copyright (c) 2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include "instr_nanos6.h" + +int +main(void) +{ + instr_start(0, 1); + + /* Until here, the nanos6 model has not been connected to the + * patchbay yet. The next event will cause the subsystem mux to + * be connected to the patchbay. We need to ensure that at that + * moment the select channel is evaluated, otherwise the mux + * will remain selecting a null input until the thread state + * changes. */ + + /* FIXME: We should be able to test that after emitting the + * nanos6 event the emulator follows some properties. */ + + instr_nanos6_worker_loop_enter(); + + instr_nanos6_worker_loop_exit(); + + instr_end(); + + return 0; +}