From: Maxim Levitsky <maximlevitsky@gmail.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: General kernel question about waiting for events
Date: Wed, 02 Dec 2009 02:10:20 +0200 [thread overview]
Message-ID: <1259712620.23837.22.camel@maxim-laptop> (raw)
Hi,
I am writing a device driver now, and am am learning to do so at same
time I can say...
I found one interesting feature of the scheduler, and I want to confirm
that I understood it correctly.
Suppose application wants to wait for an event, and doesn't specify any
timeouts.
In that case, wrapped in different packages, it always ends with
following loop:
while( event == false )
schedule();
Now suppose event doesn't happen soon, and system has no other runnable
tasks.
In that case I suspect that system will be in endless loop switching
between idle task (swapper) and this one.
Since its unknown when the event will became true, I don't think that
idle task will be able to put cpu to low power state.
Since on any system there are plenty of tasks that are blocked on
sockets, and don't use any specified timeout, I don't understand how
idle task could run.
I suspect that idle task will run for some predefined time anyway.
It uses need_resched() as an end condition.
But then, am I right that any thread that specifies wait on any event,
will actually force system to wakeup every that 'predefined time'
Which I suspect is 1/HZ seconds?
How longer wait can be done then?
Could you explain that to me a bit?
Another thing I think is wrong is the description for
wait_event_interruptible_timeout
It says, 'sleep until a condition gets true or a timeout elapses',
however it actually tests condition once, sleeps whole timeout, and then
returns.
So a naive user could call that function with large timeout, and think
that as soon as he sets the event, the wait will end.
Am I wrong here?
Best regards,
Maxim Levitsky
next reply other threads:[~2009-12-02 0:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-02 0:10 Maxim Levitsky [this message]
2009-12-02 0:24 ` Alan Cox
2009-12-02 1:28 ` Maxim Levitsky
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=1259712620.23837.22.camel@maxim-laptop \
--to=maximlevitsky@gmail.com \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®