Mixed-mode instruction stream acquisition method and device

The hybrid mode instruction stream collection method dynamically adjusts callbacks based on the instruction collection area, reducing overhead and improving efficiency by enabling callbacks only when needed, thus enhancing the speed of instruction stream collection.

CN119088657AActive Publication Date: 2024-12-06CHENGDU QUNXIN MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202411132416.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2024-12-06
Estimated Expiration
2044-08-16

AI Technical Summary

Technical Problem

Existing callback strategies in instruction stream collection for processor performance simulation lead to significant system overhead and low efficiency due to unnecessary callbacks and lack of dynamic adjustment during simulation.

Method used

Implement a hybrid mode instruction stream collection method that enables only basic block translation callbacks initially, dynamically adjusts to enable translation block execution and memory usage callbacks only when necessary by determining the entry point of the instruction collection area, and clears the code cache accordingly.

Benefits of technology

This approach reduces unnecessary information acquisition and improves sampling efficiency by dynamically adjusting callback strategies, significantly reducing system operation pressure and enhancing the speed of instruction stream collection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088657A_ABST
    Figure CN119088657A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and provides a mixed-mode instruction stream collection method and device.The method comprises the steps that after a translation block obtained by translating a basic block of a target program is stored in a code cache, basic block translation callback is called to determine whether the target program is located in an instruction collection area or not, and if not, the translation block is enabled to execute callback, if yes, enabling an instruction to execute callback and a memory to use callback; when the translation block is called to execute callback, whether the related basic block enters an entry point of an instruction collection area or not is determined, if yes, memory information and register information of the target program are obtained based on memory information of the simulation process and recorded to an instruction stream collection file, and code cache of the translation block is cleared; and when the calling instruction executes callback, acquiring instruction information and recording the instruction information to an instruction stream acquisition file, determining whether the related basic block is at the end point of the instruction acquisition area, and if so, clearing the code cache of the translation block. The instruction collection efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a mixed mode instruction stream acquisition method and device. Background Art

[0002] The performance simulation of processor microarchitecture is one of the important links in CPU processor development. The performance simulation of clock-accurate microarchitecture is usually about 1000-10000 times slower than the real machine. At the same time, since some benchmark programs (benchmark) contain a large number of instructions, such as the single test of SpecCpu2017 contains trillions of instructions, it is necessary to collect fragments of the instruction stream. The collection of instruction stream fragments is usually implemented by a functional simulator, and then the performance of the instruction stream fragments is simulated by a clock-accurate microarchitecture simulator. The instruction stream information that needs to be collected for performance simulation includes: the initial state of all registers of the CPU processor at the beginning of the sampling fragment and the initial state of the target program memory, the address of each instruction in the sampling fragment, the instruction code, the code length, the value of the register used by the instruction, the memory address and data value of the memory operation performed by the instruction, and other detailed information. Specifically, the functional simulator is loaded with an instruction stream collector in the form of a plug-in, and the instruction stream collector is used to register callbacks. The function simulator will translate the collected instructions into instructions on the host machine (translation block). To avoid multiple translations, the function simulator puts the translation block into the code cache and connects multiple translation blocks through the host machine's jump. If a callback is registered, the callback call will also be added to the translation block.

[0003] Functionally speaking, if the functional simulator wants to collect the above instruction stream information, it needs to register callbacks (such as instruction execution callbacks and memory usage callbacks) in the instruction stream collector as needed in the initial stage of simulation, so that the callback calls can be embedded in the translation block when translating the target instructions, thereby realizing the execution of instructions and the monitoring of memory usage. Summary of the invention

[0004] In the prior art, one callback strategy is to register a memory usage callback in the instruction stream collector in the initial stage of simulation, so as to obtain the memory information of the instruction stream fragment. Specifically, the memory information of the instruction is determined by enabling the memory access callback after each instruction is executed. Since the callback is a program, executing the callback after each instruction is executed from the starting point of the program will consume running time, so the above-mentioned memory usage callback slows down the running speed of the instruction simulation. In addition to the additional overhead of the memory usage callback, the instruction stream collector also needs to maintain the information of the memory usage callback, which will also increase the simulation overhead.

[0005] Other callback strategies in the prior art are to register multiple callbacks in the instruction stream collector in the initial stage of simulation, but during the simulation, the callback strategy is not dynamically adjusted (i.e., the registered callbacks are not adjusted), which leads to the use of unnecessary callbacks in the system, further reducing the speed of instruction stream collection.

[0006] The present invention is used to solve the problem that the existing callback strategy leads to large system overhead and low instruction stream collection efficiency. In order to solve the above technical problems, the first aspect of the present invention provides a hybrid mode instruction stream collection method, comprising:

[0007] Only basic block translation callbacks are enabled during the initial stage of target program simulation;

[0008] After storing the translation block obtained by translating the basic block of the target program into the code cache, the basic block translation callback is called to determine whether it is located in the instruction acquisition area, if not, the translation block execution callback is enabled, and if so, the instruction execution callback and the memory usage callback are enabled;

