EVL: EVL_HMDIAG_SYSDEMOTE is not marked
My understanding is that when setting the thread mode to T_WOSS | T_HMSIG, then when the thread switches to inband via syscall, a SIGDEBUG signal si will be delivered to the thread such that sigdebug_marked(si) is true and sigdebug_cause(si) is EVL_HMDIAG_SYSDEMOTE.
The test below tests for that but it fails: a SIGDEBUG is indeed delivereed and sigdebug_cause(si) is indeed EVL_HMDIAG_SYSDEMOTE, but sigdebug_marked(si) returns false, in fact sigdebug_code(si) is simply set to 2.
I build this from within libevl/tests with
gcc -D_GNU_SOURCE switch-warn.c helpers.c -I/usr/evl/include -L/usr/evl/lib/aarch64-linux-gnu/ -levl -pthread -o test-switch-warn
and when I run it I get:
NOT MARKED switched inband (syscall)
switch-warn.c:87: FAILED: notified (=false)
This is tested with this branch https://source.denx.de/Xenomai/xenomai4/linux-evl/-/tree/vendor/ti/v5.10.120 and commit 7ccc58d62905724f1b8de4823e0fe8e0129b0fb7 of libevl (r37 + 1 ). Other tests testing for sigdebug_marked(), e.g.: stax-warn do work as expected.
Full code below:
/*
* SPDX-License-Identifier: MIT
*
* Make sure we receive EVL_HMDIAG_STAGEX when locked out from the
* out-of-band stage because of a stax-based serialization. */
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <evl/evl.h>
#include <evl/compiler.h> // fallthrough
#include "helpers.h"
static volatile sig_atomic_t notified;
#define raw_write_out(__msg) \
do { \
int __ret; \
__ret = write(1, __msg , strlen(__msg)); \
(void)__ret; \
} while (0)static const char *sigdebug_msg[] = {
[EVL_HMDIAG_SIGDEMOTE] = "switched inband (signal)\n", [EVL_HMDIAG_SYSDEMOTE] = "switched inband (syscall)\n", [EVL_HMDIAG_EXDEMOTE] = "switched inband (fault)\n", [EVL_HMDIAG_LKDEPEND] = "switched inband while holding mutex\n", [EVL_HMDIAG_WATCHDOG] = "watchdog triggered\n", [EVL_HMDIAG_LKIMBALANCE] = "mutex lock/unlock imbalance\n", [EVL_HMDIAG_LKSLEEP] = "attempt to sleep while holding a mutex\n", [EVL_HMDIAG_STAGEX] = "locked out from out-of-band stage (stax)\n",
};
// a variation on evl_sigdebug_handler
static void sigdebug_handler(int sig, siginfo_t *si, void *ctxt)
{
raw_write_out(sigdebug_marked(si) ? "MARKED " : "NOT MARKED ");
// print cause regardless of marked status
switch (sigdebug_cause(si)) {
case EVL_HMDIAG_SYSDEMOTE:
if(sigdebug_marked(si))
notified = 1;
__fallthrough;
case EVL_HMDIAG_SIGDEMOTE:
case EVL_HMDIAG_EXDEMOTE:
case EVL_HMDIAG_LKDEPEND:
case EVL_HMDIAG_WATCHDOG:
case EVL_HMDIAG_LKIMBALANCE:
case EVL_HMDIAG_LKSLEEP:
case EVL_HMDIAG_STAGEX:
raw_write_out(sigdebug_msg[sigdebug_cause(si)]);
break;
default:
raw_write_out("SOME OTHER SIGNAL\n");
}
}static void *test_thread(void *arg)
{
int tfd, ret;
__Tcall_assert(tfd, evl_attach_self("switch-warn-test:%d", getpid()));
__Tcall_assert(ret, evl_set_thread_mode(tfd,
0
| T_WOSS
| T_HMSIG
, NULL));
evl_switch_inband();
return NULL;
}int main(int argc, char *argv[])
{
struct sigaction sa;
pthread_t tid;
int ret;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = sigdebug_handler;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGDEBUG, &sa, NULL);
new_thread(&tid, SCHED_FIFO, 1, test_thread, NULL);
pthread_join(tid, NULL);
__Texpr_assert(notified);
return 0;
}Quoted 4 lines · Giulio Moro
My understanding is that when setting the thread mode to
T_WOSS|T_HMSIG, then when the thread switches to inband via syscall, a SIGDEBUG signal si will be delivered to the thread such thatsigdebug_marked(si)is true andsigdebug_cause(si)isEVL_HMDIAG_SYSDEMOTE.The test below tests for that but it fails: a SIGDEBUG is indeed delivereed and
sigdebug_cause(si)is indeedEVL_HMDIAG_SYSDEMOTE, butsigdebug_marked(si)returns false, in factsigdebug_code(si)is simply set to 2.
Confirmed. Please let me know if this patch does help as expected:
--
commit 52f547a9a83f6e5430a72dd213968703ce0213d6 (HEAD -> rebase/v5.19-evl)
Author: Philippe Gerum <[email protected]> Date: Tue Aug 23 12:04:26 2022 +0200
evl/thread: duly mark SIGDEBUG cause on direct signal
The sigval information was not bearing the SIGDEBUG marker in case we signaled from in-band context directly. Set the marker in the common code path shared between oob and in-band contexts to fix this.
kernel/evl/thread.c +2 -2
@@ -1304,7 +1304,7 @@ static void do_inband_signal(struct evl_thread *thread, int signo, int sigval)memset (&si,'\0' ,sizeof (si)); si.si_signo = signo; si.si_code =SI_QUEUE ; - si.si_int = sigval; + si.si_int = sigval | sigdebug_marker;send_sig_info (signo, &si, p); }else send_sig (signo, p,1 );
@@ -1336,7 +1336,7 @@ void evl_signal_thread(struct evl_thread *thread, int sig, int arg)init_irq_work (&sigd->work, sig_irqwork); sigd->thread = thread; sigd->signo = sig; - sigd->sigval = sig ==SIGDEBUG ? arg | sigdebug_marker : arg; + sigd->sigval = arg;evl_get_element (&thread->element);/* Cannot fail, irq_work is local to this call. */
Signature · 1 line
Philippe.