From 7714f63f14504a7da734ff62fea57e62d1285608 Mon Sep 17 00:00:00 2001 From: Eleanor Date: Wed, 27 Aug 2025 00:49:05 +0800 Subject: [PATCH 1/2] Drop unused DECLARE_TASKLET_OLD macro Commit 3682d9e6d51b ("Move bottom-half to workqueue for safe sleep") migrated the example code away from tasklets to workqueues. However, the compatibility macro DECLARE_TASKLET_OLD was left behind even though tasklets are no longer used. Remove the unused macro for consistency and clarity. --- examples/bottomhalf.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/bottomhalf.c b/examples/bottomhalf.c index 88f895af..212391d6 100644 --- a/examples/bottomhalf.c +++ b/examples/bottomhalf.c @@ -21,13 +21,6 @@ #define NO_GPIO_REQUEST_ARRAY #endif -/* Macro DECLARE_TASKLET_OLD exists for compatibility. - * See https://lwn.net/Articles/830964/ - */ -#ifndef DECLARE_TASKLET_OLD -#define DECLARE_TASKLET_OLD(arg1, arg2) DECLARE_TASKLET(arg1, arg2, 0L) -#endif - static int button_irqs[] = { -1, -1 }; /* Define GPIOs for LEDs. From 6807fb992f6639566ce296e65a2a57868bcef2a8 Mon Sep 17 00:00:00 2001 From: Eleanor Date: Wed, 27 Aug 2025 01:02:38 +0800 Subject: [PATCH 2/2] Update documentation on bottom-half handling Since commit 3682d9e6d51b ("Move bottom-half to workqueue for safe sleep") switched the implementation to workqueues, update the description accordingly to avoid confusion and reflect the modern approach to bottom-half handling. Explain the issues with tasklets and introduce the BH workqueue as the new, reliable alternative. --- lkmpg.tex | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lkmpg.tex b/lkmpg.tex index 1aec030c..df25c4bf 100644 --- a/lkmpg.tex +++ b/lkmpg.tex @@ -2107,11 +2107,21 @@ \subsection{Detecting button presses} \subsection{Bottom Half} \label{sec:bottom_half} Suppose you want to do a bunch of stuff inside of an interrupt routine. -A common way to do that without rendering the interrupt unavailable for a significant duration is to combine it with a tasklet. +A common way to avoid blocking the interrupt for a significant duration +is to defer the time-consuming part to a workqueue. This pushes the bulk of the work off into the scheduler. - -The example below modifies the previous example to also run an additional task when an interrupt is triggered. - +This approach helps speed up the interrupt handling process itself, +allowing the system to respond to the next hardware interrupt more quickly. + +Kernel developers generally discourage using tasklets due to their design limitations, +such as memory management issues and unpredictable latencies. +Instead, they recommend more robust mechanisms like workqueues or \textbf{softirqs}. +To address tasklet shortcomings, Linux contributors introduced the BH workqueue, +activated with the \cpp|WQ_BH| flag. +This workqueue retains critical features, +such as execution in atomic (\textbf{softirq}) context on the same CPU and the inability to sleep. + +The example below extends the previous code to include an additional task executed in process context when an interrupt is triggered. \samplec{examples/bottomhalf.c} \subsection{Threaded IRQ}