Freezing all Xenomai timers while just a single RT application is under
ptrace control can be helpful in certain debugging scenarios, but it can
as well be harmful when other parts of the systems have to continue to work.

I brought this concern up back in 2006, and I originally thought we may
address this by freezing per process. But this is far too complex for a
simple problem like this: Just make the whole thing configurable, and
keep it off by default so that -ideally- only users who are aware of the
side effects will arm it.

Gilles, you recently stumbled over such a side effect and introduced
XNTIMER_NOBLCK (for customized timer instrumentations as far as I
understood this). Do you think we still need that knob when we have

 ksrc/nucleus/Kconfig  |   14 ++++++++++++++
 ksrc/nucleus/shadow.c |   22 ++++++++--------------
 2 files changed, 22 insertions(+), 14 deletions(-)

Index: b/ksrc/nucleus/Kconfig
--- a/ksrc/nucleus/Kconfig
+++ b/ksrc/nucleus/Kconfig
@@ -194,6 +194,20 @@ config XENO_OPT_DEBUG_TIMERS
 	This option activates debugging output for critical
 	timer-related operations performed by the Xenomai core.
+	bool "Freeze timers while debugging applications"
+	depends on XENO_OPT_DEBUG
+	help
+	If this feature is enabled, Xenomai no longer fires timers
+	while some real-time application is being debugged via
+	ptrace (gdb etc.). This can ease stepping through real-time
+	applications as it avoids certain types of timeouts to ocure
+	due to the debugging-related delays. On the other hand, this
+	global freeze can cause unwanted side-effects to other,
+	unrelated components in the system that rely on timers
+	continue to work.
 	bool "Watchdog support"
 	depends on XENO_OPT_DEBUG
Index: b/ksrc/nucleus/shadow.c
--- a/ksrc/nucleus/shadow.c
+++ b/ksrc/nucleus/shadow.c
@@ -840,18 +840,6 @@ static inline void set_linux_task_priori
 		       prio, p->comm);
-static inline void lock_timers(void)
-	xnarch_atomic_inc(&nkpod->timerlck);
-	setbits(nktbase.status, XNTBLCK);
-static inline void unlock_timers(void)
-	if (xnarch_atomic_dec_and_test(&nkpod->timerlck))
-		clrbits(nktbase.status, XNTBLCK);
 static void xnshadow_dereference_skin(unsigned magic)
 	unsigned muxid;
@@ -2199,6 +2187,7 @@ static inline void do_schedule_event(str
 		   SIGSTOP and SIGINT in order to encompass both the NPTL and
 		   LinuxThreads behaviours. */
 		if (xnthread_test_info(threadin, XNDEBUG)) {
 			if (signal_pending(next)) {
 				sigset_t pending;
@@ -2213,10 +2202,12 @@ static inline void do_schedule_event(str
 			xnthread_clear_info(threadin, XNDEBUG);
-			unlock_timers();
+			if (xnarch_atomic_dec_and_test(&nkpod->timerlck))
+				clrbits(nktbase.status, XNTBLCK);
 			int sigpending = signal_pending(next);
@@ -2261,6 +2252,7 @@ static inline void do_sigwake_event(stru
 	xnlock_get_irqsave(&nklock, s);
 	if ((p->ptrace & PT_PTRACED) && !xnthread_test_info(thread, XNDEBUG)) {
 		sigset_t pending;
@@ -2271,9 +2263,11 @@ static inline void do_sigwake_event(stru
 		    sigismember(&pending, SIGSTOP)
 		    || sigismember(&pending, SIGINT)) {
 			xnthread_set_info(thread, XNDEBUG);
-			lock_timers();
+			xnarch_atomic_inc(&nkpod->timerlck);
+			setbits(nktbase.status, XNTBLCK);
 	if (xnthread_test_state(thread, XNRELAX))
 		goto unlock_and_exit;

Attachment: signature.asc
Description: OpenPGP digital signature

Xenomai-core mailing list

Reply via email to