And soft real-time interrupt

And soft real-time interrupt

Translated from: Software interrupts and Realtime

Linux kernel software interrupt ( "softirq") strange mechanism, in early Linux and handling mechanism is relatively obscure, and only minimal kernel developers will be in direct contact with the soft interrupt. However, it is the most important core processing cores. In some scenarios, soft interrupt occurs in an untimely manner. In particular, real-time kernel preemption patch set is often a software interrupt conflict, the latest version of the patch set provides a solution to the problem of soft interrupt is generated, worth a visit.

Soft interrupt Introduction

In 3.6.1-rt1 declaration patch sets in, Thomas Gleixner use a soft interrupt described as follows:

First, it is not the majority of the polymerization product of related tasks, tasks to run in a random context applying / releasing control of

First of all, it's a conglomerate of mostly unrelated jobs, which run in the context of a randomly chosen victim w/o the ability to put any control on them.

Soft interrupt handling almost (but not identical) as important as the hardware interrupt. Soft interrupt priority level is relatively high (but there are exceptions, see below), but lower than the hardware interrupt, so the task will seize any interruption other than hard outside.

Long ago, Linux hardware interrupt vector 32 is present, and assign a device driver or related tasks for each vector. Most drivers have long ago with the soft interrupt points were separated (the drive will still use soft interrupt, but needs by the middle of APIs, such as tasklets and timers). There are currently 10 kinds of kernel software interrupt vectors: for two kinds of micro-threaded (the tasklet) process, 2 for the network, two kinds of the bulk layer (block layer, for block devices use ), 2 for a timer, scheduler and Update-Copy-Read ( the RCU ) each uses a process. Core CPU by a bit mask to specify the need to handle CPU (which may occur at any time) soft interrupt. For example, when calling a kernel subsystem tasklet_schedule(), it sets the CPU on the corresponding TASKLET_SOFTIRQbit, when the soft interrupt has been processed ( open interrupt ), micro-threaded run (based on the tasklet soft interrupt) .

# cat /proc/softirqs
                    CPU0       CPU1
          HI:          1          0             //高优先级的tasklet
       TIMER:  104838818  108267618             //基于系统tick的定时器
      NET_TX:          2          1             //数据发送
      NET_RX:   11622033       2698             //数据接收
       BLOCK:         37    6833945             //块设备访问
BLOCK_IOPOLL:          0          0             //
     TASKLET:          9         46             //普通优先级的tasklet
       SCHED:   61485884   65788587             //多CPU调度
     HRTIMER:          0          0             //高精度定时器
         RCU:   48876416   46889277

There are two cases will trigger a soft interrupt and preempt the current thread: one is when done with a hardware interrupt, the interrupt handler will trigger the soft interrupt ( trigger after a hard interrupt soft interrupt, hardware interrupt for processing signals or data, messages such as network cards, etc. ), for some purposes (such as reduced latency, optimized caching, etc.) need to be addressed as soon as the soft interrupt, so that you can re-enable hardware interrupt; the other is the kernel code (at any time) may ( such as by calling local_bh_enable()or spin_unlock_bh()function , these two functions are used to interrupt protection against other interrupts mixing process, similar to the locking mechanism ) re-enabled soft interrupt, this will lead to the accumulation of soft interrupt any operation in the context of a process, the process is Thomas said, "randomly selected victim" ( "randomly chosen victim") .

Readers might be running on the system ksoftirqdconfused, and the process is primarily used to reduce the processing time of the soft interrupt soft interrupt system load is too high. The formal process, if the inline code after the soft interrupt process cycle for 10 times, the findings also need to process more software interrupt (due to the constant interrupt), the interrupt will wake suitable process ksoftirqd(per CPU ksoftirqdprocess) process and exit, follow the ksoftirqdprocess to handle soft interrupt. KsoftirqdIt may be (hardware or software) interrupt soft interrupt interrupted outside the context, this treatment is necessary, otherwise Ksoftirqdyou can run at any time before in a soft interrupt handling. In the old kernel, Ksoftirqdthe process is running at the lowest priority, namely soft interrupt handling of the process is dependent on the highest priority or lowest priority on the system. 2.6.23 from the start, Ksoftirqdusing ordinary users to run the default priority.

Set in real-time soft interrupt

On the general system, the soft interrupt mechanism is sufficient to handle most cases, you do not need to do too much to improve. However, as The new visibility of RCU processing described in 3.7 kernel, read-copy-update task has been moved to its secondary thread. In real-time processing, the compulsory any way the process of doing some random work and unwelcome, traditional real-time patch will be all soft interrupt isolation to separate threads, each thread has its own priorities. In such a process, such as when the network needs real-time response, the interrupt priority thread processing will increase; the contrary, when the network event when less urgent, priority thread will be reduced.

3.0 real-time patch set from the beginning, the above approach can not continue to work. As it can not and Per-CPU variables and the realtime tree well with use, as Thomas said, using the soft interrupt thread approach will lead to configuration problems:

Often difficult to get the right parameters from a real-time system. Adding something like soft interrupt work to be as obscure system designers do matters cases not a good idea.

It's extremely hard to get the parameters right for a RT system in general. Adding something which is obscure as soft interrupts to the system designers todo list is a bad idea.

So, from 3.0, handling soft interrupt handling is very similar to the mainline kernel. This way improves code quality and enhance the non-coordination system (soft interrupt context switching to the thread by eliminating) the performance, but also deprived of the ability (some of the real-time developers to focus on in this way tend to be finely tuned very inclined to use in this way). This is why some users complain about this change of place.

In response, processing 3.6.1-rt1 soft interrupt and made changes. Now, when a thread trigger a soft interrupt, the kernel saves (such as when processing the received network packets) specific interrupt. Once the thread exits, the kernel will disable the soft interrupt context, and run a software interrupt, using this method can reduce the delay (due immediately runs under a soft interrupt) processing soft interrupt. Equally important, this approach will produce the soft interrupts and soft interrupt processes are bound together. This results in the process of network soft interrupt timer process will not mess up other processes in that localized soft interrupt handling, processing eliminate the soft interrupt other processes caused by uncertainty, and makes soft interrupt can be created in the beginning the priority task of running processes.

But there is one exception: Caused by a hardware interrupt soft interrupt processing can not be used in this way. Unable to break hard to associate with a particular thread, so you can not use the threads to do the necessary processing. These will be soft this case to interrupt ksoftirqdthe process of treatment.

Next processing logic as Thomas suggests, will disable all the changing environment a soft interrupt soft interrupt disable only a particular environment. Most soft interrupt code to disable a particular concern only the soft interrupt handler, others allow normal operation. Furthermore, Thomas added, "The best way is to completely get rid of soft interrupt." Removing the soft interrupt mechanism already in the "to-do" list for a very long time, but no one actually doing the work.

The nature of real-time patch set allows users to feel the pain of the mainline kernel defects, which lead to a lot of code to modify and upgrade the main line from the real-time community. Currently, real-time user already has an improved soft interrupt mechanism, so that it no longer low-level tuning.

TIPS:

  • linux grades according to the interrupt into the buttom half and top half, the top half is executed when the interrupt off, and in the implementation buttom half open is interrupted (interrupt process again at this time may be)
  • softirq on a CPU it is serial, tasklet itself is a good serial .softirq performance, while not considered a tasklet parallel scenes on different CPU, so it is convenient in the development.

reference:

Linux interrupt - softirq

Guess you like

Origin www.cnblogs.com/charlieroro/p/12169220.html