Tracking data generation method and device and electronic equipment
By generating trace data within the program pointer range, the problem of excessive trace data volume is solved, improving the efficiency and accuracy of processor performance analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- LOONGSON TECH CORP
- Filing Date
- 2025-12-05
- Publication Date
- 2026-04-28
AI Technical Summary
In existing technologies, the amount of trace data generated during program execution is too large, resulting in low efficiency of performance analysis.
By obtaining the instruction address of the branch instruction as the program pointer, and using register read/write commands to obtain and store the start and end pointers, trace data is generated only when the program pointer is within the range of the start and end pointers, and branch instruction data outside the range is filtered out.
This effectively reduces the total amount of tracking data, improves processing efficiency, ensures that only necessary tracking data is generated, and enhances the accuracy and efficiency of performance analysis.
Smart Images

Figure CN121934895A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of processor technology, and in particular to a method, apparatus and electronic device for generating tracking data. Background Technology
[0002] Currently, in order to optimize the program, performance analysis is required. Accordingly, it is necessary to obtain trace data generated during program execution to facilitate performance analysis based on this data.
[0003] In related technologies, trace data is often generated directly based on the instruction information of each branch instruction submitted by the processor during program execution. This approach suffers from the problem of generating excessively large amounts of trace data. Summary of the Invention
[0004] This invention provides a tracking data generation method, apparatus, and electronic device that can solve the problem of excessively large amounts of generated tracking data.
[0005] To address the aforementioned problems, this invention discloses a tracking data generation method, the method comprising: If a branch instruction is received from the processor, the instruction address of the branch instruction is obtained and used as the program pointer; Based on the preset register read command, read the value of the start pointer storage bit and the value of the end pointer storage bit of the specified register; The value of the read start pointer storage bit is determined as the start pointer, and the value of the read end pointer storage bit is determined as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data; The program pointer is compared with the start pointer and the end pointer respectively; If the program pointer is not less than the start pointer and not greater than the end pointer, then corresponding trace data is generated for the branch instruction based on the instruction-related information of the branch instruction.
[0006] On the other hand, embodiments of the present invention disclose a tracking data generation apparatus, the apparatus comprising: The acquisition module is used to acquire the instruction address of the branch instruction submitted by the processor if it receives the branch instruction, and use it as a program pointer; The first read module is used to read the value of the start pointer storage bit and the value of the end pointer storage bit of a specified register based on a preset register read command; The determining module is used to determine the value of the read start pointer storage bit as the start pointer and the value of the read end pointer storage bit as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through preset register write commands, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data; The comparison module is used to compare the program pointer with the start pointer and the end pointer respectively; The first generation module is used to generate corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction if the program pointer is not less than the start pointer and the program pointer is not greater than the end pointer.
[0007] In another aspect, embodiments of the present invention disclose an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, the executable instruction causing the processor to execute the aforementioned method.
[0008] This invention also discloses a machine-readable medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described above.
[0009] The embodiments of the present invention include the following advantages: In the trace data generation method provided by the embodiments of the present invention, if a branch instruction submitted by the processor is received, the instruction address of the branch instruction is obtained as a program pointer. Based on a preset register read command, the values of the start pointer storage bit and the end pointer storage bit of the specified register are read. The read value of the start pointer storage bit is determined as the start pointer, and the read value of the end pointer storage bit is determined as the end pointer. The start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command. The start pointer is used to represent the minimum instruction address when recording trace data, and the end pointer is used to represent the maximum instruction address when recording trace data. The program pointer is compared with the start pointer and the end pointer respectively. If the program pointer is not less than the start pointer and the program pointer is not greater than the end pointer, then the corresponding trace data is generated for the branch instruction based on the instruction-related information of the branch instruction. In the embodiments of the present invention, the corresponding trace data is only generated for the branch instruction when the program pointer of the branch instruction is not less than the start pointer and the program pointer is not greater than the end pointer. In this way, the number of trace data generated can be reduced, thereby reducing the overall data volume of the trace data and avoiding the problem of excessively large trace data volume.
[0010] Furthermore, the start and end pointers are pre-written into the start and end pointer storage bits of a specified register using preset register write commands. Subsequently, the start and end pointers can be obtained by reading the start and end pointer storage bits of the specified register using register read commands. This operation is relatively convenient and therefore has higher processing efficiency. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of the steps of a tracking data generation method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a processing flow provided in an embodiment of the present invention; Figure 3 This is a schematic diagram illustrating the implementation of a hardware tracking branch recording device provided in an embodiment of the present invention; Figure 4 This is a block diagram of a tracking data generation device provided in an embodiment of the present invention; Figure 5This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0013] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0014] Figure 1 This is a flowchart of the steps of a tracking data generation method provided in an embodiment of the present invention, as follows: Figure 1 As shown, the tracking data generation method may include the following steps: Step 101: If a branch instruction is received from the processor, obtain the instruction address of the branch instruction as the program pointer.
[0015] Step 102: Based on the preset register read command, read the value of the start pointer storage bit and the value of the end pointer storage bit of the specified register.
[0016] Step 103: Determine the value of the read start pointer storage bit as the start pointer, and determine the value of the read end pointer storage bit as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data.
[0017] Step 104: Compare the program pointer with the start pointer and the end pointer respectively.
[0018] Step 105: If the program pointer is not less than the start pointer and the program pointer is not greater than the end pointer, then generate corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction.
[0019] In this embodiment, steps 101 and 102-103 can be executed in parallel or sequentially, and this embodiment of the invention does not impose any restrictions on this. For a branch instruction submitted by the processor, upon receiving the submitted branch instruction, the processor can obtain the program pointer of the branch instruction and the start and end pointers of a preset program pointer range. When the processor submits, it can submit the branch instruction itself, the instruction-related information of the branch instruction, and the program pointer of the branch instruction. The preset program pointer range can be user-defined. The start and end pointers constitute the preset program pointer range. If the program pointer of the branch instruction is within the preset program pointer range formed by the start and end pointers, it can be determined that corresponding trace data needs to be generated for the branch instruction. Otherwise, it is determined that corresponding trace data does not need to be generated for the branch instruction. This is equivalent to implementing trace data filtering based on program pointers. Specifically, for any branch instruction in the program under test, after the branch instruction is executed, the processor sends the branch instruction itself, the instruction-related information of the branch instruction, and the program pointer of the branch instruction to the hardware trace branch recording device to achieve submission.
[0020] Furthermore, the start pointer and end pointer are preset by the user according to their needs, meaning the user can customize the program pointer range as needed. If the program pointer is not less than the start pointer and not greater than the end pointer, it can be determined that the program pointer of the branch instruction is within the preset program pointer range. This means the user needs to know the trace data corresponding to the branch instruction before generating the corresponding trace data for that branch instruction. This effectively filters out trace data corresponding to branch instructions whose program pointers are outside the preset program pointer range from the final trace data. This allows subsequent analysis based on the trace data to ignore trace data of branch instructions outside the preset program pointer range, enabling the user to focus only on trace data within the preset program pointer range. In this embodiment, the program pointer is the instruction address of the branch instruction, and the start and end pointers are preset instruction addresses. Therefore, the program pointer can be compared with the start and end pointers. The preset minimum instruction address (i.e., the start pointer) and the preset maximum instruction address (i.e., the end pointer) can be stored in designated registers. An instruction address represents a memory address; if the value represented by one instruction address is greater than the value represented by another instruction address, then that instruction address is considered greater than the other instruction address. For example, assuming the start pointer is 0x1000, the end pointer is 0x6000, and the program pointer is 0x1040, then it can be determined that the program pointer is greater than the start pointer and less than the end pointer.
[0021] Specifically, branch instructions, also known as branch type instructions, alter the control flow of program execution. For example, the branch type of a branch instruction can include function call type, function return type, indirect jump type, unconditional jump type, conditional jump type, unconditional loop type, and conditional loop type, etc. Instruction-related information includes information needed to generate trace data. The types of information included in the instruction-related information can be set according to actual needs, and this embodiment of the invention does not limit this. For example, instruction-related information can include instruction type, timestamp, branch instruction program pointer, target address, offset address, and performance counter information. The performance counter information can be the current value of a specified performance counter. The instruction-related information and program pointer of the branch instruction are submitted by the processor when submitting the branch instruction.
[0022] The tracking data generation method provided in this invention can be applied to electronic devices, specifically to a tracking data generation device within an electronic device. This tracking data generation device can be used to implement a program pointer-based filtering function. This tracking data generation device can also be called a hardware tracking branch recording device, which can be located within a processor. This tracking data generation method can be executed during program execution, and the program can be any program under test within the electronic device. The program under test can include functions, each containing multiple instructions. Execution of the program under test is achieved by executing these instructions. During execution, the processor can submit instructions to be tracked, such as branch instructions. The processor can submit the currently executed branch instructions to the hardware tracking branch recording device. It should be noted that the instructions to be tracked may include non-branch instructions; therefore, for instructions submitted by the processor, it can be first determined whether the instruction is a branch instruction.
[0023] The instruction-related information of a branch instruction can be used as the trace data corresponding to that branch instruction to generate corresponding trace data for that branch instruction. This achieves the purpose of recording relevant information about branch instructions during program execution. The trace data can ultimately be written to a designated memory buffer, which is a specially allocated memory buffer for storing trace data. It should be noted that in this embodiment of the invention, the branch instruction can be an instruction from any instruction set architecture, and this embodiment of the invention does not impose any limitations on this. Alternatively, the received branch instruction itself can be temporarily stored, and the instruction-related information of the branch instruction, along with the branch instruction itself, can be used as the trace data corresponding to that branch instruction.
[0024] In this embodiment of the invention, the designated register can be a configuration register supported by the instruction set architecture followed by the program under test. The designated register can be selected from reserved registers of that instruction set architecture and is used to configure the start and end pointers. User-defined instruction addresses can be pre-written to the start and end pointer storage bits of the designated register using pre-defined register write commands via software code for configuring the designated register, thereby configuring the start and end pointers. The value of both the start and end pointer storage bits can be n bits, where n can be set according to the length of the required value to ensure that the start and end pointer storage bits can accommodate the required value.
[0025] The preset register write and read commands can be any write and read commands supported by the instruction set architecture. For example, the preset register write command can be the `csrwr` or `csrxchg` command, and the preset register read command can be the `csrrd` command. Furthermore, when it is necessary to compare the program pointer of a branch instruction with the start and end pointers, the preset register read command can be used to read the current values of the start and end pointer storage bits from the specified registers, which will then serve as the start and end pointers.
[0026] In summary, in the trace data generation method provided by this embodiment of the invention, if a branch instruction submitted by the processor is received, the instruction address of the branch instruction is obtained as the program pointer. Based on a preset register read command, the values of the start pointer storage bit and the end pointer storage bit of a specified register are read. The read value of the start pointer storage bit is determined as the start pointer, and the read value of the end pointer storage bit is determined as the end pointer. The start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command. The start pointer is used to represent the minimum instruction address when recording trace data, and the end pointer is used to represent the maximum instruction address when recording trace data. The program pointer is compared with the start pointer and the end pointer respectively. If the program pointer is not less than the start pointer and not greater than the end pointer, then corresponding trace data is generated for the branch instruction based on the instruction-related information of the branch instruction. In this embodiment of the invention, trace data is generated for the branch instruction only when the program pointer of the branch instruction is not less than the start pointer and not greater than the end pointer. This reduces the number of trace data generated, thereby reducing the overall data volume of the trace data and avoiding the problem of excessively large trace data volume.
[0027] Furthermore, the start and end pointers are pre-written into the start and end pointer storage bits of a specified register using preset register write commands. Subsequently, the start and end pointers can be obtained by reading the start and end pointer storage bits of the specified register using register read commands. This operation is relatively convenient and therefore has higher processing efficiency.
[0028] Optionally, the operation of obtaining the program pointer of the branch instruction in this embodiment of the invention may specifically include: Step 1011: Obtain the instruction address of the branch instruction as the program pointer; the start pointer is used to represent the minimum instruction address when recording trace data, and the end pointer is used to represent the maximum instruction address branch instruction when recording trace data.
[0029] In this embodiment of the invention, obtaining the instruction address of a branch instruction as a program pointer ensures that the program pointer uniquely represents the branch instruction. During the execution of the program under test, the processor loads and executes the instruction at the value of the program counter (PC) register. After executing the instruction, the value of the PC register is increased by the length of the current instruction to update the PC register value. Then, the processor continues to load and execute the instructions at the value of the PC register. In this way, the processor can execute the instructions of the program under test sequentially. The instruction address of a branch instruction refers to the value of the PC register when the branch instruction is executed; the value of the PC register is the instruction address of the branch instruction. The processor can receive the instruction address of the branch instruction submitted by the processor to achieve retrieval. Correspondingly, the start pointer is the minimum value that the instruction address of the branch instruction must satisfy, as predefined by the user, and the end pointer is the maximum value that the instruction address of the branch instruction must satisfy, predefined by the user.
[0030] Optionally, step 104 may include: step 1041, determining whether the program pointer of the branch instruction is not less than the start pointer, and determining whether the program pointer of the branch instruction is not greater than the end pointer.
[0031] Specifically, the program pointer of the branch instruction can be compared with the start pointer to determine if the program pointer of the branch instruction is not less than the start pointer, and the program pointer of the branch instruction can be compared with the end pointer to determine if the program pointer of the branch instruction is not greater than the end pointer. The execution order of the two judgment operations is not unique. For example, these two judgment operations can be executed simultaneously, or the program pointer can be judged first to determine if it is not less than the start pointer, and then judged if it is not greater than the end pointer. Alternatively, the program pointer can be judged first to determine if it is not greater than the end pointer, and then judged if it is not less than the start pointer. In this embodiment of the invention, by judging whether the program pointer of the branch instruction is not less than the start pointer, and whether the program pointer of the branch instruction is not greater than the end pointer, it can be determined whether the program pointer of the branch instruction is within a preset program pointer range, which can ensure processing efficiency to a certain extent.
[0032] Optionally, determining whether the program pointer of the branch instruction is less than the starting pointer includes: subtracting the starting pointer from the program pointer of the branch instruction to obtain a first difference; if the first difference is not less than 0, determining that the program pointer is not less than the starting pointer; if the first difference is less than 0, determining that the program pointer is less than the starting pointer.
[0033] The step of determining whether the program pointer of the branch instruction is greater than the end pointer includes: subtracting the end pointer from the program pointer of the branch instruction to obtain a second difference; if the second difference is not greater than 0, determining that the program pointer is not greater than the end pointer; if the second difference is greater than 0, determining that the program pointer is greater than the end pointer.
[0034] Specifically, the instruction address of the branch instruction can be compared with the smallest instruction address represented by the start pointer. For example, the first difference is calculated by subtracting the smallest instruction address from the branch instruction's instruction address. If this first difference is not less than 0, it can be determined that the program pointer of the branch instruction is not less than the start pointer. Otherwise, it can be determined that the program pointer of the branch instruction is less than the start pointer. Further, the instruction address of the branch instruction can be compared with the largest instruction address represented by the end pointer. For example, the second difference is calculated by subtracting the largest instruction address from the branch instruction's instruction address. If this second difference is not greater than 0, it can be determined that the program pointer of the branch instruction is not greater than the end pointer. Otherwise, it can be determined that the program pointer of the branch instruction is greater than the end pointer. Thus, by calculating the differences between the program pointer of the branch instruction and the start and end pointers, the relative sizes of the branch instruction's program pointer and these pointers can be easily determined.
[0035] Optionally, embodiments of the present invention may further include the following steps: Step S21: If the program pointer is less than the start pointer, or the program pointer is greater than the end pointer, then no trace data is generated for the branch instruction.
[0036] Step S22: If the preset termination condition has not been met, return to the step of obtaining the instruction address of the branch instruction as a program pointer if a branch instruction submitted by the processor is received and continue execution.
[0037] In this embodiment of the invention, the preset program pointer range can correspond to a specific segment that the software analyst needs to analyze. The specified address of the starting instruction of the specific segment can be used as the starting pointer of the preset program pointer range, and the specified address of the starting instruction of the specific segment can be used as the ending pointer of the preset program pointer range. In practical applications, before analyzing the program under test, software analysts often obtain the program segments they want to further analyze through preset methods. These preset methods may include analyzing hot-spot functions or hot-spot basic blocks. Correspondingly, the specific segment can be a segment corresponding to the hot-spot function to be analyzed or a segment corresponding to the hot-spot basic block. In this case, software analysts often need to obtain only the trace data corresponding to the branch instructions within the specific segment, and do not want to include trace data corresponding to branch instructions outside the specific segment. That is, during program analysis, only the hot-spot segments within the preset program pointer range are considered, and the trace data of non-hot-spot segments are ignored.
[0038] In this embodiment of the invention, if the program pointer is less than the start pointer, or greater than the end pointer, it indicates that the program pointer of the branch instruction is outside the preset program pointer range. Therefore, it can be determined that the user does not need to know the trace data corresponding to that branch instruction. Thus, the relevant information of that branch instruction can be directly discarded, and no corresponding trace data can be generated for that branch instruction. In this way, based on the program pointer filtering mechanism, trace data corresponding to branch instructions within non-specific segments can be effectively filtered out, reducing unimportant branch record trace data. This allows the trace data of branch instructions outside the preset program pointer range to be ignored during subsequent analysis based on the trace data, enabling the user to focus only on the trace data within the preset program pointer range.
[0039] Specifically, temporarily stored instruction-related information, as well as the branch instruction and its program pointer, can be discarded. Furthermore, the preset termination condition can include all instructions of the program under test being executed, i.e., the program under test has been completed. In other words, after executing step 105 or step S21, if there are still instructions that have not been executed, i.e., the preset termination condition has not been met, execution will restart from step 101 until the program under test is completed.
[0040] In this embodiment of the invention, if the program pointer is less than the start pointer or greater than the end pointer, no trace data is generated for the branch instruction. If the preset termination condition has not been met, execution returns to step 101. This allows for continuous determination of whether trace data needs to be generated for the branch instruction based on the program pointer during the execution of the program under test, thereby ensuring the filtering effect.
[0041] In this embodiment of the invention, based on other tracking data filtering mechanisms, the tracking data generation method provided by this embodiment can further filter tracking data of branch instructions outside the preset program pointer range, thereby further reducing the amount of tracking data. Specifically, it can detect whether a branch instruction is a branch instruction that needs to be filtered in the tracking data filtering mechanism. If it is, then no corresponding tracking data is generated for that branch instruction, so as to achieve filtering according to the tracking data filtering mechanism. If it is not, then the corresponding tracking data is generated for that branch instruction only when the tracking data generation method provided by this embodiment determines that corresponding tracking data needs to be generated for that branch instruction.
[0042] Optionally, before generating corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction, the embodiments of the present invention further include the following steps: Step S31: Determine whether the privilege level of the branch instruction is a preset filtering level, and determine whether the branch type of the branch instruction is a preset filtering type.
[0043] Accordingly, the step of generating corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction may specifically include: step 1051, when the privilege level of the branch instruction is not the filter level and the branch type of the branch instruction is not the filter type, generating corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction.
[0044] Filtering based on preset privilege levels can be considered a type of trace data filtering mechanism, ensuring security by disabling specific privilege levels. Filtering based on preset filter types can also be considered a trace data filtering mechanism. Thus, filtering by branch type and privilege level can effectively reduce trace data. Further reducing trace data by pre-setting trace data for branch instructions outside the program pointer range can further decrease trace data. Specifically, when privilege level filtering is enabled, it can determine whether the privilege level of the branch instruction is a preset filter level, i.e., whether it is a branch instruction that needs to be filtered under the filtering mechanism based on privilege level. When type filtering is enabled, it can determine whether the branch type of the branch instruction is a preset filter type, i.e., whether it is a branch instruction that needs to be filtered under the filtering mechanism based on type.
[0045] The preset filtering level can be the privilege level of branch instructions that do not require trace data generation. Privilege levels can include kernel mode, user mode, and virtualization mode. If the branch instruction is in kernel code, its privilege level is determined to be kernel mode; if it is in user code, its privilege level is determined to be user mode; and if it is in virtualization code, its privilege level is determined to be virtualization mode. For any privilege level, disabling it will set it as the filtering level. The preset filtering type can be the instruction type of branch instructions that do not require trace data generation. The filtering level and type can be preset by the user according to actual needs. For any branch type, disabling it will set it as the filtering type. For example, the Last Branch Record (LBR) select register can provide fields corresponding to each privilege level and branch type. Setting a field to 1 enables the corresponding privilege level or branch type. Setting a field to 0 disables the corresponding privilege level or branch type. Accordingly, if the field corresponding to the privilege level of a branch instruction is 0, it can be determined that the privilege level of the branch instruction is a preset filtering level; otherwise, it can be determined that the privilege level of the branch instruction is not a preset filtering level. Similarly, if the field corresponding to the branch type of a branch instruction is 0, it can be determined that the branch type of the branch instruction is a preset filtering type; otherwise, it can be determined that the branch type of the branch instruction is not a preset filtering type.
[0046] If the privilege level of the branch instruction is a filter level or the branch type is a filter type, then trace data can be generated for the branch instruction without relying on its instruction-related information, thus achieving filtering. Conversely, if the privilege level of the branch instruction is not a filter level and the branch type is not a filter type, then trace data will be generated for the branch instruction based on its instruction-related information only if the program pointer of the branch instruction is not less than the start pointer and not greater than the end pointer.
[0047] Optionally, the designated register further includes a pointer filtering enable bit. Accordingly, embodiments of the present invention may also include the following steps: Step S41: Based on the register read command, read the value of the pointer filtering function enable bit of the instruction register.
[0048] Step S42: When the value of the pointer filtering function enable bit indicates that the function is enabled, execute the steps of obtaining the program pointer of the branch instruction if a branch instruction is received from the processor, and obtaining the start pointer and end pointer of a custom preset program pointer range.
[0049] Step S43: If the value of the pointer filtering function enable bit indicates that it is not enabled, generate corresponding trace data for the branch instruction directly based on the instruction-related information of the branch instruction.
[0050] The pointer filtering enable bit can be 1 bit. This bit enables filtering based on the program pointer. When enabled, the steps described above—if a branch instruction is received from the processor, obtaining the instruction address of that branch instruction as the program pointer, and obtaining the start and end pointers of a custom preset program pointer range—can be executed to determine whether to generate corresponding trace data for that branch instruction. When disabled, step 101 is not executed, meaning the determination of whether to generate corresponding trace data for that branch instruction is not based on the start and end pointers. This allows users to flexibly control whether filtering is based on the program pointer, improving the flexibility of the solution. It should be noted that in another implementation, the pointer filtering function can be enabled by default, i.e., step 101 is executed by default; this embodiment of the invention does not impose any restrictions on this.
[0051] The pointer filtering enable bit can be configured by pre-writing a value to the pointer filtering enable bit of a specified register using a preset register write command. For example, 0 or 1 can be written to the pointer filtering enable bit. This specified register can also be called the program pointer filtering mechanism related configuration register, and the specified register may include the register bits described in Table 1 below:
[0052] Table 1 The filter enable bit, start pointer storage bit, and end pointer storage bit can be located in the same register, and they do not overlap. For example, the specified register can be a 64-bit register, the filter enable bit can be bit 0 of the specified register, the start pointer storage bit can be bit 1 to bit 17 of the specified register, and the end pointer storage bit can be bit 18 to bit 34 of the specified register.
[0053] First, a preset register read command can be used to read the value of the pointer filtering enable bit from a specified register. If the value of the pointer filtering enable bit indicates that it is not enabled, it can be determined that the program pointer filtering mechanism is not currently enabled, and corresponding trace data can be generated directly for the branch instruction based on the instruction-related information of the branch instruction. If the value of the pointer filtering enable bit indicates that it is enabled, it can be determined that the program pointer filtering mechanism is currently enabled, i.e., step 101 is executed, so as to determine whether to generate trace data based on whether the program pointer belongs to the preset program pointer range. That is to say, in this embodiment of the invention, specifically, when the program pointer filtering mechanism is enabled, if the program pointer is less than the start pointer or greater than the end pointer, corresponding trace data is not generated for the branch instruction. Specifically, if the value of the pointer filtering enable bit is 0, it can be determined that the pointer filtering enable bit indicates that it is not enabled. If the value of the pointer filtering enable bit is 1, it can be determined that the pointer filtering enable bit indicates that it is enabled. It should be noted that if the branch record configuration is modified, for example, if the pointer filtering enable bit is changed to 0 to disable the program pointer filtering function, the above trace data generation method can also be terminated.
[0054] In this embodiment of the invention, the value of the pointer filtering enable bit in a specified register is read based on a register read command. If the value of the pointer filtering enable bit indicates that it is disabled, then corresponding trace data is directly generated for the branch instruction based on the instruction-related information of the branch instruction. If the value of the enable bit indicates that it is enabled, then the operations of obtaining the program pointer of the branch instruction, and obtaining the start and end pointers of a custom preset program pointer range are performed. In this way, by configuring the value of the pointer filtering enable bit, the activation or deactivation of the program pointer filtering mechanism can be conveniently controlled.
[0055] It should be noted that, in one implementation, the processor can generate corresponding trace data for branch instructions by default; in another implementation, the processor can set a branch recording mechanism enable bit. When this enable bit is set to a valid value (e.g., set to 1), the branch recording mechanism is enabled. Specifically, in this embodiment of the invention, the above-described trace data generation method can be executed when the processor's branch recording mechanism is enabled. Enabling the branch recording mechanism refers to enabling the function of generating corresponding trace data for branch instructions.
[0056] Figure 2 This is a schematic diagram of a processing flow provided by an embodiment of the present invention, such as... Figure 2 As shown, this processing flow can be implemented through both software and hardware in an electronic device. Specifically, the start and end pointers, the program pointer filtering function for branch records, and the branch record mechanism can be configured first through software. Of course, in practical applications, other branch record configurations can also be performed, such as configuring preset filtering levels and preset filtering types. Next, the program under test can be run through software for performance analysis. Then, the branch instruction submission operation is executed through hardware; for example, the processor can submit the branch instruction, instruction-related information, and the program pointer of the branch instruction. Then, it can be determined whether the program pointer of the branch instruction is not less than the start pointer and not greater than the end pointer. If so, the corresponding trace data can be generated.
[0057] It should be noted that when the program pointer filtering function is not enabled, corresponding trace data can be directly generated for branch instructions. Furthermore, hardware can be used to repeatedly execute the code until a preset termination condition is met, such as the program under test completing execution or the branch record configuration being modified. Upon reaching the preset termination condition, hardware tracing of branch records can be disabled via software, i.e., the trace data generation function can be turned off, and the trace data can be exported.
[0058] Furthermore, the hardware tracing branch recording device may include the hardware and software required to filter tracing data outside the preset program pointer range. For example, it may include the aforementioned designated register, software for configuring the designated register, software for implementing the aforementioned tracing data generation method, and hardware components required to run the aforementioned tracing data generation method.
[0059] Figure 3 This is a schematic diagram illustrating the implementation of a hardware tracking branch recording device provided in an embodiment of the present invention, as shown below. Figure 3As shown, the hardware tracing branch recording device may include branch type judgment logic, instruction program pointer greater than or equal to / less than or equal to judgment logic, program pointer filtering judgment logic, instruction information temporary register, tracing data generator, and tracing data storage buffer. The branch type judgment logic, instruction program pointer greater than or equal to / less than or equal to judgment logic, and program pointer filtering judgment logic can be the circuit structure of the hardware tracing branch recording device, and the temporary register can be a memory with storage function.
[0060] The processor's commit logic can commit branch instructions, branch instruction information, and program pointers to the instruction information register. Furthermore, it can commit the instruction type to the branch type determination logic to confirm whether the committed instruction is a branch instruction. If so, the committed information is temporarily stored. Further, the instruction program pointer greater than or equal to / less than or equal to the instruction type determination logic checks whether the branch instruction's program pointer is not less than the start pointer and whether it is not greater than the end pointer, and submits the determination result to the program pointer filtering logic. The program pointer filtering logic determines whether to generate corresponding trace data for the branch instruction based on the determination result. If the program pointer filtering logic determines that corresponding trace data needs to be generated for the branch instruction (i.e., the program pointer is not less than the start pointer and not greater than the end pointer), trace data is generated by the trace data generator. The trace data generator then caches the generated trace data in the trace data storage cache and writes it to the memory buffer via the last-level cache. If the program pointer is less than the start pointer or greater than the end pointer, the previously stored information is discarded.
[0061] This invention can be specifically applied to the fields of post-silicon performance analysis and performance monitoring of microprocessors. In practical scenarios, code segments such as functions, loops, and basic blocks are often the main code locations where performance bottlenecks occur. Accordingly, current performance analysis transforms the analysis of the entire program into the analysis of specific code segments such as functions, loops, and basic blocks within the program. During program execution, these code segments are demarcated by branch instructions; branch instructions are executed when these code segments begin or end execution. Therefore, by generating corresponding trace data for branch instructions, performance data support can be provided for performance analysis. For example, by reading this trace data, analysts can obtain performance data and execution time when the program execution control flow changes, and further performance analysis can be performed on code segments such as functions, loops, and basic blocks within the control flow analysis demarcated by branch instructions.
[0062] In related technologies, processor manufacturers offer various hardware tracing branch recording solutions, such as LBR and Processor Trace (PT). However, these solutions directly generate corresponding trace data for every committed branch instruction, requiring the hardware to record trace data for all branch instructions. Since programs often contain a large number of branch instructions, this leads to excessive trace data volume. This necessitates significant storage space, resulting in higher hardware costs and area overhead, as well as higher power consumption for generating and storing trace data. Furthermore, excessive trace data volume increases trace data export time, impacting processor performance and increasing performance analysis time overhead. Additionally, generating trace data for a large number of branch instructions may cause instruction commit pauses during program execution, further increasing execution time and reducing performance.
[0063] In this embodiment of the invention, a program pointer filtering mechanism is added to the hardware tracing branch recording device. Based on user-defined start and end pointers, branch instructions where the program pointer is less than the start pointer or greater than the end pointer do not generate tracing data. This effectively reduces the amount of tracing data, thereby reducing the recording of unimportant performance data, reducing redundant tracing data, and effectively reducing the amount of tracing data, allowing for better subsequent analysis. Simultaneously, the reduced amount of tracing data saves storage space, reduces hardware costs and area overhead, lowers power consumption for generating and storing tracing data, saves tracing data export time, improves processor performance, and reduces performance analysis time. Furthermore, it avoids the problem of instruction submission pauses during program execution caused by tracing data generation, which increases program execution time and reduces program performance.
[0064] Reference Figure 4 The diagram shows a block diagram of a tracking data generation device provided in an embodiment of the present invention, such as... Figure 4 As shown, the tracking data generation device may specifically include: The acquisition module 201 is used to acquire the instruction address of the branch instruction if a branch instruction submitted by the processor is received, and use it as a program pointer; The first reading module 202 is used to read the value of the start pointer storage bit and the value of the end pointer storage bit of a specified register based on a preset register read command; The determining module 203 is used to determine the value of the read start pointer storage bit as the start pointer and the value of the read end pointer storage bit as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through preset register write commands, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data; Comparison module 204 is used to compare the program pointer with the start pointer and the end pointer respectively; The first generation module 205 is used to generate corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction if the program pointer is not less than the start pointer and the program pointer is not greater than the end pointer.
[0065] The acquisition module 201 corresponds to the aforementioned branch type judgment logic and instruction information register. The acquisition module 201 judges the instructions submitted by the processor using the branch type judgment logic. If it determines that a branch instruction submitted by the processor has been received, it reads the instruction address of the branch instruction from the instruction information register as the program pointer. The first reading module 202 and the determination module 203 correspond to the aforementioned branch type judgment logic. When the first reading module 202 and the determination module 203 determine that a branch instruction submitted by the processor has been received using the branch type judgment logic, they obtain the start and end pointers of a preset program pointer range from the start and end pointer storage bits of the specified registers. The comparison module 204 includes the aforementioned instruction program pointer greater than or equal to / less than or equal to judgment logic. The comparison module 204 compares the program pointer with the start and end pointers respectively using the instruction program pointer greater than or equal to / less than or equal to judgment logic to determine the size relationship between the program pointer and the start and end pointers. The first generation module 205 includes the aforementioned program pointer filtering and judgment logic, a trace data generator, and a trace data storage buffer. The first generation module 205 uses the program pointer filtering and judgment logic to determine whether to generate corresponding trace data for a branch instruction based on the judgment result of the instruction program pointer being greater than or equal to / less than or equal to judgment logic. Specifically, if the judgment result is that the program pointer is not less than the start pointer and not greater than the end pointer, the trace data generator generates corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction and stores it in the trace data storage buffer.
[0066] Optionally, the comparison module 204 is specifically used for: Determine whether the program pointer of the branch instruction is not less than the start pointer, and determine whether the program pointer of the branch instruction is not greater than the end pointer.
[0067] Optionally, the comparison module 204 is further configured to: Subtract the starting pointer from the program pointer of the branch instruction to obtain the first difference; If the first difference is not less than 0, it is determined that the program pointer is not less than the start pointer; If the first difference is less than 0, it is determined that the program pointer is less than the start pointer; Subtract the end pointer from the program pointer of the branch instruction to obtain the second difference; If the second difference is not greater than 0, it is determined that the program pointer is not greater than the end pointer; If the second difference is greater than 0, it is determined that the program pointer is greater than the end pointer.
[0068] Optionally, the device further includes: The processing module is configured to not generate corresponding trace data for the branch instruction if the program pointer is less than the start pointer or the program pointer is greater than the end pointer. The return module is used to return to the step of obtaining the instruction address of the branch instruction as a program pointer if the preset termination condition has not been met, and continue execution.
[0069] Optionally, the designated register further includes a pointer filtering enable bit; the device further includes: The second read module is used to read the value of the pointer filtering function enable bit of the instruction register based on the register read command; The execution module is configured to, when the value of the pointer filtering function enable bit indicates that the pointer is enabled, execute the steps of obtaining the program pointer of the branch instruction if a branch instruction is received from the processor, and obtaining the start pointer and end pointer of a custom preset program pointer range. The second generation module is used to generate corresponding trace data for the branch instruction directly based on the instruction-related information of the branch instruction when the value of the pointer filtering function enable bit indicates that the branch instruction is not enabled.
[0070] In summary, in the trace data generation apparatus provided by this embodiment of the invention, if a branch instruction submitted by the processor is received, the instruction address of the branch instruction is obtained as the program pointer. Based on a preset register read command, the values of the start pointer storage bit and the end pointer storage bit of a specified register are read. The read value of the start pointer storage bit is determined as the start pointer, and the read value of the end pointer storage bit is determined as the end pointer. The start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command. The start pointer is used to represent the minimum instruction address when recording trace data, and the end pointer is used to represent the maximum instruction address when recording trace data. The program pointer is compared with the start pointer and the end pointer respectively. If the program pointer is not less than the start pointer and not greater than the end pointer, then corresponding trace data is generated for the branch instruction based on the instruction-related information of the branch instruction. In this embodiment of the invention, trace data is generated for the branch instruction only when the program pointer of the branch instruction is not less than the start pointer and not greater than the end pointer. This reduces the number of trace data generated, thereby reducing the overall data volume of the trace data and avoiding the problem of excessively large trace data volume.
[0071] Furthermore, the start and end pointers are pre-written into the start and end pointer storage bits of a specified register using preset register write commands. Subsequently, the start and end pointers can be obtained by reading the start and end pointer storage bits of the specified register using register read commands. This operation is relatively convenient and therefore has higher processing efficiency.
[0072] Reference Figure 5 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Figure 5 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus.
[0073] The processor, the memory, and the communication interface communicate with each other via the communication bus; the memory stores at least one executable instruction, which causes the processor to execute the tracking data generation method of the aforementioned embodiment. The executable instructions can form a program.
[0074] This invention provides a machine-readable medium storing instructions that, when executed by one or more processors, enable the processors to perform the tracking data generation method of the foregoing embodiments. The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0075] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0076] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.
[0077] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0078] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0079] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0080] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0081] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0082] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0083] The foregoing has provided a detailed description of a tracking data generation method, a tracking data generation device, an electronic device, and one or more readable media provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for generating tracking data, characterized in that, The method includes: If a branch instruction is received from the processor, the instruction address of the branch instruction is obtained and used as the program pointer; Based on the preset register read command, read the value of the start pointer storage bit and the value of the end pointer storage bit of the specified register; The value of the read start pointer storage bit is determined as the start pointer, and the value of the read end pointer storage bit is determined as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through a preset register write command, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data; The program pointer is compared with the start pointer and the end pointer respectively; If the program pointer is not less than the start pointer and not greater than the end pointer, then corresponding trace data is generated for the branch instruction based on the instruction-related information of the branch instruction.
2. The method according to claim 1, characterized in that, The step of comparing the program pointer with the start pointer and the end pointer respectively includes: Determine whether the program pointer of the branch instruction is not less than the start pointer, and determine whether the program pointer of the branch instruction is not greater than the end pointer.
3. The method according to claim 2, characterized in that, The step of determining whether the program pointer of the branch instruction is less than the starting pointer includes: Subtract the starting pointer from the program pointer of the branch instruction to obtain the first difference; If the first difference is not less than 0, it is determined that the program pointer is not less than the start pointer; If the first difference is less than 0, it is determined that the program pointer is less than the start pointer; The step of determining whether the program pointer of the branch instruction is greater than the end pointer includes: Subtract the end pointer from the program pointer of the branch instruction to obtain the second difference; If the second difference is not greater than 0, it is determined that the program pointer is not greater than the end pointer; If the second difference is greater than 0, it is determined that the program pointer is greater than the end pointer.
4. The method according to claim 1, characterized in that, The method further includes: If the program pointer is less than the start pointer, or if the program pointer is greater than the end pointer, then no trace data will be generated for the branch instruction; If the preset termination condition has not been met, return to the step of obtaining the instruction address of the branch instruction as a program pointer if a branch instruction submitted by the processor is received and continue execution.
5. The method according to any one of claims 1-4, characterized in that, The designated register also includes a pointer filtering enable bit; the method further includes: Based on the register read command, read the value of the pointer filtering enable bit of the instruction register; When the value of the pointer filtering function enable bit indicates that the function is enabled, the steps of obtaining the program pointer of the branch instruction if a branch instruction is received from the processor, and obtaining the start pointer and end pointer of a custom preset program pointer range are executed. When the value of the pointer filtering function enable bit indicates that it is not enabled, the corresponding trace data is directly generated for the branch instruction based on the instruction-related information of the branch instruction.
6. A tracking data generation device, characterized in that, The device includes: The acquisition module is used to acquire the instruction address of the branch instruction submitted by the processor if it receives the branch instruction, and use it as a program pointer; The first read module is used to read the value of the start pointer storage bit and the value of the end pointer storage bit of a specified register based on a preset register read command; The determining module is used to determine the value of the read start pointer storage bit as the start pointer and the value of the read end pointer storage bit as the end pointer; the start pointer and the end pointer are pre-stored in the start pointer storage bit and the end pointer storage bit respectively through preset register write commands, the start pointer is used to represent the minimum instruction address when recording tracking data, and the end pointer is used to represent the maximum instruction address when recording tracking data; The comparison module is used to compare the program pointer with the start pointer and the end pointer respectively; The first generation module is used to generate corresponding trace data for the branch instruction based on the instruction-related information of the branch instruction if the program pointer is not less than the start pointer and the program pointer is not greater than the end pointer.
7. The apparatus according to claim 6, characterized in that, The comparison module is specifically used for: Determine whether the program pointer of the branch instruction is not less than the start pointer, and determine whether the program pointer of the branch instruction is not greater than the end pointer.
8. The apparatus according to claim 7, characterized in that, The comparison module is further used for: Subtract the starting pointer from the program pointer of the branch instruction to obtain the first difference; If the first difference is not less than 0, it is determined that the program pointer is not less than the start pointer; If the first difference is less than 0, it is determined that the program pointer is less than the start pointer; Subtract the end pointer from the program pointer of the branch instruction to obtain the second difference; If the second difference is not greater than 0, it is determined that the program pointer is not greater than the end pointer; If the second difference is greater than 0, it is determined that the program pointer is greater than the end pointer.
9. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store executable instructions that cause the processor to perform the method as described in any one of claims 1 to 5.
10. One or more machine-readable media, characterized in that, It stores instructions that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-5.