In-Depth Analysis of Linux Soft Interrupts: From Principles to Practice
1 Overview of Linux Soft Interrupts
1.1 What are Soft Interrupts and Their Design Motivation
In the Linux kernel, soft interrupts (Softirq) are a very importantdelayed processing mechanism, which is entirely triggered by software. Although referred to as “interrupts”, they are actually a mechanism fordelayed execution in kernel space. Soft interrupts are fundamentally different from hardware interrupts (hard interrupts): hardware interrupts are triggered by external devices requesting immediate attention from the CPU, while soft interrupts are triggered by the kernel itself at appropriate times to handle tasks thatdo not require immediate completion but need to be processed as soon as possible.
The main motivation for introducing the soft interrupt system in the Linux kernel stems from the following core requirement:hardware interrupt handlers need to execute as quickly as possible to re-enable interrupts and avoid data loss. However, in practical applications, there are many processing logics that are relatively complex and time-consuming. This creates an inherent contradiction—if all processing is completed in the hardware interrupt context, it will lead to prolonged interrupt disablement, increasing the risk of event loss. To resolve this contradiction, kernel designers divided interrupt handling into two parts:
- • Top Half: Executes in the interrupt context, responsible for the most urgent operations that must be completed immediately, such as acknowledging interrupt receipt and resetting hardware. This part usuallydisables other interrupts during execution, so it needs to be extremely fast.
- • Bottom Half: Delays the execution ofnon-urgent, time-consuming operations outside the interrupt context, at which point hardware interrupts have been re-enabled, thus not affecting new interrupt requests.
A relatable analogy: Imagine the working mode of a hospital emergency room. When a critically ill patient arrives (hardware interrupt), the doctor will immediately perform the most urgent rescue (Top Half), stabilizing the patient’s vital signs. Once the patient’s condition is stable, more detailed examinations, surgical arrangements, and rehabilitation treatments (Bottom Half) can be carried out later, ensuring that other emergency patients are not delayed and providing comprehensive treatment for the current patient.
1.2 Importance and Application Scenarios of Soft Interrupts
Soft interrupts play a crucial role in the modern Linux kernel, serving as one of the key mechanisms forperformance optimization throughout the kernel. Through the soft interrupt system, the kernel canbalance response speed and processing throughput, ensuring timely responses to hardware interrupts while not losing important subsequent processing tasks.
The application scenarios for soft interrupts are very broad, primarily including the following core areas:
- • Network Data Processing: This is the most typical and important application scenario for soft interrupts. Whether for sending (
<span>NET_TX_SOFTIRQ</span>) or receiving (<span>NET_RX_SOFTIRQ</span>) data packets, soft interrupt mechanisms are heavily relied upon. When a network card receives a data packet and triggers a hardware interrupt, the interrupt handler only performs the most basic acknowledgment, and then the subsequent protocol stack processing is completed through soft interrupts. - • Timer Handling (
<span>TIMER_SOFTIRQ</span>): The callback functions for kernel timers are not executed in the hardware interrupt context but are executed through the soft interrupt mechanism, ensuring that timer interrupts can be processed quickly without being blocked by multiple timer expirations. - • Tasklet Delayed Processing (
<span>TASKLET_SOFTIRQ</span>): Tasklet is a simpler delayed execution mechanism based on soft interrupts, particularly suitable for driver developers. Unlike soft interrupts, tasklets of the same type cannot be executed concurrently on multiple CPUs, reducing the complexity of synchronization. - • Block Device Operations (
<span>BLOCK_SOFTIRQ</span>): The processing of I/O operations after block devices complete is also executed through soft interrupts, allowing block device drivers to respond quickly to hardware interrupts while delaying time-consuming I/O completion processing to soft interrupts. - • Scheduler Load Balancing (
<span>SCHED_SOFTIRQ</span>): The process load balancing operations between multiple CPUs are triggered by soft interrupts, allowing the scheduler to redistribute CPU loads at appropriate times, optimizing system performance.
Design Philosophy: Soft interrupts embody an important concept in Linux kernel design—“separation of mechanism and policy”. The soft interrupt itself is amechanism, providing the capability for delayed execution; how various subsystems utilize this mechanism falls underpolicy decisions. This separation allows the kernel to maintain a high degree of flexibility and scalability.
2 Code Framework and Data Structures of Soft Interrupts
2.1 Core Data Structure Analysis
The implementation of the Linux soft interrupt system relies on several key data structures, and understanding these structures is fundamental to mastering the soft interrupt mechanism. The kernel manages the registration, triggering, and execution of soft interrupts through carefully designed data structures, while ensuring efficiency and safety in a multi-core environment.
The softirq_action structure is the core of the soft interrupt system, representing a soft interrupt handler. Its definition is very simple, reflecting the simplicity of the Unix design philosophy:
struct softirq_action {
void (*action)(struct softirq_action *);
};
This structure contains only one member—<span>action</span> function pointer, which points to the actual handling function of the soft interrupt. When a soft interrupt is triggered, the kernel calls this function. This minimalist design reflects a basic principle of the Linux kernel:data structures should focus on a single responsibility. <span>softirq_action</span> is only responsible for describing the soft interrupt handler and does not involve its state management.
Why use such a simple design? Overly complex data structures increase maintenance costs and the risk of introducing bugs. By keeping the<span>softirq_action</span> simple, the kernel ensures thereliability and efficiency of the soft interrupt mechanism. The handling function accepts a pointer to<span>softirq_action</span> itself as a parameter, allowing the same handling function to serve multiple soft interrupts, enhancing code reusability.
The types of soft interrupts arestatically defined in the kernel, explicitly listing all supported soft interrupts through an enumeration type. This static definition ensures thedeterminacy and efficiency of soft interrupt types:
enum {
HI_SOFTIRQ = 0, /* High priority tasklet */
TIMER_SOFTIRQ, /* Timer */
NET_TX_SOFTIRQ, /* Network data transmission */
NET_RX_SOFTIRQ, /* Network data reception */
BLOCK_SOFTIRQ, /* Block device operations */
BLOCK_IOPOLL_SOFTIRQ, /* Block device I/O polling */
TASKLET_SOFTIRQ, /* General tasklet */
SCHED_SOFTIRQ, /* Process scheduling */
HRTIMER_SOFTIRQ, /* High precision timer */
RCU_SOFTIRQ, /* RCU delayed cleanup */
NR_SOFTIRQS /* Total number of soft interrupts */
};
This enumeration defines all available soft interrupt types in the system. Note that<span>NR_SOFTIRQS</span> is not an actual soft interrupt but a marker used to represent the number of soft interrupts. The Linux kerneldoes not recommend developers to add new soft interrupt types, as this requires modifying core code and undergoing strict review. Most drivers should use the tasklet mechanism based on<span>TASKLET_SOFTIRQ</span> or<span>HI_SOFTIRQ</span>.
The irq_cpustat_t structure is responsible for recording the soft interrupt status information for each CPU, which is a key data structure formulti-core awareness:
typedef struct {
unsigned int __softirq_pending;
} ____cacheline_aligned irq_cpustat_t;
<span>____cacheline_aligned</span> is an important optimization that ensures each CPU’s<span>irq_cpustat_t</span> instance occupies a cache line, preventingfalse sharing. False sharing can severely degrade performance in multi-core systems.
<span>__softirq_pending</span> is abitmap, where each bit represents whether a type of soft interrupt is in a pending state. For example, when a network data packet arrives, the interrupt handler for the network card sets the corresponding bit for<span>NET_RX_SOFTIRQ</span>, indicating that there is a network receive soft interrupt waiting to be processed.
2.2 Detailed Explanation of Soft Interrupt Types
Each type of soft interrupt has its specific purpose and execution context, and understanding these characteristics is crucial for correctly using soft interrupts. Below is a detailed description of the main soft interrupt types:
- • HI_SOFTIRQ and TASKLET_SOFTIRQ: These two soft interrupts are specifically used for handling tasklets. HI_SOFTIRQ has a higher priority and will execute before TASKLET_SOFTIRQ. Their existence reflects the kernel’s balance betweengenerality and specificity—soft interrupts are a general mechanism, while tasklets are a specialized simplified interface based on soft interrupts.
- • NET_TX_SOFTIRQ and NET_RX_SOFTIRQ: The network subsystem is aheavy user of soft interrupts. These two soft interrupts handle the sending and receiving of network data packets. Their implementation is carefully optimized to cope with high-throughput network traffic. In particular, NET_RX_SOFTIRQ may consume a significant amount of CPU time on modern servers, making it a key focus for network performance tuning.
- • TIMER_SOFTIRQ: Responsible for handling timer callback functions. When a hardware timer interrupt occurs, the interrupt handler only marks the timer as expired, and the actual callback function execution occurs in TIMER_SOFTIRQ. Thisseparation ensures that timer interrupts are processed quickly and are not blocked by a large number of simultaneous timer expirations.
- • BLOCK_SOFTIRQ: The block device subsystem uses this soft interrupt to handle operations after I/O completion. When disk read/write operations are completed, the hardware interrupt handler is very brief, while the heavy I/O completion processing is executed in BLOCK_SOFTIRQ.
To visually illustrate the relationships between the core data structures of soft interrupts, here is a relationship diagram:

