posix skin pthread_create issue
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Pierre Quelin
Thank you for quick answer.
my context
xenomai : 2.6.0 adeos : 2.11-02 kernel : 2.6.38.8 arch : pentium pro gcc : 4.6.3 distro : Ubuntu 12.04
If you use this version, add "-fno-omit-frame-pointer" to the CFLAGS passed to the configure script.
Quoted 4 lines
I already read the TROUBLESHOOTING guide but I don't understand all the informations contained in //proc/<pid>/maps/. I already try "ulimit -s 81920" without success.
You usually want to decrease ulimit -s, not increase it.
Quoted 5 lines
After your answer, I try xenomai 2.6.1 and I increase the size of the
private stack pool from 128 to 2048 with the same result.Is there any limits for the number of threads in Xenomai ?
Not that I know of. There are only a few dynamic allocations in the various pools you already mentioned. The corresponding options are:XENO_OPT_REGISTRY_NRSLOTS (maximum number of objects in the registry, each thread is registered in the registry) XENO_OPT_SYS_HEAPSZ (system heap, used for various calls to xnmalloc) XENO_OPT_SEM_HEAPSZ (semaphore heap, use for allocating 4 bytes per thread + 4 bytes per mutex)
But anyway, debugging the issue you have should be relatively easy by adding printfs/printks, starting from src/skins/posix/thread.c (function __wrap_pthread_create), continuing in ksrc/skins/posix/syscall.c, function __pthread_create, etc...
Quoted 7 lines
I don't know if there is the link with my problem but I have some strange things.
With Xenomai 2.6.1, when I launch the latency/switch test I obtain some negative values like -1.03µs.
That is a known issue. See for instance:
http://www.blaess.fr/christophe/2012/07/23/les-latences-de-xenomai/
After mlockall() in
Quoted 9 lines
//proc/xenomai/faults/ I obtain 2 or more Page fault without visible software effects. I can't locate it. If you could help me.
Our application is writting in C++. At the begining it initialise a lot of static objects as mutex and do a lot of allocation/syscall. So it do a lot of switch in secondary mode. To solve this, at first, I just catch the SIGXCPU in a static class..
Well, you should be able to catch the page faults with SIGXCPU, but you have to ensure that pthread_set_mode and the signal handler installation are done before the static objects constructors. And of course, you have to ensure that Xenomai libpthread_rt library constructor gets run before your static initializers. That is a problem with C++. Also note that PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER do not work with Xenomai posix skin.
Quoted 5 lines
Sorry for messages at the end of the mail but I can't remove it (!?.§§!! Lotus N..es and security policy) Could you please send me a copy of your answer to [email protected]
The free.fr address is fine.
Signature · 1 line
Gilles.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 27 lines · Pierre Quelin
Quoted 11 lines · Gilles Chanteperdrix
Quoted 6 lines · Pierre Quelin
Thank you for quick answer.
my context
xenomai : 2.6.0 adeos : 2.11-02 kernel : 2.6.38.8 arch : pentium pro gcc : 4.6.3 distro : Ubuntu 12.04
If you use this version, add "-fno-omit-frame-pointer" to the CFLAGS passed to the configure script.
I have tryed this with xenomai 2.6.0 and 2.6.1 without success. Maybe an incompatible option in my CMakeLists file.
...
ELSEIF ($ENV{SOLYSTIC_BUILD_TARGET} STREQUAL "linux-x86")
SET(CMAKE_C_FLAGS "-O0 -g3 -mtune=pentium -march=pentium -ansi(quoted diff) +0
-4-fno-builtin -fno-defer-pop -Wall -finput-charset=iso-8859-1 -fexec-charset=iso-8859-1") SET(CMAKE_CXX_FLAGS "-O0 -g3 -mtune=pentium -march=pentium -ansi -fno-builtin -fno-defer-pop -Wall -Wreorder -finput-charset=iso-8859-1 -fexec-charset=iso-8859-1")ELSEIF ($ENV{SOLYSTIC_BUILD_TARGET} STREQUAL "xenomai-x86")
EXECUTE_PROCESS(COMMAND xeno-config --skin posix --cflags OUTPUT_VARIABLE XENO_POSIX_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) SET(CMAKE_C_FLAGS "${XENO_POSIX_CFLAGS} -O0 -g3 -mtune=pentium
Review
Quoted 7 lines
(quoted diff) +0
-5-march=pentium -ansi *-fno-omit-frame-pointer* -fno-builtin -fno-defer-pop -Wall -finput-charset=iso-8859-1 -fexec-charset=iso-8859-1") SET(CMAKE_CXX_FLAGS "${XENO_POSIX_CFLAGS} -O0 -g3 -mtune=pentium -march=pentium -ansi *-fno-omit-frame-pointer* -fno-builtin -fno-defer-pop -Wall -Wreorder -finput-charset=iso-8859-1 -fexec-charset=iso-8859-1")
If you have a compilation issue, you will know it, because the syscall in __wrap_pthread_create will not return the same value as the value printed in __pthread_create in kernel space, or the arguments received in kernel space will not be the same as the ones you pass in user-space. So, printf/printk is the way to go. Anyway, I am talking about the CFLAGS of the Xenomai library, the one passed to Xenomai configure script. Not the CFLAGS of your application. As I said, you should not need this with Xenomai 2.6.1.
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
After your answer, I try xenomai 2.6.1 and I increase the size of the
private stack pool from 128 to 2048 with the same result.Is there any limits for the number of threads in Xenomai ?
Not that I know of. There are only a few dynamic allocations in the various pools you already mentioned. The corresponding options are:
XENO_OPT_REGISTRY_NRSLOTS(maximum number of objects in the registry, each thread is registered in the registry)XENO_OPT_SYS_HEAPSZ(system heap, used for various calls to xnmalloc)XENO_OPT_SEM_HEAPSZ(semaphore heap, use for allocating 4 bytes per thread + 4 bytes per mutex)
Quoted 5 lines
Quoted 4 lines
But anyway, debugging the issue you have should be relatively easy by adding printfs/printks, starting from
src/skins/posix/thread.c(function__wrap_pthread_create), continuing inksrc/skins/posix/syscall.c, function__pthread_create, etc...I try to obtain information about my context but all seems to be ok.
You have to put a "pause" after the failing call to pthread_create, because otherwise if calling exit, when the process fails, all the memory it allocated in the various pools is freed.
Quoted 17 lines
Quoted 10 lines
After
mlockall()inQuoted 8 lines
//proc/xenomai/faults/ I obtain 2 or more Page fault without visible software effects. I can't locate it. If you could help me.
Our application is writting in C++. At the begining it initialise a lot of static objects as mutex and do a lot of allocation/syscall. So it do a lot of switch in secondary mode. To solve this, at first, I just catch the SIGXCPU in a static class..
Quoted 7 lines
Well, you should be able to catch the page faults with SIGXCPU, but you have to ensure that
pthread_set_modeand the signal handler installation are done before the static objects constructors. And of course, you have to ensure that Xenomailibpthread_rtlibrary constructor gets run before your static initializers. That is a problem with C++. Also note thatPTHREAD_MUTEX_INITIALIZERandPTHREAD_COND_INITIALIZERdo not work with Xenomai posix skin.
Quoted 7 lines
I watch this problem for the first time when I try to resolve the
pthread_create()error.
The problem, there is a lot of SIGXCPU generated by the switch between rt and linux domain that mask the page fault in a lot of noise. I tried to disable everything with pthread_set_mode_np(PTHREAD_WARNSW,
0) in all the thread context (body) but I don't understand why, it still remains.
Not all SIGXCPU are due to page faults. There are various reasons for SIGXCPU, for an example of how to know for which reason you receive the signal, see examples/sigdebug.c in xenomai sources.
Quoted 7 lines
I know that the application is not real time with the domain switch but at first how can I disable the SIGXCPU in every context to solve this page fault ?
You say that I have to be sure that Xenomai
libpthread_rtlibrary constructor gets run before our static initializers, but how to do that ?
Well, the static objects constructors order is a general C++ problem which goes well beyond the context of Xenomai. See:
http://www.parashift.com/c++-faq-lite/static-init-order.html
The short story is: don't use static objects with constructors.
Quoted 11 lines
When I switch between xenomai 2.6.0 to xenomai 2.6.1 It seems that an #include is missing in the
include/xenomai/posix/stdio.hfile for the newsize_ttype.#include_next <
stdio.h>#ifndef
STDIO_H
#defineSTDIO_H#include <
stdarg.h>
*#include <unistd.h> /*size_t*/*
Thanks for reporting this issue.
That is strange, given the fact that stdio.h defines fwrite for instance, which uses size_t. Could you provide a small .c or .C file which fails to compile?
We are certainly not going to include unistd.h, which is a POSIX header, in stdio.h, which is an ANSI header, more like stddef.h, but AFAIK, stddef.h should already be included in the system stdio.h
Signature · 1 line
Gilles.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 18 lines · Pierre Quelin
Quoted 18 lines
Quoted 17 lines
Quoted 12 lines
Quoted 4 lines
After your answer, I try xenomai 2.6.1 and I increase the size of the
private stack pool from 128 to 2048 with the same result.Is there any limits for the number of threads in Xenomai ?
Not that I know of. There are only a few dynamic allocations in the various pools you already mentioned. The corresponding options are:
XENO_OPT_REGISTRY_NRSLOTS(maximum number of objects in the registry, each thread is registered in the registry)XENO_OPT_SYS_HEAPSZ(system heap, used for various calls to xnmalloc)XENO_OPT_SEM_HEAPSZ(semaphore heap, use for allocating 4 bytes per thread + 4 bytes per mutex)Quoted 4 lines
But anyway, debugging the issue you have should be relatively easy by adding printfs/printks, starting from
src/skins/posix/thread.c(function__wrap_pthread_create), continuing inksrc/skins/posix/syscall.c, function__pthread_create, etc...I try to obtain information about my context but all seems to be ok.
Quoted 7 lines
Quoted 3 lines
You have to put a "pause" after the failing call to
pthread_create, because otherwise if calling exit, when the process fails, all the memory it allocated in the various pools is freed.I found the problem. It seems that the private sem heap is to small.
I'm not sure about which parameter to increase in kernel menu so at first I increase :
"private sem heap" -> "private semaphores heap", how can this not be clear?
Quoted 11 lines
generation@emb:~$ cat /proc/xenomai/heapTOTAL USED PAGESZ NAME
118784 64 4096 global sem heap
2600960 287120 512 main heap
129536 0 512 stack pool
*118784 13424 4096 private sem heap [5633]*and now it works fine.
But just to understand, could you explain to me how I can retrive the value 118784 with the kernel parameters ?
see include/nucleus/heap.h
Quoted 2 lines
? Is calling
pthread_set_mode_np(PTHREAD_WARNSW, 0) inhibits the rise of the signal for a page fault?
Yes, it inhibits the rise of the signal for any cause of switch to secondary mode. Quoting the documentation:
"PTHREAD_WARNSW, when set, cause the signal SIGXCPU to be sent to the current thread, whenever it involontary switches to secondary mode;"
so, obviously, when clear, the SIGXCPU is NOT SENT to the current thread whenever it involontary switches to secondary mode. What else did you understand when reading this documentation ?
Quoted 31 lines
Quoted 14 lines
Quoted 11 lines
When I switch between xenomai 2.6.0 to xenomai 2.6.1 It seems that an #include is missing in the
include/xenomai/posix/stdio.hfile for the newsize_ttype.#include_next <
stdio.h>#ifndef
STDIO_H
#defineSTDIO_H#include <
stdarg.h>
*#include <unistd.h> /*size_t*/*Thanks for reporting this issue.
Quoted 9 lines
That is strange, given the fact that
stdio.hdefines fwrite for instance, which usessize_t. Could you provide a small .c or .C file which fails to compile?We are certainly not going to include
unistd.h, which is a POSIX header, instdio.h, which is an ANSI header, more likestddef.h, but AFAIK,stddef.hshould already be included in the systemstdio.hcf.
pme.h/ pme.cppIn file included from
/usr/include/wchar.h:37:0,from /usr/include/c++/4.6/cwchar:46, from /usr/include/c++/4.6/bits/postypes.h:42, from /usr/include/c++/4.6/bits/char_traits.h:42, from /usr/include/c++/4.6/string:42, from
Quoted 5 lines
/home/generation/workspace/Projects/Application.xenomai/Libraries/libpme/pme/pme.h:16,
from/home/generation/workspace/Projects/Application.xenomai/Libraries/libpme/pme/pme.cpp:14:/usr/include/xenomai/posix/stdio.h:30:1: erreur: ‘size_t’ does not name
a type
weird localization, it is an "erreur", but the rest of the error messages are in english. Ok, will check. Thanks for posting the test cases.
Signature · 1 line
Gilles.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 26 lines · Pierre Quelin
Quoted 24 lines · Gilles Chanteperdrix
Quoted 22 lines · Pierre Quelin
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
After your answer, I try xenomai 2.6.1 and I increase the size of the
private stack pool from 128 to 2048 with the same result.Is there any limits for the number of threads in Xenomai ?
Not that I know of. There are only a few dynamic allocations in the various pools you already mentioned. The corresponding options are:
XENO_OPT_REGISTRY_NRSLOTS(maximum number of objects in the registry, each thread is registered in the registry)XENO_OPT_SYS_HEAPSZ(system heap, used for various calls to xnmalloc)XENO_OPT_SEM_HEAPSZ(semaphore heap, use for allocating 4 bytes per thread + 4 bytes per mutex)Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
But anyway, debugging the issue you have should be relatively easy by adding printfs/printks, starting from
src/skins/posix/thread.c(function__wrap_pthread_create), continuing inksrc/skins/posix/syscall.c, function__pthread_create, etc...I try to obtain information about my context but all seems to be ok.
You have to put a "pause" after the failing call to
pthread_create, because otherwise if calling exit, when the process fails, all the memory it allocated in the various pools is freed.I found the problem. It seems that the private sem heap is to small.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'm not sure about which parameter to increase in kernel menu so at first I increase :
"private sem heap" -> "private semaphores heap", how can this not be clear?
This link is clear, but I don't understand the link between "private semaphores heap", "global semaphores heap" and "system heap" ? I just try to fix the right values for my context and my application.
There is no link between the various heaps, which is the reason why they have separate configuration options. Now if the question is to know how much space in each heap consumes a thread, a mutex, etc... I guess nobody ever did the computation. For the semaphore heaps at least it is
clear: each thread consumes 4 bytes in the semaphore heap, each mutex consumes 4 bytes in the private or global heap depending on whether it is a process-private, or global mutex (for posix mutexes, this is related to pthread_mutexattr_setpshared).
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
? Is calling
pthread_set_mode_np(PTHREAD_WARNSW, 0) inhibits the rise of the signal for a page fault?Yes, it inhibits the rise of the signal for any cause of switch to secondary mode. Quoting the documentation:
Quoted 8 lines
Quoted 6 lines
"
PTHREAD_WARNSW, when set, cause the signal SIGXCPU to be sent to the current thread, whenever it involontary switches to secondary mode;"so, obviously, when clear, the SIGXCPU is NOT SENT to the current thread whenever it involontary switches to secondary mode. What else did you understand when reading this documentation ?
I don't understand that a page fault is 'just' a switch to secondary mode.
A switch to secondary mode is devastating for a real-time thread running in primary mode.
A page fault causes a switch to secondary mode so that the Linux kernel can handle the page fault, the only alternative is probably crashing, or suspending the thread that had the fault. SIGXCPU is sent, if you enabled the PTHREAD_WARNSW bit.
So, PTHREAD_WARNSW should be armed for threads which should stay in primary mode. The critical ones.
Anyway, it is not really normal to have page faults, using mlockall and the disabling of on-demand mappings by the I-pipe patch should prevent page faults from happening. So, it would be interesting to know what cause these faults.
Quoted 4 lines
Before posting a message on this mailing list I tried to read all documents on Xenomaiand solve the problem by myself. Maybe I did not read the right papers or I did not understand what I have read and I apologize.
No need to apologize, the mailing list is here so that people can ask questions. I guess there are more answers (maybe not the good ones) in the mailing list archives than in the documentation.
Regards.
Signature · 1 line
Gilles.
Quoted 69 lines · Gilles Chanteperdrix
Quoted 26 lines · Pierre Quelin
Quoted 24 lines · Gilles Chanteperdrix
Quoted 22 lines · Pierre Quelin
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
After your answer, I try xenomai 2.6.1 and I increase the size of the
private stack pool from 128 to 2048 with the same result.Is there any limits for the number of threads in Xenomai ?
Not that I know of. There are only a few dynamic allocations in the various pools you already mentioned. The corresponding options are:
XENO_OPT_REGISTRY_NRSLOTS(maximum number of objects in the registry, each thread is registered in the registry)XENO_OPT_SYS_HEAPSZ(system heap, used for various calls to xnmalloc)XENO_OPT_SEM_HEAPSZ(semaphore heap, use for allocating 4 bytes per thread + 4 bytes per mutex)Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
But anyway, debugging the issue you have should be relatively easy by adding printfs/printks, starting from
src/skins/posix/thread.c(function__wrap_pthread_create), continuing inksrc/skins/posix/syscall.c, function__pthread_create, etc...I try to obtain information about my context but all seems to be ok.
You have to put a "pause" after the failing call to
pthread_create, because otherwise if calling exit, when the process fails, all the memory it allocated in the various pools is freed.I found the problem. It seems that the private sem heap is to small.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'm not sure about which parameter to increase in kernel menu so at first I increase :
"private sem heap" -> "private semaphores heap", how can this not be clear?
This link is clear, but I don't understand the link between "private semaphores heap", "global semaphores heap" and "system heap" ? I just try to fix the right values for my context and my application.
There is no link between the various heaps, which is the reason why they have separate configuration options. Now if the question is to know how much space in each heap consumes a thread, a mutex, etc... I guess nobody ever did the computation. For the semaphore heaps at least it is
clear: each thread consumes 4 bytes in the semaphore heap, each mutex consumes 4 bytes in the private or global heap depending on whether it is a process-private, or global mutex (for posix mutexes, this is related topthread_mutexattr_setpshared).Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
? Is calling
pthread_set_mode_np(PTHREAD_WARNSW, 0) inhibits the rise of the signal for a page fault?Yes, it inhibits the rise of the signal for any cause of switch to secondary mode. Quoting the documentation:
Quoted 8 lines
Quoted 6 lines
"
PTHREAD_WARNSW, when set, cause the signal SIGXCPU to be sent to the current thread, whenever it involontary switches to secondary mode;"so, obviously, when clear, the SIGXCPU is NOT SENT to the current thread whenever it involontary switches to secondary mode. What else did you understand when reading this documentation ?
I don't understand that a page fault is 'just' a switch to secondary mode.
A switch to secondary mode is devastating for a real-time thread running in primary mode.
A page fault causes a switch to secondary mode so that the Linux kernel can handle the page fault, the only alternative is probably crashing, or suspending the thread that had the fault. SIGXCPU is sent, if you enabled thePTHREAD_WARNSWbit.
Quoted 7 lines
So,
PTHREAD_WARNSWshould be armed for threads which should stay in primary mode. The critical ones.Anyway, it is not really normal to have page faults, using mlockall and the disabling of on-demand mappings by the I-pipe patch should prevent page faults from happening. So, it would be interesting to know what cause these faults.
Again, due to the C++ static objects constructors "feature", it may simply be that you start using Xenomai before the call to mlockall, and you simply somehow fail to see the signal sent by Xenomai, because it is also SIGXCPU and the handler you installed does not check the reason sent by Xenomai, for instance, the following commit, fixes exactly this issue for the latency test:
Signature · 1 line
Gilles.