Skip to contentSkip to conversation

Check for NPTL and factor user-space skins initialization.

PATCH In review Gilles Chanteperdrix 3 participants 10 messages Apr 18, 2006 – Apr 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check for NPTL and factor user-space skins initialization.

For review...

Signature · 1 line
					    Gilles Chanteperdrix.
asm-i386/features.h +31 -0
Index: include/asm-i386/features.h
===================================================================
@@ -76,4 +76,35 @@
     }
 }
 
+#ifndef __KERNEL__
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {
+      char *buf = malloc(n);
+      int isnptl;
+      
+      confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
+      isnptl = strstr (buf, "NPTL") != NULL;
+      free(buf);
+
+      if (isnptl)
+          return;
+      }
+
+  fprintf(stderr, "Xenomai: SEP instruction needs NPTL and NPTL was not detected"
+          "\nplease install NPTL or recompile Xenomai without enabling SEP.\n");
+  exit(1);
+#endif /* CONFIG_XENO_X86_SEP */
+}
+#define xeno_arch_features_check() xeno_x86_features_check()
+#endif /* __KERNEL__ */
+
 #endif /* !_XENO_ASM_I386_FEATURES_H */
nucleus/Makefile.am +2 -0
Index: include/nucleus/Makefile.am
===================================================================
@@ -22,3 +22,5 @@
 	types.h \
 	version.h \
 	xenomai.h
+
+EXTRA_DIST = skin_init.h
skins/rtai/init.c +2 -41

53 lines not on this page · raw message

skins/posix/init.c +3 -72

99 lines not on this page · raw message

skins/vxworks/init.c +12 -66

94 lines not on this page · raw message

skins/vrtx/init.c +18 -69

107 lines not on this page · raw message

skins/native/init.c +9 -83

109 lines not on this page · raw message

skins/rtdm/init.c +4 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -30,6 +30,10 @@
     xnfeatinfo_t finfo;
     int muxid;
 
+#ifdef xeno_arch_features_check
+    xeno_arch_features_check();
+#endif /* xeno_arch_features_check */
+
     muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 			    XENOMAI_FEAT_DEP,
 			    XENOMAI_ABI_REV,
skins/uvm/init.c +3 -41

55 lines not on this page · raw message

nucleus/skin_init.h new file +87 -0

87 lines not on this page · raw message

#1 lore raw
Quoted 29 lines · Gilles Chanteperdrix

For review...

------------------------------------------------------------------------

Index: include/asm-i386/features.h
===================================================================

asm-i386/features.h +15 -0
@@ -76,4 +76,35 @@
     }
 }
 
+#ifndef __KERNEL__
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {
+      char *buf = malloc(n);
+      int isnptl;
+      

asm-i386/features.h line 103

Quoted 10 lines
asm-i386/features.h +10 -0
+      confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
+      isnptl = strstr (buf, "NPTL") != NULL;
+      free(buf);
+
+      if (isnptl)
+          return;
+      }
+
+  fprintf(stderr, "Xenomai: SEP instruction needs NPTL and NPTL was not detected"
+          "\nplease install NPTL or recompile Xenomai without enabling SEP.\n");

- "\nplease install NPTL or recompile Xenomai without enabling SEP.\n");
+ "\nplease install NPTL or rebuild the user-space support passing --disable-x86-sep.\n");

<snip>

asm-i386/features.h

Quoted 12 lines
asm-i386/features.h +12 -0
+static inline void xeno_mlock_alert_end(void)
+{
+    struct sigaction sa;
+
+    sigaction(SIGXCPU, NULL, &sa);
+    if (sa.sa_handler == &xeno_handle_mlock_alert)
+        {
+        sa.sa_handler = SIG_DFL;
+        sigaction(SIGXCPU, &sa, NULL);
+        }
+}
+

-ENOPARSE here. Which code is expected to call xeno_mlock_alert_end()?

<snip>

Signature · 1 line
Philippe.
#2 lore raw
Quoted 2 lines · Philippe Gerum

-ENOPARSE here. Which code is expected to call xeno_mlock_alert_end()?

pthread_set_mode_np and rt_task_set_mode. Sorry.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-i386/features.h +31 -0
Index: include/asm-i386/features.h
===================================================================
@@ -76,4 +76,35 @@
     }
 }
 
