A dynamic call tree analysis device and analysis method for heterogeneous many-core programs
By using dynamic call tree analysis devices and analysis methods on heterogeneous multi-core processors, the problem of difficulty in analyzing the dynamic characteristics of programs in the existing technology is solved, efficient code logic analysis is achieved, and code porting and development efficiency is improved.
Patent Information
- Application Number
- CN202110479676.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-30
- Publication Date
- 2025-05-20
- Estimated Expiration
- 2041-04-30
AI Technical Summary
Existing code logic analysis methods mainly rely on static analysis, making it difficult to understand some dynamic characteristics during program operation, especially when facing complex high-level language features and domestic heterogeneous multi-core processors.
It provides a heterogeneous multi-core program dynamic call tree analysis device and analysis method, records dynamic call tree information during program execution through the instrumentation library, and displays dynamic call tree using the result display module, and automatically instrumented by the compiler.
Through dynamic call tree analysis, users can effectively obtain the dynamic call relationship of the program, make up for the shortcomings of static analysis, improve the efficiency of code logic analysis, and simplify the code porting and development process.
Smart Images

Figure CN114217812B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an analysis device and method for a dynamic call tree of a heterogeneous many-core program, belonging to the field of code logic analysis. Background Art
[0002] Currently, when reading code for code logic analysis, there are mainly two methods to obtain the program call tree: one is to use lexical and syntactic analysis tools for the adopted programming language, which belongs to the static analysis method and cannot obtain some behaviors that change dynamically during program operation; the other is to obtain it by the user inserting code (usually print statements) into the program, which belongs to the dynamic analysis method.
[0003] Some call processes that need to be dynamically determined during program execution (such as calls based on function pointers, etc.) are difficult to obtain through static analysis methods. For large-scale application programs, it is obviously extremely time-consuming and laborious to determine by user code instrumentation. Based on the current technical status, when porting code on domestic heterogeneous many-core processors, it often needs to be done in two steps: first, use the former method to obtain the overall static call tree of the program, and then combine the latter to conduct in-depth analysis on the key parts.
[0004] With the continuous development of domestic heterogeneous many-core processors and the influence of the domestic and international situations, more and more application software has the need to be ported to domestic heterogeneous many-core processors or redeveloped on them. During this process, the study of relevant code is the primary link. However, the abstraction of high-level languages has brought great difficulties to this link, such as features like templates and inheritance in the C++ language, and function pointers in the C language. The existing code logic analysis means mainly rely on static analysis and are difficult to understand some dynamic characteristics during program operation. Summary of the Invention
[0005] The purpose of the present invention is to provide an analysis device and method for a dynamic call tree of a heterogeneous many-core program to solve the problem that the existing code logic analysis means mainly rely on static analysis and are difficult to understand some dynamic characteristics during program operation.
[0006] To achieve the above object, the technical solution adopted by the present invention is: to provide an analysis device for a dynamic call tree of a heterogeneous many-core program, including the following functional modules:
[0007] An instrumentation library for recording dynamic call tree information during program execution;
[0008] A result display module for displaying the dynamic call tree information of the program, displaying the recorded data in the storage order, and realizing hierarchical display of the multi-way tree based on the L value in the record, that is, L + 1 is displayed as the child node of L;
[0009] The stub library includes an InitFunc function, an EntryFunc function, a LeaveFunc function, a STACKPC data structure, and a DA data structure. The STACKPC is a stack structure, and the DA is a sequential storage structure. Both the STACKPC and DA support dynamic expansion;
[0010] The InitFunc function is called at the very beginning of all user programs, and is used to apply for the initial storage space of the STACKPC and DA data structures and initialize the L value;
[0011] The EntryFunc function is used to push the function entry PC value onto the STACKPC and is responsible for recording data. Each data entry consists of the current stack layer L, the PC value stored in the current stack layer L (i.e., the PC value of the currently recorded user function entry), and the PC stored in the L-1 stack layer (i.e., the PC of the current function's caller), denoted as D(L, PC, CPC). When L = 0, that is, there is no caller of the current function, make CPC = 0;
[0012] The LeaveFunc function is used to implement the stack pop operation and, when the stack is empty, output the DA.
[0013] There is also provided a method for analyzing the dynamic call tree of a heterogeneous many-core program. Based on the above-mentioned device for analyzing the dynamic call tree of a heterogeneous many-core program, it includes the following steps:
[0014] S1. Modify the compiler source code to add a compilation option whose function is to insert the InitFunc function before the user's main function, insert the EntryFunc function at the entry of each user function, and insert the LeaveFunc function at the exit of each user function;
[0015] S2. Compile the program using the newly added compilation option in S1;
[0016] S3. Run the program generated in S2;
[0017] S4. When the program in S3 runs to InitFunc, InitFunc applies for space and initializes both the arithmetic control core and the L value of the operation to -1.
[0018] S5. When the program runs to EnterFunc, the L value is incremented by 1. Check whether D(L, PC, CPC) exists in the STACKPC. If it does not exist, add a new record to the DA. If it exists, filter out the record and only save one (L, PCB, PCA) record in the DA;
[0019] S6. When the program runs to LeaveFunc, the value of L is decremented by 1. If the value of L is equal to -1, an output operation is performed. At this time, if it is in the arithmetic core, the record is transmitted to the arithmetic control core through DMA. If it is the arithmetic control core, the record is output to a file. The record includes the arithmetic core and the arithmetic control core;
[0020] S7. After all the records in S6 are output to the file, the result display module is called for display.
[0021] The further improved solutions in the above technical solutions are as follows:
[0022] 1. In the above solution, in S7, the display module outputs the data of the arithmetic control core and each arithmetic core respectively in the order of the records.
[0023] 2. In the above solution, the output method for each record is as follows: First, indent L blank characters, then output the function name converted from the PC value of the record through the libbfd library, and then line feed.
[0024] Due to the application of the above technical solutions, the present invention has the following advantages compared with the prior art:
[0025] The present invention relates to a heterogeneous multi-core program dynamic call tree analysis device and analysis method, which is oriented to domestic heterogeneous multi-core processors. Based on the automatic instrumentation of the compiler, with a simple algorithm and low overhead, users can obtain the dynamic call tree of the program through one run, which can effectively make up for the deficiencies of static analysis and improve the efficiency of code logic analysis. Brief Description of the Drawings
[0026] Attached Figure 1 is a schematic diagram of the core principle of the instrumentation module of the present invention. Detailed Embodiment
[0027] Embodiment: The present invention provides a heterogeneous multi-core program dynamic call tree analysis device, which includes the following functional modules:
[0028] An instrumentation library for recording dynamic call tree information during program execution;
[0029] A result display module for displaying the dynamic call tree information of the program, displaying the recorded data in the storage order, and realizing the hierarchical display of the multi-way tree based on the L value in the record, that is, L + 1 is displayed as the child node of L;
[0030] The instrumentation library includes an InitFunc function, an EntryFunc function, a LeaveFunc function, a STACKPC data structure, and a DA data structure. The STACKPC is a stack structure, and the DA is a sequential storage structure, and both the STACKPC and the DA support dynamic expansion;
[0031] The InitFunc function is called at the very beginning of all user programs, such as the entry of the main function in C language, and is used for applying for the initial storage space of the STACKPC and DA data structures and initializing the L value.
[0032] The EntryFunc function is used to push the function entry PC value onto the STACKPC and is responsible for recording data. Each data entry consists of the current stack layer L, the PC value stored in the current stack layer L (i.e., the PC value of the currently recorded user function entry), and the PC stored in the L-1 stack layer (i.e., the PC of the caller of the current function), denoted as D(L, PC, CPC). When L = 0, that is, there is no caller of the current function, CPC = 0.
[0033] The LeaveFunc function is used to implement the stack pop operation and, when the stack is empty (i.e., when all user functions end, which can be known from the fact that EnterFunc and LeaveFunc appear in pairs and the characteristics of the stack structure), output DA.
[0034] There is also provided a method for analyzing the dynamic call tree of a heterogeneous many-core program. Based on the above-mentioned device for analyzing the dynamic call tree of a heterogeneous many-core program, it includes the following steps:
[0035] S1. Modify the compiler source code to add a compilation option whose function is to insert the InitFunc function before the user's main function, insert the EntryFunc function at the entry of each user function, and insert the LeaveFunc function at the exit of each user function.
[0036] S2. Compile the program using the newly added compilation option in S1.
[0037] S3. Run the program generated in S2.
[0038] S4. When the program in S3 runs to InitFunc, InitFunc applies for space and initializes both the operation control core and the L value of the operation to -1.
[0039] S5. When the program runs to EnterFunc, the L value is incremented by 1. Check whether D(L, PC, CPC) exists in STACKPC. If it does not exist, add a new record to DA. If it exists, filter out the record (used to filter out loop call records existing in the program. For example, if A calls B in a loop, denote the entry PCs of A and B as PCA and PCB respectively, and denote the stack layer in B as L. Then there will be multiple consecutive records of (L, PCB, PCA). Only one record of (L, PCB, PCA) is saved in DA).
[0040] S6. When the program runs to LeaveFunc, the value of L is decremented by 1. If the value of L is equal to -1 (i.e., the STACKPC stack is empty, indicating that all user function calls have ended), then an output operation is performed. At this time, if it is in the arithmetic core, the record is transmitted to the arithmetic control core through DMA. If it is the arithmetic control core, the record is output to a file. The record includes all records of the arithmetic core and the arithmetic control core.
[0041] S7. After all the records in S6 are output to the file, the result display module is called for display.
[0042] The further improved solutions in the above technical solutions are as follows:
[0043] 1. In the above solution, in S7, the display module outputs the data of the arithmetic control core and each arithmetic core respectively in the order of the records.
[0044] 2. The output method for each record is as follows: First, indent by L blank characters, then output the function name converted from the PC value of the record through the libbfd library, and then line feed.
[0045] The further explanation of the above embodiments is as follows:
[0046] By inserting processing functions at the entrance and exit of user functions through the compiler instrumentation interface, automated processing function instrumentation is achieved, which significantly improves efficiency compared with manual user instrumentation.
[0047] The processing function saves the dynamic call stack information of the program through a stack structure and a sequential storage structure, generates call stack data after running, and achieves the effect of static analysis on the dynamically executed function calls.
[0048] Provide an intuitive display form combining function names with multi-way trees.
[0049] The device proposed by the present invention is used in three steps: (1) Add relevant compilation and linking options and compile the program; (2) Run the program; (3) Call the parsing module to view the results.
[0050] The device mainly includes two parts: an instrumentation library and a result display module. Among them, the instrumentation library is the core component, which is used to record the dynamic call tree information during the program execution process. The core principle is as Figure 1 shown; the result display module is used to display the dynamic call tree information of the program.
[0051] The instrumentation library includes three main functions InitFunc, EntryFunc, and LeaveFunc, and involves two main data structures. Among them, STACKPC is a stack structure, and DA is a sequential storage structure. Both support dynamic expansion.
[0052] InitFunc is called at the very beginning of all user programs, such as the entry point of the main function in C language, and is used for the initialization-related work of important data structures such as STACKPC and DA.
[0053] EnterFunc implements pushing the function entry PC value onto the stack of STACKPC and is responsible for recording data. Each data entry consists of the current stack layer L, the PC value stored in the current stack layer L (i.e., the PC value of the currently recorded user function entry), and the PC stored in the L - 1 stack layer (i.e., the PC of the caller of the current function), denoted as D(L, PC, CPC).
[0054] LeaveFunc is responsible for implementing the stack pop operation and, when the stack is empty (i.e., when all user functions end, which can be known from the fact that EnterFunc and LeaveFunc appear in pairs and combined with the characteristics of the stack structure), outputting DA.
[0055] In heterogeneous multi-core programs, the operation control core and the operation cores will each have a main entry of the user function similar to the main function. Therefore, we need to implement the EnterFunc and LeaveFunc functions mentioned above respectively. InitFunc only needs to be instrumented at the main entry of the user function of the operation control core. In addition, considering the low output efficiency on the operation cores, we transfer the data on the operation cores to the main core through DMA means and then output it uniformly.
[0056] Considering that in a program, it often occurs that another function is called in a loop. We add a filtering function when recording data in EnterFunc, that is, when there is an existing data item that is exactly the same as the current record in the existing records, the current record is not stored repeatedly, which will greatly reduce the overhead of DA.
[0057] The result display module implements displaying the recorded data in the storage order, and based on the L value in the record, it realizes the hierarchical display of the multi-way tree, that is, L + 1 is displayed as the child node of L. In addition, based on the libbfd library, it realizes the function of converting the PC value to the function name, and displays the result with better readability to the user.
[0058] When adopting the above-mentioned heterogeneous multi-core program dynamic call tree analysis device and analysis method, it is oriented to domestic heterogeneous multi-core processors, based on the automatic instrumentation of the compiler, with a simple algorithm and low overhead. Users can obtain the dynamic call tree of the program through one run, which can effectively make up for the deficiencies of static analysis and improve the efficiency of code logic analysis.
[0059] To facilitate a better understanding of the present invention, the following will briefly explain the terms used in this article:
[0060] Code logic analysis: Analyze the internal logic of the code.
[0061] Heterogeneous many-core program: A program compiled and run on a heterogeneous many-core processor.
[0062] Call tree: A description of the call relationships between various procedures (functions) in a program, usually expressed in the form of a multi-way tree.
[0063] Dynamic call tree: Refers to the call tree formed by the call relationships of each function during the dynamic running process of the program.
[0064] PC value: Program Counter value, used to represent the position of the instruction executed at a certain moment in the program.
[0065] Main entry of user function: Refers to the entry of the function encoded by the user in the program, such as the main function in a C program, etc.
[0066] libbfd: BFD (Binary format descriptor), that is, a binary file format descriptor. It is the standard interface for the linker tool (ld) and the binary operation tool (bin-util) to operate on binary object files. libbfd is a library that implements the interface of BFD and can be used in the present invention to convert the PC value into a function name.
[0067] The above embodiments are only for illustrating the technical concept and features of the present invention, and the purpose is to enable those who are familiar with this technology to understand the content of the present invention and implement it accordingly. It cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made according to the spirit and essence of the present invention should be covered within the protection scope of the present invention.
Claims
1. A dynamic call tree analysis device for heterogeneous multi-core programs, characterized in that: Includes the following functional modules: The instrumentation library is used to record dynamic call tree information during program execution; The result display module is used to display the dynamic call tree information of the program, display the recorded data in the order in which they are stored, and implement the hierarchical display of the multi-branch tree based on the L value in the record, that is, L+1 is displayed as a child node of L; The instrumentation library includes an InitFunc function, an EntryFunc function, a LeaveFunc function, a STACKPC data structure and a DA data structure, wherein the STACKPC is a stack structure, the DA is a sequential storage structure, and both the STACKPC and the DA support dynamic expansion; The InitFunc function is called at the beginning of all user programs to apply for initial storage space and initialize L value of STACKPC and DA data structures; The EntryFunc function is used to push the function entry PC value to STACKPC and is responsible for recording data, where each data entry consists of the current stack layer L, the PC value stored in the current stack layer L, and the PC stored in the L-1 stack layer, recorded as D (L, PC, CPC). When L=0, that is, there is no caller of the current function, making CPC=0; The LeaveFunc function is used to implement a pop operation and output DA when the stack is empty.
2. A method for dynamic call tree analysis of heterogeneous many-core programs, characterized by: The heterogeneous multi-core program dynamic call tree analysis device according to claim 1 comprises the following steps: S1. Modify the compiler source code and add a compilation option, which is to insert the InitFunc function before the user's main function, insert the EntryFunc function at the entrance of each user function, and insert the LeaveFunc function at the exit of each user function; S2. Compile the program using the newly added compilation options in S1; S3, run the program generated in S2; S4. When the program runs to InitFunc in S3, InitFunc applies for space and initializes the operation control core and the L value of the operation to -1; S5. When the program runs to EnterFunc, the L value is increased by 1, and it is checked whether D (L, PC, CPC) exists in STACKPC. If not, a new record is added to DA. If it exists, the record of the record is filtered out, and only one record (L, PCB, PCA) is saved in DA. S6. When the program runs to LeaveFunc, the L value is reduced by 1. If the L value is equal to -1, an output operation is performed. At this time, if it is in the operation core, the record is transferred to the operation control core through DMA. If it is the operation control core, the record is output to a file. The record includes the operation core and the operation control core. S7. After all records in S6 are output to the file, the result display module is called for display.
3. A method for dynamic call tree analysis of heterogeneous many-core programs according to claim 2, characterized in that: In S7, the display module outputs the data of the operation control core and each operation core respectively according to the recorded order.
4. The method for dynamic call tree analysis of heterogeneous many-core programs according to claim 3, characterized in that: The output method for each record is: first indent L blank characters, then output the recorded PC value conversion function name through the libbfd library, and then wrap.
Citation Information
Patent Citations
Data distribution and local optimization method for heterogeneous many-core architecture multi-level storage structure
CN103226487A
Cost model-based polyhedron optimization method for heterogeneous many-core rear end
CN112558977A