From: Shan Hai <haishan.bai@gmail.com>
To: Yong Zhang <yong.zhang0@gmail.com>
Cc: sifram rajas <sifram.rajas@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: General question about TASK_INTERRUPTIBLE and schedule_timeout()
Date: Fri, 02 Sep 2011 14:18:11 +0800 [thread overview]
Message-ID: <4E607523.30907@gmail.com> (raw)
In-Reply-To: <20110901020947.GA9096@zhy>
On 09/01/2011 10:09 AM, Yong Zhang wrote:
> On Wed, Aug 31, 2011 at 06:18:19PM +0530, sifram rajas wrote:
>> Hi,
>>
>> I have a general question about the following 2 lines of code I see
>> all over the kernel:
>> 1 set_current_state(TASK_INTERRUPTIBLE) ;
>> 2 schedule_timeout(<some value>);
>>
>> In the above code, if we encounter an interrupt after executing line
>> 1, we will end up
>> call schedule() from the architecture specific code for CONFIG_PREEMPT
>> kernels, after
>> the interrupt handler has been invokled.
> Yes.
>
>> This will cause the current task to sleep interruptibly forever
Actually, sleeping forever in the TASK_INTERRUPTIBLE state is not correct,
because even though the task is preempted by higher priority one
it will finally get a chance to run, but you will get time out value
of <some value> + preemption latency.
>> instead of for a certain timeout interval.
> No.
>
> schedule() will not put an preempted task to sleep, see:
This might be problematic, because on the IRQ to preemption check path
the PREEMPT_ACTIVE was already set and the following 'if' statement
could not hold because of
!(preempt_count() & PREEMPT_ACTIVE) == false
and the pick_next_task() might put the preempted task to sleep.
Correct me on any misunderstanding :-)
Cheers
Shan Hai
> asmlinkage void __sched schduule(void)
> {
> ...
> if (prev->state&& !(preempt_count()& PREEMPT_ACTIVE)) {
> if (unlikely(signal_pending_state(prev->state, prev))) {
> prev->state = TASK_RUNNING;
> } else {
> ...
> }
> }
> ...
> }
>
> Thanks,
> Yong
>
>> Won't this defeat the purpose of the above code to schedule out or
>> sleep for a certain finite timeout ?
>> If yes, then what are the techniques to solve this problem ?
>>
>>
>> Thanks,
>> Sifram.
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2011-09-02 6:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-31 12:48 General question about TASK_INTERRUPTIBLE and schedule_timeout() sifram rajas
2011-08-31 13:05 ` sifram rajas
2011-09-01 2:09 ` Yong Zhang
2011-09-02 6:18 ` Shan Hai [this message]
2011-09-02 7:06 ` Shan Hai
2011-09-02 7:31 ` kautuk.c @samsung.com
2011-09-02 7:44 ` kautuk.c @samsung.com
2011-09-02 8:08 ` Shan Hai
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=4E607523.30907@gmail.com \
--to=haishan.bai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sifram.rajas@gmail.com \
--cc=yong.zhang0@gmail.com \
/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