+#ifndef __KERNEL__
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {
+      char *buf = malloc(n);
+      int isnptl;
+      
+      confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
+      isnptl = strstr (buf, "NPTL") != NULL;
+      free(buf);
+
+      if (isnptl)
+          return;
+      }
+
+  fprintf(stderr, "Xenomai: SEP instruction needs NPTL and NPTL was not detected"
+          "\nplease install NPTL or recompile Xenomai without enabling SEP.\n");
+  exit(1);
+#endif /* CONFIG_XENO_X86_SEP */
+}
+#define xeno_arch_features_check() xeno_x86_features_check()
+#endif /* __KERNEL__ */
+
 #endif /* !_XENO_ASM_I386_FEATURES_H */
nucleus/Makefile.am +2 -0
Index: include/nucleus/Makefile.am
===================================================================
@@ -22,3 +22,5 @@
 	types.h \
 	version.h \
 	xenomai.h
+
+EXTRA_DIST = skin_init.h
skins/rtai/init.c +2 -41

53 lines not on this page · raw message

skins/posix/init.c +3 -72

99 lines not on this page · raw message

skins/posix/thread.c +4 -4
Index: src/skins/posix/thread.c
===================================================================
@@ -19,10 +19,11 @@
 #include <stddef.h>
 #include <errno.h>
 #include <signal.h>
-#include <posix/syscall.h>
 #include <pthread.h>
 #include <semaphore.h>
+#include <nucleus/skin_init.h>
 #include <nucleus/thread.h>
+#include <posix/syscall.h>
 
 extern int __pse51_muxid;
 
@@ -202,7 +203,6 @@
 int pthread_set_mode_np (int clrmask,
 			 int setmask)
 {
-    extern int __pse51_sigxcpu_no_mlock;
     pthread_t tid = pthread_self();
     int err;
 
@@ -217,8 +217,8 @@
        locked, otherwise we would have caught the latter signal upon
        thread creation. */
 
-    if (!err && __pse51_sigxcpu_no_mlock)
-	__pse51_sigxcpu_no_mlock = !(setmask & PTHREAD_WARNSW);
+    if (!err)
+	xeno_mlock_alert_end();
 
     return err;
 }
skins/vxworks/init.c +12 -66

94 lines not on this page · raw message

skins/vrtx/init.c +18 -69

107 lines not on this page · raw message

skins/native/init.c +9 -83

109 lines not on this page · raw message

skins/native/task.c +3 -3
Index: src/skins/native/task.c
===================================================================
@@ -24,6 +24,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include <limits.h>
+#include <nucleus/skin_init.h>
 #include <native/syscall.h>
 #include <native/task.h>
 
@@ -311,7 +312,6 @@
 		      int setmask,
 		      int *oldmode)
 {
-    extern int __native_sigxcpu_no_mlock;
     int err;
 
     err = XENOMAI_SKINCALL3(__native_muxid,
@@ -325,8 +325,8 @@
        locked, otherwise we would have caught the latter signal upon
        thread creation. */
 
-    if (!err && __native_sigxcpu_no_mlock)
-	__native_sigxcpu_no_mlock = !(setmask & T_WARNSW);
+    if (!err)
+        xeno_mlock_alert_end();
 
     return err;
 }
skins/rtdm/init.c +4 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -30,6 +30,10 @@
     xnfeatinfo_t finfo;
     int muxid;
 
+#ifdef xeno_arch_features_check
+    xeno_arch_features_check();
+#endif /* xeno_arch_features_check */
+
     muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 			    XENOMAI_FEAT_DEP,
 			    XENOMAI_ABI_REV,
skins/uvm/init.c +3 -41

55 lines not on this page · raw message

nucleus/skin_init.h new file +87 -0

87 lines not on this page · raw message

#3 lore raw
Quoted 5 lines · Gilles Chanteperdrix
Quoted 2 lines · Philippe Gerum

-ENOPARSE here. Which code is expected to call xeno_mlock_alert_end()?

pthread_set_mode_np and rt_task_set_mode. Sorry.

The issue I see doing so, is that you are going to trigger a SIGXCPU right after setting the XNTRAPSW bit for the current thread, as a result of calling sigaction and friends. This is why I used a plain and dumb memory flag instead, the logic being:

- first, trap SIGXCPU in the library ctor to detect the lack of process memory locking when mapping a shadow thread, and emit an explanatory message when caught.

- as soon as a thread succeeds in setting modes (set_mode_np and friends), then we know that a previous shadow mapping for the current Linux task has succeeded, otherwise the nucleus would not have been able to carry out the set_mode request. In such a case, make sure to cause our internal SIGXCPU handler to switch to the default behaviour, in case we did set the WARNSW bit for the current thread successfully. In all other cases, either the user has set its own SIGXCPU handler overriding our internal one, and we have no part in the play, or she did not and we won't spuriously emit the "missing mlock" message.

Signature · 1 line
Philippe.
#4 lore raw
Quoted 16 lines · Philippe Gerum
Quoted 5 lines · Gilles Chanteperdrix
Quoted 2 lines · Philippe Gerum

-ENOPARSE here. Which code is expected to call xeno_mlock_alert_end()?

pthread_set_mode_np and rt_task_set_mode. Sorry.

The issue I see doing so, is that you are going to trigger a SIGXCPU right after setting the XNTRAPSW bit for the current thread, as a result of calling sigaction and friends. This is why I used a plain and dumb memory flag instead, the logic being:

- first, trap SIGXCPU in the library ctor to detect the lack of process memory locking when mapping a shadow thread, and emit an explanatory message when caught.

Quoted 9 lines

- as soon as a thread succeeds in setting modes (set_mode_np and friends), then we know that a previous shadow mapping for the current Linux task has succeeded, otherwise the nucleus would not have been able to carry out the set_mode request. In such a case, make sure to cause our internal SIGXCPU handler to switch to the default behaviour, in case we did set the WARNSW bit for the current thread successfully. In all other cases, either the user has set its own SIGXCPU handler overriding our internal one, and we have no part in the play, or she did not and we won't spuriously emit the "missing mlock" message.

Ok. Another try.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-i386/features.h +29 -0
Index: include/asm-i386/features.h
===================================================================
@@ -76,4 +76,33 @@
     }
 }
 
