From: "Eugeny S. Mints" <emints@ru.mvista.com>
To: Esben Nielsen <simlo@phys.au.dk>
Cc: Ingo Molnar <mingo@elte.hu>, linux-kernel@vger.kernel.org
Subject: Re: [patch] Real-Time Preemption, deactivate() scheduling issue
Date: Fri, 04 Mar 2005 14:56:11 +0300 [thread overview]
Message-ID: <42284CDB.5010309@ru.mvista.com> (raw)
In-Reply-To: <Pine.OSF.4.05.10503032311510.22011-100000@da410.phys.au.dk>
Esben Nielsen wrote:
> As I read the code the driver task (A) should _not_ be removed from the
> runqueue. It has to be waken up to call schedule_timeout() such it gets
> back on the runqueue after 10 ms. If it is taken out of the runqueue at
> line 76 it will stay off the runqueue forever in the TASK_UNINTERRUBTIBLE
> state!
Exactly. This is definilty the bug in the driver code - a developer just
didn;t care about proper utilization of set_current_state(). The driver
works
just because as you have described - his fortune
that scheduler doesn't remove task in not TASK_RUNNING state from a run
queue.
And my main question was - does everybody think it's ok have task in not
TASK_RUNNING state in run queue. My current feeling is that this should
not be allowed.
> As I read the use PREEMPT_ACTIVE, it is there to test on wether this
> rescheduling is volentery or forced (a preemption). If it is forced the
> task shall ofcourse not go off the runqueue but stay there to run again
> when it gets the highest priority. That is why PREEMPT_ACTIVE is set in
> preempt_schedule() and preempt_schedule_irq(). On the other hand if the
> task itself has called schedule() or schedule_timeout() it has to go out
> of the runqueue and wait for some event to wake it up.
You right - it works perfectly - but not for my test case - I believe
task in not TASK_RUNNING state should be removed from a run queue by the
first (any - volontery or forced) execution of the schedule() which
detects the task state is not TASK_RUNNIG.
>
> Yes there will be tasks in state other that TASK_RUNNING on the runqueue.
> The "bug" as I see it is in the scheduler interface: There is no way to
> set the task state and call schedule() or schedule_timeout() atomicly.
> Therefore you can be preempted while the state is not TASK_RUNNING.
Exactly. IMO this interface is weird and needs rework. I don;t undestand
what the reason to set task state before schedule_timeout() call but not
inside, right before the schedule(). The actual task state may be passed
as a parameter.
As to tasks in not TASK_RUNNING state into a run queue - I always
believe the definition of a run queue is - queue of tasks ready to run,
i.e. in TASK_RUNNING state.
Eugeny
>
> Esben
>
>
> On Thu, 3 Mar 2005, Eugeny S. Mints wrote:
>
>
>>please consider the following scenario for full RT kernel.
>>
>>Task A is running then an irq is occured which in turn wakes up irq
>>related thread (B) of a higher priority than A.
>>
>>my current understanding that actual context switch between A and B will
>>occure at preempt_schedule_irq() on the "return form irq " path.
>>
>>in this case the following "if" statement in __schedule() always returns
>>false since preempt_schedule_irq() always sets up PREEMPT_ACTIVE
>>before __schedule() call.
>>
>> if ((prev->state & ~TASK_RUNNING_MUTEX) &&
>> !(preempt_count() & PREEMPT_ACTIVE)) {
>>
>>as result the deactivate() is never called for preempted task A in this
>>scenario. BUt if the task A is preempted while not in TASK_RUNNING state
>>such behaviour seems incorrect since we get a task in not TASK_RUNNING
>>state linked into a run queue.
>>
>>An example:
>>
>>drivers/net/irda/sir_dev.c: 76 (2.6.10 kernel)
>>
>> spin_lock_irqsave(&dev->tx_lock, flags); /* serialize th other
>>tx operations */
>> while (dev->tx_buff.len > 0) { /* wait until tx idle */
>> spin_unlock_irqrestore(&dev->tx_lock, flags);
>>76: set_current_state(TASK_UNINTERRUPTIBLE);
>> schedule_timeout(msecs_to_jiffies(10));
>> spin_lock_irqsave(&dev->tx_lock, flags);
>> }
>>
>>At line 76 irqs are enabled, preemption is enabled.
>>Let assume the task A executes this code and gets preempted right after
>>line 76. Task state is TASK_UNINTERRUPTIBLE but it will not be
>>deactevated. Of cource this is the bug in set_current_state()
>>utilization in this particular driver but schedule stuff should be
>>robust to such bugs I believe. There are a lot such bugs in the kernel I
>>believe.
>>
>>Not sure what the actual reason for !(preempt_count() & PREEMPT_ACTIVE))
>> condition is but if it's just a sort of optimization (not remove a
>>task from run queue if it was preemped in TASK_RUNNING state) then
>>probably it should be removed in order to save correctness. Patch attached.
>>
>> Eugeny
>>
>>
>
>
>
>
next prev parent reply other threads:[~2005-03-04 12:20 UTC|newest]
Thread overview: 125+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-04 10:03 [patch] Real-Time Preemption, -RT-2.6.11-rc3-V0.7.38-01 Ingo Molnar
2005-02-04 15:19 ` Kevin Hilman
2005-02-04 17:30 ` Ingo Molnar
2005-02-04 18:19 ` Tom Rini
2005-02-07 9:03 ` Ingo Molnar
2005-02-07 14:35 ` Tom Rini
2005-02-08 8:27 ` Ingo Molnar
2005-02-06 4:19 ` Valdis.Kletnieks
2005-02-07 9:21 ` Ingo Molnar
2005-02-07 15:08 ` Real-Time Preemption and UML? Esben Nielsen
2005-02-07 18:35 ` Jeff Dike
2005-02-07 23:14 ` Esben Nielsen
2005-02-08 8:39 ` Ingo Molnar
2005-02-08 18:55 ` Jeff Dike
2005-02-08 21:20 ` Esben Nielsen
2005-02-08 21:44 ` Ingo Molnar
2005-02-08 23:02 ` Esben Nielsen
2005-02-08 7:55 ` [patch] Real-Time Preemption, -RT-2.6.11-rc3-V0.7.38-01 Valdis.Kletnieks
2005-02-08 8:45 ` Ingo Molnar
2005-02-08 10:26 ` Valdis.Kletnieks
2005-02-08 21:58 ` William Weston
2005-02-09 11:51 ` Ingo Molnar
2005-02-10 2:13 ` William Weston
2005-02-10 7:52 ` Ingo Molnar
2005-02-10 20:21 ` George Anzinger
2005-02-10 20:40 ` Ingo Molnar
2005-02-10 21:05 ` George Anzinger
2005-02-11 8:34 ` Ingo Molnar
2005-02-11 9:38 ` Sven Dietrich
2005-02-11 9:42 ` Ingo Molnar
2005-02-11 0:09 ` Sven Dietrich
2005-02-11 6:01 ` George Anzinger
2005-02-11 8:28 ` Ingo Molnar
2005-02-11 9:53 ` Sven Dietrich
2005-02-11 10:04 ` Ingo Molnar
2005-02-11 21:49 ` Steven Rostedt
2005-02-13 12:59 ` Ingo Molnar
2005-02-13 15:11 ` Steven Rostedt
2005-03-03 19:36 ` [patch] Real-Time Preemption, deactivate() scheduling issue Eugeny S. Mints
2005-03-03 22:32 ` Esben Nielsen
2005-03-04 11:56 ` Eugeny S. Mints [this message]
2005-03-04 15:45 ` George Anzinger
2005-03-29 8:45 ` Ingo Molnar
2005-02-09 12:48 ` [patch] Real-Time Preemption, -RT-2.6.11-rc3-V0.7.38-01 Stephen Smalley
2005-02-10 2:20 ` William Weston
2005-02-19 5:08 ` Lee Revell
2005-02-19 6:47 ` Lee Revell
2005-02-19 9:00 ` Ingo Molnar
2005-02-19 9:03 ` Ingo Molnar
2005-02-19 20:45 ` Lee Revell
2005-02-20 0:19 ` Lee Revell
2005-03-17 16:33 ` Lee Revell
2005-02-23 2:22 ` Lee Revell
2005-03-10 9:37 ` Steven Rostedt
2005-03-10 9:54 ` Steven Rostedt
2005-03-11 9:57 ` Ingo Molnar
2005-03-11 10:15 ` Steven Rostedt
2005-03-11 10:17 ` Ingo Molnar
2005-03-11 10:24 ` Steven Rostedt
2005-03-11 10:43 ` Andrew Morton
2005-03-11 10:53 ` Steven Rostedt
2005-03-11 14:40 ` Steven Rostedt
2005-03-11 15:08 ` Steven Rostedt
2005-03-11 15:30 ` K.R. Foley
2005-03-11 15:38 ` Ingo Molnar
2005-03-11 16:01 ` Steven Rostedt
2005-03-11 20:39 ` Steven Rostedt
2005-03-11 20:46 ` Lee Revell
2005-03-11 22:06 ` Lee Revell
2005-03-14 7:37 ` Steven Rostedt
2005-03-14 9:33 ` Steven Rostedt
2005-03-14 10:10 ` Steven Rostedt
2005-03-14 15:50 ` Steven Rostedt
2005-03-14 19:02 ` Steven Rostedt
2005-03-15 11:44 ` Steven Rostedt
2005-03-15 12:00 ` Ingo Molnar
2005-03-15 13:07 ` Steven Rostedt
2005-03-15 13:35 ` Ingo Molnar
2005-03-15 13:55 ` Steven Rostedt
2005-03-15 19:12 ` Andrew Morton
2005-03-15 18:05 ` Steven Rostedt
2005-03-15 19:09 ` Lee Revell
2005-03-16 7:50 ` Steven Rostedt
2005-03-16 18:21 ` Lee Revell
2005-03-16 7:31 ` Steven Rostedt
2005-03-16 8:50 ` Ingo Molnar
2005-03-16 9:15 ` Andrew Morton
2005-03-16 9:51 ` [patch 0/3] j_state_lock, j_list_lock, remove-bitlocks Ingo Molnar
2005-03-16 9:53 ` [patch 1/3] j_state_lock -> j_state_sem Ingo Molnar
2005-03-16 9:53 ` [patch 2/3] j_list_lock -> j_list_sem Ingo Molnar
2005-03-16 9:57 ` [patch 3/3] remove bitlocks Ingo Molnar
2005-03-16 10:04 ` [patch 0/3] j_state_lock, j_list_lock, remove-bitlocks Andrew Morton
2005-03-16 10:12 ` Ingo Molnar
2005-03-16 10:23 ` Steven Rostedt
2005-03-16 10:26 ` Ingo Molnar
2005-03-16 10:26 ` Andrew Morton
2005-03-16 10:29 ` Ingo Molnar
2005-03-16 10:41 ` Andrew Morton
2005-03-16 10:34 ` Arjan van de Ven
2005-03-16 10:19 ` Ingo Molnar
2005-03-16 10:40 ` Andrew Morton
2005-03-16 10:51 ` Ingo Molnar
2005-03-16 11:05 ` Steven Rostedt
2005-03-16 11:19 ` Andrew Morton
2005-03-16 14:04 ` Steven Rostedt
2005-03-16 16:47 ` Steven Rostedt
2005-03-16 17:47 ` Steven Rostedt
2005-03-16 19:20 ` Lee Revell
2005-03-17 7:15 ` Steven Rostedt
2005-03-17 15:41 ` Lee Revell
2005-03-17 16:23 ` Steven Rostedt
2005-03-17 16:36 ` Lee Revell
2005-03-18 6:58 ` Steven Rostedt
2005-03-18 18:19 ` Lee Revell
2005-03-16 21:15 ` Andrew Morton
2005-03-17 9:21 ` Steven Rostedt
2005-03-18 9:23 ` [PATCH] remove lame schedule in journal inverted_lock (was: Re: [patch 0/3] j_state_lock, j_list_lock, remove-bitlocks) Steven Rostedt
2005-03-18 9:32 ` Andrew Morton
2005-03-18 10:38 ` Steven Rostedt
2005-03-18 11:07 ` Andrew Morton
2005-03-18 12:10 ` Steven Rostedt
2005-03-17 9:58 ` [patch 0/3] j_state_lock, j_list_lock, remove-bitlocks Steven Rostedt
2005-03-11 9:28 ` [patch] Real-Time Preemption, -RT-2.6.11-final-V0.7.40-00 Ingo Molnar
2005-03-11 12:10 ` Andrew Walrond
2005-03-14 20:19 ` Tom Rini
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=42284CDB.5010309@ru.mvista.com \
--to=emints@ru.mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=simlo@phys.au.dk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox