wait_event and interrupts

Rune Torgersen runet at innovsys.com
Wed Sep 21 03:56:02 EST 2005

I have a driver that roughly does something like:

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

    if (!hw_done)
        ret = wait_event_interruptible_timeout(inq, hw_done, TIMEOUT);
        if (ret == 0)
            if (hw_done)
                goto hw_finished;
            return -EIO;
    return len;

static irqreturn_t myinterrupt(int irq, void * dev_id, struct pt_regs *
    hw_done = 1;

    return IRQ_HANDLED;

static void do_softint(void *private_)


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.

More information about the Linuxppc-embedded mailing list