Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Processor interrupt (2)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Let's look at interrupts today. What is an interrupt? Interrupts are a mechanism by which the processor communicates with peripherals to "notify" the processor that an "important event" has occurred outside. In general, interrupts need to be responded to by the processor. Let's look at the interrupt service program (ISR): 1. Read the value of the interrupt status register from the peripheral to understand the interrupt type;2. Design the processing logic according to the interrupt type;3. Clear the interrupt identification bit in the peripheral status register;4. Clear the interrupt identification bit in the processor. specific process is as follows

We see that the external device triggers an interrupt, and then the processor responds by saving the current context information. Then, by obtaining the interrupt type of the external device, the processor performs corresponding processing after the type of the external device is transmitted. After processing, clear the flag bit of external interrupt, and then clear the flag bit of interrupt, and finally obtain the context information saved before to continue execution.

So what does an interrupt service routine look like to a software engineer? 1, there can be no return value, there can be no parameter transfer;2, must be small and efficient, avoid floating point operations. The following procedure is not allowed.

Let's look at the meaning of interruption. 1. The application program does not have to care about the occurrence and handling of interrupts;2. The interrupt service program does not have to care about the execution state of the application program;3. The interrupt is the "separation boundary" between the "upper application" and the "bottom code." as follows

There are two types of interrupts: hard interrupts and soft interrupts. A hard interrupt is an interrupt generated by the processor interrupt signal line; a soft interrupt is an interrupt triggered by an illegal or special instruction. Interrupts are prioritized, and when multiple interrupts occur simultaneously, the processor responds to the higher-priority interrupt first. When an ISR with a low priority interrupt executes, it can be interrupted again by a high priority interrupt, and the ISR has a higher execution priority than the App Code. Then one application of interrupt is program breakpoint, breakpoint refers to the instruction position used by debugging tool to pause code execution, and the implementation principle of breakpoint is interrupt support of processor. Software breakpoint refers to the use of illegal instruction exception to generate interrupt implementation, while hardware interrupt refers to the use of interrupt register characteristics to generate interrupt implementation.

The realization principle of program breakpoint: 1. Obtain the code address corresponding to the specified line of the original program;2. Replace the instruction in the code address with the interrupt trigger instruction;3. Give the control right to the debugging program in the interrupt service program;4. The debugging program reads and writes the context information of the original program;5. The debugging program restores the instruction in the code address;6. The original program continues to execute downward from the breakpoint. process is as follows

Let's look at an engineering product case, is to make a tool that can be breakpoint debugging, but can not affect its real-time. The background is that embedded real-time systems have strict timing requirements, and the execution of each thread has relatively strict time requirements. The pain point is that breakpoint debugging does not work in embedded real-time systems. Then the most common solution is the log debugging method, its principle is: 1, in the code "key position" to add print statements;2, print statements as detailed as possible print context information (function name, local variables, etc.);3, when the system has problems, view log files, analyze the problem. However, log debugging method also has certain problems: 1. It is not easy to maintain, and the print statements are scattered in all corners of the product code;2. It affects efficiency, and too many print statements mean that too many IO operations will eventually affect the overall efficiency of the product;3. It is difficult to analyze, and when the log output is very large, it is difficult to accurately locate the problem. Another is that only the engineer who adds the print statement can understand the log output information.

Then Elder Tang had a crazy idea: combine the advantages of log debugging method and breakpoint debugging method at the same time, so that when debugging real-time system, you can arbitrarily view the information of the specified code line context; and do not add print statements, do not pause execution. The solution is: 1. Get the code address corresponding to the specified line of the original program;2. Replace the instruction in the code address with the interrupt trigger instruction;3. Grab the global information and stack information in the interrupt service program;4. Send the captured information back to the debugger for parsing and outputting. The result of practice is MProbe, which has the following characteristics: 1. Complete implementation based on ARM + Linux platform;2. Successful acquisition of context information through interrupt principle;3. No impact on program execution timing at all;4. Key technical points of the product include interrupt, ISR, compilation information, GDB, GUI, Socket and multithreading.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report