linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* wait_event and interrupts
@ 2005-09-20 17:56 Rune Torgersen
  2005-09-20 18:40 ` Jeff Angielski
  2005-09-21  6:16 ` Kalle Pokki
  0 siblings, 2 replies; 4+ messages in thread
From: Rune Torgersen @ 2005-09-20 17:56 UTC (permalink / raw)
  To: linuxppc-embedded

Hi
I have a driver that roughly does something like:

int driver_read(int cs, int addr, void *buf, int len)
{
    hw_done =3D 0;
    /* init_hw */

    if (!hw_done)
    {
        ret =3D wait_event_interruptible_timeout(inq, hw_done, TIMEOUT);
        if (ret =3D=3D 0)
        {
            if (hw_done)
                goto hw_finished;
		=09
            return -EIO;
        }
    }
hw_finished:
    return len;
}

static irqreturn_t myinterrupt(int irq, void * dev_id, struct pt_regs *
regs)
{
    hw_done =3D 1;
    schedule_work(&tqueue);

    return IRQ_HANDLED;
}

static void do_softint(void *private_)
{
    wake_up_interruptible(&inq);

}

I have a problem however with this, because in about 10% of my cases,
the interrupt triggers very fast, and ends up being served between the
check for hw_done and the wait_event call. This cause the wait to
timeout instead of getting waked up.

Is there a better way of doing this?
I do not want to do a busy wait, because the hardware can take up to
several 100's of ms to return, but most often returns within 20us.

^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: wait_event and interrupts
@ 2005-09-20 19:14 Rune Torgersen
  0 siblings, 0 replies; 4+ messages in thread
From: Rune Torgersen @ 2005-09-20 19:14 UTC (permalink / raw)
  To: jeff; +Cc: linuxppc-embedded

> -----Original Message-----
> From: Jeff Angielski [mailto:jeff@theptrgroup.com]=20
> Sent: Tuesday, September 20, 2005 13:40
> On Tue, 2005-09-20 at 12:56 -0500, Rune Torgersen wrote:
>=20
> > Is there a better way of doing this?
>=20
> If you *must* share the variable between interrupt and non-interrupt
> context, you must mutex it in an interrupt safe way.  The use of
> spin_lock_irqsave() comes to mind for you read function.

The shared variable is an int, which should be atomic to access anyways.
Someone else told me to try to set the shared variable to volatile.

> But you are going to have other problems with this approach anyways
> since you "appear" to be assuming a one-to-one relationship=20
> between your
> interrupt handler and the read function.  Is that really true?
Yes. The read function starts the hardware, and the hardware responds
with an interrupt when it's done.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-09-21  6:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-20 17:56 wait_event and interrupts Rune Torgersen
2005-09-20 18:40 ` Jeff Angielski
2005-09-21  6:16 ` Kalle Pokki
  -- strict thread matches above, loose matches on Subject: below --
2005-09-20 19:14 Rune Torgersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).