Skip to contentSkip to conversation

posix: Skip auto-shadowing if current thread is already shadowed

PATCH In review Jan Kiszka 2 participants 6 messages Jun 12, 2013 – Jul 26, 2013

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 posix: Skip auto-shadowing if current thread is already shadowed

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

---
 src/skins/posix/init.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/skins/posix/init.c +2 -1
index 80725c5..ca1d9e1 100644
@@ -31,6 +31,7 @@
 #include <rtdk.h>
 
 #include <asm-generic/xenomai/bind.h>
+#include <asm-generic/xenomai/current.h>
 
 int __pse51_muxid = -1;
 int __pse51_rtdm_muxid = -1;
@@ -67,7 +68,7 @@ static __constructor__ void __init_posix_interface(void)
 	}
 
 	noshadow = getenv("XENO_NOSHADOW");
-	if (!noshadow || !*noshadow) {
+	if ((!noshadow || !*noshadow) && xeno_get_current() == XN_NO_HANDLE) {
 		err = __real_pthread_getschedparam(pthread_self(), &policy,
 						   &parm);
 		if (err) {
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 6 lines · Jan Kiszka

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

Well, last time I checked, calling __wrap_pthread_setschedparam for an already shadowed threads was a nop. It usefaults the thread stack though, maybe we can move the faulting of the tread stack to the "promoted" case.

Signature · 1 line
                                                                Gilles.
author
#2 lore raw
Quoted 10 lines · Gilles Chanteperdrix
Quoted 6 lines · Jan Kiszka

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

Quoted 2 lines

Well, last time I checked, calling __wrap_pthread_setschedparam for an already shadowed threads was a nop.

I'm getting an EBUSY from xnshadow_map as called by __pthread_shadow. And that, of course, lets the lib init code bail out.

Quoted 3 lines

It usefaults the thread stack
though, maybe we can move the faulting of the tread stack to the "promoted" case.

Isn't it reasonable to assume that an existing Xenomai thread also properly went through stack faulting?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
author
#3 lore raw
Quoted 11 lines · Jan Kiszka
Quoted 10 lines · Gilles Chanteperdrix
Quoted 6 lines · Jan Kiszka

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

Quoted 5 lines
Quoted 2 lines

Well, last time I checked, calling __wrap_pthread_setschedparam for an already shadowed threads was a nop.

I'm getting an EBUSY from xnshadow_map as called by __pthread_shadow. And that, of course, lets the lib init code bail out.

BTW, the test pattern is pretty simple:

main()

{
	...
	rt_task_shadow(&task, "test", 0, 0);
	handle = dlopen("libpthread_rt.so", RTLD_LAZY);
	...
}

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
author
#4 lore raw
In reply to Jan Kiszka
Quoted 26 lines · Jan Kiszka

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

---
 src/skins/posix/init.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/skins/posix/init.c +1 -0
index 80725c5..ca1d9e1 100644
@@ -31,6 +31,7 @@
 #include <rtdk.h>
 
 #include <asm-generic/xenomai/bind.h>
+#include <asm-generic/xenomai/current.h>
 
 int __pse51_muxid = -1;
 int __pse51_rtdm_muxid = -1;

src/skins/posix/init.c static __constructor__ void __init_posix_interface(void) · line 74

Quoted 8 lines
src/skins/posix/init.c +1 -1
@@ -67,7 +68,7 @@ static __constructor__ void __init_posix_interface(void)
 	}
 
 	noshadow = getenv("XENO_NOSHADOW");
-	if (!noshadow || !*noshadow) {
+	if ((!noshadow || !*noshadow) && xeno_get_current() == XN_NO_HANDLE) {
 		err = __real_pthread_getschedparam(pthread_self(), &policy,
 						   &parm);
 		if (err) {

Ping for this patch. Any concerns remaining?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 28 lines · Jan Kiszka
Quoted 27 lines · Jan Kiszka

While the user can also avoid double shadowing by providing the XENO_NOSHADOW environment variable, there is still no reason to attempt auto-shadowing in their absence if the current thread is already a Xenomai thread. This helps, e.g., in complex dlopen scenarios where the POSIX lib is pulled in belatedly, potentially after some other lib already shadowed the dlopen caller.

---
  src/skins/posix/init.c |    3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)
src/skins/posix/init.c +1 -0
index 80725c5..ca1d9e1 100644
@@ -31,6 +31,7 @@
  #include<rtdk.h>
 
  #include<asm-generic/xenomai/bind.h>
+#include<asm-generic/xenomai/current.h>
 
  int __pse51_muxid = -1;
  int __pse51_rtdm_muxid = -1;
@@ -67,7 +68,7 @@ static __constructor__ void __init_posix_interface(void)
  	}
 
Quoted 9 lines

src/skins/posix/init.c static __constructor__ void __init_posix_interface(void) · line 74

Quoted 7 lines
src/skins/posix/init.c +1 -1
  	noshadow = getenv("XENO_NOSHADOW");
-	if (!noshadow || !*noshadow) {
+	if ((!noshadow || !*noshadow)&&  xeno_get_current() == XN_NO_HANDLE) {
  		err = __real_pthread_getschedparam(pthread_self(),&policy,
  						&parm);
  		if (err) {

Ping for this patch. Any concerns remaining?

Will merge, thanks for the reminder.

Signature · 1 line
                                                                Gilles.