+#ifndef __KERNEL__
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {
+      char buf[n];
+      
+      confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
+
+      if (strstr (buf, "NPTL"))
+          return;
+      }
+
+  fprintf(stderr, "Xenomai: SEP instruction needs NPTL and NPTL was not detected"
+          "\nplease install NPTL or rebuild the user-space support passing "
+          "--disable-x86-sep.\n"); 
+  exit(1);
+#endif /* CONFIG_XENO_X86_SEP */
+}
+#define xeno_arch_features_check() xeno_x86_features_check()
+#endif /* __KERNEL__ */
+
 #endif /* !_XENO_ASM_I386_FEATURES_H */
nucleus/Makefile.am +2 -0
Index: include/nucleus/Makefile.am
===================================================================
@@ -22,3 +22,5 @@
 	types.h \
 	version.h \
 	xenomai.h
+
+EXTRA_DIST = skin_init.h
skins/rtai/init.c +2 -41

53 lines not on this page · raw message

skins/posix/init.c +3 -73

99 lines not on this page · raw message

skins/posix/thread.c +4 -4
Index: src/skins/posix/thread.c
===================================================================
@@ -19,10 +19,10 @@
 #include <stddef.h>
 #include <errno.h>
 #include <signal.h>
-#include <posix/syscall.h>
 #include <pthread.h>
 #include <semaphore.h>
 #include <nucleus/thread.h>
+#include <posix/syscall.h>
 
 extern int __pse51_muxid;
 
@@ -202,7 +202,7 @@
 int pthread_set_mode_np (int clrmask,
 			 int setmask)
 {
-    extern int __pse51_sigxcpu_no_mlock;
+    extern int xeno_sigxcpu_no_mlock;
     pthread_t tid = pthread_self();
     int err;
 
@@ -217,8 +217,8 @@
        locked, otherwise we would have caught the latter signal upon
        thread creation. */
 
-    if (!err && __pse51_sigxcpu_no_mlock)
-	__pse51_sigxcpu_no_mlock = !(setmask & PTHREAD_WARNSW);
+    if (!err && xeno_sigxcpu_no_mlock)
+	xeno_sigxcpu_no_mlock = !(setmask & PTHREAD_WARNSW);
 
     return err;
 }
skins/vxworks/init.c +12 -66

94 lines not on this page · raw message

skins/vrtx/init.c +18 -69

107 lines not on this page · raw message

skins/native/init.c +9 -83

109 lines not on this page · raw message

