Thread (3 messages) flat view 3 messages, 3 authors, 2005-09-21

wait_event and interrupts

From: Rune Torgersen <hidden>
Date: 2005-09-20 17:56:03

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help