[Linux kernel] [Linux interrupt]--soft interrupt mechanism

Source: Internet
Author: User

Click to open link

One, the concept of Linux soft interrupt
Soft interrupts (SOFTIRQ) often represent all kinds of deferred functions, and the number of soft interrupts currently used on Linux is limited, with Linux registering up to 32, currently using 10, Defined in Interrupt.h, interrupt context: Indicates that the kernel is currently executing an interrupt handler or a deferred function. Soft interrupts (even soft interrupts of the same type) can run concurrently on multiple CPUs, so soft interrupts are reentrant functions that must use a spin lock to protect their data structures. A soft interrupt does not preempt another soft interrupt.

The difference between soft interrupts and Tasklet
Because a soft interrupt must use a reentrant function, this results in a high degree of complexity in design, which adds a burden to the developer as a device driver. If an application does not need to be executed in parallel on multiple CPUs, then a soft interrupt is not necessary. Therefore, Tasklet was born to make up the above two requirements. It has the following characteristics:
A) a specific type of tasklet can only be run on one CPU, cannot be parallel, and can only be executed serially.
b) Multiple different types of tasklet can be parallel on multiple CPUs.
c) Soft interrupts are statically allocated and cannot be changed after the kernel has been compiled. However, Tasklet is much more flexible and can be changed at runtime (e.g. when adding modules).

Implementation of soft interrupts:
Soft interrupts are represented by the softirq_action structure

[CPP]View Plaincopy
    1. struct softirq_action{
    2. void (*action) (struct sotfirq_action*)
    3. An array containing 32 of the struct is defined in KERNEL/SOFTIRQ.C
    4. Static struct softirq_action Softirq_vec[nr_softirqs]

1, register soft interrupt function Open_softirq

[CPP]View Plaincopy
    1. void Open_softirq (int nr, void (*action) (struct softirq_action *))
    2. {
    3. / * Softirq_vec is an array of struct softirq_action types * /
    4. Softirq_vec[nr].action = action;
    5. }


2, the function that triggers the soft interrupt RAISE_SOFTIRQ see KERNEL/SOFTIRQ.C file

[CPP]View Plaincopy
    1. void Raise_softirq (unsigned int nr)
    2. {
    3. unsigned long flags;
    4. Local_irq_save (flags);
    5. Raise_softirq_irqoff (NR);
    6. Local_irq_restore (flags);
    7. }


3, perform soft interrupt do_softirq see KERNEL/SOFTIRQ.C file, if a soft interrupt is pending, DO_SOFTIRQ () loops through each of the handlers that call them.

[CPP]View Plaincopy
  1. Asmlinkage void Do_softirq (void)
  2. {
  3. __U32 pending;
  4. unsigned long flags;
  5. / * Determine if processing is interrupted, and return directly to/*
  6. if (In_interrupt ())
  7. return;
  8. / * Save the value of the current register * /
  9. Local_irq_save (flags);
  10. / * Get a bitmap of the currently registered soft interrupt * /
  11. Pending = Local_softirq_pending ();
  12. / * Cycle through all registered soft interrupts * /
  13. if (pending)
  14. __DO_SOFTIRQ ();
  15. / * Restore the value of the register to before interrupt processing * /
  16. Local_irq_restore (flags);
  17. }



4, perform the corresponding soft interrupt-perform your own write interrupt processing in Linux, perform soft interrupts with a dedicated kernel thread, each processor corresponding to a thread, name ksoftirqd/n

[Linux kernel] [Linux interrupt]--soft interrupt mechanism

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.