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
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Linux Interrupt Management
1. @ 2021-21 Embitude Trainings <info@embitude.in>
All Rights Reserved
Interrupt Management
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. @ 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. @ 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. @ 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. @ 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. @ 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. @ 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
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. @ 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. @ 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. @ 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. @ 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