Day18 - Blocking I/O and Event-Driven Driver¶
๐ฏ Objective¶
Upgrade mygpio driver to support:
- blocking read()
- non-blocking read()
- poll()
- event queue + wakeup
๐ง Step 1 โ Event Queue Helper¶
- protect with spinlock
- return success / failure
๐ง Step 2 โ Workqueue Handler¶
if (!enqueue)
return;
enqueue_done = mygpio_event_enqueue(...);
if (enqueue_done)
wake_up_interruptible(&dev->read_queue);
๐ง Step 3 โ Blocking read()¶
if (!event_ready) {
if (file->f_flags & O_NONBLOCK)
return -EAGAIN;
ret = wait_event_interruptible(dev->read_queue,
dev->event_count > 0);
if (ret)
return ret;
}
๐ง Step 4 โ Dequeue + copy_to_user¶
๐ง Step 5 โ poll()¶
๐งช Test 1 โ Blocking¶
Expected:
- no input โ block
- press button โ output
๐งช Test 2 โ Non-blocking¶
Expected:
- no event โ -EAGAIN
๐งช Test 3 โ poll¶
Expected:
- no busy loop
- event-driven output
๐งช Test 4 โ Overflow¶
Rapid button press
Expected:
- event drop log
- no crash
๐งช Test 5 โ sysfs + ioctl¶
Expected:
- driver stable
- debounce updated
โ Result¶
Driver supports:
- blocking I/O
- async event notification
- proper Linux behavior