This diagram clearly shows the relationships between the core components of soft interrupts:<span>softirq_vec</span> is a global array containing all registered soft interrupt handling functions; <span>irq_cpustat_t</span> is the data structure for each CPU, recording which soft interrupts are in a pending state on that CPU; while <span>task_struct</span> represents the ksoftirqd kernel thread on each CPU.
3 Workflow of Soft Interrupts
3.1 Complete Lifecycle of Soft Interrupts
The lifecycle of a soft interrupt involves multiple precisely coordinated stages from registration to execution completion, and understanding this complete lifecycle is crucial for mastering the soft interrupt mechanism. The lifecycle of a soft interrupt can be divided into three main stages:registration initialization, triggering pending, and scheduling execution. Each stage has specific APIs and internal mechanisms supporting it, collectively forming the efficient and reliable workflow of soft interrupts.
Registration Stage occurs during the kernel initialization process, where various subsystems register their soft interrupt handlers through the <span>open_softirq()</span> function. This process is typically completed early in the kernel startup to ensure system stability and determinacy:
void open_softirq(int nr, void (*action)(struct softirq_action *)) {
softirq_vec[nr].action = action;
}
For example, the network subsystem registers the network transmission and reception soft interrupts during initialization:
open_softirq(NET_TX_SOFTIRQ, net_tx_action);
open_softirq(NET_RX_SOFTIRQ, net_rx_action);
Thiscentralized registration mechanism reflects the modular design principle of the kernel—each subsystem focuses only on its processing logic, while the soft interrupt framework is responsible for general management and scheduling.
Triggering Stage is the second link in the lifecycle of soft interrupts. When a subsystem needs to delay the execution of a task, it calls <span>raise_softirq()</span> or <span>raise_softirq_irqoff()</span> functions to trigger the corresponding soft interrupt. This operation typically occurs in two contexts: during the exit process of hardware interrupt handlers or when other parts of the kernel discover tasks that need to be processed.
<span>raise_softirq()</span> function’s implementation demonstrates the kernel’s meticulous consideration for concurrency safety:
void raise_softirq(unsigned int nr) {
unsigned long flags;
local_irq_save(flags);
raise_softirq_irqoff(nr);
local_irq_restore(flags);
}
This function first saves the current interrupt state and disables interrupts, then actually triggers the soft interrupt, and finally restores the original interrupt state. Thisprotection mechanism ensures that modifications to the soft interrupt pending bitmap in a multi-core environment do not encounter race conditions.
3.2 Triggering and Executing Soft Interrupts
The triggering and execution mechanisms of soft interrupts are key to understanding their workflow. When the <span>raise_softirq_irqoff()</span> function is called, it sets the corresponding bit in the soft interrupt pending bitmap of the current CPU, and then decides how to wake up the soft interrupt handler based on the current context:
inline void raise_softirq_irqoff(unsigned int nr) {
__raise_softirq_pending(nr);
if (!in_interrupt())
wakeup_softirqd();
}
The condition <span>!in_interrupt()</span> is crucial—if the current context is already in an interrupt context, there is no need to specifically wake up the ksoftirqd thread, as soft interrupts will be automatically processed upon exiting the interrupt. Thisintelligent wake-up mechanism avoids unnecessary thread switching overhead.
Execution Stage is the final and most complex part of the soft interrupt lifecycle. The execution of soft interrupts has two main entry points:interrupt exit path and ksoftirqd kernel thread. This dual execution mechanism is the core innovation of the soft interrupt system, achieving a delicate balance betweenlow latency and fairness.
When the kernel exits the interrupt handler, it checks for any pending soft interrupts, and if there are any, it executes them directly:
void irq_exit(void) {
// ...
sub_preempt_count(IRQ_EXIT_OFFSET);
if (!in_interrupt() && local_softirq_pending())
invoke_softirq();
// ...
}
In <span>invoke_softirq()</span>, the kernel calls <span>do_softirq()</span> or directly calls <span>__do_softirq()</span> to execute the pending soft interrupts. This is thefast path for soft interrupt processing, ensuring low latency.
However, soft interrupt processing may be delayed for various reasons, or not all pending soft interrupts can be completed in a single execution. To prevent soft interrupts fromoverusing the CPU and causing starvation of user processes, the kernel introduces the ksoftirqd mechanism. Each CPU has a dedicated ksoftirqd kernel thread that takes over the processing of soft interrupts when they cannot be processed in a timely manner in the interrupt context or when the system load is too high.
Below is a diagram illustrating the complete workflow of soft interrupts:

This flowchart shows the complete path of soft interrupts from triggering to execution, reflecting the Linux kernel’s thoughtful consideration forperformance optimization—ensuring low latency through the fast path and fairness through the slow path.
3.3 Scheduling Timing of Soft Interrupts
The scheduling timing of soft interrupts has a decisive impact on their performance characteristics. The kernel carefully selects several key scheduling points to check and execute pending soft interrupts:
- • Return from Interrupt Handling: This is the most important timing for executing soft interrupts. When the hardware interrupt handler completes, before returning to the interrupted code, the kernel checks for any pending soft interrupts and executes them. This arrangement allows soft interrupts to be executedwith almost no delay.
- • Local BH Enable: When the kernel re-enables bottom half processing through
<span>local_bh_enable()</span><span>, it checks for pending soft interrupts. This ensures that previously delayed soft interrupts can be processed in a timely manner.</span> - • Scheduler Decision: If the ksoftirqd thread is awakened, the scheduler will allocate CPU to it at an appropriate time, ensuring that soft interrupts can ultimately be completed, even under high system load.
A relatable analogy: The scheduling mechanism of soft interrupts can be likened to a restaurant’s order processing system. When the chef receives an order (hardware interrupt), they will immediately start cooking the most urgent parts (Top Half), and then mark tasks that require time but do not need to be completed immediately (like preparing afternoon tea) as pending (soft interrupt triggering). The restaurant manager (kernel scheduler) will handle these pending tasks in two scenarios: during idle time after completing urgent orders (return from interrupt) or when a backlog of pending tasks accumulates, assigning a dedicated assistant (ksoftirqd thread) to handle them. This arrangement ensures a quick response to urgent orders while ensuring that all tasks are eventually completed.
4 Practical Application Examples of Soft Interrupts
4.1 Simple Driver Example Based on Tasklet
Tasklet is a delayed execution mechanism built on soft interrupts, simplifying the work of device driver developers. Compared to directly using soft interrupts, Tasklet has a simpler interface and safer concurrency semantics—the same Tasklet will not execute concurrently on multiple CPUs, significantly reducing the synchronization burden for driver developers.
Below, we demonstrate how to use Tasklet for delayed processing through a simple character device driver example:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
// Define device data structure
struct my_device {
struct tasklet_struct my_tasklet;
int data;
} my_dev;
// Tasklet handler function
static void my_tasklet_handler(unsigned long data)
{
struct my_device *dev = (struct my_device *)data;
printk(KERN_INFO "Tasklet executed on CPU %d, processing data: %d\n",
smp_processor_id(), dev->data);
// Here you can execute more complex processing logic
dev->data *= 2;
}
// Device read function - Simulate triggering Tasklet
static ssize_t my_device_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
// Update data
my_dev.data = 123;
printk(KERN_INFO "Triggering tasklet from CPU %d\n",
smp_processor_id());
// Schedule Tasklet for execution
tasklet_schedule(&my_dev.my_tasklet);
return count;
}
// File operations structure
static struct file_operations my_fops = {
.owner = THIS_MODULE,
.read = my_device_read,
};
// Module initialization
static int __init my_init(void)
{
// Initialize Tasklet
tasklet_init(&my_dev.my_tasklet, my_tasklet_handler,
(unsigned long)&my_dev);
// Register character device
register_chrdev(0, "my_device", &my_fops);
printk(KERN_INFO "My device module loaded\n");
return 0;
}
// Module exit
static void __exit my_exit(void)
{
// Disable and wait for Tasklet to complete
tasklet_kill(&my_dev.my_tasklet);
printk(KERN_INFO "My device module unloaded\n");
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");
This simple driver demonstrates the typical usage of Tasklet:
- • Initialization: During module initialization, the Tasklet handler function and the parameters passed are set using the
<span>tasklet_init()</span>function. - • Scheduling: When the user space reads the device, the driver calls
<span>tasklet_schedule()</span>to mark the Tasklet for execution. - • Execution: At the appropriate time chosen by the kernel, the Tasklet handler function is called to perform delayed operations.
- • Cleanup: When the module is unloaded,
<span>tasklet_kill()</span>is used to ensure that the Tasklet does not continue executing after the module is unloaded.
Key Advantages: The main advantage of using Tasklet instead of directly using soft interrupts is that itsimplifies concurrency control. Driver developers do not need to worry about multiple CPUs executing the same Tasklet simultaneously, as the kernel guarantees the serialized execution of the same Tasklet. This significantly reduces the complexity of developing device drivers.
4.2 Application of Soft Interrupts in Network Transmission and Reception
The network subsystem is the most classic and important application scenario for soft interrupt technology. Understanding the soft interrupt mechanism in network packet transmission and reception is crucial for network performance analysis and tuning. Network transmission and reception use two dedicated soft interrupts:<span>NET_RX_SOFTIRQ</span><span> for data reception and </span><code><span>NET_TX_SOFTIRQ</span><span> for data transmission.</span>
Below is a simplified sequence diagram of the soft interrupts involved in the network packet reception process:

This sequence diagram clearly illustrates the collaboration between hardware interrupts and soft interrupts during the network packet reception process:
- 1. Hardware Interrupt Stage: When the network card receives a data packet, it triggers a hardware interrupt. The interrupt handler performs the most urgent operations—disabling the network card interrupt (to prevent repeated interrupts), acknowledging the interrupt receipt, and then scheduling the network receive soft interrupt through the
<span>napi_schedule()</span><span> function. This process is very quick, ensuring that interrupt handling does not take up too much time.</span> - 2. Soft Interrupt Stage: After the interrupt handling, the
<span>NET_RX_SOFTIRQ</span>soft interrupt is triggered, executing the<span>net_rx_action()</span><span> function. This function contains the complete logic for processing the data packet: reading the data packet from the network card's DMA area, performing protocol parsing (IP, TCP/UDP, etc.), and ultimately delivering the data to the corresponding application.</span>
Performance Considerations: In cases of high network traffic, the <span>NET_RX_SOFTIRQ</span><span> may consume a significant amount of CPU time. This can be observed through the </span><code><span>top</span><span> command's </span><code><span>si</span><span> (soft interrupt) field. If a single CPU's soft interrupt handling becomes a bottleneck, consider using </span><strong><span>RPS (Receive Packet Steering)</span></strong><span> technology to distribute the soft interrupt load across multiple CPUs.</span>
The process of sending network data packets is similar, but it uses the <span>NET_TX_SOFTIRQ</span><span> soft interrupt. When an application sends data, the kernel does not immediately pass the data to the network card but first caches it, and then processes the actual data transmission asynchronously through soft interrupts. This </span><strong><span>delayed sending</span></strong><span> mechanism can merge small data packets, improving network utilization.</span>
5 Monitoring and Debugging Tools and Methods
5.1 Common Monitoring Tools Explained
To gain a deeper understanding of the behavior and performance characteristics of soft interrupts, Linux provides various powerful monitoring and debugging tools. These tools present the activity of soft interrupts from different dimensions, helping developers diagnose performance issues and abnormal behaviors.
/proc/softirqs file is the most direct monitoring interface for soft interrupts, displaying the trigger counts of various types of soft interrupts on each CPU in the system. Checking this file provides a global view of soft interrupt activity:
$ cat /proc/softirqs
CPU0 CPU1 CPU2 CPU3
HI: 0 0 0 0
TIMER: 2831512516 1337085411 1103326083 1423923272
NET_TX: 15774435 779806 733217 749512
NET_RX: 1671622615 1257853535 2088429526 2674732223
BLOCK: 1800253852 1466177 1791366 634534
BLOCK_IOPOLL: 0 0 0 0
TASKLET: 25 0 0 0
SCHED: 2642378225 1711756029 629040543 682215771
HRTIMER: 2547911 2046898 1558136 1521176
RCU: 2056528783 4231862865 3545088730 844379888
When analyzing this output, several key points should be noted:
- • Load Balancing: Check the distribution of the same type of soft interrupt across different CPUs. If a certain soft interrupt is overly concentrated on a specific CPU (as seen in the output above where NET_RX is significantly higher on CPU3), it may become a performance bottleneck. In this case, consider using interrupt balancing techniques (such as RPS, RFS) to improve load distribution.
- • Relative Proportions: Observe the relative proportions of different types of soft interrupts. In a normally running system, TIMER, NET_RX, NET_TX, and SCHED usually have higher values. If a specific type of soft interrupt is abnormally active, it may indicate issues with the related subsystem or a special workload.
The top command provides a real-time view of system-level soft interrupt activity. In the top interface, you can view the <span>si</span> field on the third line, which indicates the percentage of CPU time spent on soft interrupts:
$ top -n1 | head -n3
top - 18:14:05 up 86 days, 23:45, 2 users, load average: 5.01, 5.56, 6.26
Tasks: 969 total, 2 running, 733 sleeping, 0 stopped, 2 zombie
%Cpu(s): 13.9 us, 3.2 sy, 0.0 ni, 82.7 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
Here, the <span>si</span> value is 0.1%, indicating that currently, 0.1% of CPU time is used for processing soft interrupts. Under network-intensive or block device-intensive workloads, this value may significantly increase. If the <span>si</span> remains high, it may indicate that the system is processing a large number of soft interrupts, requiring further analysis of which types of soft interrupts are causing it.
5.2 Advanced Debugging Techniques and Performance Optimization
When preliminary monitoring reveals issues related to soft interrupts, more advanced debugging techniques are needed for in-depth analysis. These techniques can help pinpoint the root causes of performance bottlenecks and abnormal behaviors.
Dynamic Debugging is a powerful tool for analyzing soft interrupt behavior. You can use the kernel’s dynamic debugging feature to observe the triggering and execution of soft interrupts in real-time:
# Enable soft interrupt related debug information
echo 'file kernel/softirq.c +p' > /sys/kernel/debug/dynamic_debug/control
echo 'file net/core/dev.c +p' > /sys/kernel/debug/dynamic_debug/control
# View debug output
dmesg -w
This method allows real-time tracking of the scheduling and execution processes of soft interrupts, which is very helpful for understanding soft interrupt behavior in complex systems.
Performance Profiling tools such as <span>perf</span> can provide detailed performance data on soft interrupts, helping to identify hot functions:
# Record performance events related to soft interrupts
perf record -e softirq:softirq_entry -a sleep 10
# Analyze performance data
perf report
Or analyze the CPU time of soft interrupt handling functions more directly:
# Record performance data for all functions in the system
perf record -g -a sleep 10
# Generate flame graph data
perf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > softirq.svg
Optimization Strategies: Based on monitoring and debugging results, various optimization measures can be taken to improve soft interrupt-related performance:
- • Interrupt Balancing: For network interrupts, you can use the
<span>ethtool</span>command to adjust the interrupt affinity of multi-queue network cards, distributing interrupt handling across multiple CPUs:
# Set RX queue 0 of network card eth0 to be handled by CPU0
ethtool -X eth0 equal 2
# Or manually set the queue to CPU mapping
ethtool -X eth0 queue 0 0 1 2 3
- • Threading Soft Interrupts: In some scenarios with high real-time requirements, consider threading soft interrupts, but this requires configuring the kernel with the appropriate options and may increase latency.
- • Adjusting Soft Interrupt Budget: The kernel controls the maximum number of packets processed in a single soft interrupt loop through the
<span>net.core.netdev_budget</span>parameter. Adjusting this value appropriately can balance latency and throughput:
# View current budget value
sysctl net.core.netdev_budget
# Adjust budget value (default 300)
sysctl -w net.core.netdev_budget=600
The following table summarizes commonly used soft interrupt monitoring tools and their applicable scenarios:
| Tool/Method | Information Provided | Applicable Scenarios | Advantages | Limitations |
|---|---|---|---|---|
| /proc/softirqs | Soft interrupt counts for each CPU | Load analysis, bottleneck identification | Global view, fine granularity | Missing historical data |
| top command | System-level soft interrupt CPU usage percentage | Real-time monitoring, quick assessment | Simple and intuitive, system view | Lacks detailed information |
| dynamic_debug | Soft interrupt execution flow | Problem debugging, behavior analysis | Detailed tracking, dynamically enabled | Large output volume, needs filtering |
| perf tool | Performance hotspots, call relationships | Performance optimization, bottleneck analysis | Powerful functionality, visualization | Requires expertise |
6 Conclusion
6.1 Design Philosophy and Essence of Soft Interrupts
The Linux soft interrupt mechanism embodies several important philosophical ideas in operating system design, the core of which isseparation of concerns and balancing trade-offs. By dividing interrupt handling into the urgent top half and the delayed bottom half, soft interrupts successfully resolve the contradiction betweenrapid response and complete processing in hardware interrupt handling.
The implementation of soft interrupts showcases several essential principles of Linux kernel design:
- • Separation of Mechanism and Policy: The soft interrupt framework itself is a general mechanism that does not concern itself with specific processing logic, only providing the infrastructure for delayed execution. How various subsystems utilize this mechanism falls under policy decisions. This separation allows the kernel to maintain a high degree of flexibility and scalability.
- • Multi-Core Aware Design: From initially supporting only single processors to fully supporting SMP systems, the implementation of soft interrupts has always considered performance and behavior in multi-core environments. Each CPU has an independent pending bitmap and processing thread, along with carefully designed locking strategies, ensuring efficient operation in multi-core systems.
- • Balancing Performance and Fairness: By combining the fast path (direct processing upon interrupt return) and the slow path (ksoftirqd thread), soft interrupts achieve a balance between low-latency processing and system fairness. When the load of soft interrupts is too high, ksoftirqd actively yields the CPU to prevent starvation of user processes.
6.2 Significance of Soft Interrupts in Practical Systems
In modern Linux systems, soft interrupts have evolved into anindispensable infrastructure, supporting the normal operation of multiple critical subsystems. Core functions such as networking, storage, and scheduling rely on the delayed processing capabilities provided by soft interrupts.
For system developers and operations personnel, a deep understanding of the soft interrupt mechanism has important practical significance:
- • Performance Tuning: By monitoring the
<span>/proc/softirqs</span>and the<span>si</span>indicator in top, bottlenecks in the system can be identified, and targeted optimization measures can be taken, such as adjusting interrupt affinity, using RPS/RFS, etc. - • Problem Diagnosis: Abnormal soft interrupt patterns are often early indicators of system issues. For example, a sudden increase in NET_RX soft interrupts may indicate a surge in network traffic or some form of network attack; while abnormal BLOCK soft interrupts may indicate issues with the storage subsystem.
- • Architectural Design: For developers of kernel modules or drivers, understanding the characteristics and constraints of soft interrupts helps design more efficient and reliable code. Knowing when to use tasklets, when to use work queues, and how to correctly synchronize data between interrupt context and process context is key to high-quality kernel programming.