[0009] When calling the translation block to execute the callback, determine whether the entry point of the instruction collection area is entered after the relevant basic block, and if so, obtain the memory information and register information of the target program based on the memory information of the simulation process and record them in the instruction stream collection file, and clear the code cache of the translation block;

[0010] When the instruction execution callback is called, instruction information is obtained and recorded in the instruction stream acquisition file, and it is determined whether the relevant basic block is at the end point of the instruction acquisition area. If so, the code cache of the translation block is cleared.

[0011] In some embodiments of the present invention, obtaining the memory information and register information of the target program based on the memory information of the simulation process includes:

[0012] Get the memory information of the simulation process;

[0013] Identify a memory address in the memory information, and obtain a page table and page table attributes corresponding to the memory address;

[0014] Determine whether the page table attribute contains the identifier of the target program, and if so, determine that the memory address corresponding to the page table is the memory address of the target program, and record the page table and its corresponding memory address in the instruction stream acquisition file;

[0015] Get register information and record it in the instruction stream capture file.

[0016] As some embodiments of the present invention, before enabling the instruction execution callback and the memory usage callback, it also includes: traversing the instruction machine code of each instruction in the translation block, and performing the following operations on the instruction machine code of each instruction: checking whether the instruction machine code is in the hash table, if not, parsing the instruction machine code to obtain instruction register information, and inserting the instruction machine code and instruction register information into the hash table, if yes, continuing to traverse the next instruction in the translation block;

[0017] After all instructions in the translation block have been traversed, the instruction execution callback and the memory usage callback are enabled.

[0018] As some embodiments of the present invention, before the basic block translation callback determines whether to enter the instruction collection area, it also includes: querying the number of instructions in the translation block;

[0019] When enabling the translation block to execute the callback, the number of instructions in the translation block is also passed into the translation block execution callback;

[0020] When the instruction execution callback is enabled, the instruction machine code of each instruction in the translation block is also passed into the instruction execution callback.

[0021] In some embodiments of the present invention, obtaining instruction information includes:

[0022] Searching the register information of the instruction machine code of the current instruction in the hash table, and recording the register information and the instruction machine code of the current instruction in the instruction stream acquisition file;

[0023] Acquire a register value in the current register state of the processor, and record the register value in the instruction stream acquisition file;

[0024] Check whether the current instruction crosses the page table, and if so, record the additional page table information in the instruction stream acquisition file;

[0025] Check whether the current instruction is a jump instruction and whether it is a system call;

[0026] If it is a jump instruction, the page table information of the destination address is recorded in the instruction stream acquisition file;

[0027] If it is not a jump instruction but a system call, the memory before and after the instruction call is compared, and the comparison result is recorded in the instruction stream acquisition file;

[0028] If it is not called by the system, check whether there is an exception. If there is an exception, record the exception information in the instruction stream collection file.

[0029] In some embodiments of the present invention, the memory usage callback execution process includes:

[0030] Obtaining instruction memory information, wherein the instruction memory information includes: data length, type, data virtual address and logistics address of memory access;

[0031] Recording the instruction memory information in the instruction stream acquisition file;

[0032] Determine whether the data access crosses pages. If so, record additional page table information in the instruction stream acquisition file.

[0033] In some embodiments of the present invention, the translation block executes a callback to determine whether to enter an entry point of the instruction collection area after the relevant basic block enters, including:

[0034] Adding the number of instructions in the translation block to the historical instruction accumulation value to obtain a new instruction accumulation value;

[0035] Determine whether to enter the instruction collection area based on the new instruction accumulation value.

[0036] A second aspect of the present invention provides a hybrid mode instruction stream collection device, the instruction stream collection device comprising:

[0037] A first configuration unit is used to enable only basic block translation callbacks in an initial stage of target program simulation;

[0038] A second configuration unit is used to store the translation block obtained by translating the basic block of the target program into the code cache and then call the basic block translation callback to determine whether it is located in the instruction acquisition area, if not, enable the translation block execution callback, and if so, enable the instruction execution callback and the memory usage callback;

[0039] An instruction collection area entry point monitoring unit is used to determine whether the relevant basic block enters the entry point of the instruction collection area when calling the translation block execution callback, and if so, obtain the memory information and register information of the target program based on the memory information of the simulation process and record them in the instruction stream collection file, and clear the code cache of the translation block;

[0040] The instruction collection area end point monitoring unit is used to obtain instruction information and record it to the instruction stream collection file when calling the instruction execution callback, determine whether the relevant basic block is at the end point of the instruction collection area, and if so, clear the code cache of the translation block.

[0041] A third aspect of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in any of the foregoing embodiments when executing the computer program.

[0042] A fourth aspect of the present invention provides a computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor of a computer device, implements the method described in any of the foregoing embodiments.

[0043] A fifth aspect of the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor of a computer device, the method described in any of the above embodiments is implemented.

