Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

Embedded system is a hot spot in today’s computer software field, and real-time performance is the basic requirement of embedded system. With the continuous development of embedded technology, in the case of the continuous growth of embedded applications and the increasing complexity of embedded systems, the debug 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 development time of embedded systems and reduce the workload of system development.

Embedded system is a hot spot in today’s computer software field, and real-time performance is the basic requirement of embedded system. With the continuous development of embedded technology, in the case of the continuous growth of embedded applications and the increasing complexity of embedded systems, the debug 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 development time of embedded systems and reduce the workload of system development.

There are mainly two ways to trace and debug the system: JTAG online debug and run-time trace debug. JTAG online debugging has great limitations when debugging real-time systems. For example, after querying parameters through breakpoints, the system can no longer run according to the normal timing sequence, and the transition state of the system’s sequential execution cannot be detected. Run-time trace debugging adopts software instrumentation technology. By embedding trace points in the program, developers can observe the output information in real time through the trace points during the running process 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 the run-time tracking and debugging method, uses ARM11 series processors as the hardware development platform, and runs on the Nucleus real-time operating system. The Nucl eus RTOS is a preemptive multitasking operating system. During program execution, low-priority tasks will be preempted by high-priority tasks, which may cause conflicting tracking tasks, resulting in overlapping tracking information and out-of-order problems. 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 special caching mechanism and parsing mechanism, which can solve the problem of tracking information loss and realize complete and orderly transmission of tracking information.

1 Original tracking scheme

The real-time tracking system consists of a tracking information cache unit, a transmission control unit and a PC-side parsing unit, as shown in Figure 1. The tracking information cache unit is responsible for assembling the tracking information and managing the tracking cache, the transmission control unit is responsible for moving the tracking information from the tracking cache to the PC, and the PC parsing unit is responsible for parsing the tracking information.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software 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 the changes of the read and write indexes. In the tracking scheme with the 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 the 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 a race to the global trace information cache. The tracking conflict scenario 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 order of the tracking information, but conflicts will occur when the tracking sources of different priorities are switched, and the write pointer site needs to be protected.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

Since blocking high-priority tasks will cause abnormal system processes, 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 the high-priority tasks can be discarded. When operating system tasks are switched frequently, a lot of tracking information will be discarded. The characteristics of the tracking information discarding phenomenon are that the entire tracking information is lost and continuously lost (actively preempting all the tracking in the task), and the tracking information discarding has nothing to do with the transmission loss of the tracking information. Therefore, the caching mechanism in the tracking system needs to be optimized.

2 Tracking optimization scheme one

2.1 Physical Cache Management Mechanism

The physical cache management mechanism adopts the tracking information frame format including the tracking header, the content of the tracking information and the tracking tail. The integrity of the tracking information is not considered when the tracking source data is interrupted, and the tracking information is sorted according to the priority of interruption. Write trace cache. The trace information writing scene is shown in Figure 3. Task 1 was interrupted by an advanced interrupt/timer while the trace information was being written to the trace information cache. The advanced interrupt/timer writes its trace header to the current write pointer until the entire trace is written. Task 1 obtains the execution right, and its unwritten trace information is written immediately after the tail of the advanced interrupt/timer trace information until the entire trace information is written.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

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 memory without going through the CPU of the ARM processor. In the DMA mode, the CPU only needs to issue an instruction 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. The transmission control unit adopts DMA synchronous interrupt to send the tracking information, and transfers the tracking information to the serial port sending register each time with equal-length bytes, and then sends the tracking information to the PC-side analysis Display unit by configuring the serial port sending register.

2.3 Recursive call parsing mechanism

According to the trace cache scene in FIG. 4 , in order to ensure the complete continuity of the trace information, the parsing unit parses the current code stream by means of recursive calls.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

First, a circular queue (ie, circular buffer) is opened in 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 recursively called and analyzed. At the same time, a tracking cache space with a size of N×L (that is, N consecutive cache spaces with a length of L) is opened on the PC side to store the complete parsed tracking information, and each cache with a length of L stores a complete tracking information. . Apply for a pointer array to save the starting address of each complete memory, that is, record the change of each write pointer in the N×L cache. The flow of the recursive analysis function of the tracking information is shown in Figure 5.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

Finally, the parsed tracking information code stream is converted into visible characters, and the output is displayed on the PC.

3 Tracking optimization plan 2

3.1 Backup Cache Management Mechanism

