The difference between SOFTIRQ, Tasklet and Workqueue _SOFTIRQ

Source: Internet
Author: User
Tags mongodb postgresql


Of the current version 2.6 kernel, there are three possible options: Softirq, Tasklet, and Work queue. Tasklet is based on SOFTIRQ implementations, so the two are very similar. The work queue is completely different from them, and it is implemented by kernel threading.



1, SOFTIRQ


Soft interrupts support SMP, and the same SOFTIRQ can be run concurrently on different CPUs, SOFTIRQ must be reentrant. Soft interrupts are statically allocated during compilation and are not dynamically registered or removed as Tasklet. An array containing 32 softirq_action structures is defined in the KERNEL/SOFTIRQ.C. Each registered soft interrupt occupies an item in the array. As a result, there may be a maximum of 32 soft interrupts. The 2.6 version of the kernel defines six soft interrupts: Hi_softirq, TIMER_SOFTIRQ, Net_tx_softirq, NET_RX_SOFTIRQ, SCSI_SOFTIRQ, and TASKLET_SOFTIRQ.



Features of soft interrupts:
1). A soft interrupt does not preempt another soft interrupt.
2). The only thing that can preempt a soft interrupt is an interrupt handler.
3).Other soft interrupts (including the same type) can be performed concurrently on other processing.
4). A registered soft interrupt must be marked before it can be executed.
5). Soft interrupts are not allowed to hibernate themselves (that is, call blocking functions or sleep, and so on).
6). Soft interrupts with small index numbers are executed before the soft interrupt of the index number is large.



2, Tasklet

The introduction of Tasklet, the most important consideration is to support SMP, improve SMP multiple CPU utilization; two identical tasklet never execute at the same time. Tasklet can be understood as a derivation of SOFTIRQ, so its scheduling timing is the same as for soft interrupts. Most of the tasks that need to be deferred in the kernel can be done with Tasklet, because the same tasklet itself has been synchronized protection, so using Tasklet is much simpler and more efficient than soft interrupts. Tasklet a way to delay a task to a safe time, run it during an outage, and run it only once, even if it is scheduled more than once, but Tasklet can run in parallel with different tasklet on the SMP system. On an SMP system, Tasklet is also ensured to run on the CPU that first schedules it, because it provides better caching behavior and thus improves performance.



Tasklet characteristics:. Two two identical types of tasklet are not allowed to execute concurrently, even on different processors.



3. Work Queue


If the deferred task requires sleep, select the work queue. Also, if you need to use an entity that can be scheduled to perform your lower half processing, you should use the Task Force column as well. It is the only mechanism that can be implemented in the lower half of the process context, and only it can sleep. This means that when you need to get a lot of memory, when you need to get semaphores, it is useful when you need to perform blocking I/O operations. The work queue is the most expensive because it involves kernel threads and even context switches. This is not to say that the work queue is inefficient, but there are thousands of interrupts per second, as the network subsystem has often experienced, so it might be more appropriate to adopt other mechanisms. However, for most cases work queues provide sufficient support.



Work Queue characteristics:
1. The work queue is executed in the context of the process.
2). can block. (The first two mechanisms cannot be blocked)
3). Can be re scheduled. (The first two can only be interrupted by an interrupt handler)
4).Use two forms of work queues:
1> default worker thread (works threads)
2>-built worker threads
5). Use a lock mechanism between work queues and other parts of the kernel as in other process contexts.
6). Default allow response interrupts.
7). Default does not hold any locks.



4, SOFTIRQ and Tasklet in common


Both soft interrupts and Tasklet are run in the interrupt context, regardless of any process, and no supported process completes the rescheduling. So soft interrupts and tasklet cannot sleep and cannot block, and their code cannot contain actions that cause sleep, such as reducing semaphores, copying data from user space, or manually allocating memory. It is also because they run in the interrupt context that their execution on the same CPU is serial, which is not conducive to the prioritization of real-time multimedia tasks.



5, summary


Table 1. Comparison of the lower half of the lower half of the context order execution security soft interrupt interrupt no Tasklet interrupt same type cannot execute Work queue process (as scheduled as process context)        ; To put it simply, the creator of a generic driver needs to make two choices. First, do you need a scheduled entity to perform the work that needs to be done backwards--basically, there's a need for hibernation. If so, the work queue is your only option. Otherwise, it's best to use Tasklet. If you have to focus on performance improvement, consider SOFTIRQ.  


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.