[0044] The hybrid mode instruction stream acquisition method and device provided by the present invention only enable the basic block translation callback in the initial stage of target program simulation; after the translation block obtained by translating the basic block of the target program is stored in the code cache, the basic block translation callback is called to determine whether it is located in the instruction acquisition area, if not, the translation block execution callback is enabled, and if so, the instruction execution callback and memory usage callback are enabled; when the translation block execution callback is called, it is determined whether the entry point of the instruction acquisition area is entered after the relevant basic block, if so, the memory information and register information of the target program are obtained based on the memory information of the simulation process and recorded in the instruction stream acquisition file, the code cache of the translation block is cleared, and when the instruction execution callback is called, the instruction information is obtained and recorded in the instruction stream acquisition file, and it is determined whether the relevant basic block is at the end point of the instruction acquisition area, and if so, the code cache of the translation block is cleared. The present invention distinguishes between the instruction acquisition area and the non-instruction acquisition area, and only enables the translation block execution callback in the non-instruction acquisition area, and enables the instruction execution callback and memory usage callback in the instruction acquisition area, which can reduce the information acquisition in the non-instruction acquisition area and improve the sampling efficiency. The present invention can timely clear the translation blocks in the code cache, and re-execute the judgment of whether it is in the instruction collection area, so as to adjust the enabling strategy of the callback according to the judgment result and improve the sampling efficiency.

[0045] Furthermore, when entering the entry point of the instruction collection area, the memory information and register information of the target program are obtained through the memory information of the simulation process and recorded in the instruction stream collection file. Specifically, when executing to the entry point of the instruction collection area, the memory information of the simulation process is obtained; the memory address in the memory information is identified, and the page table corresponding to the memory address is obtained; the page table attributes are determined according to the page table corresponding to the memory address; it is determined whether the page table attributes contain the identification of the target program. If so, the memory address corresponding to the page table is determined to be the memory address of the target program, and the page table and its corresponding memory address are recorded in the instruction stream collection file. The above technical solution can distinguish the memory of the target program and the memory of the function simulator, thereby realizing the collection of memory information at the entry point of the instruction collection area. At the same time, the above technical solution omits the operation of the memory usage callback and the maintenance of the memory usage callback information, which can reduce the system operation pressure and improve the efficiency of instruction stream collection.

[0046] In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0048] Figure 1 A structural diagram of the mixed mode instruction stream acquisition system of an embodiment of the present invention is shown;

[0049] Figure 2A A schematic diagram showing the corresponding relationship between the basic block and the translation block according to an embodiment of the present invention is shown;

[0050] Figure 2B A schematic diagram showing the relationship between the translation block and the callback according to an embodiment of the present invention;

[0051] Figure 3 A schematic diagram showing a sampling segment of a benchmark test program according to an embodiment of the present invention is shown;

[0052] Figure 4 A flow chart showing a method for collecting instruction streams in a mixed mode according to an embodiment of the present invention is shown;

[0053] Figure 5 A flowchart showing a basic block translation callback execution process according to an embodiment of the present invention is shown;

[0054] Figure 6 A flowchart of a process of executing a callback by a translation block according to an embodiment of the present invention is shown;

[0055] Figure 7 A flowchart showing the instruction execution callback execution process according to an embodiment of the present invention is shown;

[0056] Figure 8 A flowchart showing a memory usage callback execution process according to an embodiment of the present invention is shown;

[0057] Fig. 9 A structural diagram of an instruction stream acquisition device in a hybrid mode according to an embodiment of the present invention is shown;

[0058] Fig.10 A structural diagram of a computer device according to an embodiment of the present invention is shown.

[0059] Description of the accompanying symbols:

[0060] 101. Functional simulator;

[0061] 102. Instruction stream collector;

[0062] 103. Processor;

[0063] 104. Code cache;

[0064] 901, first configuration unit;

[0065] 902, second configuration unit;

[0066] 903, command collection area entry point monitoring unit;

[0067] 904, command collection area end point monitoring unit;

[0068] 1002. Computer equipment;

[0069] 1004. Processor;

[0070] 1006. Memory;

[0071] 1008. Driving mechanism;

[0072] 1010, input / output module;

[0073] 1012. Input device;

[0074] 1014. Output device;

[0075] 1016. Presentation equipment;

[0076] 1018. Graphical user interface;

[0077] 1020. Network interface;

[0078] 1022. Communication link;

[0079] 1024. Communication bus. DETAILED DESCRIPTION

[0080] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0081] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or equipment that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0082] This specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on routine or non-creative work. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the system or device product is executed in practice, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel.

[0083] It should be noted that the data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties.

