Use kernel programming in Linux to interrupt the processing program

Source: Internet
Author: User
In Linux, kernel programming is used to interrupt the processing program-general Linux technology-Linux programming and kernel information. The following is a detailed description. Interrupt handling program

In addition to the last chapter, what we are currently doing in the kernel is to respond to a process request, possibly by processing a special file, sending an ioctl, or making a system call. However, the kernel does not only respond to process requests, but also publishes commands or messages to the hardware connected to the machine.

There are two types of interaction between CPU and other hardware. First, the CPU sends commands to the hardware. The other is that the hardware needs to tell the CPU something. The second type of interaction is called interruption, which is hard to implement because it needs to process hardware instead of CPU. Hardware devices are usually made up of a very small ram, and they will be lost if you read them when they are not available in this ram.

In Linux, hardware interruption is called IRQ (abbreviated as Interrupt Requests ). There are two types of IRQ: Short Type and long type. Short IRQ takes a short time, during which other parts of the machine are locked and no other interruptions are processed. A long IRQ takes a long time, during which other interruptions may occur (but not from the same device ). If possible, it is best to declare a middle section as a long type.

If the CPU receives an interrupt, it stops all operations (unless it is dealing with a more important interrupt, in this case, the interrupt will not be processed until the more important interrupt processing is completed.) store the relevant parameters in the stack and call the interrupt processing program. This means that some tasks in the interrupt handler itself are not allowed, because the system is in an unknown state. The solution to this problem is to let the interrupt handler do what needs to be done immediately, usually reading information from the hardware or sending information to the hardware, then, schedule the processing of new information to the Future (this is called the half bottom) and return it. The kernel ensures that the half base is called as soon as possible. During the call, anything that can be done in the kernel module can be done.

The method is to call the interrupt handler when it is connected to the related IRQ (16 IRQ on the Intel platform. This function is connected to the IRQ Number, function name, flag, a/proc/interrupts name, and a parameter passed to the interrupt handler. The flag can include SA_SHIRQ to indicate that you want to share this IRQ with other processing programs (usually many devices share an IRQ), or a SA_INTERRUPT to indicate that this is an emergency interrupt. This function runs only when IRQ does not have any other handler or shares all the handlers.

With the interrupt processing program, we can communicate with the hardware, and use queue_task_irq and tq_immediate and mark_bh (BH_IMMEDIATE) to schedule the half-bottom. Standard queue_task cannot be used in version 2.0 because the interruption may occur in the middle of a queue_task. We need mark_bh because in earlier Linux versions, there was only one half-bottom queue with a length of 32. Now one of them (BH_IMMEDIATE) is used for the semi-bottom Chain List of drivers that are not allocated to them.

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.