“Embedded systems are a hot spot in the field of computer software today, and real-time performance is the basic requirement of embedded systems. With the continuous development of embedded technology, in the context of the continuous growth of embedded applications and the increasing complexity of embedded systems, the debugging phase accounts for an increasing proportion of the entire system development process. The debugging environment and debugging technology directly affect the efficiency and quality of software development. An efficient debugging system can greatly reduce the time for embedded system development and reduce the workload of system development.
Embedded systems are a hot spot in the field of computer software today, and real-time performance is the basic requirement of embedded systems. With the continuous development of embedded technology, in the context of the continuous growth of embedded applications and the increasing complexity of embedded systems, the debugging phase accounts for an increasing proportion of the entire system development process. The debugging environment and debugging technology directly affect the efficiency and quality of software development. An efficient debugging system can greatly reduce the time for embedded system development and reduce the workload of system development.
The tracking and debugging system mainly has two methods: JTAG online debugging and runtime tracking and debugging. JTAG online debugging has great limitations when debugging real-time systems. For example, after querying parameters through breakpoints, the system can no longer run in accordance with the normal sequence, and the transition state of the sequential execution of the system cannot be detected. Run-time tracking and debugging adopts software instrumentation technology. By embedding tracking points in the program, developers can observe the output information in real time through the tracking points during the running of the program, such as the interaction information between modules and the sequence of program running, etc. .
The real-time tracking system designed in this project is based on runtime tracking and debugging methods, using ARM11 series processors as the hardware development platform and running on the Nucleus real-time operating system. Nucl eus real-time operating system is a preemptive multi-tasking operating system. During program execution, low-priority tasks will be preempted by high-priority tasks, and tracking task conflicts may occur, which may lead to problems such as mutual coverage of tracking information and disorder. Especially when the amount of tracking information is large, once the transmission peak is exceeded, the tracking information will be lost. The real-time tracking system adopts a special caching mechanism and analysis mechanism, which can solve the problem of tracking information loss and realize the complete and orderly transmission of tracking information.
1 Original tracking plan
The real-time tracking system is composed of a tracking information buffer unit, a transmission control unit, and a PC-side parsing unit, as shown in Figure 1. Among them, the tracking information cache unit is responsible for the assembly of the tracking information and the management of the tracking cache, the transmission control unit is responsible for moving the tracking information from the tracking cache to the PC side, and the PC-side parsing unit is responsible for parsing the tracking information.
The tracking cache management mechanism refers to how to manage the read and write permissions of the tracking cache, and how to record changes in the read and write indexes. In the tracking scheme with tracking backup cache, the tracking cache management mechanism is also responsible for the management of the backup cache. In the tracking system, all tracking information is encapsulated into a fixed frame format (message header + message content) when the tracking point is output, and written into the same circular queue with a length of X bytes in the tracking information buffer unit.
Since the tracking sources in the real-time tracking system under Nucleus multitasking operating system are mainly divided into low-level interrupts, high-level interrupts/timers and tasks, etc., in the process of tracking the tracking points in the tracking source, the tracking points of different priorities may be There is competition for the global tracking information cache. The tracking conflict scene is shown in Figure 2. Only one write pointer is set in the tracking information cache unit to access the tracking information cache, which ensures the orderliness of the tracking information, but conflicts will occur when the tracking sources of different priority levels are switched, and the write pointer needs to be protected on site.
Since blocking high-priority tasks will cause system flow abnormalities, when conflicts occur, in order to ensure the integrity of the tracking information and at the same time not block high-priority tasks, only the tracking requests in high-priority tasks can be discarded. When operating system tasks are frequently switched, more tracking information will be discarded. The feature of the tracking information discarding phenomenon is that the entire piece of tracking information is lost and continuously lost (all tracking in the active preemption task), and the tracking information discarding has nothing to do with the tracking information transmission loss. Therefore, the caching mechanism in the tracking system needs to be optimized.
2 Tracking optimization plan one
2.1 Physical cache management mechanism
The physical cache management mechanism adopts the tracking information frame format with tracking header, tracking information content and tracking tail. When the tracking source data is interrupted each other, the integrity of the tracking information is not considered, and the tracking information will be tracked according to the priority order of interruption. Write to the trace cache. The trace information writing scenario is shown in Figure 3. The task 1 trace information was written into the trace information cache and was interrupted by the advanced interrupt/timer. The advanced interrupt/timer writes its tracking information header to the current write pointer until the entire tracking information is written. Task 1 obtains the execution right, and its uncompleted trace information is immediately written at the tail of the advanced interrupt/timer trace information until the entire trace information is written.
2.2 Transmission control mechanism
The real-time tracking system communicates between the PC and the ARM subsystem through the serial port. The transmission control unit describes the communication process between the PC and the ARM subsystem. It uses the DMA bus controller to move the tracking information. DMA is a data exchange mode that directly accesses data from the memory without going through the CPU of the ARM processor. In the DMA mode, the CPU only needs to give instructions to the DMA bus controller to process the data transmission and receive the feedback information that the data transmission is completed, thereby greatly reducing the CPU resource occupancy rate. The transmission control unit uses the DMA synchronous interrupt to send the tracking information. Each time it is transmitted in equal-length bytes, the tracking information is moved to the serial port sending register, and then the tracking information is sent to the PC end analysis Display unit by configuring the serial port sending register.
2.3 Recursive call resolution mechanism
According to the tracking cache scenario in Figure 4, in order to ensure the complete continuity of the tracking information, the parsing unit uses a recursive call to analyze the current code stream.
First, a circular queue (that is, circular buffer) is opened on the PC-side tracking information analysis unit to store the tracking information output by the serial port, and the circular buffer is accessed through a read pointer and recursive call analysis is performed. At the same time, an N×L tracking buffer space (that is, N continuous buffer spaces with length L) is opened on the PC side to store the parsed complete tracking information, and each buffer with a length of L stores a complete tracking information. . Apply for an array of pointers to save the starting address of each complete memory, that is, to record the change of each write pointer in the N×L cache. The flow of tracking information recursive analysis function is shown in Figure 5.
Finally, the parsed tracking information code stream is converted into visible characters, and displayed and output on the PC.
3 Tracking optimization plan two
3.1 Backup cache management mechanism
The backup buffer management mechanism adopts the tracking information frame format containing the tracking header and tracking information, and writes the tracking information into a global tracking information buffer of size N. In order to avoid data loss when the current task is interrupted by high-priority tasks when task switching is frequent, apply for a backup cache with a nesting depth of M to store high-priority task tracking information. Among them, the length of each sub-cache in the backup cache area is m, the busy tracking flag is set, and the initial value is 0. The tracking source sets the tracking busy flag to 1 by calling the tracking interface function provided by the tracking system, and fills the current tracking source tracking information into the global tracking information cache. After completing the current trace information writing operation, set the trace busy flag to 0. If the current tracking source is performing a write operation, that is, when the tracking busy flag is 1, the high-priority task calls the tracking interface, and the tracking information of the high-level task is written into the backup buffer, and the current tracking source continues to perform the unfinished write operation. Every time you finish writing the current tracking information, check whether there are any data in the backup cache-if so, copy the tracking information in the backup cache back to the global tracking information cache (the tracking cache scenario is shown in Figure 6), that is, in the current task When the tracking information is written into the tracking information cache, if an advanced task arrives, the advanced task tracking information will be encapsulated and written into the backup cache. After the output of the current trace completion write operation is successful, check whether there is trace information in the backup cache – if so, copy the trace information in the backup cache back to the global trace information cache to ensure the tracking information in the global trace information cache Continuity.
3.2 Transmission control mechanism
Same as the transmission control mechanism in the tracking optimization scheme 1.
3.3 General query resolution mechanism
According to the second tracking buffer management mechanism, since the tracking information in the global tracking information buffer is completely and continuously distributed, the decoding method adopts the traversal query method.
First, a circular queue (ie, circular buffer before parsing) is opened on the PC-side tracking information receiving unit to store the tracking information received from the serial port.
Then, a post-analysis circular cache is opened on the PC-side parsing Display unit to store the complete tracking information after parsing. Use the read pointer to traverse the pre-parsing loop cache, query the string beginning with the tracking header identifier X, and write the complete tracking information thereafter to the loop cache after parsing, until the next time the tracking header identifier X is encountered, the loop before parsing is recorded Cache the read index and save the current parsed cache write index. Repeat the above operations to parse the tracking information in the loop cache before parsing one by one, and put it into the loop cache after parsing.
Finally, the complete tracing information code stream that has been parsed in the circular cache after parsing is converted into visible characters, and displayed and output on the PC.
4 Performance analysis and comparison
4.1 Tracking optimization plan one
The tracking information is stored in a physically continuous storage manner, that is, the tracking source controls the writing of the tracking information through the global write pointer during the assembly process of a single tracking information. All tracking points track the current priority order and write to the tracking information buffer area to ensure that there is only one tracking information buffer, and the tracking buffer is written according to the priority level when the tracking sources preempt each other. The tracking information in the tracking cache of this mechanism presents nested and interrupted incomplete code streams.
The tracking information sending mechanism uses the tracking interface function to trigger the transmission device to move the data. In the transmission control unit, the tracking information in the global tracking information buffer is moved to the serial port register by configuring the DMA bus. The PC-side receiving device fetches data from the serial port register, puts it into the PC-side parsing unit buffer space, and parses the incomplete tracking information into complete and continuous tracking information through the tracking information recursive analysis mechanism. A protected data area is set at the end of each tracking information buffer area, and the length of the protected area is the maximum length L of a single piece of information.
This solution solves the problem of tracking information loss, and decodes the discontinuous code stream by analyzing the display unit on the PC side. Because this mechanism adopts a physical and continuous data storage method in the embedded tracking cache unit, it reduces the consumption of ARM system resources by the tracking software, and ensures that the tracking system consumes the ARM processor CPU as low as possible under high-speed operation. In this way, in a high-speed running system, the tracking system occupies a large amount of CPU and the system running rate is low. This scheme is suitable for terminal systems that require higher operating speed of the ARM subsystem.
4.2 Tracking optimization plan 2
Apply for a global tracking information ring cache space in the embedded tracking information cache unit, and apply for a set of backup caches at the same time. When the write pointer conflicts, the tracking information of the advanced task is written into the backup buffer, and the current tracking source continues to write its tracking information into the global tracking information buffer. Each time you finish writing the current track information, check whether there is a number in the backup cache-if so, copy it back to the global cache. This mechanism manages the write pointers according to the priority of the task, and solves the problem of discontinuous tracking information caused by write pointer conflicts.
In the transmission control unit, by configuring the DMA bus, setting the sending destination address and length, the tracking information in the global tracking information buffer is moved to the serial port register. The PC-side receiving device fetches data from the serial port register and puts it into the PC-side analytic display unit tracking information cache area. Through the tracking information general query analysis mechanism, the complete tracking information starting with X and ending with X is parsed out. A protected data area is set at the end of each tracking information buffer area, and the length of the protected area is the maximum length L of a single piece of information.
This solution solves the problem of data loss through a backup cache mechanism and ensures the continuity and integrity of the output of the tracking information. However, due to the process of copying back tracking information from the backup cache to the global tracking cache, it takes up a lot of ARM processor CPU resources, which results in a low operating efficiency of the solution in an environment that requires a high operating speed of an embedded system.
In view of the low running rate of the existing tracking software, disorder of tracking information, serious loss, etc., two solutions are proposed. One is to use a physical continuous storage method for encoding on the ARM side, and reassemble the nested tracking information through a recursive call algorithm on the PC side, and finally convert the parsed complete code stream into a visible string for output. This solution is suitable for software tracking systems that require higher operating speed of the ARM subsystem and sufficient resources available on the PC side. Another solution is to write advanced task tracking information into the backup cache on the ARM side, and then write the tracking information in the backup cache into the global tracking information cache area by means of data copy-back. When decoding on the PC side, this solution only needs to query the tracking header identifier for decoding, and convert the parsed continuous code stream into a visible string output. It is suitable for software tracking that does not require high operating speed of the embedded system and has limited resources on the PC side. system.
The above two schemes can ensure the continuous integrity of the output tracking information, and solve the problem that low priority tasks under the Nucleus real-time operating system will be preempted by high priority tasks, so that tracking task conflicts may cause tracking information to overlap and disorder each other. It provides a more reliable embedded software real-time tracking system for software developers to analyze and locate problems, and improve the efficiency of their analysis and problem solving.