[0084] by Figure 3 For example, Figure 3 The BC and DE segments in the byte array are instruction sampling areas. In order to collect the starting point of the instruction stream segment ( Figure 3 The instruction stream collector needs to collect memory information from the starting point of the program ( Figure 3 The memory operations of all instructions between point A in the instruction stream and point B in the instruction stream segment. In order to monitor memory usage, it is necessary to enable the memory access callback. The callback function itself is also a program that consumes running time, so the above callbacks slow down the running speed of instruction simulation. In addition to the additional overhead of memory callback, the instruction stream collector also needs to maintain the information of memory callback, which is also an additional overhead.

[0085] In addition, if Figure 2AAs shown, the functional simulator T10 translates the basic block T20 in the target program code into the translation block of the host machine. Each basic block T20 contains multiple instructions T30, and the instructions T30 in the basic block T20 correspond to the translation T60 in the translation block T50. In order to avoid multiple translations, the functional simulator puts the translation block into the host machine code cache T40, and connects multiple translation blocks through the host machine jump T70. If the callback function is enabled, the call of the callback function will also be added to the translation block, such as Figure 2B As shown in the figure, the usual instruction stream collector enables instruction callback and memory usage callback at the initial stage of simulation, but does not dynamically adjust the callback strategy during simulation, which also causes the speed of instruction stream collection process to decrease.

[0086] In one embodiment of the present invention, a mixed mode instruction stream acquisition system is provided, such as Figure 1 As shown, it includes: a function simulator 101, an instruction stream collector 102, a processor 103 and a code cache 104.

[0087] Functional simulator 101 refers to a functional simulator that simulates the instruction set of a specified architecture, such as open source QEMU, GEM5, and closed source Intel SDE, for simulating a target program. Instruction stream collector 102 is loaded into functional simulator 101 in the form of a plug-in, and instruction stream collector 102 is used to register callbacks (functions), such as Figure 2B As shown, the callback function includes:

[0088] Basic block translation callback: This function is called when a basic block is translated;

[0089] Translation block execution callback: This function is called after a translation block is executed;

[0090] Instruction execution callback: This function is called when a target instruction is executed;

[0091] Memory usage callback: This function is called when an instruction uses memory operations.

[0092] The functional simulator 101 is used to translate the basic blocks of the target program into translation blocks and store them in the code cache 104 .

[0093] The processor 103 is used to register only the basic block translation callback in the instruction stream collector 102 in the initial stage of the target program simulation; after storing the translation block in the code cache 104, the basic block translation callback is called to determine whether it is located in the instruction collection area. If not, the translation block execution callback is registered in the instruction stream collector 102. If so, the instruction execution callback and the memory usage callback are registered in the instruction stream collector 102; when calling the translation block execution callback, it is determined whether the entry point of the instruction collection area is entered after the relevant basic block. If so, the memory information and register information of the target program are obtained based on the memory information of the simulation process and recorded in the instruction stream collection file, and the code cache 104 of the translation block is cleared; when calling the instruction execution callback, the instruction information is obtained and recorded in the instruction stream collection file, and it is determined whether the relevant basic block is at the end point of the instruction collection area. If so, the code cache of the translation block is cleared.

[0094] Before implementing this embodiment, it is necessary to establish a basic block translation callback, a basic block translation callback, an instruction execution callback and a memory usage callback in advance.

[0095] This embodiment distinguishes between the instruction collection area and the non-instruction collection area. In the non-instruction collection area, only the translation block execution callback is enabled, and in the instruction collection area, the instruction execution callback and the memory usage callback are enabled, which can reduce the information acquisition in the non-instruction collection area and improve the sampling efficiency. The present invention can re-execute the judgment of whether it is in the instruction collection area by timely clearing the translation block in the code cache, thereby adjusting the callback enabling strategy according to the judgment result and improving the sampling efficiency.

[0096] In some embodiments of the present invention, the program operation and sampling fragment schematic diagram is as follows Figure 3 As shown, Figure 3 In the example, AZ represents the entire operation of a benchmark program. Since there are too many instructions, it is impossible to sample the entire process. In specific implementation, based on the instruction statistics in the basic blocks of the program, representative instruction fragments can be found, such as Figure 3 The BC and DE segments in the program are instruction sampling areas. The instructions in these segments are used to represent the execution of the entire program with the weight of each segment attached. Figure 3 The number of instructions in the irrelevant area is much larger than the number of instructions in the sampling area. This requires collecting instruction flow information for the BC and DE segments. Taking the BC segment as an example, the following information needs to be collected:

[0097] At the initial point B of the fragment, collect the complete register information of point B, register snapshot; at the initial point B of the fragment, collect the current memory information of the entire program, memory snapshot; from point B to point C, the execution status of each instruction, including the instruction address, instruction code, and the register status used by the instruction. If the instruction has a memory operation, record the memory operation information.

[0098] In one embodiment of the present invention, a mixed mode instruction stream acquisition method is also provided, such as Figure 4 As shown, including:

[0099] Step 401 , in the initial stage of target program simulation, only basic block translation callback is enabled.

[0100] In detail, this step of enabling the basic block translation callback refers to registering the basic block translation callback function in the instruction stream collector, and when the basic block in the target program is translated to obtain the translation block and the translation block is stored in the code cache, the basic block translation callback can be called. Both the basic block and the translation block contain multiple instructions, and the instructions in the basic block correspond to the instructions in the translation block.

[0101] Step 402, after storing the translation block in the code cache, the basic block translation callback is called to determine whether it is located in the instruction collection area. If not, the translation block execution callback is enabled. If so, the instruction execution callback and the memory usage callback are enabled.

[0102] In this step, enabling the translation block execution callback refers to registering the translation block execution callback in the instruction stream collector, and enabling the instruction stream execution callback and memory usage callback refers to registering the instruction execution callback and memory usage callback in the instruction stream collector.

[0103] When the translation block execution callback is enabled, the translation block execution callback will be called after the translation block is executed.

[0104] Enable instruction execution callback and memory usage callback. After the instructions in the translation block are executed, the instruction execution callback and memory usage callback will be called.

[0105] Step 403, when calling the translation block to execute the callback, determine whether the entry point of the instruction collection area is entered after the relevant basic block. If so, the memory information and register information of the target program are obtained based on the memory information of the simulation process and recorded in the instruction stream collection file, and the code cache of the translation block is cleared.

[0106] This step clears the code cache of the translation block after entering the entry point of the instruction collection area, so that the basic block can be re-translated to obtain the translation block, and returns to step 402 to re-determine the enable instruction execution callback and memory usage callback, so as to achieve the purpose of dynamically adjusting the callback strategy.

[0107] During implementation, if the entry point of the instruction collection area is not entered, the translation block execution callback is enabled again after the translation block is executed.

[0108] Step 404, when calling the instruction execution callback, obtain the instruction information and record it into the instruction stream acquisition file, determine whether the related basic block is at the end point of the instruction acquisition area, and if so, clear the code cache of the translation block.

[0109] After the instruction is executed, the number of executed instructions will be added to the historical instruction cumulative value to obtain the updated instruction cumulative value. According to the updated instruction cumulative value, it is determined whether to exit the end point of the collection area.

[0110] This step clears the code cache of the translation block after entering the end point of the instruction acquisition area, so that the basic block can be retranslated to obtain the translation block, and returns to step 402 to re-determine the translation block execution callback, thereby achieving the purpose of dynamically adjusting the callback strategy.

[0111] In one embodiment of the present invention, Figure 5 As shown in the figure, the execution flow inside the basic block translation callback includes:

[0112] Step 501, query the number of instructions in the translation block.

[0113] In detail, the number of instructions in the translation block here refers to the number of instructions of the executed translation block, that is, the total number of executed instructions.

[0114] Step 502: Determine whether it is in the instruction collection area according to the number of instructions in the translation block.

[0115] In detail, after the translation block is executed, the number of instructions executed in the translation block will be added to the historical instruction accumulation value to obtain the total number of executed instructions (i.e. the updated historical instruction accumulation value). The total number of executed instructions will be used to determine whether to enter the collection area. For example, if the number of instructions in the collection area is between [1,000,000-2,000,000], it will enter the collection area after executing 1 million instructions and exit the collection area after executing 2 million instructions. Then, when the total number of executed instructions is greater than or equal to 1 million, it will enter the collection area and when the total number of executed instructions is equal to 2 million, it will exit the collection area.

[0116] Step 503, if not in the instruction collection area, register the translation block instruction callback function in the instruction stream collector, and use the instruction number of the current translation block as the input parameter of the translation block instruction callback function. By inputting the instruction number of the translation block, multiple queries can be avoided and the sampling efficiency can be improved.

[0117] Step 504: If in the instruction collection area, traverse each instruction in the translation block and perform the following operations:

[0118] Step 5041, obtain the instruction machine code (opcode) of the instruction.

[0119] Step 5042, check whether the instruction machine code is in the hash table. If not, parse the instruction machine code opcode to obtain the instruction register information (source / target register information required for the instruction), and insert the instruction machine code and instruction register information into the hash table. If it is in the hash table, continue to traverse the next instruction in the translation block.

[0120] Step 505, after traversing the instructions in the translation block, register the instruction execution callback and memory usage callback in the instruction stream collector, and pass the instruction machine code to the instruction callback function.

[0121] In one embodiment of the present invention, Figure 6 As shown, after the translation block is executed, the execution process of the translation block execution callback includes:

[0122] Step 601, receiving the number n of instructions in a translation block.

[0123] Step 602: There is an instruction counter in the instruction stream collector. The instruction counter is used to calculate the cumulative value of instructions. n instructions are added to the historical instruction cumulative value, that is, g_instCount+=n, to obtain a new instruction cumulative value.

[0124] The historical instruction accumulation value in this step refers to the total number of executed instructions in the previous text.

[0125] Step 603, determining whether to enter the entry point of the instruction collection area after the translation block is executed according to the new instruction accumulation value.

[0126] If the entry point of the instruction collection area is not entered, it returns directly and continues to call the translation block execution callback after the next translation block is executed.

[0127] If you enter the entry point of the instruction collection area, the following process will be executed:

[0128] Step 6041, obtain the memory information of the simulation process.

[0129] Specifically, when the simulation process is loaded into the memory by the operating system, the operating system will provide a memory mapping file to express the memory mapping information. In this step, the memory information can be determined through the memory mapping file.

[0130] The memory information of the simulation process usually includes multiple lines of memory information, each line of memory information includes a memory address range, range usage permissions, offset, device number, file number and file name loaded corresponding to the memory range, etc.

[0131] Step 6042, identifying the memory address in the memory information of the simulation process, and obtaining the page table and page table attributes corresponding to the memory address.

[0132] In detail, a page table is a data structure used for memory management. It is used to record the mapping relationship between virtual memory addresses and physical memory addresses. In a system that uses paged memory management, the virtual memory space is divided into pages of fixed size. The page table is located in the page table area of ​​the system space, and each process has its own page table. The page table attributes include access permission attributes, memory type attributes, and mapping attributes.

[0133] Step 6043, determine whether the page table attribute contains the target program's identifier, if so, determine that the memory address corresponding to the page table is the target program's memory address, and record the page table and its corresponding memory address in the instruction stream acquisition file. If not, execute step 6044.

[0134] Step 6044, determine whether all memory addresses in the memory information of the simulation process have been analyzed, if so, execute step 6045, if not, return to step 6041 to continue execution.

[0135] Step 6045, obtain register information and record it in the instruction stream acquisition file, and clear the code cache of the translation block. In detail, the register information obtained in this step refers to the information of all registers of the current CPU processor, including integer, floating point, and system registers. In detail, this step can obtain the register information from the functional simulator.

[0136] Among them, obtaining register information is part of the origin state of instruction collection. Clearing the translation block code cache can prepare for subsequent re-translation and enable instruction execution callback.

[0137] This embodiment can distinguish the memory of the target program and the memory of the function simulator, thereby realizing the collection of memory information of the entry point of the instruction collection area. At the same time, the above technical solution omits the operation of the memory usage callback and the maintenance of the memory usage callback information, which can reduce the system operation pressure and improve the efficiency of instruction stream collection.

[0138] In one embodiment of the present invention, Figure 7 As shown in the figure, the execution process of the instruction execution callback includes:

[0139] Step 701, receiving an incoming parameter, wherein the incoming parameter includes: an instruction machine code of a current instruction.

[0140] Step 702, searching the hash table for register information of the instruction machine code of the current instruction, and recording the register information and instruction machine code of the current instruction in the instruction stream collection file.

[0141] This step can avoid multiple instruction parsing and improve the efficiency of obtaining instruction register information by searching the register information of the instruction machine code in the hash table.

[0142] Step 703, obtaining a register value in the current register state of the processor, and recording the register value in an instruction stream acquisition file.

[0143] Step 704, check whether the current instruction crosses the page table, if so, record the additional page table information in the instruction stream acquisition file. The page table conversion is maintained by the operating system, and whether it crosses pages is determined based on the starting address of the instruction, the length of the instruction, and the length of the current page table. If it crosses pages, a page walk is required, and the page walk is performed one level at a time according to the number of multi-level page tables. The specific determination process of the additional page table information can refer to the prior art and will not be described in detail here.

[0144] Step 705, check whether the current instruction is a jump instruction.

[0145] Step 706: If it is a jump instruction, the page table information of the destination address is recorded in the instruction stream collection file. Specifically, the page table information of the destination address is obtained through address translation.

[0146] Step 707: If it is not a jump instruction, check whether it is a system call.

[0147] Step 708: If it is a system call, compare the memory before and after the instruction call, and record the comparison result in the instruction stream acquisition file.

[0148] Step 709, if it is not a system call, then check whether there is an exception. If there is an exception, the exception information is recorded in the instruction stream acquisition file. In detail, the exception here includes but is not limited to the instruction causing overflow or page table missing. After the exception handling mechanism is in place, come back and re-execute this instruction. The state of the exception is usually stored in the computer system program status register. This step can determine whether there is an exception by querying the status register.

[0149] Step 710: If there is no exception, the instruction machine code is recorded in the instruction stream collection file.

[0150] Step 711, the cumulative number of instructions is increased by 1, that is, g_instCont+=1, to determine whether it is at the end point of the instruction collection area.

[0151] If it is at the end point of the instruction collection area, clear the code cache of the translation block, update the next instruction collection area information, and determine whether it is the last instruction collection area. If so, end the entire simulation instruction collection. If not, continue to translate the basic block and execute Figure 4 The process shown.

[0152] If it is not the end point of the acquisition area, the next instruction is executed and the above steps 601 to 711 are repeated.

[0153] In one embodiment of the present invention, Figure 8 As shown in the figure, the memory usage callback execution process includes the following steps:

[0154] Step 801, obtain instruction memory information, wherein the instruction memory information includes: data length of memory access, type of memory access, data virtual address and logistics address of memory access.

[0155] Specifically, the types of memory access include but are not limited to read (load), write (store), prefetch, etc.

[0156] Step 802, record the instruction memory information in the instruction stream collection file.

[0157] Step 803, determine whether the data access crosses pages, if so, record the additional page table information in the instruction stream acquisition file.

[0158] The information obtained in this embodiment can provide data basis for input of other projects, such as a micro-architecture performance simulator, etc.

[0159] In some specific embodiments of the present invention, the hybrid instruction stream sampling method of the above-mentioned multiple callback modes is used to collect instruction streams for SPECCPU 2017, which only takes 1-2 days. Compared with the 3-4 weeks of the existing instruction stream sampling method (such as Intel SDE pinball) before the present invention, the sampling efficiency can be greatly improved.

[0160] Based on the same inventive concept, the present invention also provides a hybrid mode instruction stream acquisition device, as described in the following embodiments. Since the principle of solving the problem by the hybrid mode instruction stream acquisition device is similar to that of the hybrid mode instruction stream acquisition method, the implementation of the hybrid mode instruction stream acquisition device can refer to the hybrid mode instruction stream acquisition method, and the repeated parts will not be repeated. Specifically, Fig. 9 As shown, the mixed mode instruction stream acquisition device includes:

[0161] A first configuration unit 901 is used to enable only basic block translation callbacks in the initial stage of target program simulation;

[0162] A second configuration unit 902 is used to store the translation block obtained by translating the basic block of the target program into the code cache and then call the basic block translation callback to determine whether it is located in the instruction acquisition area, if not, enable the translation block execution callback, and if so, enable the instruction execution callback and the memory usage callback;

[0163] The instruction collection area entry point monitoring unit 903 is used to determine whether the relevant basic block enters the entry point of the instruction collection area when calling the translation block execution callback. If so, the memory information and register information of the target program are obtained based on the memory information of the simulation process and recorded in the instruction stream collection file, and the code cache of the translation block is cleared;

[0164] The instruction collection area end point monitoring unit 904 is used to obtain instruction information when calling the instruction execution callback and record it to the instruction stream collection file, determine whether the relevant basic block is at the end point of the instruction collection area, and if so, clear the code cache of the translation block.

[0165] In specific implementation, the execution process of basic block translation callback, translation block execution callback, instruction execution callback and memory usage callback can refer to Figures 5 to 8 The embodiment shown is not described in detail in this embodiment.

[0166] This embodiment distinguishes between the instruction collection area and the non-instruction collection area. In the non-instruction collection area, only the translation block execution callback is enabled, and in the instruction collection area, the instruction execution callback and the memory usage callback are enabled, which can reduce the information acquisition in the non-instruction collection area and improve the sampling efficiency. The present invention can re-execute the judgment of whether it is in the instruction collection area by timely clearing the translation block in the code cache, thereby adjusting the callback enabling strategy according to the judgment result and improving the sampling efficiency.

[0167] In one embodiment of the present invention, a computer device is also provided, such as Fig.10 As shown, the computer device 1002 may include one or more processors 1004, such as one or more central processing units (CPUs), each of which may implement one or more hardware threads. The computer device 1002 may also include any memory 1006, which is used to store any kind of information such as code, settings, data, etc. In specific implementation, the method described in any of the above embodiments is stored in the memory 1006. Non-limitingly, for example, the memory 1006 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory device, hard disk, optical disk, etc. More generally, any memory may use any technology to store information. Further, any memory may provide volatile or non-volatile retention of information. Further, any memory may represent a fixed or removable component of the computer device 1002. In one case, when the processor 1004 executes an associated instruction stored in any memory or a combination of memories, the computer device 1002 may perform any operation of the associated instruction. The computer device 1002 also includes one or more drive mechanisms 1008 for interacting with any memory, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.

[0168] The computer device 1002 may also include an input / output module 1010 (I / O) for receiving various inputs (via input device 1012) and for providing various outputs (via output device 1014). A specific output mechanism may include a presentation device 1016 and an associated graphical user interface 1018 (GUI). In other embodiments, the input / output module 1010 (I / O), input device 1012, and output device 1014 may not be included, and the computer device 1002 may be used as a computer device in a network. The computer device 1002 may also include one or more network interfaces 1020 for exchanging data with other devices via one or more communication links 1022. One or more communication buses 1024 couple the components described above together.

[0169] The communication link 1022 may be implemented in any manner, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 1022 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.

[0170] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are executed.

[0171] An embodiment of the present invention further provides a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to execute the method described in any of the aforementioned embodiments.

[0172] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor of a computer device, the method described in any of the above embodiments is implemented.

[0173] It should be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0174] It should also be understood that in the embodiments of the present invention, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present invention generally indicates that the associated objects before and after are in an "or" relationship.

[0175] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present invention can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0176] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0177] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.