The backup cache management mechanism adopts the tracking information frame format including the tracking header and tracking information, and writes the tracking information into a global tracking information cache with a size of N. To avoid data loss caused by the current task being interrupted by high-priority tasks when tasks are switched frequently, apply for a backup cache with a nesting depth of M to store high-priority task tracking information. The length of each sub-cache in the backup cache area is m, and the tracking busy flag is set, and the initial value is 0. The trace source sets the trace busy flag to 1 by calling the trace interface function provided by the trace system, and fills the current trace source trace information into the global trace information cache. After completing the write operation of the current trace information, set the trace busy flag to 0. If the current trace source is performing a write operation, that is, when the trace busy flag is 1, the high-priority task calls the trace interface, and writes the trace information of the high-level task into the backup cache, and the current trace source continues the unfinished write operation. Each time the current tracking information is written, check whether there is any number 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 trace information is written into the trace information cache, if an advanced task arrives, the advanced task trace information is encapsulated and written into the backup cache. After the output of the current trace end 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, so as to ensure the trace information in the global trace information cache. continuity.

Design of Nested Cache Mechanism and Parsing Mechanism for Embedded Software Tracking Information

3.2 Transmission Control Mechanism

The same as the transmission control mechanism in the tracking optimization scheme 1.

3.3 Common query parsing mechanism

According to the second tracking cache management mechanism, since the tracking information in the global tracking information cache is completely and continuously distributed, the decoding method adopts the traversal query method.

First, a circular queue (that is, a circular buffer before parsing) is opened in the tracking information receiving unit on the PC side to store the tracking information received from the serial port.

Then, a post-parse circular cache is opened in the PC-side parsing and display unit to store the complete trace information after parsing. Use the read pointer to traverse the pre-parse circular cache, query the string starting with the trace header ID X, and write the complete trace information after it into the post-parse circular cache, until the next time the trace header ID X is encountered, record the pre-parse loop Cache the read index and save the current parsing post-cycle cache write index. Repeat the above operations, parse the tracking information in the pre-parse circular cache in turn, and put them into the post-parse circular cache.

Finally, the complete tracking information code stream parsed in the parsed circular buffer is converted into visible characters, and the output is displayed on the PC.

4 Performance analysis and comparison

4.1 Tracking optimization scheme one

The tracking information is stored in a physically continuous storage method, that is, the tracking source controls the writing of the tracking information through the global write pointer during the assembly process of a single piece of tracking information. All trace points track the current priority order, and write operations to the trace information buffer to ensure that there is only one trace information buffer. When the trace sources preempt each other, the trace buffer is written according to the priority. The mechanism traces the information in the cache to present nested, interrupted, incomplete code streams.

The tracking information sending mechanism adopts the tracking interface function to trigger the transmission device to move the data. In the transmission control unit, the trace information in the global trace information buffer is moved to the serial port register by configuring the DMA bus. The PC-side receiving device takes 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 parsing mechanism. A protection data area is set at the end of each tracking information buffer area, and the length of the protection 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 the mechanism adopts the way of physically continuous data storage in the embedded trace cache unit, the consumption of the ARM system resources by the trace software is reduced, and the consumption of the ARM processor CPU by the trace system is guaranteed to be as low as possible under the condition of high-speed operation. Therefore, in a high-speed running system, the tracking system occupies a large amount of CPU, resulting in a low system running rate. This solution 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 trace information of the advanced task is written into the backup cache, and the current trace source continues to write its trace information into the global trace information cache. Each time the current piece of trace information is written, check whether there is a number in the backup cache – if so, copy it back to the global cache. This mechanism manages the write pointer according to the priority of the task, and solves the problem of discontinuous tracking information caused by the conflict of the write pointer.

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 cache is moved to the serial port register. The PC-side receiving device takes data from the serial port register and puts it into the PC-side analysis and display unit tracking information buffer area, and parses the complete tracking information starting with X and ending with X through the common query and analysis mechanism of tracking information. A protection data area is set at the end of each tracking information buffer area, and the length of the protection area is the maximum length L of a single piece of information.

The scheme solves the problem of data loss through the backup cache mechanism, and ensures the continuity and integrity of the output of tracking information. However, the process of copying back the trace information from the backup cache to the global trace cache requires a large amount of CPU resources of the ARM processor, resulting in a low operating efficiency of this solution in an environment that requires a high operating speed of the embedded system.

Epilogue

Aiming at the low running speed of the existing tracking software, the disorder of tracking information, and the serious loss, two solutions are proposed. One is to use the physical continuous storage method for encoding on the ARM side, reassemble the nested tracking information through a recursive calling algorithm on the PC side, and finally convert the parsed complete code stream into a visible string output. This solution is suitable for a software tracking system with high requirements on the running rate of the ARM subsystem and sufficient resources available on the PC side. Another solution is to write the 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 through data copyback. This solution only needs to query the tracking header identifier for decoding when decoding on the PC side, and convert the parsed continuous code stream into a visible string output. system.

Both of the above two schemes can ensure the continuous integrity of output tracking information, and solve the problem that low-priority tasks will be preempted by high-priority tasks under the Nucleus real-time operating system, and the tracking information may overlap and mess up due to conflicting tracking tasks. It provides a more reliable embedded software real-time tracking system for software developers to analyze and locate problems, and improves the efficiency of their analysis and problem solving.

The Links:   NL2432HC22-44B MG50N2YS1

Related Posts