From: Andrew Morton <akpm@osdl.org>
To: root@chaos.analogic.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: timing code in 2.6.1
Date: Fri, 16 Jan 2004 15:31:22 -0800 [thread overview]
Message-ID: <20040116153122.2c4adffe.akpm@osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.53.0401161150390.28039@chaos>
"Richard B. Johnson" <root@chaos.analogic.com> wrote:
>
>
> Some drivers are being re-written for 2.6++. The following
> construct seems to work for "waiting for an event" in
> the kernel modules.
>
> // No locks are being held
> tim = jiffies + EVENT_TIMEOUT;
> while(!event() && time_before(jiffies, tim))
> schedule_timeout(0);
>
> Is there anything wrong?
This is not a good thing to be doing. You should add this task to a
waitqueue and then sleep. Make the code which causes event() to come true
deliver a wake_up to that waitqueue. There are many examples of this in
the kernel.
If the hardware only supports polling then gee, you'd be best off spinning
for a few microseconds then fall into a schedule_timeout(1) polling loop.
Or something like that. Or make the hardware designer write the damn
driver.
> Do I have to execute "set_current_state(TASK_INTERRUPTIBLE)" before?
> Do I have to execute "set_current_state(TASK_RUNNING)" after?
>
> I don't want to have to change this again so I really need to
> know. For instance, if I execute "set_current_state(TASK_INTERRUPTIBLE)"
> in version 2.4.24, it didn't hurt anything. In 2.6.1, there are
> conditions where schedule_timeout(0) doesn't return if another
> task is spinning "while(1) ; ". This is NotGood(tm).
As you have it, you may as well be calling schedule() inside that loop.
You _have_ to be in state TASK_RUNNING, else you'll sleep forever.
next prev parent reply other threads:[~2004-01-16 23:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-16 16:51 timing code in 2.6.1 Richard B. Johnson
2004-01-16 23:31 ` Andrew Morton [this message]
2004-01-19 14:11 ` Richard B. Johnson
2004-01-20 9:59 ` George Anzinger
2004-01-22 2:26 ` Jamie Lokier
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=20040116153122.2c4adffe.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.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 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.