[0178] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.

[0179] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0180] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0181] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A mixed mode instruction stream acquisition method, characterized in that: include: Only basic block translation callbacks are enabled during the initial stage of target program simulation; After storing the translation block obtained by translating the basic block of the target program into the code cache, the basic block translation callback is called to determine whether it is located in the instruction acquisition area, if not, the translation block execution callback is enabled, and if so, the instruction execution callback and the memory usage callback are enabled; When calling the translation block to execute the callback, determine whether the entry point of the instruction collection area is entered after the relevant basic block, and if so, obtain the memory information and register information of the target program based on the memory information of the simulation process and record them in the instruction stream collection file, and clear the code cache of the translation block; When the instruction execution callback is called, instruction information is obtained and recorded in the instruction stream acquisition file, and it is determined whether the relevant basic block is at the end point of the instruction acquisition area. If so, the code cache of the translation block is cleared.

2. The method according to claim 1, characterized in that The memory information and register information of the target program are obtained based on the memory information of the simulation process, including: Get the memory information of the simulation process; Identify a memory address in the memory information, and obtain a page table and page table attributes corresponding to the memory address; Determine whether the page table attribute contains the identifier of the target program, and if so, determine that the memory address corresponding to the page table is the memory address of the target program, and record the page table and its corresponding memory address in the instruction stream acquisition file; Get register information and record it in the instruction stream capture file.

