All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai] [Xenomai-git] Jan Kiszka : switchtest: Account for invalid last_switch.from field
Date: Mon, 18 Nov 2013 15:30:30 +0100	[thread overview]
Message-ID: <528A2486.4030606@xenomai.org> (raw)
In-Reply-To: <528A21A9.9050502@siemens.com>

On 11/18/2013 03:18 PM, Jan Kiszka wrote:
> On 2013-11-18 14:26, Gilles Chanteperdrix wrote:
>> On 11/18/2013 01:41 PM, git repository hosting wrote:
>>> Module: xenomai-jki
>>> Branch: for-forge
>>> Commit: 3e6d8ff9a99262e78655329dc043aacc607eb158
>>> URL:
>>> http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3e6d8ff9a99262e78655329dc043aacc607eb158
>>>
>>>
>>> Author: Jan Kiszka <jan.kiszka@siemens.com>
>>> Date:   Mon Nov 18 13:19:34 2013 +0100
>>>
>>> switchtest: Account for invalid last_switch.from field
>>>
>>> If we close a test device early, no switch may have yet taken place when
>>> the first call to rtswitch_to_rt/nrt happens. This can cause to_idx to
>>> become -1, and the system will crash. Handle this corner case
>>> gracefully.
>>>
>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>>>
>>> ---
>>>
>>>    kernel/drivers/testing/switchtest.c |   10 ++++++++--
>>>    1 file changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/drivers/testing/switchtest.c
>>> b/kernel/drivers/testing/switchtest.c
>>> index 6f77ee9..7d17c5f 100644
>>> --- a/kernel/drivers/testing/switchtest.c
>>> +++ b/kernel/drivers/testing/switchtest.c
>>> @@ -147,8 +147,11 @@ static int rtswitch_to_rt(rtswitch_context_t *ctx,
>>>
>>>        /* to == from is a special case which means
>>>           "return to the previous task". */
>>> -    if (to_idx == from_idx)
>>> +    if (to_idx == from_idx) {
>>>            to_idx = ctx->error.last_switch.from;
>>> +        if (to_idx == -1)
>>> +            return -EINVAL;
>>> +    }
>>
>> I do not see how we can reach rtswitch_to_rt without having switched
>> context, since the first task to run is not an rt task.
>
> Counter question: What should enforce this ordering? And via which call
> stack should last_switch.from be first updated?
>
> I suspect that the RT tasks overtake the non-RT one here, but - granted
> - I didn't understand the control flow and synchronization of this
> driver yet.

At any time, there is at most one task running on each cpu. This task 
then switches to every other task, in turn. The first task to run is the 
"sleeper" task, which calls nanosleep in order to avoid the system to be 
completely paralized.

For instance, with 3 tasks you would get:
1(sleeper)
2
3
1(sleeper)
3
2
1(sleeper)
2
3

etc...


>
> So even if this is not the cause, just curing a symptom, I think it is a
> valid safety measure.

I do not think we need this safety measure: AFAIK it works on 2.6, so I 
would rather make it work on -forge.

-- 
					    Gilles.


  reply	other threads:[~2013-11-18 14:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1ViO8p-0004L8-4y@sd-51317.dedibox.fr>
2013-11-18 13:26 ` [Xenomai] [Xenomai-git] Jan Kiszka : switchtest: Account for invalid last_switch.from field Gilles Chanteperdrix
2013-11-18 14:18   ` Jan Kiszka
2013-11-18 14:30     ` Gilles Chanteperdrix [this message]
2013-11-18 14:34       ` Jan Kiszka
2013-11-18 14:43         ` Gilles Chanteperdrix
2013-11-18 15:01           ` Jan Kiszka
2013-11-18 15:17             ` Gilles Chanteperdrix
2013-11-18 15:58               ` Jan Kiszka
2013-11-18 16:14                 ` Gilles Chanteperdrix
2013-11-18 16:46                   ` Jan Kiszka
2013-11-18 16:58                     ` Jan Kiszka
2013-11-18 17:42                       ` Gilles Chanteperdrix
2013-11-18 17:57                         ` Jan Kiszka
2013-11-18 18:03                           ` Gilles Chanteperdrix
2013-11-18 18:13                             ` Jan Kiszka
2013-11-20 18:25                       ` Jan Kiszka
2013-11-24  8:43                         ` Philippe Gerum
2013-11-18 13:44 ` Gilles Chanteperdrix
2013-11-18 14:00   ` Philippe Gerum

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=528A2486.4030606@xenomai.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=jan.kiszka@siemens.com \
    --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.