Skip to contentSkip to conversation

pthread exit and PTHREAD_WARNSW

Xenomai-help Jeff Weber 2 participants 6 messages Apr 12, 2011 – Apr 14, 2011

lore
Share & tools
lore

Jeff Weber

author
#0 lore raw
Quoted 1 line

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I must

explicitly disable this mode before the thread terminates, or the thread draws a signal 24 SIGXCPU.

I've tried to simplify my thread terminations by pushing a function which calls pthread_set_mode_np(PTHREAD_WARNSW, 0) onto the thread cleanup stack, and always terminating the thread via pthread_exit(). However, this method
still draws a signal 24 SIGXCPU. Here's a sample backtrace:

Program terminated with signal 24, CPU time limit exceeded. #0 0xffffe424 in __kernel_vsyscall ()
(gdb) bt full
#0 0xffffe424 in __kernel_vsyscall ()
No symbol table info available.
#1 0xb781d561 in pthread_once () from /lib/libpthread.so.0 No symbol table info available.
#2 0xb76e0450 in ?? () from /lib/libgcc_s.so.1
No symbol table info available.
#3 0xb76e09de in _Unwind_ForcedUnwind () from /lib/libgcc_s.so.1 No symbol table info available.
#4 0xb7821032 in _Unwind_ForcedUnwind () from /lib/libpthread.so.0 No symbol table info available.
#5 0xb781ea97 in __pthread_unwind () from /lib/libpthread.so.0 No symbol table info available.
#6 0xb7818a5e in pthread_exit () from /lib/libpthread.so.0 No symbol table info available.
#7 0x0804969b in my program termination code

Am I coding this incorrectly, or is this just the way pthreads interacts with Xenomai?

my config:

# xeno-config --version
2.5.6
# ldd ./mq_test
        linux-gate.so.1 =>  (0xffffe000)
        libpthread_rt.so.1 => /usr/xenomai/lib/libpthread_rt.so.1
(0xb778b000)
        libxenomai.so.0 => /usr/xenomai/lib/libxenomai.so.0 (0xb7785000)
        libpthread.so.0 => /lib/libpthread.so.0 (0xb776a000)
        librt.so.1 => /lib/librt.so.1 (0xb7760000)
        librtdk.so.0 => /usr/xenomai/lib/librtdk.so.0 (0xb775a000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb766a000)
        libm.so.6 => /lib/libm.so.6 (0xb7640000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7622000)
        libc.so.6 => /lib/libc.so.6 (0xb74b7000)
        /lib/ld-linux.so.2 (0xb77b4000)
#> rpm -qf /lib/libpthread.so.0
glibc-2.11.2-3.1.1.i686
# uname -a
Linux xeno2 2.6.37.3-xeno-2.5.6-smp #1 SMP PREEMPT Fri Mar 11 12:43:02 CST
2011 i686 i686 i386 GNU/Linux

TIA,
Jeff

#1 lore raw

Jeff Weber wrote:

Hi Jeff,

any news about the hostrt patch I sent you for x86_32? Does it work?

Quoted 3 lines

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I must explicitly disable this mode before the thread terminates, or the thread draws a signal 24 SIGXCPU.

Yes, the problem is that we can put such migration if the thread function returns, but it will not work in case pthread_exit is called.

Quoted 5 lines

I've tried to simplify my thread terminations by pushing a function which calls pthread_set_mode_np(PTHREAD_WARNSW, 0) onto the thread cleanup stack, and always terminating the thread via pthread_exit(). However, this method
still draws a signal 24 SIGXCPU. Here's a sample backtrace:

... and pthread_exit is basically a Linux service, so, we can not guarantee that it does not make any syscall before executing the cleanup handlers.

Signature · 1 line
					    Gilles.
author
#2 lore raw

Gilles:

Quoted 6 lines · Gilles Chanteperdrix

Jeff Weber wrote:

Hi Jeff,

any news about the hostrt patch I sent you for x86_32? Does it work?

Yes it works. However my call to clock_gettime(CLOCK_HOST_REALTIME) takes too long (110 nsec on my CPU) for my ISR, so I will read the TSC instead, and convert the TSC to host time in another thread. Thanks for your help though.

Quoted 9 lines
Quoted 2 lines

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I

