Successfully reported this slideshow.
Your SlideShare is downloading. ×

Linux Interrupt Management

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Linux dma engine
Linux dma engine
Loading in …3
×

Check these out next

1 of 14 Ad

Linux Interrupt Management

Covers the basic of interrupt handling, Interrupt Request Number (IRQ), registering the interrupts handler in Linux device driver, registering the bottom halves, tasklets, work queues, threaded irq handler

Covers the basic of interrupt handling, Interrupt Request Number (IRQ), registering the interrupts handler in Linux device driver, registering the bottom halves, tasklets, work queues, threaded irq handler

Advertisement
Advertisement

More Related Content

Recently uploaded (20)

Advertisement

Linux Interrupt Management

  1. 1. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Interrupt Management
  2. 2. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved What to Expect ● Need for interrupts ● IRQ numbers ● Interrupt Registration ● SoftIRQ ● Tasklets ● Work Queues ● Threaded Irq handling
  3. 3. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Need for interrupts ● Interrupt is the intervention ● Interrupt is the mechanism to get the immediate CPU attention ● Speed mismatch between CPU & the periperal devices ● Avoiding the polling for better effieciency
  4. 4. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved How interrupts work? ● Whenever there is a change in the hardware state, CPU is interrupted ● The ISR is invoked to service the interrupts ● Typically process has very few interrupts – So, the processor is occompanied with interrupt controller to service various interrupts
  5. 5. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Interrupt Request (IRQ) ● Number for which the ISR is registered ● Depends on the SOC & connections on the board ● So, its part of Board Support Packages (BSP) ● Linux uses the Virtual IRQ numbers
  6. 6. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Interrupt Registration API ● int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev_id); – typedef irqreturn_t (*irq_handler_t)(int, void *); ● void free_irq(unsigned int irq, void *dev_id); ● Flags – IRQF_TRIGGER_RISING, ..., IRQF_TRIGGER_HIGH, ... – IRQF_SAMPLE_RANDOM – IRQF_SHARED, ...
  7. 7. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Soft IRQ ● Triggered by Sotware ● Basic bottom half ● Also, known as synchronous interrupts – HI_SOFTIRQ=0, – TIMER_SOFTIRQ, – NET_TX_SOFTIRQ, – NET_RX_SOFTIRQ, – BLOCK_SOFTIRQ, – IRQ_POLL_SOFTIRQ, – TASKLET_SOFTIRQ, – SCHED_SOFTIRQ, – HRTIMER_SOFTIRQ, – RCU_SOFTIRQ, – NR_SOFTIRQS
  8. 8. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Tasklets ● One of the bottom halves ● Takes up the remaining portion of the processing left over by ISR ● Executes in the software interrupt context ● Sleeping is not allowed
  9. 9. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Tasklet Data Structures ● struct tasklet_struct ● void tasklet_init(struct tasklet_struct *t, void (*func) (unsigned long), unsigned long data); ● DECLARE_TASKLET(name, func, data); ● DECLARE_TASKLET_DISABLED(name, func, data); ● tasklet_enable(t); tasklet_disable(t); ● tasklet_disable_nosync(t); ● tasklet_[hi_]schedule(t); ● tasklet_kill(t);
  10. 10. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Work Queues ● Bottom half, similar to tasklet ● Does the remaining portion of task ● Executes in the special kernel thread ● Can sleep or block
  11. 11. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Work Queue APIs ● struct workqueue_struct, struct work_struct ● Create Work Queue – q = create_workqueue(name); – q = create_singlethread_workqueue(name); ● Destroy Work Queue – flush_workqueue(q); – destroy_workqueue(q);
  12. 12. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Work Queue APIs ● Initializing the Work – DECLARE_WORK(w, void (*function)(struct work_struct *)); – INIT_WORK(w, void (*function)(struct work_struct *)); ● Scheduling the work – int queue_work(q, &w); – int queue_delayed_work(q, &w, d); ● Cancelling the work – int cancel_delayed_work(&w); ● Shared Work queue – schedule_work(&w)
  13. 13. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved Threaded IRQ ● Reduce the time spent in ISR ● Similar to Tasklets & Work Queues, but simplifies the registration & scheduling ● Runs in kernel thread with pre-emption enabled ● Suitable for scenarios where long processing needs to be done ● API – Int request_threaded_irq(unsigned int irq, irq_handler_t thread_fn, unsigned long flags, const char *name, void *dev)
  14. 14. @ 2021-21 Embitude Trainings <info@embitude.in> All Rights Reserved What all did we learn? ● Need for interrupts ● IRQ numbers ● Interrupt Registration ● SoftIRQ ● Tasklets ● Work Queues ● Threaded Irq handling

×