Ulk---Chap 4:softirqs and tasklets (Note)

Source: Internet
Author: User

We mentioned earlier in the sections "Interrupt handling" that several tasks among those executed

By the kernel is not critical: They can is deferred for along period of time, if necessary. Remember

That the interrupt service routines of an interrupt handler is serialized, and often there should be

No occurrence of an interrupt until the corresponding interrupt handler have terminated. Conversely,

The deferrable tasks can execute with all interrupts enabled. Taking them out of the interrupt handler

Helps keep kernel response time small. This was a very important property of many time-critical applications

That is expect their interrupt requests to being serviced in a few milliseconds.

Linux 2.6 Answers Such a challenge by using the kinds of non-urgent interruptiblekernel functions:

The so-called deferrable functions (Softirqs and Tasklets), and those executed by means of some

queues.

Softirqs and Tasklets are strictly correlated, because Tasklets is implemented on top of Softirqs.

As a matter of fact, the term "SOFTIRQ", which appears in the kernel source code, often denotes both

Kinds of deferrable functions. Another widely used term was interrupt context: It specifies that the kernel

is currently executing either an interrupt handler or a deferrable function.

Softirqs is statically allocated (i.e., defined at compile time), while Tasklets can also be allocated and

Initialized at runtime (for instance, when loading a kernel module). Softirqs can run concurrently on several

CPUs, even if they is of the same type. Thus, Softirqs is reentrant functions and must explicitly protect

Their data structures with spin locks. Tasklets do not has to worry about this, because their execution is

Controlled more strictly by the kernel. Tasklets of the same type is always serialized:in other words, the

Same type of takslet cannot is executed by and CPUs at the same time. However, tasklets of different types

can is executed concurrently on several CPUs. Serializing the Tasklet simplifies the life of the device driver

Developers, because the Tasklet function needs not be reentrant.

Generally speaking, four kinds of operations can is performed on deferrable functions:

initialization: Defines a new deferrable function; This operation is usually do when the kernel initializes

itself or a module is loaded.

Activation: Marks a deferrable function as "pending"---to be run the next time the kernel schedules a round

of executions of deferrable functions.

Masking: Selectively disables a deferrable function so that it won't be executed by the kernel even if Activat Ed.

execution: Executes a pending deferrable function together with all other pending deferrable of the

same type; Execution is performed at well-specified Times, explained later.

Activation and execution is bound together: a deferrable function that have been activated by a given CPU

must is executed on the same CPU. There is no self-evident reason suggesting the this rule is beneficial

For system performance. Binding the Deferrable function to the activating CPU could on theory make better use of

The CPU hardware cache. After all, it was conceivable that the activating kernel thread accesses some data structures

That'll also is used by the deferrable function. However, the relevant lines could esasily is no longer in the cache

When the Deferrable function is run because it execution can be delayed a long time. Moreover, binding a function

To a CPU are always a potentially dangerous operation, because one CPU might end up very busy while the others

is mostly idle.

Softirqs

Linux 2.6 uses a limited number of IRQs. For most purposes, tasklets is good enough and is much easier to

Write because they do not need to be reentrant.

As a matter of fact, only the six kinds of Softirqs listed in following table is currently defined.

SOFTIRQ Index (priority) Description

HI_SOFTIRQ 0 Handles High priority tasklets

TIMER_SOFTIRQ 1 Tasklets related to timer interrupts

NET_TX_SOFTIRQ 2 transmits packets to network cards

NET_RX_SOFTIRQ 3 receives packets from network cards

SCSI_SOFTIRQ 4 post-interrupt processing of SCSI commands

TASKLET_SOFTIRQ 5 Handles Regular tasklets

The index of a SOFTIRQ determines its priority:a lower index means higher priority because SOFTIRQ function

'll is executed starting from index 0.

The main data structures used to represent Softirqs is the Softirq_vec array, which includes, elements of

Type softirq_action. The priority of a SOFTIRQ is the index of the corresponding softirq_action element inside

The array. As shown in above list, only the first six entries of the array is effectively used. The softirq_action

Data structure consists of : A action pointer to the SOFTIRQ function and a data pointer to a generic

Data structure is needed by the SOFTIRQ function.

Another critical field used to keep track both of kernel preemption and of the nesting of kernel control paths

Is the-the-preempt_count field stored in the Thread_info field of each process descriptor. This field encodes

Three distinct counters plus a flag shown in following table.

Bits Description

0-7 preemption counter (max value = 255)

8-15 SOFTIRQ counter (max value = 255)

16-27 HARDIRQ counter (max value = 4096)

Preempt_active Flag

The first counter keeps track of many times kernel preemption have been explicitly disabled on the local CPU;

The value zero means that kernel preemption have not been explicitly disabled at all.

Ulk---Chap 4:softirqs and tasklets (Note)

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.