must

Quoted 2 lines

explicitly disable this mode before the thread terminates, or the thread draws a signal 24 SIGXCPU.

Yes, the problem is that we can put such migration if the thread function returns, but it will not work in case pthread_exit is called.

I'm interested if there is a way to automatically disable PTHREAD_WARNSW as threads terminate, using return from the entry function. I was only using pthread_exit() to leverage the thread cleanup stack capability, and queue a call to pthread_set_mode_np(PTHREAD_WARNSW, 0) .

Quoted 4 lines
Quoted 4 lines

I've tried to simplify my thread terminations by pushing a function which calls pthread_set_mode_np(PTHREAD_WARNSW, 0) onto the thread cleanup

Quoted 9 lines

stack,

Quoted 1 line

and always terminating the thread via pthread_exit(). However, this

method

Quoted 1 line

still draws a signal 24 SIGXCPU. Here's a sample backtrace:

... and pthread_exit is basically a Linux service, so, we can not guarantee that it does not make any syscall before executing the cleanup handlers.

Right, I saw there was no __wrap_pthread_exit
in /usr/xenomai/lib/libpthread_rt.so

Jeff

Quoted 4 lines

--
Gilles.

#3 lore raw
Quoted 9 lines · Jeff Weber

Gilles:

Quoted 4 lines · Gilles Chanteperdrix

Jeff Weber wrote:

Hi Jeff,

Quoted 7 lines
Quoted 2 lines

any news about the hostrt patch I sent you for x86_32? Does it work?

Yes it works. However my call to clock_gettime(CLOCK_HOST_REALTIME) takes too long (110 nsec on my CPU) for my ISR, so I will read the TSC instead, and convert the TSC to host time in another thread. Thanks for your help though.

Wow, it makes me wonder what kind of ISR with a multi-us latency can not handle a 110ns service. But I admit that the hostrt clock_gettime service is a bit heavy. I am afraid there is not much we can do. Could you get me disassembly of the kernel-space clock.o file, so that I verify that we do not end up using divisions? For instance clock_gettime(CLOCK_MONOTONIC) is wrong, and uses the real division.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I

must

Quoted 2 lines

explicitly disable this mode before the thread terminates, or the thread draws a signal 24 SIGXCPU.

Quoted 8 lines
Quoted 3 lines

Yes, the problem is that we can put such migration if the thread function returns, but it will not work in case pthread_exit is called.

I'm interested if there is a way to automatically disable PTHREAD_WARNSW as threads terminate, using return from the entry function. I was only using pthread_exit() to leverage the thread cleanup stack capability, and queue a call to pthread_set_mode_np(PTHREAD_WARNSW, 0) .

You can do that in the trampoline in src/skins/posix/thread.c, right after the call to entry(cookie). I will send a patch tonight if you prefer.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I've tried to simplify my thread terminations by pushing a function which calls pthread_set_mode_np(PTHREAD_WARNSW, 0) onto the thread cleanup

stack,

Quoted 1 line

and always terminating the thread via pthread_exit(). However, this

method

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

still draws a signal 24 SIGXCPU. Here's a sample backtrace:

... and pthread_exit is basically a Linux service, so, we can not guarantee that it does not make any syscall before executing the cleanup handlers.

Right, I saw there was no __wrap_pthread_exit
in /usr/xenomai/lib/libpthread_rt.so

That is something else we can do, add a __wrap_pthread_exit which removes the bit before calling __read_pthread_exit. Neither of the two methods will work for pthread_cancel though.

Quoted 7 lines

Jeff

Quoted 3 lines

--
Gilles.

Signature · 1 line
					    Gilles.
author
#4 lore raw
Quoted 19 lines · Gilles Chanteperdrix
Quoted 5 lines · Jeff Weber

Gilles:

On Tue, Apr 12, 2011 at 9:38 AM, Gilles Chanteperdrix < [email protected]> wrote:

Quoted 8 lines
Quoted 6 lines

Jeff Weber wrote:

Hi Jeff,

any news about the hostrt patch I sent you for x86_32? Does it work?

Yes it works. However my call to clock_gettime(CLOCK_HOST_REALTIME)

takes

Quoted 3 lines

