Skip to contentSkip to conversation

set pthread stack size broken

Xenomai-core Jan Kiszka 3 participants 6 messages Dec 8, 2005 – Dec 10, 2005

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

and the other time against xeno's posix skin

gcc xeno-config --posix-cflags xeno-config --posix-ldflags \
-o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used. Strange - and also critical when considering larger applications...

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Any ideas?

Jan

#include <sys/mman.h>
#include <unistd.h>
#include <limits.h>
#include <pthread.h>

static void *simple_thread(void *arg)

{
    sleep(30);
    return 0;
}

int main (int ac, char **av)

{
    pthread_t pth;
    pthread_attr_t attr;


    mlockall(MCL_CURRENT | MCL_FUTURE);

    pthread_attr_init(&attr);
    pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
    pthread_create(&pth, &attr, simple_thread, NULL);

    sleep(30);

    return 0;
}
author
#1 lore raw
Quoted 10 lines · Jan Kiszka

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

Quoted 8 lines

and the other time against xeno's posix skin

gcc xeno-config --posix-cflags xeno-config --posix-ldflags \
-o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used. Strange - and also critical when considering larger applications...

This has been nailed down now to be some strange linker problem: while the standard version of the stacksize demo calls the latest pthread_create (__pthread_create_2_1 in glibc-2.3.x), the wrapped real-time version and likely also applications linked against libnative call an older pthread_create (__pthread_create_2_0). That variant assumes that pthread_attr_t does not yet contain things like the stack size and fills in the standard value again. :(

Can anyone with another build environment than my SuSE 10 confirm this?

Quoted 4 lines

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Same behaviour on 2.0.x (SVN).

Jan

#2 lore raw
Quoted 30 lines · Jan Kiszka
Quoted 10 lines · Jan Kiszka

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

Quoted 8 lines

and the other time against xeno's posix skin

gcc xeno-config --posix-cflags xeno-config --posix-ldflags \
-o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used. Strange - and also critical when considering larger applications...

This has been nailed down now to be some strange linker problem: while the standard version of the stacksize demo calls the latest pthread_create (__pthread_create_2_1 in glibc-2.3.x), the wrapped real-time version and likely also applications linked against libnative call an older pthread_create (__pthread_create_2_0). That variant assumes that pthread_attr_t does not yet contain things like the stack size and fills in the standard value again. :(

Can anyone with another build environment than my SuSE 10 confirm this?

Quoted 8 lines
Quoted 3 lines

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Same behaviour on 2.0.x (SVN).

Jan

The attached patch fixes this issue for 2.1-SVN. A similar patch should be applied to 2.0.x as well. And maybe it also hits the UVM, but this is something I cannot assess ATM.

Well, you know, the smaller the bug... :-/

Jan

PS: For those you are interested why we need this, read

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=145941

Found via google:"pthread_create NOTYPE" after I noticed the differences in "readelf -s libnative.so".

skins/native/Makefile.am +1 -1
Index: src/skins/native/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libnative.la
 
-libnative_la_LDFLAGS = -module -version-info 0:0:0
+libnative_la_LDFLAGS = -module -version-info 0:0:0 -pthread
 
 libnative_la_SOURCES = \
 	alarm.c \
skins/posix/Makefile.am +1 -1
Index: src/skins/posix/Makefile.am
===================================================================
@@ -2,7 +2,7 @@
 
 lib_LTLIBRARIES = libpthread_rt.la
 
-libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0
+libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0 -lpthread
 
 libpthread_rt_la_SOURCES = \
 	init.c \
#3 lore raw
Quoted 80 lines · Jan Kiszka
Quoted 32 lines · Jan Kiszka
Quoted 10 lines · Jan Kiszka

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

Quoted 8 lines

and the other time against xeno's posix skin

   gcc `xeno-config --posix-cflags` `xeno-config --posix-ldflags` \
       -o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used. Strange - and also critical when considering larger applications...

This has been nailed down now to be some strange linker problem: while the standard version of the stacksize demo calls the latest pthread_create (__pthread_create_2_1 in glibc-2.3.x), the wrapped real-time version and likely also applications linked against libnative call an older pthread_create (__pthread_create_2_0). That variant assumes that pthread_attr_t does not yet contain things like the stack size and fills in the standard value again. :(

Can anyone with another build environment than my SuSE 10 confirm this?

Quoted 8 lines
Quoted 3 lines

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Same behaviour on 2.0.x (SVN).

Jan

The attached patch fixes this issue for 2.1-SVN. A similar patch should be applied to 2.0.x as well. And maybe it also hits the UVM, but this is something I cannot assess ATM.

Well, you know, the smaller the bug... :-/

Jan

PS: For those you are interested why we need this, read

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=145941

Found via google:"pthread_create NOTYPE" after I noticed the differences in "readelf -s libnative.so".

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

Index: src/skins/native/Makefile.am
===================================================================

skins/native/Makefile.am +1 -1
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libnative.la
 
-libnative_la_LDFLAGS = -module -version-info 0:0:0
+libnative_la_LDFLAGS = -module -version-info 0:0:0 -pthread
 
 libnative_la_SOURCES = \
 	alarm.c \

Index: src/skins/posix/Makefile.am
===================================================================

skins/posix/Makefile.am line 8

Quoted 8 lines
skins/posix/Makefile.am +1 -1
@@ -2,7 +2,7 @@
 
 lib_LTLIBRARIES = libpthread_rt.la
 
-libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0
+libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0 -lpthread
 
 libpthread_rt_la_SOURCES = \
 	init.c \

Applied (with -pthread everywhere), thanks.

Signature · 1 line
Philippe.
#4 lore raw
Quoted 87 lines · Philippe Gerum
Quoted 85 lines · Jan Kiszka
Quoted 34 lines · Jan Kiszka
Quoted 12 lines · Jan Kiszka

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

and the other time against xeno's posix skin

Quoted 7 lines
   gcc `xeno-config --posix-cflags` `xeno-config --posix-ldflags` \
       -o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used.
Strange - and also critical when considering larger applications...

This has been nailed down now to be some strange linker problem: while the standard version of the stacksize demo calls the latest pthread_create (__pthread_create_2_1 in glibc-2.3.x), the wrapped real-time version and likely also applications linked against libnative call an older pthread_create (__pthread_create_2_0). That variant assumes that pthread_attr_t does not yet contain things like the stack size and fills in the standard value again. :(

Can anyone with another build environment than my SuSE 10 confirm this?

Quoted 8 lines
Quoted 3 lines

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Same behaviour on 2.0.x (SVN).

Jan

The attached patch fixes this issue for 2.1-SVN. A similar patch should be applied to 2.0.x as well. And maybe it also hits the UVM, but this is something I cannot assess ATM.

Well, you know, the smaller the bug... :-/

Jan

PS: For those you are interested why we need this, read

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=145941

Found via google:"pthread_create NOTYPE" after I noticed the differences in "readelf -s libnative.so".

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

Index: src/skins/native/Makefile.am
===================================================================

skins/native/Makefile.am (working copy) renamed from skins/native/Makefile.am (revision 243) +1 -1
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libnative.la
 
-libnative_la_LDFLAGS = -module -version-info 0:0:0
+libnative_la_LDFLAGS = -module -version-info 0:0:0 -pthread
 
 libnative_la_SOURCES = \
     alarm.c \

Index: src/skins/posix/Makefile.am
===================================================================

skins/posix/Makefile.am (working copy) renamed from skins/posix/Makefile.am (revision 243) +0 -0
@@ -2,7 +2,7 @@
 
 lib_LTLIBRARIES = libpthread_rt.la
 
Quoted 9 lines

skins/posix/Makefile.am (working copy) line 8

Quoted 5 lines
skins/posix/Makefile.am (working copy) renamed from skins/posix/Makefile.am (revision 243) +1 -1
-libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0
+libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0 -lpthread
 
 libpthread_rt_la_SOURCES = \
     init.c \

Applied (with -pthread everywhere), thanks.

Hmm, shouldn't is spell -lpthread? Seems like the autotools resolve this because it works with both versions for me (current posix/Makefile.in still has "-lpthread").

Jan

#5 lore raw
Quoted 104 lines · Jan Kiszka
Quoted 91 lines · Philippe Gerum
Quoted 88 lines · Jan Kiszka
Quoted 36 lines · Jan Kiszka
Quoted 12 lines · Jan Kiszka

Hi,

something for the night: Can someone explain why normal pthreads can be restricted to initially use only the stack size provided via pthread_attr_setstacksize() while any rt-mapped thread (posix and native) refuse to accept this? For a simple test, compile the attached program one time as normal

gcc -lpthread -o stacksize stacksize.c

and the other time against xeno's posix skin

Quoted 7 lines
  gcc `xeno-config --posix-cflags` `xeno-config --posix-ldflags` \
      -o stacksize.o stacksize.c

Then compare the memory requirements of both processes - they should differ by 2M, the stack size when pthread_attr_setstacksize is not used.
Strange - and also critical when considering larger applications...

This has been nailed down now to be some strange linker problem: while the standard version of the stacksize demo calls the latest pthread_create (__pthread_create_2_1 in glibc-2.3.x), the wrapped real-time version and likely also applications linked against libnative call an older pthread_create (__pthread_create_2_0). That variant assumes that pthread_attr_t does not yet contain things like the stack size and fills in the standard value again. :(

Can anyone with another build environment than my SuSE 10 confirm this?

Quoted 8 lines
Quoted 3 lines

So far I only tested against 2.1, but I don't see a reason why 2.0.x should behave different. Will get checked, though.

Same behaviour on 2.0.x (SVN).

Jan

The attached patch fixes this issue for 2.1-SVN. A similar patch should be applied to 2.0.x as well. And maybe it also hits the UVM, but this is something I cannot assess ATM.

Well, you know, the smaller the bug... :-/

Jan

PS: For those you are interested why we need this, read

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=145941

Found via google:"pthread_create NOTYPE" after I noticed the differences in "readelf -s libnative.so".

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

Index: src/skins/native/Makefile.am
===================================================================

skins/native/Makefile.am (working copy) renamed from skins/native/Makefile.am (revision 243) +0 -0
@@ -1,6 +1,6 @@

lib_LTLIBRARIES = libnative.la

skins/native/Makefile.am (working copy) renamed from skins/native/Makefile.am (revision 243) +1 -1
-libnative_la_LDFLAGS = -module -version-info 0:0:0
+libnative_la_LDFLAGS = -module -version-info 0:0:0 -pthread
libnative_la_SOURCES = \
    alarm.c \

Index: src/skins/posix/Makefile.am
===================================================================

skins/posix/Makefile.am (working copy) renamed from skins/posix/Makefile.am (revision 243) +0 -0
@@ -2,7 +2,7 @@
 

lib_LTLIBRARIES = libpthread_rt.la

Quoted 9 lines
Quoted 5 lines
skins/posix/Makefile.am (working copy) renamed from skins/posix/Makefile.am (revision 243) +1 -1
-libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0
+libpthread_rt_la_LDFLAGS = -module -version-info 0:0:0 -lpthread
libpthread_rt_la_SOURCES = \
    init.c \

Applied (with -pthread everywhere), thanks.

Quoted 4 lines

Hmm, shouldn't is spell -lpthread? Seems like the autotools resolve this because it works with both versions for me (current posix/Makefile.in still has "-lpthread").

gcc supports this actually, as a way to specify "whatever the platform needs to support POSIX threads". But, well, since not all platforms support this feature using the same option, I need to further check for the existing ports.

Signature · 1 line
Philippe.