From: Wolfgang Grandegger <wg@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai-help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] pthread cancelation and scheduling magics
Date: Wed, 03 Dec 2008 21:02:50 +0100 [thread overview]
Message-ID: <4936E5EA.1060008@domain.hid> (raw)
In-Reply-To: <4936DBC6.9080805@domain.hid>
Gilles Chanteperdrix wrote:
> Wolfgang Grandegger wrote:
>> Gilles Chanteperdrix wrote:
>>> Wolfgang Grandegger wrote:
>>>> Gilles Chanteperdrix wrote:
>>>>> Wolfgang Grandegger wrote:
>>>>>> Gilles Chanteperdrix wrote:
>>>>>>> Wolfgang Grandegger wrote:
>>>>>>>> Running under gdb shows:
>>>>>>>>
>>>>>>>> Program received signal SIGSEGV, Segmentation fault.
>>>>>>>> [Switching to Thread 0x4885d4b0 (LWP 1127)]
>>>>>>>> 0x0ff49100 in pthread_cancel () from /lib/libpthread.so.0
>>>>>>>> (gdb) where
>>>>>>>> #0 0x0ff49100 in pthread_cancel () from /lib/libpthread.so.0
>>>>>>>> #1 0x10001d64 in ctrl_func (parm=0x0) at cancel-test.c:104
>>>>>>>> #2 0x0ffa98e4 in __pthread_trampoline ()
>>>>>>>> from /home/wolf/xenomai/lib/libpthread_rt.so.1
>>>>>>>> #3 0x0ff42a6c in start_thread () from /lib/libpthread.so.0
>>>>>>>> #4 0x0fdd18a0 in clone () from /lib/libc.so.6
>>>>>>>> Backtrace stopped: previous frame inner to this frame (corrupt stack?)
>>>>>>>>
>>>>>>>> Is pthread_cancel used from the Linux pthread library? And
>>>>>>>> pthread_testcancel() as well?
>>>>>>> Yes, and I guess, as you said, that it happens because calc_func is dead
>>>>>>> when you try and cancel it.
>>>>>> Yep, but it should not crash.
>>>>> The spec says:
>>>>> The pthread_cancel() function may fail if:
>>>>>
>>>>> [ESRCH]
>>>>> No thread could be found corresponding to that specified by the
>>>>> given thread ID.
>>>>>
>>>>>
>>>>> So, it is a "may", returning ESRCH, as Xenomai does in kernel-space, is
>>>>> not mandatory.
>>>> I also got the return value ESRCH in another test. Nevertheless, a crash
>>>> is not the expected behaviour, to say the least. Here pthread_cancel()
>>>> obvoiusly get's interrupted and the calc_thread continues. Is it
>>>> possible that pthread_cancel() switches to secondary mode?
>>> pthread_cancel switches to secondary mode if it has to send a signal (if
>>> cancellation is in asynchronous mode, this happens when the target
>>> thread is blocked inside a blocking call). But this should not be a
>>> problem with RPI.
>> I disabled priority coupling in the kernel and it did not help or harm.
>> This test uses PTHREAD_CANCEL_DEFERRED, which is also the default, if
>> I understood correctly.
>
> You should definitely enable priority coupling. Even if you use
> PTHREAD_CANCEL_DEFERRED, when you call a blocking call, the cancellation
> is switched for the time of the blocking call to asynchronous. But since
> you do not call any blocking call, I agree that pthread_cancel should
> not switch to secondary mode, it should just set a bit in some TCB
> attached to the target thread.
>
>>> But the problem you should focus on is why the scheduler does not let
>>> pthread_cancel run earlier.
>> Don't know what you mean. The calc_func gets preempted and the ctrl_func
>> calls pthread_cancel as expected...
>>
>> calc_func: at count 20
>> calc_func: at count 21
>> calc_func: at count 22
>> ctrl_func: cancel at count 23
>> ^^^^^^^^^
>> calc_func: at count 23
>>
>> But then it stops somehow in pthread_cancel and calc_func continues to run.
>
> Yes, but since "ctrl_func: stopped at count 23" does not appear, it
> means that ctrl_func is somehow blocked in pthread_cancel.
>
> Does the test work if calc_func calls nanosleep instead of
> create_load_100ms ?
Yes.
I'm getting closer now, I think, I hope. pthread_cancel seems only to
work if calc_thread runs in secondary mode. If I set policy and priority
at the beginning of the thread function, nor pthread_setschedparam nor
clock_gettime switches to primary mode and therefore calc_thread runs in
secondary mode. If I add explicit
pthread_set_mode_np(0, PTHREAD_PRIMARY), pthread_cancel is not able to
terminate the calc_thread anymore, even with pthread_testcancel.
Wolfgang.
next prev parent reply other threads:[~2008-12-03 20:02 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-30 21:34 [Xenomai-help] pthread cancelation and scheduling magics Wolfgang Grandegger
2008-11-30 21:46 ` Gilles Chanteperdrix
2008-11-30 21:59 ` Gilles Chanteperdrix
2008-12-01 10:22 ` Gilles Chanteperdrix
2008-12-01 14:16 ` Wolfgang Grandegger
2008-12-01 14:15 ` Gilles Chanteperdrix
2008-12-01 15:10 ` Gilles Chanteperdrix
2008-12-02 15:59 ` Wolfgang Grandegger
2008-12-02 15:55 ` Gilles Chanteperdrix
2008-12-02 18:18 ` Wolfgang Grandegger
2008-12-02 18:35 ` Gilles Chanteperdrix
2008-12-02 19:50 ` Wolfgang Grandegger
2008-12-02 20:03 ` Philippe Gerum
2008-12-07 16:05 ` Wolfgang Grandegger
2008-12-10 11:16 ` Wolfgang Grandegger
2008-12-11 15:26 ` Jan Kiszka
2008-12-13 15:55 ` Wolfgang Grandegger
2009-01-01 13:34 ` Gilles Chanteperdrix
2009-01-01 17:07 ` Philippe Gerum
2009-01-01 18:00 ` Gilles Chanteperdrix
2009-01-09 13:08 ` Gilles Chanteperdrix
2009-01-09 13:38 ` Philippe Gerum
2009-01-01 17:10 ` Wolfgang Grandegger
2009-01-01 18:11 ` Gilles Chanteperdrix
2008-12-03 10:16 ` Gilles Chanteperdrix
2008-12-03 11:19 ` Wolfgang Grandegger
2008-12-03 13:30 ` Gilles Chanteperdrix
2008-12-03 18:02 ` Wolfgang Grandegger
2008-12-03 17:57 ` Gilles Chanteperdrix
2008-12-03 18:37 ` Wolfgang Grandegger
2008-12-03 18:32 ` Gilles Chanteperdrix
2008-12-03 18:55 ` Wolfgang Grandegger
2008-12-03 18:55 ` Gilles Chanteperdrix
2008-12-03 19:19 ` Wolfgang Grandegger
2008-12-03 19:19 ` Gilles Chanteperdrix
2008-12-03 20:02 ` Wolfgang Grandegger [this message]
2008-12-03 20:02 ` Gilles Chanteperdrix
2008-12-04 15:29 ` Wolfgang Grandegger
2008-12-04 15:38 ` Gilles Chanteperdrix
2008-12-04 15:42 ` Gilles Chanteperdrix
2008-12-04 16:31 ` Wolfgang Grandegger
2008-12-04 16:26 ` Gilles Chanteperdrix
2008-12-04 16:49 ` Wolfgang Grandegger
2008-12-04 17:02 ` Gilles Chanteperdrix
2008-12-04 17:52 ` Wolfgang Grandegger
2008-12-04 17:51 ` Gilles Chanteperdrix
2008-12-05 14:58 ` Wolfgang Grandegger
2008-12-03 8:04 ` Wolfgang Grandegger
2008-12-03 10:12 ` Gilles Chanteperdrix
2008-12-03 10:46 ` Wolfgang Grandegger
2008-12-03 10:40 ` Gilles Chanteperdrix
2008-12-03 11:16 ` Wolfgang Grandegger
2008-12-03 11:11 ` Philippe Gerum
2008-12-03 11:22 ` Wolfgang Grandegger
2008-12-01 13:31 ` Wolfgang Grandegger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4936E5EA.1060008@domain.hid \
--to=wg@domain.hid \
--cc=gilles.chanteperdrix@xenomai.org \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.