3. The method according to claim 1, characterized in that Before enabling instruction execution callback and memory usage callback, it also includes: Traversing the instruction machine code of each instruction in the translation block, and performing the following operations on the instruction machine code of each instruction: checking whether the instruction machine code is in the hash table, if not, parsing the instruction machine code to obtain instruction register information, and inserting the instruction machine code and instruction register information into the hash table, if yes, continuing to traverse the next instruction in the translation block; After all instructions in the translation block have been traversed, the instruction execution callback and the memory usage callback are enabled.

4. The method according to claim 3, characterized in that Before the basic block translation callback determines whether to enter the instruction collection area, it also includes: querying the number of instructions in the translation block; When enabling the translation block to execute the callback, the number of instructions in the translation block is also passed into the translation block execution callback; When the instruction execution callback is enabled, the instruction machine code of each instruction in the translation block is also passed into the instruction execution callback.

5. The method according to claim 3, characterized in that The command information includes: Searching the register information of the instruction machine code of the current instruction in the hash table, and recording the register information and the instruction machine code of the current instruction in the instruction stream acquisition file; Acquire a register value in the current register state of the processor, and record the register value in the instruction stream acquisition file; Check whether the current instruction crosses the page table, and if so, record the additional page table information in the instruction stream acquisition file; Check whether the current instruction is a jump instruction and whether it is a system call; If it is a jump instruction, the page table information of the destination address is recorded in the instruction stream acquisition file; If it is not a jump instruction but a system call, the memory before and after the instruction call is compared, and the comparison result is recorded in the instruction stream acquisition file; If it is not called by the system, check whether there is an exception. If there is an exception, record the exception information in the instruction stream collection file.