skins/native/task.c +3 -3
Index: src/skins/native/task.c
===================================================================
@@ -311,7 +311,7 @@
 		      int setmask,
 		      int *oldmode)
 {
-    extern int __native_sigxcpu_no_mlock;
+    extern int xeno_sigxcpu_no_mlock;
     int err;
 
     err = XENOMAI_SKINCALL3(__native_muxid,
@@ -325,8 +325,8 @@
        locked, otherwise we would have caught the latter signal upon
        thread creation. */
 
-    if (!err && __native_sigxcpu_no_mlock)
-	__native_sigxcpu_no_mlock = !(setmask & T_WARNSW);
+    if (!err && xeno_sigxcpu_no_mlock)
+	xeno_sigxcpu_no_mlock = !(setmask & T_WARNSW);
 
     return err;
 }
skins/rtdm/init.c +4 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -30,6 +30,10 @@
     xnfeatinfo_t finfo;
     int muxid;
 
+#ifdef xeno_arch_features_check
+    xeno_arch_features_check();
+#endif /* xeno_arch_features_check */
+
     muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 			    XENOMAI_FEAT_DEP,
 			    XENOMAI_ABI_REV,
skins/uvm/init.c +3 -41

55 lines not on this page · raw message

nucleus/skin_init.h new file +94 -0

94 lines not on this page · raw message

#5 lore raw
Quoted 27 lines · Gilles Chanteperdrix
Quoted 16 lines · Philippe Gerum
Quoted 5 lines · Gilles Chanteperdrix
Quoted 2 lines · Philippe Gerum

-ENOPARSE here. Which code is expected to call xeno_mlock_alert_end()?

pthread_set_mode_np and rt_task_set_mode. Sorry.

The issue I see doing so, is that you are going to trigger a SIGXCPU right after setting the XNTRAPSW bit for the current thread, as a result of calling sigaction and friends. This is why I used a plain and dumb memory flag instead, the logic being:

- first, trap SIGXCPU in the library ctor to detect the lack of process memory locking when mapping a shadow thread, and emit an explanatory message when caught.

Quoted 9 lines

- as soon as a thread succeeds in setting modes (set_mode_np and friends), then we know that a previous shadow mapping for the current Linux task has succeeded, otherwise the nucleus would not have been able to carry out the set_mode request. In such a case, make sure to cause our internal SIGXCPU handler to switch to the default behaviour, in case we did set the WARNSW bit for the current thread successfully. In all other cases, either the user has set its own SIGXCPU handler overriding our internal one, and we have no part in the play, or she did not and we won't spuriously emit the "missing mlock" message.

Quoted 2 lines

Ok. Another try.

Looks good. Merged, thanks.

Signature · 1 line
Philippe.
#6 lore raw
In reply to Gilles Chanteperdrix
Quoted 8 lines · Gilles Chanteperdrix

For review...

asm-i386/features.h +2 -0
+#ifndef __KERNEL__
+#include <stdio.h>

asm-i386/features.h line 90

Quoted 10 lines
asm-i386/features.h +10 -0
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {

since this is user code, its possible to read /proc/cpuinfo, and find the sep flag.

Is this worth doing also ?
if so, I can work a patch up later, unless you feel the urge.

#7 lore raw
Quoted 24 lines · Jim Cromie
Quoted 8 lines · Gilles Chanteperdrix

For review...

asm-i386/features.h +2 -0
+#ifndef __KERNEL__
+#include <stdio.h>

asm-i386/features.h line 90

Quoted 10 lines
asm-i386/features.h +10 -0
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void xeno_x86_features_check(void)
+{
+#ifdef CONFIG_XENO_X86_SEP
+  size_t n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
+  if (n > 0)
+      {

since this is user code, its possible to read /proc/cpuinfo, and find the sep flag.

Quoted 1 line

Is this worth doing also ?

Some deeply embedded stuff (something like buried in the silicon actually...) might configure out CONFIG_PROC_FS, so we can't rely on this pseudo-fs to be always present.

Quoted 7 lines

if so, I can work a patch up later, unless you feel the urge.

_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.
#8 lore raw
Quoted 5 lines · Philippe Gerum
Quoted 1 line

Is this worth doing also ?

Some deeply embedded stuff (something like buried in the silicon actually...) might configure out CONFIG_PROC_FS, so we can't rely on this pseudo-fs to be always present.

Maybe we could use the information if available?

Signature · 1 line
					    Gilles Chanteperdrix.
#9 lore raw
Quoted 9 lines · Gilles Chanteperdrix
Quoted 5 lines · Philippe Gerum
Quoted 1 line

Is this worth doing also ?

Some deeply embedded stuff (something like buried in the silicon actually...) might configure out CONFIG_PROC_FS, so we can't rely on this pseudo-fs to be always present.

Maybe we could use the information if available?

It would be redundant, since the nucleus already tells us whether sep is known or not at kernel level.

Signature · 1 line
Philippe.