too long (110 nsec on my CPU) for my ISR, so I will read the TSC instead, and convert the TSC to host time in another thread. Thanks for your help though.

Quoted 7 lines

Wow, it makes me wonder what kind of ISR with a multi-us latency can not handle a 110ns service. But I admit that the hostrt clock_gettime service is a bit heavy. I am afraid there is not much we can do. Could you get me disassembly of the kernel-space clock.o file, so that I verify that we do not end up using divisions? For instance clock_gettime(CLOCK_MONOTONIC) is wrong, and uses the real division.

See attached. Let me know if attachment gets stripped off along the way.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I

must

Quoted 1 line

explicitly disable this mode before the thread terminates, or the

thread

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

draws a signal 24 SIGXCPU.

Yes, the problem is that we can put such migration if the thread function returns, but it will not work in case pthread_exit is called.

I'm interested if there is a way to automatically disable PTHREAD_WARNSW

as

Quoted 9 lines
Quoted 1 line

threads terminate, using return from the entry function. I was only

using

Quoted 1 line

pthread_exit() to leverage the thread cleanup stack capability, and queue

a

Quoted 1 line

call to pthread_set_mode_np(PTHREAD_WARNSW, 0) .

You can do that in the trampoline in src/skins/posix/thread.c, right after the call to entry(cookie). I will send a patch tonight if you prefer.

Yes, a patch would be appreciated at your earliest convenience. No need to rush it tonight. Do you consider this a candidate for released code, or should I consider this a 1-off?

Quoted 2 lines

thanks,

Jeff

#5 lore raw
Quoted 45 lines · Jeff Weber
Quoted 17 lines · Gilles Chanteperdrix
Quoted 5 lines · Jeff Weber

Gilles:

On Tue, Apr 12, 2011 at 9:38 AM, Gilles Chanteperdrix < [email protected]> wrote:

Quoted 7 lines
Quoted 6 lines

Jeff Weber wrote:

Hi Jeff,

any news about the hostrt patch I sent you for x86_32? Does it work?

Yes it works. However my call to clock_gettime(CLOCK_HOST_REALTIME)

takes

Quoted 3 lines

too long (110 nsec on my CPU) for my ISR, so I will read the TSC instead, and convert the TSC to host time in another thread. Thanks for your help though.

Quoted 7 lines

Wow, it makes me wonder what kind of ISR with a multi-us latency can not handle a 110ns service. But I admit that the hostrt clock_gettime service is a bit heavy. I am afraid there is not much we can do. Could you get me disassembly of the kernel-space clock.o file, so that I verify that we do not end up using divisions? For instance clock_gettime(CLOCK_MONOTONIC) is wrong, and uses the real division.

See attached. Let me know if attachment gets stripped off along the way.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

From testing, I found that if I enable PTHREAD_WARNSW for a pthread, I

must

Quoted 1 line

explicitly disable this mode before the thread terminates, or the

thread

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

draws a signal 24 SIGXCPU.

Yes, the problem is that we can put such migration if the thread function returns, but it will not work in case pthread_exit is called.

I'm interested if there is a way to automatically disable PTHREAD_WARNSW

as

Quoted 1 line

threads terminate, using return from the entry function. I was only

using

Quoted 1 line

pthread_exit() to leverage the thread cleanup stack capability, and queue

a

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

call to pthread_set_mode_np(PTHREAD_WARNSW, 0) .

You can do that in the trampoline in src/skins/posix/thread.c, right after the call to entry(cookie). I will send a patch tonight if you prefer.

Yes, a patch would be appreciated at your earliest convenience. No need to rush it tonight. Do you consider this a candidate for released code, or should I consider this a 1-off?

Ok. Here it comes. Sorry for the delay.

src/skins/posix/thread.c +1 -0
index 109650c..c913ac4 100644
@@ -235,6 +235,7 @@ static void *__pthread_trampoline(void *arg)
 		if (policy != SCHED_OTHER)
 			XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_XENO_DOMAIN);
 		status = start(cookie);
+		XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_LINUX_DOMAIN);
 	} else
 		status = (void *)-err;
 

Since it does not fix the issue completely, I am not sure it is the right solution. I guess doing something in kernel-space would be better.

Signature · 1 line
					    Gilles.