-
Notifications
You must be signed in to change notification settings - Fork 0
Linux Device Driver Development
Topics to cover for Linux Device Driver Development
Spin lock protects resources that only one CPU can take access at a time. HW Locking mechanism. Provides atomic operations Inter-cpu locking primitive/object.
Two ways to create/initialize the spin lock
- Statically: DEFINE_SPINLOCK macro. Declares and initialise the spin lock. static DEFINE_SPINLOCK(foo_lock)
- Dynamically: spin_lock_init(). For dynamic (runtime) allocation, you need to embed the spinlock into a bigger structure, allocate memory for this structure, and then call spin_lock_init() on the spinlock element.
E.g.
struct bigger_struct { spinlock_t lock; unsigned int foo; [...] };
static struct bigger_struct *fake_alloc_init_function() { struct bigger_struct *bs; bs = kmalloc(sizeof(struct bigger_struct), GFP_KERNEL); if (!bs) return -ENOMEM; spin_lock_init(&bs->lock); return bs; }
Task will be suspended if mutex is acquired by other task. Will be woken when mutex is released.
A spinlock is a lock held by a CPU, while a mutex is a lock held by a task.
Stands for software interrupt. Preempt all tasks except HW IRQs(since executed with IRQ enabled) Network devices and block devices directly uses softIRQs. Statically located during compile time. Represented by struct softirq_action structure. SoftIRQ can not preempt another soft IRQ. Only HW interrupts can. Executed with high priority with schedular preemption disabled but IRQ enabled. Concurrency: Soft IRQ can run on other processor at same time.(Advantage of Soft IRQ over hard IRQ). spin_lock and spin_unlock() should be used to acquire access of shared resource on other cores.
How to define the event when to raise_soft_irq?
Built on top of HI_SOFTIRQ. Follow same rules as softIRQs but same tasklets never run concurrently.
The interrupts are enabled/disabled by setting/clearing the bits in processor status/control register. ISR must be registers at special location called vector table. Task which is done when interrupt is generated. Context saving and masking interrupt on local CPU then interrupt servicing.
- Defining each system call for each device connected.
insmod
rmmod