From: Dmitry Adamushko <dmitry.adamushko@domain.hid>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] [BUG] racy xnshadow_harden under CONFIG_PREEMPT
Date: Mon, 30 Jan 2006 15:02:18 +0200 [thread overview]
Message-ID: <b647ffbd0601300502y3f33c3cdv@domain.hid> (raw)
In-Reply-To: <43DDFD03.5030104@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 3268 bytes --]
On 30/01/06, Jan Kiszka <jan.kiszka@domain.hid> wrote:
>
> Dmitry Adamushko wrote:
> >>> ...
> >
> >> I have not checked it yet but my presupposition that something as easy
> as
> >> :
> >>> preempt_disable()
> >>>
> >>> wake_up_interruptible_sync();
> >>> schedule();
> >>>
> >>> preempt_enable();
> >> It's a no-go: "scheduling while atomic". One of my first attempts to
> >> solve it.
> >
> >
> > My fault. I meant the way preempt_schedule() and preempt_irq_schedule()
> call
> > schedule() while being non-preemptible.
> > To this end, ACTIVE_PREEMPT is set up.
> > The use of preempt_enable/disable() here is wrong.
> >
> >
> > The only way to enter schedule() without being preemptible is via
> >> ACTIVE_PREEMPT. But the effect of that flag should be well-known now.
> >> Kind of Gordian knot. :(
> >
> >
> > Maybe I have missed something so just for my curiosity : what does
> prevent
> > the use of PREEMPT_ACTIVE here?
> > We don't have a "preempted while atomic" message here as it seems to be
> a
> > legal way to call schedule() with that flag being set up.
>
> When PREEMPT_ACTIVE is set, task gets /preempted/ but not removed from
> the run queue - independent of its current status.
Err... that's exactly the reason I have explained in my first mail for this
thread :) Blah.. I wish I was smoking something special before so I would
point that as the reason of my forgetfulness.
Actually, we could use PREEMPT_ACTIVE indeed + something else (probably
another flag) to distinguish between a case when PREEMPT_ACTIVE is set by
Linux and another case when it's set by xnshadow_harden().
xnshadow_harden()
{
struct task_struct *this_task = current;
...
xnthread_t *thread = xnshadow_thread(this_task);
if (!thread)
return;
...
gk->thread = thread;
+ add_preempt_count(PREEMPT_ACTIVE);
// should be checked in schedule()
+ xnthread_set_flags(thread, XNATOMIC_TRANSIT);
set_current_state(TASK_INTERRUPTIBLE);
wake_up_interruptible_sync(&gk->waitq);
+ schedule();
+ sub_preempt_count(PREEMPT_ACTIVE);
...
}
Then, something like the following code should be called from schedule() :
void ipipe_transit_cleanup(struct task_struct *task, runqueue_t *rq)
{
xnthread_t *thread = xnshadow_thread(task);
if (!thread)
return;
if (xnthread_test_flags(thread, XNATOMIC_TRANSIT))
{
xnthread_clear_flags(thread, XNATOMIC_TRANSIT);
deactivate_task(task, rq);
}
}
-----
schedule.c :
...
switch_count = &prev->nivcsw;
if (prev->state && !(preempt_count() & PREEMPT_ACTIVE))
switch_count = &prev->nvcsw;
if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
unlikely(signal_pending(prev)) ))
prev->state = TASK_RUNNING;
else {
if (prev->state == TASK_UNINTERRUPTIBLE)
rq->nr_uninterruptible++;
deactivate_task(prev, rq);
}
}
// removes a task from the active queue if PREEMPT_ACTIVE + //
XNATOMIC_TRANSIT
+ #ifdef CONFIG_IPIPE
+ ipipe_transit_cleanup(prev, rq);
+ #endif /* CONFIG_IPIPE */
...
Not very gracefully maybe, but could work or am I missing something
important?
--
Best regards,
Dmitry Adamushko
[-- Attachment #2: Type: text/html, Size: 4629 bytes --]
next prev parent reply other threads:[~2006-01-30 13:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-21 10:47 [Xenomai-core] [BUG] racy xnshadow_harden under CONFIG_PREEMPT Jan Kiszka
2006-01-21 10:51 ` [Xenomai-core] " Jeroen Van den Keybus
2006-01-21 16:47 ` [Xenomai-core] " Hannes Mayer
2006-01-21 17:01 ` Jan Kiszka
2006-01-22 8:10 ` Dmitry Adamushko
2006-01-22 16:19 ` Jeroen Van den Keybus
2006-01-23 18:22 ` Gilles Chanteperdrix
2006-01-23 19:16 ` Jan Kiszka
2006-01-30 14:51 ` Philippe Gerum
2006-01-30 15:33 ` Philippe Gerum
2006-01-30 16:01 ` Jan Kiszka
2006-01-30 23:10 ` Philippe Gerum
2006-01-31 19:01 ` Jan Kiszka
2006-01-30 15:35 ` Philippe Gerum
2006-01-31 21:09 ` Jeroen Van den Keybus
2006-01-31 21:45 ` Philippe Gerum
2006-02-01 9:57 ` Jeroen Van den Keybus
2006-02-01 10:03 ` Jan Kiszka
2006-02-01 12:23 ` Jeroen Van den Keybus
2006-02-01 12:34 ` Jan Kiszka
2006-01-24 13:14 ` Dmitry Adamushko
2006-01-24 13:26 ` Jan Kiszka
2006-01-30 11:37 ` Dmitry Adamushko
2006-01-30 11:48 ` Jan Kiszka
2006-01-30 13:02 ` Dmitry Adamushko [this message]
2006-01-29 23:48 ` Philippe Gerum
2006-01-30 10:14 ` 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=b647ffbd0601300502y3f33c3cdv@domain.hid \
--to=dmitry.adamushko@domain.hid \
--cc=jan.kiszka@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.