The interruption of kernel learning

Source: Internet
Author: User
Tags execution

Each device in the management system is the kernel task, and the kernel can be implemented in 2 ways.

1, polling: to a certain amount of time to access the device, see its status and processing.

2, Interrupt: The device to the kernel to send requests, the kernel to complete processing.

Interrupted classification: Interrupts can be divided into synchronous interrupts and asynchronous interrupts.

Synchronous interrupts are generated by the CPU, also known as internal interrupts. The synchronization here means that the interrupt instruction signal and the code are executed at the same time, and the interrupt signal is not generated until a single code is executed, not during execution. Usually occurs when the CPU detects an exception or illegal condition during execution, which is directly related to the current instruction, such as a divisor of 0.

Asynchronous interrupts are generated by other hardware, also known as external interrupts. Asynchronous interrupts can occur at any time, including during instruction execution.

In general, a synchronous interrupt is called an exception, and an asynchronous interrupt is called an interrupt.

Exceptions are divided into: fault (fault) traps (TRAP) abort (abort).

Failure: Notifies the exception of an exception to the system before the instruction that caused the failure. Go back to the original position and continue.

Traps: Svc

Abort: Notifies a system of an exception when a system is in serious condition. The command that caused the abort is unpredictable. The execution is not recoverable when the abort occurs.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/

Interrupt: It is also divided into shielding interrupts and unshielded interrupts.

Interrupt Controller: Programmable Interrupt Controller (PIC) is used for but processing platform, such as 8259A. The Advanced Programmable Interrupt Controller (APIC) can be used in a multiprocessor controller.

A single 8259A can manage only 8 interrupt sources, and can manage up to 64 interrupt sources in a cascading manner.

Whether it's an interrupt or an exception. The CPU corresponding process is basically consistent, and skips to the appropriate address to execute the handler according to the interrupt source.

Interrupt API:

The kernel provides a set of API interfaces for controlling interrupts. Understanding these are the fundamentals of driving development.

1. Registration and release

IRQ lines are a very valuable resource. The driver should be registered when it is in use and should be released when it is not used.

REQUEST_IRQ is declared in Include/linux/interrupt.h.

REQUEST_IRQ (unsigned int IRQ, Irq_handler_thandler, unsigned long flags,  
        const char *name, void *dev);

IRQ: The IRQ number to be applied, many of the device's IRQ numbers are preset, such as keyboard devices and system clocks.

Handler: Registered interrupt Service program.

Flags: Interrupt type identification, irqf_shared indicates that the same IRQ line is shared with other devices. Irq_disable means that on the local CPU, the interrupt handler disables all interrupts at run time, so that it is unaffected by other interrupts. Without this flag, the interrupt number for the interrupt handler is prohibited, and is not interrupted by this type. Irqf_sample_random: This interrupt can generate kernel entropy.

Name: The names of the interrupt sources, which are visible in the/proc/interrupts file.

Dev: Parameters passed to the hander.

Returns 0. Indicates success, the IRQ is activated. The return Non-zero fails. A common error-ebusy indicates that the IRQ has been occupied.

Note: To prevent interrupt handlers from being invoked before the device initialization completes, initialize the hardware and IRQ registration order correctly.

FREE_IRQ you uninstall a device driver, you must call this function to delete the corresponding irqaction node in the interrupt request queue and to release the disconnected thread. If the IRQ is not shared, the IRQ line is immediately blocked after the Irqaction node is deleted. Otherwise, only the corresponding irqaction node is deleted until the IRQ line is removed from all irqaction in the interrupt request queue.

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.