6. The method according to claim 1, characterized in that The memory usage callback execution process includes: Obtaining instruction memory information, wherein the instruction memory information includes: data length, type, data virtual address and logistics address of memory access; Recording the instruction memory information in the instruction stream acquisition file; Determine whether the data access crosses pages. If so, record additional page table information in the instruction stream acquisition file.

7. The method according to claim 1, characterized in that The translation block executes the callback to determine whether to enter the entry point of the instruction collection area after the relevant basic block enters, including: Adding the number of instructions in the translation block to the historical instruction accumulation value to obtain a new instruction accumulation value; Determine whether to enter the instruction collection area based on the new instruction accumulation value.

8. A mixed mode instruction stream acquisition device, characterized in that: The instruction stream acquisition device comprises: A first configuration unit is used to enable only basic block translation callbacks in an initial stage of target program simulation; A second configuration unit is used to store the translation block obtained by translating the basic block of the target program into the code cache and then call the basic block translation callback to determine whether it is located in the instruction acquisition area, if not, enable the translation block execution callback, and if so, enable the instruction execution callback and the memory usage callback; An instruction collection area entry point monitoring unit is used to determine whether the relevant basic block enters the entry point of the instruction collection area when calling the translation block execution callback, and if so, obtain the memory information and register information of the target program based on the memory information of the simulation process and record them in the instruction stream collection file, and clear the code cache of the translation block; The instruction collection area end point monitoring unit is used to obtain instruction information and record it to the instruction stream collection file when calling the instruction execution callback, determine whether the relevant basic block is at the end point of the instruction collection area, and if so, clear the code cache of the translation block.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor of a computer device, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method and device for realizing embedded type system function monitoring

    CN101788949A

  • A component bus invocation execution system based on transaction flow

    CN109408232A

  • A dynamic binary translation method and device for a VLIW architecture

    CN109710268A

  • Data acquisition method and device, and computer readable storage medium

    CN115145806A

  • Kernel injection method of process entry, code execution method, system and equipment

    CN116932046A