All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Wolfgang Grandegger <wg@domain.hid>
Cc: xenomai-help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] pthread cancelation and scheduling magics
Date: Thu, 04 Dec 2008 18:51:06 +0100	[thread overview]
Message-ID: <4938188A.2010105@domain.hid> (raw)
In-Reply-To: <493818F5.1010209@domain.hid>

Wolfgang Grandegger wrote:
> Gilles Chanteperdrix wrote:
>> Wolfgang Grandegger wrote:
>>> Gilles Chanteperdrix wrote:
>>>> Wolfgang Grandegger wrote:
>>>>> Gilles Chanteperdrix wrote:
>>>>>> Wolfgang Grandegger wrote:
>>>>>>> Gilles Chanteperdrix wrote:
>>>>> [...deletions...]
>>>>>>>> That is not expected. But this brings me back to my initial question, do
>>>>>>>> you have to work with a real world application that runs without issuing
>>>>>>>> any syscall ?
>>>>>>> If a add long nanosleeps, e.g. 100, 10 or 1 ms, cancellation works but
>>>>>>> it fails with short nanosleeps. A syscall seems not sufficient. I have
>>>>>>> the impression that pthread_cancel needs some time in secondary mode to
>>>>>> When calling nanosleep, the threads spends on time in secondary mode. I
>>>>> What do you mean? nanosleep switches to secondary mode?
>>>> I meant spends "no" time in secondary mode. nanosleep does not switch to
>>>> secondary mode.
>>>>
>>>>>> think the problem is rather that only asynchronous cancelation (meaning
>>>>>> cancelation with a signal) works. Setting the cancelation bit somehow
>>>>>> gets lost.
>>>>>>
>>>>>>> do it's duties, e.g. mark the thread as canceled. Would it make sense to
>>>>>>> wrap pthread_cancel, and friends to the corresponding kernel functions
>>>>>>> in ksrc/skins/posix?
>>>>>>> Is there a way to force a thread switching to secondary mode?
>>>>>> No, there is no way to force a thread to switch to secondary mode, the
>>>>>> xnshadow_relax call explicitely requires to be called by the target
>>>>>> thread. Before I wrap pthread_cancel, I would really like to understand
>>>>>> why setting a bit with pthread_cancel and testing it with
>>>>>> pthread_testcancel does not work.
>>>>>>
>>>>>> What is the trace of your test when run:
>>>>>> - on ARM
>>>>>> - with root thread priority inheritance,
>>>>>> - with USE_EXPLICIT_SCHED and USE_TEST_CANCEL, and CANCEL_TYPE set to
>>>>>> PTHREAD_CANCEL_DEFERRED
>>>>>> - posting a semaphore in ctrl_func before calling nanosleep, and waiting
>>>>>> for that semaphore in main before creating the calc_func thread.
>>>>> The calc_thread is not canceled and a segmentation fault happens.
>>>>> Canceling the calc_thread does *not* work if it's running in primrary
>>>>> mode, nor on ARM, nor on PowerPC. It does work when calc_thread does run
>>>>> in secondary mode, which happened with USE_EXPLICIT_SCHED not set. If
>>>>> you want do to some tests, I could send you my revised test program.
>>>>> My conclusion is that pthread_cancel can not be used to cancel busy
>>>>> realtime threads. I'm going to re-write the program using the native
>>>>> skin and rt_task_delete.
>>>> Yes, but what interests me is how it fails, that is seeing the trace of
>>>> your program.
>>> With pthread_cancel you do not see too much because the rt_printf
>>> messages do not get printed:
>> As a temporary quirk, could you try, in rtdk, to install a handler for
>> SIGSEGV which flushes the print buffers ?
> 
> OK. Hm, flushing the rt_print buffers before exit is what I'm actually
> looking for. Registering an cleanup handler would already be enough. But
>   an active real-time task will also delay the exit().

In case of segmentation fault, the SIGSEGV signal is sent to the
application and exit is not called at all, which is why the buffers do
not get flushed, and why I am suggesting to flush them in the SIGSEGV
handler.

> 
> Nevertheless, I tried with the native skin and it cancellation works
> fine with:
> 
> 		rt_task_suspend(&calc_thread);
> 		rt_task_delete(&calc_thread);
> 
> Can I do a task suspend with the Xenomai POSIX skin?

You should not need to suspend the task with the native skin either.
With the posix skin, you still have the same problem: send the SIGSTOP
signal to the task, but it will not work if the task does not issue any
syscall.

-- 
                                                 Gilles.


  reply	other threads:[~2008-12-04 17:51 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
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 [this message]
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=4938188A.2010105@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=wg@domain.hid \
    --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.