posix: Skip auto-shadowing if current thread is already shadowed
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
@@ -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
Quoted 6 lines · Jan Kiszka
While the user can also avoid double shadowing by providing the
XENO_NOSHADOWenvironment 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.
Quoted 10 lines · Gilles Chanteperdrix
Quoted 6 lines · Jan Kiszka
While the user can also avoid double shadowing by providing the
XENO_NOSHADOWenvironment 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_setschedparamfor 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
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_NOSHADOWenvironment 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_setschedparamfor an already shadowed threads was a nop.I'm getting an EBUSY from
xnshadow_mapas 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
Quoted 26 lines · Jan Kiszka
While the user can also avoid double shadowing by providing the
XENO_NOSHADOWenvironment 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.Signed-off-by Jan Kiszka <[email protected]>--- src/skins/posix/init.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)src/skins/posix/init.c +1
-0@@ -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
Quoted 28 lines · Jan Kiszka
Quoted 27 lines · Jan Kiszka
While the user can also avoid double shadowing by providing the
XENO_NOSHADOWenvironment 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.Signed-off-by Jan Kiszka<[email protected]>--- src/skins/posix/init.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)src/skins/posix/init.c +1
-0@@ -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
-1noshadow =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.