wake_up & wait_event are counting events ?

Ran Shalit ranshalit at gmail.com
Thu Jan 19 08:14:15 EST 2017


Hello,

I am trying to correctly register interrupt in kernel for user interface:

irq handler
=========

static irqreturn_t irq_handler(int irq, void *dev_id)
{
   struct elbit_irq_dev *elbit_irq = &elbit_irq_devices[0];
    printk("irq in\n");

 <<==== clear interrupt in fpga  here or after the call to wake_up,
(at the bottom of routine below ) ?

    atomic_set(&elbit_irq->flag, 1);
    wake_up_interruptible(&elbit_irq->pollw);



    return IRQ_HANDLED;
}

ioctl for waiting on interrupts
======================

static long elbit_device_ioctl( struct file *filp, /* ditto */
         unsigned int ioctl_num, /* number and param for ioctl */
         unsigned long ioctl_param)
{
    struct elbit_irq_dev *elbit_irq = &elbit_irq_devices[0];

    switch (ioctl_num) {
    case IOCTL_WAIT_IRQ:
        atomic_set(&elbit_irq->flag, 0);
        wait_event_interruptible(elbit_irq->pollw,
atomic_read(&elbit_irq->flag) != 0) ;
        break;


    default:
        break;
    }
    return 0;
}

my questions:
1. does wake_up and wait_event are countable, i.e. if there are 2
interrupts for example before wait_event is called, does it mean it
wake_event will not sleep on 2 consecutive calls ?

2. should we put the clear of interrupts in fpga in the interrupt
before or after the wake_up ? can we put them instead in the userspace
handler (IOCTL_WAIT_IRQ)  instead of  clearing the interrupt in the
interrupt handler ?

Thank you,
Ran



More information about the Kernelnewbies mailing list