Skip to contentSkip to conversation

posix signals rework

Xenomai New Gilles Chanteperdrix 1 participant 3 messages May 11, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

following the discussions on the I-pipe patch, here is a proposed modification for the posix thread signals relying on xnshadow_call_mayday. xnshadow_call_mayday is modified to not send a signal, expecting its caller to have sent one, then a pending signal to a user-space posix skin thread causes xnshadow_call_mayday to be called.

Whereas it works, what still seems strange with this implementation is to have to set the XNAMOK bit to cause xnshadow_sys_mayday to switch to secondary mode.

Thanks in advance for your review.
Regards.

Signature · 1 line
                                                                Gilles.
#1 lore raw

PATCH 1/2 nucleus/shadow: generalize xnshadow_call_mayday

Allow skins to use it to send other signals than SIGDEBUG

---
 include/nucleus/shadow.h |    5 ++---
 ksrc/nucleus/sched.c     |    3 ++-
 ksrc/nucleus/shadow.c    |    3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)
include/nucleus/shadow.h +2 -3
index 9c8784c..bca3c48 100644
@@ -99,10 +99,9 @@ void xnshadow_rpi_check(void);
 
 #ifdef RTHAL_HAVE_RETURN_EVENT
 #define XNARCH_HAVE_MAYDAY  1
-void xnshadow_call_mayday(struct xnthread *thread, int sigtype);
+void xnshadow_call_mayday(struct xnthread *thread);
 #else
-static inline void xnshadow_call_mayday(struct xnthread *thread,
-					int sigtype)
+static inline void xnshadow_call_mayday(struct xnthread *thread)
 {
 	/* no luck, I-pipe too old. Nobody hears you screaming... */
 }
ksrc/nucleus/sched.c +2 -1
index 5d2f074..3391f4a 100644
@@ -99,7 +99,8 @@ static void xnsched_watchdog_handler(struct xntimer *timer)
 		xnprintf("watchdog triggered -- signaling runaway thread "
 			 "'%s'\n", xnthread_name(thread));
 		xnthread_set_info(thread, XNAMOK);
-		xnshadow_call_mayday(thread, SIGDEBUG_WATCHDOG);
+		xnshadow_send_sig(thread, SIGDEBUG, SIGDEBUG_WATCHDOG, 1);
+		xnshadow_call_mayday(thread);
 	} else
 #endif /* CONFIG_XENO_OPT_PERVASIVE */
 	{
ksrc/nucleus/shadow.c +1 -2
index 7c4e032..50ee035 100644
@@ -1643,11 +1643,10 @@ static unsigned long map_mayday_page(struct task_struct *p)
 	return IS_ERR_VALUE(u_addr) ? 0UL : u_addr;
 }
 
-void xnshadow_call_mayday(struct xnthread *thread, int sigtype)
+void xnshadow_call_mayday(struct xnthread *thread)
 {
 	struct task_struct *p = xnthread_archtcb(thread)->user_task;
 	xnthread_set_info(thread, XNKICKED);
-	xnshadow_send_sig(thread, SIGDEBUG, sigtype, 1);
 	xnarch_call_mayday(p);
 }
 EXPORT_SYMBOL_GPL(xnshadow_call_mayday);
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/2 skins/posix: rework user-space thread signals

In reply to Gilles Chanteperdrix

Calling xnshadow_relax() from xnpod_schedule() signals dispatcher causes issues with the I-pipe patch. Rely on xnshadow_call_mayday() to cause a switch to secondary mode instead.

---
 ksrc/skins/posix/signal.c |   34 ++++++++++------------------------
 1 files changed, 10 insertions(+), 24 deletions(-)
ksrc/skins/posix/signal.c +10 -24
index dfc4b77..42829a4 100644
@@ -318,16 +318,19 @@ int pse51_sigqueue_inner(pthread_t thread, pse51_siginfo_t * si)
 #ifdef CONFIG_XENO_OPT_PERVASIVE
 	if (xnthread_test_state(&thread->threadbase, XNSHADOW)) {
 		pse51_schedule_lostage(PSE51_LO_SIGNAL_REQ, thread, 0);
+		thread->threadbase.signals = 0;
 		if (xnthread_test_state(&thread->threadbase,
 					XNDELAY|XNPEND|XNSUSP|XNRELAX)) {
 			/* Thread is suspended in a syscall, or already relaxed,
-			   we do not need to run the signal dispatcher, the
+			   we do not need to cann xnshadow_call_mayday, the
 			   signal APC will cause the sigwake_event to be
 			   generated, which will kick the thread. */
-			thread->threadbase.signals = 0;
 			return 0;
-		} else
-			return thread == pse51_current_thread();
+		} 
+
+		xnthread_set_info(&thread->threadbase, XNAMOK);
+		xnshadow_call_mayday(&thread->threadbase);
+		return thread == pse51_current_thread();
 	}
 #endif /* CONFIG_XENO_OPT_PERVASIVE */
 
@@ -1086,16 +1089,6 @@ static void pse51_dispatch_signals(xnsigmask_t sigs)
 }
 
 #ifdef CONFIG_XENO_OPT_PERVASIVE
-static void pse51_dispatch_shadow_signals(xnsigmask_t sigs)
-{
-	spl_t dummy;
-	/* Migrate to secondary mode in order to get the signals delivered by
-	   Linux. */
-	xnshadow_relax(1, SIGDEBUG_MIGRATE_SIGNAL);
-	xnlock_get_irqsave(&nklock, dummy);
-	(void)dummy;
-}
-
 void pse51_signal_handle_request(pthread_t thread)
 {
 	pse51_siginfo_t *si;
@@ -1103,8 +1096,6 @@ void pse51_signal_handle_request(pthread_t thread)
 
 	xnlock_get_irqsave(&nklock, s);
 
-	thread->threadbase.signals = 0;
-
 	while ((si = pse51_getsigq(&thread->pending,
 				   &thread->pending.mask, NULL))) {
 		siginfo_t info = si->info;
@@ -1121,13 +1112,10 @@ void pse51_signal_handle_request(pthread_t thread)
 		   reschedule. */
 		xnlock_put_irqrestore(&nklock, s);
 
-		send_sig_info(info.si_signo,
-			      &info,
+		send_sig_info(info.si_signo, &info,
 			      xnthread_user_task(&thread->threadbase));
 
 		xnlock_get_irqsave(&nklock, s);
-
-		thread->threadbase.signals = 0;
 	}
 
 	xnlock_put_irqrestore(&nklock, s);
@@ -1148,14 +1136,12 @@ void pse51_signal_init_thread(pthread_t newthread, const pthread_t parent)
 		emptyset(&newthread->sigmask);
 
 #ifdef CONFIG_XENO_OPT_PERVASIVE
-	if (testbits(newthread->threadbase.state, XNSHADOW))
-		newthread->threadbase.asr = &pse51_dispatch_shadow_signals;
-	else
+	if (testbits(newthread->threadbase.state, XNSHADOW) == 0)
 #endif /* CONFIG_XENO_OPT_PERVASIVE */
 		newthread->threadbase.asr = &pse51_dispatch_signals;
 
-	newthread->threadbase.asrmode = 0;
 	newthread->threadbase.asrimask = 0;
+	newthread->threadbase.asrmode = 0;
 }
 
 /* Unqueue, and free any pending siginfo structure. Assume we are called nklock
Signature · 1 line
1.7.2.5