Branch history recording system, branch history recording method, and branch control program
The branch history recording system facilitates branch history recording and probability calculation, enhancing program performance by recording branch information in a cyclic buffer and using a hash table to efficiently branch to corresponding code blocks, addressing the lack of LBR in CPUs.
Patent Information
- Application Number
- JP2023071975
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2024-11-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The inability to collect branch history information for calculating branch probabilities due to the absence of Last Branch Record (LBR) in the CPU complicates optimization methods like Profile-Guided Optimization (PGO), affecting performance enhancement in program execution.
A branch history recording system comprising a storage unit, first and second arithmetic processing units, and an acquisition unit that records and processes branch information during program execution, enabling branch history recording without relying on LBR, by writing and reading branch information to a cyclic buffer and using a hash table to efficiently branch to corresponding code blocks.
Enables easy recording and calculation of branch probabilities, allowing for efficient rearrangement of basic blocks in programs, thereby improving performance without the overhead of traditional binary instrumentation methods.
Smart Images

Figure 2024157581000001_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to a branch history recording technique. [Background technology]
[0002] Profile-Guided Binary Optimization (PGO) is a well-known optimization method for compilers. In PGO, an executable file is optimized based on its performance profile at run time. PGO is also known as feedback-driven optimization.
[0003] According to PGO, branch misses and instruction cache misses can be reduced by rearranging the basic blocks (BBs) of a program based on the branch probability of the branch instructions at run time. BBs are the basic units of program fragments handled by compilers. Rearranging BBs has a large effect on performance improvement.
[0004] Regarding an optimization method in a compiler, a compilation processing device is known that can reduce processing time and quickly generate an executable program (see, for example, Patent Document 1). [Prior art documents] [Patent documents]
[0005] [Patent Document 1] JP 2000-81984 A Summary of the Invention [Problem to be solved by the invention]
[0006] If a Central Processing Unit (CPU) does not implement a Last Branch Record (LBR), it is difficult to collect branch history information used to calculate branch probabilities.
[0007] This problem does not only occur when PGO is performed, but also occurs when branch history information is collected for various purposes.
[0008] In one aspect, the present invention aims to easily record the branch history during execution of a program. [Means for solving the problem]
[0009] In one proposal, the branch history recording system includes a storage unit, a first calculation processing unit, a second calculation processing unit, and an acquisition unit.
[0010] The first processing unit executes the write program to write, into the storage unit, branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation that occurs when the write program is executed.
[0011] The second arithmetic processing unit executes a branch control program to read branch information from the storage unit and execute a process of branching to a code block corresponding to the branch information among a plurality of code blocks included in the branch control program. The acquisition unit acquires an instruction address of an executed instruction when the branch control program is executed, and records operation information including the instruction address of the executed instruction. Effect of the Invention
[0012] According to one aspect, it is possible to easily record the branch history of a program during execution. [Brief description of the drawings]
[0013] [Figure 1] FIG. 11 is a diagram showing profile information. [Diagram 2] Figure 1 shows the performance profile file. [Diagram 3] FIG. 13 is a diagram showing a symbol table. [Figure 4] FIG. 13 is a diagram showing a compilation result file. [Diagram 5] FIG. 1 is a functional configuration diagram of a branch history recording system according to an embodiment. [Figure 6] 13 is a flowchart of a branch history recording process. [Figure 7] FIG. 2 is a functional configuration diagram of the information processing system. [Figure 8] FIG. 13 is a diagram illustrating a branch history recording process. [Figure 9] FIG. 13 illustrates an address correspondence table. [Figure 10] FIG. 13 illustrates a branch control program. [Figure 11] FIG. 2 illustrates a code block. [Figure 12] FIG. 13 is a diagram showing a symbol table that associates code blocks with branch information. [Figure 13] FIG. 13 is a diagram showing a performance profile file generated by an acquisition unit. [Figure 14] FIG. 11 is a diagram showing a first branch history file. [Figure 15] 1 is a flowchart of a binary instrumentation process. [Figure 16] 13 is a flowchart of a block generation process. [Figure 17] FIG. 1 illustrates a binary instrumentation process. [Figure 18] FIG. 13 shows a binary file after binary instrumentation. [Figure 19] 13 is a flowchart of a branch control process. [Figure 20] FIG. 2 illustrates a first state of the cyclic buffer. [Figure 21] FIG. 11 illustrates a second state of the cyclic buffer. [Figure 22] FIG. 11 illustrates a third state of the cyclic buffer. [Figure 23] FIG. 11 illustrates a fourth state of the cyclic buffer. [Figure 24] FIG. 13 illustrates a fifth state of the cyclic buffer. [Diagram 25] FIG. 2 illustrates a first state of a hash table. [Figure 26] FIG. 11 illustrates a second state of the hash table. [Figure 27] FIG. 13 is a diagram illustrating an execution sequence of a branch control program. [Figure 28] 13 is a flowchart of a conversion process. [Figure 29] 13 is a flowchart of an tally table generation process. [Diagram 30] FIG. 13 is a diagram showing a tally table. [Diagram 31] 13 is a flowchart of a counting process. [Diagram 32] FIG. 13 is a diagram showing an updated summary table. [Diagram 33] 13 is a flowchart of a conversion table generation process. [Diagram 34] FIG. 13 is a diagram showing a conversion table. [Diagram 35] 13 is a flowchart of an instruction address replacement process. [Diagram 36] FIG. 13 is a diagram showing a converted summary table. [Figure 37] 13 is a flowchart of an output process. [Figure 38] FIG. 11 illustrates a second branch history file. [Figure 39] FIG. 11 is a diagram showing a first branch probability. [Diagram 40] FIG. 13 is a diagram illustrating a second branch probability. [Diagram 41] FIG. 13 illustrates a third branch probability. [Diagram 42] FIG. 2 is a hardware configuration diagram of an information processing device. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0014] Hereinafter, the embodiments will be described in detail with reference to the drawings.
[0015] BOLT (Binary Optimization and Layout Tool) is an example of a tool that rearranges BBs using PGO. BOLT rearranges BBs using the execution frequency of the BBs and the branch probability of each branch instruction.
[0016] Modern CPUs are equipped with hardware called a CPU monitor mechanism, which can obtain information on the frequency of BB execution by sampling instructions based on a cycle counter.
[0017] Instruction sampling based on the cycle counter is performed by the cooperation of the CPU monitor mechanism and the interrupt handler of the OS (Operating System). The CPU monitor mechanism uses an interrupt counter to output an interrupt trigger signal every certain number of clock cycles. When the interrupt trigger signal is output, the interrupt handler interrupts the CPU and records the instruction address indicated by the program counter at that time in a profile buffer, which is a storage area in memory.
[0018] Figure 1 shows an example of profile information recorded in a profile buffer. The profile information in Figure 1 includes a quadruplet of a core number, a thread ID, a cycle counter, and an instruction address. The profile buffer records multiple quadruplets in chronological order. In this example, the CPU is a multi-core processor and includes multiple cores.
[0019] The core number is identification information of a core included in the CPU, and the thread ID is identification information of a thread running in the core. The cycle counter is the value of the clock in the CPU, and counts up from 0 when the computer is turned on. The instruction address is the value of the program counter at the time indicated by the cycle counter.
[0020] The profile information is persisted in a performance profile file or the like before the profile buffer overflows, and once persistence is complete, the profile information is deleted from the profile buffer.
[0021] Figure 2 shows an example of a performance profile file generated from the profile information in Figure 1. The performance profile file in Figure 2 contains the same quads as the profile information in Figure 1.
[0022] In general usage of performance profiling, it is important to know the execution time for each symbol. A symbol represents a function name, a branch label name, etc. In this case, the number of times the most recent instruction address of each symbol was recorded is tallied from the contents of the performance profile file.
[0023] Fig. 3 shows an example of a symbol table showing the correspondence between symbols and addresses. The symbol table in Fig. 3 includes Address and Symbol. Address indicates an instruction address in an executable file, and Symbol indicates the name of the symbol to be counted.
[0024] In a normal program, the symbol table is generated by the compiler and embedded in the executable file. The summary result file is generated using the performance profile file and the symbol table.
[0025] Figure 4 shows an example of a compilation result file generated using the performance profile file in Figure 2 and the symbol table in Figure 3. The compilation result file in Figure 3 includes Overhead, Count, and Symbol. Count indicates the number of times the most recent instruction address of the symbol indicated by Symbol was recorded, and Overhead indicates the ratio of the number of times indicated by Count to the whole.
[0026] Among the information used for BB relocation, information indicating the execution frequency of BB is obtained from the count result file. In addition, if the CPU monitor mechanism includes the LBR, the branch probability of each branch instruction can be easily calculated from the information recorded in the LBR.
[0027] The LBR includes a branch source instruction address buffer and a branch destination instruction address buffer for each core included in the CPU. Each entry of the branch source instruction address buffer records a branch source instruction address, and a corresponding entry of the branch destination instruction address buffer records a branch destination instruction address.
[0028] The number of entries in the branch destination instruction address buffer is the same as the number of entries in the branch source instruction address buffer. The number of entries in each buffer varies depending on the type of CPU. However, LBR is implemented only in some CPUs from some vendors, but not in all CPUs.
[0029] Modern CPUs operate at frequencies of 1 GHz or higher, and a typical executable file contains a branch instruction every 5 to 10 instructions. Therefore, if the LBR is not implemented in the CPU and information equivalent to the LBR is collected by software, a huge amount of data will be generated.
[0030] For example, in a core operating at 3 GHz, if a 64-bit instruction address is recorded for every 10 instructions, a branch operation occurs approximately once every 3 nsec, generating 2.2 GB of data per second per core. If the generated data is not thinned out or compressed, the data generation speed will far exceed the IO (Input / Output) bandwidth of a normal computer.
[0031] Therefore, it is effective to apply binary instrumentation to compiled binary files to generate binary files that can collect information equivalent to that of LBR. With binary instrumentation, before executing a program in a binary file, instrumentation processing such as the following is embedded immediately before every branch instruction in the program:
[0032] (P1) In the case of a branch instruction whose branch destination is statically known, the CPU increments a counter variable prepared for each position of the branch instruction.
[0033] (P2) In the case of a branch instruction whose branch destination is not statically known, the CPU searches the hash table using a pair of the branch source instruction address and the branch destination instruction address as a key, and increments a counter variable in the entry corresponding to the key.
[0034] However, if the process of (P2) is embedded immediately before the branch instruction, the processing time for searching the hash table and incrementing the counter variable is added directly to the execution time of the program. Since branch instructions are generally executed frequently, the overhead of the process of (P2) becomes very large.
[0035] 5 shows an example of a functional configuration of a branch history recording system according to an embodiment. A branch history recording system 501 in FIG.
[0036] Fig. 6 is a flowchart showing an example of a branch history recording process performed by the branch history recording system 501 of Fig. 5. First, the first arithmetic processing unit 512 executes a write program to write branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation that occurs when the write program is executed, into the storage unit 511 (step 601).
[0037] Next, the second arithmetic processing unit 513 executes the branch control program to read branch information from the storage unit 511 and executes processing to branch to a code block corresponding to the branch information among a plurality of code blocks included in the branch control program (step 602).Then, the acquisition unit 514 acquires an instruction address of an executed instruction during execution of the branch control program (step 603) and records operation information including the instruction address of the executed instruction (step 604).
[0038] According to the branch history recording system 501 in FIG. 5, the branch history during program execution can be easily recorded.
[0039] Fig. 7 shows an example of a functional configuration of an information processing system corresponding to the branch history recording system 501 of Fig. 3. The information processing system 701 of Fig. 7 includes an instrumentation unit 711, a core 712-1, a core 712-2, a cyclic buffer 713, a CPU monitor mechanism 714, an acquisition unit 715, a conversion unit 716, a calculation unit 717, an output unit 718, and a storage unit 719.
[0040] The information processing system 701 includes a CPU, which is hardware. The CPU is a multi-core processor and includes multiple cores. A core 712-1 and a core 712-2 correspond to any of the cores included in the CPU. A CPU monitor mechanism 714 is a hardware circuit included in the CPU.
[0041] 5. The core 712-1, the core 712-2, the cyclic buffer 713, and the acquisition unit 715 correspond to the first arithmetic processing unit 512, the second arithmetic processing unit 513, the storage unit 511, and the acquisition unit 514 in FIG. 5, respectively.
[0042] The storage unit 719 stores a binary file 721, an instrumentation program 722, a branch control program 723, and a conversion program 724. The binary file 721 is a compiled executable file and includes a plurality of branch instructions. The binary file 721 is an example of a program to be analyzed.
[0043] Fig. 8 shows an example of a branch history recording process performed by the information processing system 701 in Fig. 7. A cyclic buffer 713 is provided for each core included in the CPU. The cyclic buffer 713 is a finite-length buffer including a plurality of storage areas.
[0044] The instrumentation unit 711 executes the instrumentation program 722 to perform binary instrumentation on the binary file 721. By performing the binary instrumentation, the instrumentation unit 711 embeds a code for writing branch information into the cyclic buffer 713 at the position of each branch instruction included in the binary file 721, and generates a binary file 725. Then, the instrumentation unit 711 stores the generated binary file 725 in the storage unit 719. The binary file 725 is an example of a writing program.
[0045] Furthermore, the instrumentation unit 711 generates an address correspondence table 726 and stores it in the storage unit 719. By performing the binary instrumentation, the size of each BB changes and the start address of each BB changes, so a pair of the start addresses of each BB before and after the binary instrumentation is recorded in the address correspondence table 726. This makes it possible to replace the branch destination instruction address of each branch instruction in the binary file 725 with the branch destination instruction address in the binary file 721 using the address correspondence table 726.
[0046] The address correspondence table 726 is an example of address correspondence information that associates a branch destination instruction address included in the branch information with a branch destination instruction address in the program to be analyzed.
[0047] Fig. 9 shows an example of the address correspondence table 726. The address correspondence table 726 in Fig. 9 includes BB_no, start_addr, and post_addr. BB_no is identification information of each BB included in the binary file 721. start_addr represents the start address of the BB in the binary file 721 before binary instrumentation, and post_addr represents the start address of the BB in the binary file 725 after binary instrumentation. "0x" indicates a hexadecimal numerical value.
[0048] Core 712-1 executes binary file 725 to write branch information of each branch instruction to a storage area of cyclic buffer 713 indicated by write pointer WP. The branch information includes a pair of a branch source instruction address and a branch destination instruction address of a branch operation generated by execution of a branch instruction. The branch source instruction address included in the branch information is the branch source instruction address in binary file 721, and the branch destination instruction address is the branch destination instruction address in binary file 725.
[0049] The core 712-2 executes the branch control program 723 asynchronously with the execution of the binary file 725 by the core 712-1, thereby simulating the branching operations that occur when the binary file 725 is executed.
[0050] Fig. 10 shows an example of the branch control program 723. The branch control program 723 in Fig. 10 includes a hash table 1001 and a code block 1002-0. The hash table 1001 includes code blocks 1002-1 to 1002-4 as entries. The hash table 1001 is a table that associates each of a plurality of hash values with one of the code blocks.
[0051] Code block 1002-0 represents an empty entry, and is included in the branch control program 723 when the branch control program 723 starts to execute. Code blocks 1002-1 to 1002-4 are dynamically generated during execution of the branch control program 723, and registered in the hash table 1001. Each code block 1002-k (k=0 to 4) contains the same code, and the execution time of each code block 1002-k is the same.
[0052] Code_min represents the minimum address value of the code block area including code blocks 1002-0 to 1002-4, and code_max represents the maximum address value of the code block area. Code_max is updated every time a new code block 1002-k is generated.
[0053] Figure 11 shows an example of code block 1002-k of Figure 10. Code block 1002-k of Figure 11 includes code 1101 to code 1104. Code 1101 is code for reading branch information from a storage area of the cyclic buffer 713 indicated by the read pointer RP. Code 1102 is code for calculating a hash value of the branch information.
[0054] Code 1103 is code that performs branch processing when the hash value hits the hash table 1001. If the code block 1002-k associated with the calculated hash value is included in the hash table 1001, the hash value hits.
[0055] Code 1104 is code that performs branch processing when a hash value misses in the hash table 1001. If the code block 1002-k associated with the calculated hash value is not included in the hash table 1001, the hash value misses.
[0056] The core 712-2 executes the branch control program 723 asynchronously with the execution of the binary file 725 by the core 712-1. By executing the code 1101 in the code block 1002-k, the branch information is read from the storage area of the cyclic buffer 713 indicated by the read pointer RP asynchronously with the write operation by the core 712-1.
[0057] Next, the core 712-2 executes the code 1102 to calculate a hash value of the read branch information, and checks whether the calculated hash value hits the hash table 1001 or not.
[0058] If the hash value is a match, the core 712-2 executes the code 1103 to identify the code block 1002-k associated with the hash value as a branch destination, and executes a process to branch to the branch destination code block 1002-k. The core 712-2 then executes the branch destination code block 1002-k.
[0059] When the hash value is a miss-hit, the core 712-2 executes the code 1104 to copy any one of the code blocks 1002-k included in the hash table 1001 and generate a code block 1002-k of the branch destination corresponding to the branch information. Then, the core 712-2 registers the code block 1002-k of the branch destination in the hash table 1001 in association with the hash value.
[0060] Furthermore, the core 712-2 associates the start address of the branch destination code block 1002-k with the branch information and records it in the symbol table 727 in the storage unit 719. The symbol table 727 is an example of code block information. The core 712-2 then executes a process to branch to the branch destination code block 1002-k, and executes the branch destination code block 1002-k.
[0061] By using the hash table 1001 that associates hash values of branch information with code blocks 1002-k, the code block 1002-k that corresponds to the branch information read from the cyclic buffer 713 can be identified at high speed.
[0062] Furthermore, if the hash value misses, the code block 1002-k is copied to generate a code block 1002-k that corresponds to the branch information, thereby making it possible to align the execution time of each code block 1002-k to a fixed time.
[0063] Fig. 12 shows an example of a symbol table 727 that associates a code block 1002-k with branch information. The symbol table 727 in Fig. 12 is provided for each core and each thread, and includes a code block address, a sip, and a tip. The code block address indicates the start address of the branch destination code block 1002-k. The sip indicates the branch source instruction address included in the branch information, and the tip indicates the branch destination instruction address included in the branch information.
[0064] "0x5000000" represents the start address of code block 1002-0. The sip and tip corresponding to code block 1002-0 are "0".
[0065] "0x5001000" represents the start address of code block 1002-1. The sip corresponding to code block 1002-1 is "0xFA0", and the tip is "0x42201". "0x5002000" represents the start address of code block 1002-2. The sip corresponding to code block 1002-2 is "0x380", and the tip is "0x403F0".
[0066] "0x5003000" represents the start address of code block 1002-3. The sip corresponding to code block 1002-3 is "0x40", and the tip is "0x40000". "0x5004000" represents the start address of code block 1002-4. The sip corresponding to code block 1002-4 is "0x316", and the tip is "0x56044".
[0067] When the branch control program 723 is being executed by the core 712-2, the CPU monitor mechanism 714 uses an interrupt counter to output an interrupt trigger signal every fixed number of clock cycles.
[0068] When an interrupt trigger signal is output, the acquisition unit 715 executes an interrupt handler to acquire profile information 728 including the instruction addresses of the executed instructions, and records the profile information 728 in the storage unit 719. The acquisition unit 715 then generates a performance profile file 729 from the profile information 728 and stores the performance profile file 729 in the storage unit 719. The performance profile file 729 is an example of operation information including the instruction addresses of the executed instructions.
[0069] Fig. 13 shows an example of a performance profile file 729 generated by the acquisition unit 715. The performance profile file 729 in Fig. 13 includes quadruplets similar to those in the performance profile file in Fig. 2. Fig. 13 shows only a portion of the quadruplets included in the performance profile file 729, with the remaining quadruplets omitted.
[0070] The conversion unit 716 executes the conversion program 724 using the address correspondence table 726 and the symbol table 727 to convert the performance profile file 729 into a branch history file 730. The branch history file 730 includes pairs of branch source instruction addresses and branch destination instruction addresses in the binary file 721 before binary instrumentation. The branch history file 730 is an example of branch history information including pairs of branch source instruction addresses and branch destination instruction addresses in the analysis target program.
[0071] Fig. 14 shows an example of a first branch history file 730. The branch history file 730 in Fig. 14 includes a sip, a tip, and a tally counter. The sip and tip included in the branch history file 730 represent a pair of a branch source instruction address and a branch destination instruction address in the binary file 721. The tally counter represents the number of times a branch operation corresponding to the pair of sip and tip has occurred during execution of the binary file 725.
[0072] The calculation unit 717 calculates the branch probability for each branch instruction using the branch history file 730, and the output unit 718 outputs the calculated branch probability. The user can rearrange the BB by the BOLT using the calculated branch probability and the execution frequency of the BB. The output unit 718 may output the branch history file 730 instead of the branch probability.
[0073] Here, the branch probability will be explained using a virtual die representing the branch history. The die is a polyhedron having multiple faces, and the number M of faces is the same as the total number of branch operations that occurred during the execution of the binary file 725. The number X(k) (k=1 to K) displayed on each face includes a pair of sip and tip. K represents the total number of pairs of sip and tip recorded in the branch history file 730.
[0074] The probability P(k) of getting a particular number X(k) when rolling a die is proportional to the number M(k) of faces that have X(k) and is expressed by the following formula:
[0075] P(k)=M(k) / M (1)
[0076] Even when dice numbers are sampled, the probability of a particular number X(k) being sampled is expressed by formula (1). Therefore, by replacing all faces with processes of the same execution time and sampling the numbers corresponding to each process using the CPU monitor mechanism 714, it becomes possible to calculate the branch probability.
[0077] Each code block 1002-k in Fig. 10 is associated with branch information via the hash value of the branch information. Also, each code block 1002-k starts from a different instruction address, but has the same execution time. In this case, the code block 1002-k can be associated with the number X(k) on the dice.
[0078] When an instruction address is sampled by the CPU monitor mechanism 714 at any timing during execution of the branch control program 723, the probability that the sampled instruction address is an instruction address within the code block 1002-k coincides with the probability P(k). Therefore, the cooperation between the branch control program 723 and the CPU monitor mechanism 714 is equivalent to stochastically simulating an LBR.
[0079] 7, even if an LBR is not implemented in a CPU, the branch history during execution of a binary file 725 can be easily recorded by the cooperative operation of a branch control program 723 and a CPU monitor mechanism 714. This makes it possible to calculate the branch probability for each branch instruction in the same way as when an LBR is implemented in a CPU.
[0080] Since the branch history can be recorded without depending on the LBR, which is not a very common piece of hardware, the versatility of the information processing system 701 is increased.
[0081] 8, only the code for writing branch information to the cyclic buffer 713 is embedded in the binary file 725. Then, a core 712-2 different from the core 712-1 executing the binary file 725 searches the hash table 1001 and asynchronously performs the process of branching to the next code block 1002-k.
[0082] Therefore, the processing time required for manipulating the hash table 1001 is not added to the execution time of the binary file 725, and the overhead during execution of the binary file 725 is reduced.
[0083] 15 is a flowchart showing an example of binary instrumentation processing performed by the instrumentation unit 711. First, the instrumentation unit 711 reads the binary file 721 (step 1501), and converts the binary file 721 into an intermediate representation of machine instructions (step 1502).
[0084] Next, the instrumentation unit 711 repeats the processes of steps 1503 to 1505 while incrementing the control variable pos, which indicates the position of an instruction included in the intermediate representation, by 1 from 0 to N. 0 represents the position of the first instruction, and N represents the position of the last instruction.
[0085] In step 1503, the instrumentation unit 711 sets the instruction instructions[pos] at the position indicated by pos to the variable instr. In step 1504, the instrumentation unit 711 checks whether instr is a branch instruction.
[0086] If instr is a branch instruction (step 1504, YES), the instrumentation unit 711 performs the block generation process in step 1505. Then, the instrumentation unit 711 processes the instruction at the next position. If instr is not a branch instruction (step 1504, NO), the instrumentation unit 711 processes the instruction at the next position without performing the block generation process.
[0087] Next, the instrumentation unit 711 generates code for the instructions added or changed by the block generation process (step 1506), and generates an address correspondence table 726 (step 1507). Then, the instrumentation unit 711 generates a binary file 725 using the code generated in step 1506 (step 1508).
[0088] Fig. 16 is a flowchart showing an example of the block generation process in step 1505 in Fig. 15. First, the instrumentation unit 711 generates a block B (step 1601). The block B includes the following intermediate representation.
[0089] R1: Save the register and machine status values onto the stack. R2: Read core number c. R3:bp=cycle_buff[c] R4:widx=write_index[c] R5: Write (sip, tip) to bp[Mod(widx, bufsz)]. R6: write_index[c]=widx+1 R7: Restores register and machine status values from the stack. R8: Branch
[0090] The machine status of R1 represents a flag register different from the general-purpose register. R3 is a process of setting the head position cycle_buff[c] of the cyclic buffer 713 for the core indicated by the core number c to the variable bp. R4 is a process of setting the write index write_index[c] for the core indicated by the core number c to the variable widx.
[0091] The buffer size bufsz in R5 represents the number of memory areas included in the cyclic buffer 713. Mod(widx, bufsz) represents the remainder when widx is divided by bufsz. bp[Mod(widx, bufsz)] represents the position where Mod(widx, bufsz) is added to bp, and is used as the write pointer WP. (sip, tip) represents a pair of the branch source instruction address sip in the binary file 721 and the branch destination instruction address tip in the binary file 725. R6 is a process of setting widx+1 to write_index[c].
[0092] Next, the instrumentation unit 711 sets the generated block B to instructions[pos] (step 1602).
[0093] 17 shows an example of binary instrumentation processing. FIG. 17(a) shows an example of a branch instruction included in a binary file 721 before binary instrumentation. “0x40” represents the branch source instruction address, and “call * "%rax" represents a branch instruction. This branch instruction is an indirect branch, and the branch destination instruction address is stored in the register %rax.
[0094] Fig. 17(b) shows an example of a block B generated by the block generation process for the branch instruction in Fig. 17(a). push_allregs corresponds to the process of R1, the call of the function write_cyclic_buffer corresponds to the processes of R2 to R6, and pop_allregs corresponds to the process of R7.
[0095] 17(b), block B performs processing to branch to the branch destination instruction address in register %rax after the branch source instruction address “0x40” and the branch destination instruction address in register %rax are written to the cyclic buffer 713. Writing to the cyclic buffer 713 is performed by calling the function write_cyclic_buffer.
[0096] Fig. 18 shows an example of a binary file 725 after binary instrumentation. The binary file 725 in Fig. 18 includes the block B shown in Fig. 17(b). When the core 712-1 executes the instruction at the instruction address "0x100", the branch destination instruction address "0x210" is set in the register %rax.
[0097] Next, when the core 712-1 executes instructions from instruction address "0x130" to immediately before instruction address "0x140", (0x40, 0x210) is written to the cyclic buffer 713. (0x40, 0x210) represents a pair of a branch source instruction address and a branch destination instruction address. After that, the core 712-1 executes a branch instruction at instruction address "0x140", thereby branching to branch destination instruction address "0x210" and executing instructions at and after the branch destination instruction address "0x210".
[0098] 19 is a flowchart showing an example of branch control processing performed by the core 712-2. The core 712-2 executes any one of the code blocks 1002-k included in the branch control program 723 to perform the branch control processing of FIG.
[0099] When the execution of the branch control program 723 starts, none of the code blocks 1002-k are registered in the hash table 1001, so the code block 1002-0 included in the branch control program 723 is executed.
[0100] First, the core 712-2 checks whether the cyclic buffer 713 is empty (step 1901). If the cyclic buffer 713 is empty (step 1901, YES), the core 712-2 branches to the code block 1002-0, which is an empty entry (step 1911). Then, the core 712-2 repeats the branch control process by executing the code block 1002-0, which is the branch destination.
[0101] If the cyclic buffer 713 is not empty (step 1901, NO), the core 712-2 reads (sip, tip) from the storage area indicated by the read pointer RP (step 1902). The core 712-2 then calculates the hash value hash(sip, tip) of (sip, tip) and sets hash(sip, tip) to the variable index (step 1903).
[0102] Next, the core 712-2 searches the hash table 1001 using the index as a key, and obtains the value of the variable next_ip that indicates the code block 1002-k that corresponds to the index (step 1904). If the index hits the hash table 1001, the value of next_ip is the start address of the branch destination code block 1002-k. If the index misses the hash table 1001, the value of next_ip is NULL.
[0103] Next, the core 712-2 checks whether next_ip is NULL (step 1905). If next_ip is NULL (step 1905, YES), the core 712-2 allocates an area for a new code block 1002-k to the position of code_max in Fig. 10 (step 1906). The core 712-2 then updates code_max by setting the upper limit of the address of the allocated area to code_max.
[0104] Next, the core 712-2 generates a new code block 1002-k by copying the code of any of the code blocks 1002-k registered in the hash table 1001 to the allocated area (step 1907). Then, the core 712-2 registers the generated code block 1002-k in the hash table 1001 in association with the index (step 1908). As a result, the code block 1002-k corresponding to the index is added to the branch control program 723.
[0105] Next, the core 712-2 sets the start address of the generated code block 1002-k to next_ip, and records the set of next_ip, sip, and tip in the symbol table 727 (step 1909). Next_ip is recorded as the code block address in the symbol table 727.
[0106] Next, the core 712-2 branches to the code block 1002-k indicated by next_ip (step 1910).Then, the core 712-2 executes the code block 1002-k of the branch destination, thereby repeating the branch control process.
[0107] If next_ip is not NULL (step 1905 , NO), the core 712 - 2 performs the process of step 1910 .
[0108] 20 shows an example of the first state of the cyclic buffer 713. IDX represents the index of the cyclic buffer 713, and the branch information represents (sip, tip).
[0109] The write pointer WP is the remainder when the write index is divided by the buffer size bufsz. The read pointer RP is the remainder when the read index is divided by bufsz. If the write index is 100002 and bufsz is 10, then WP = Mod(100002,10) = 2.
[0110] The write index is always greater than the read index. When the read index overtakes the write index, it means that the cyclic buffer 713 is empty.
[0111] 21 shows an example of a second state of the cyclic buffer 713. When (0x40, 0x210) is written to the position IDX=2 and then the write index is incremented by 1 to 100003, WP=Mod(100003, 10)=3. Then, (0x316, 0x3E8) is written to the position IDX=3.
[0112] 22 shows an example of a third state of the cyclic buffer 713. When the read index is equal to or greater than the write index, the cyclic buffer 713 is empty, so processing is performed to branch to code block 1002-0.
[0113] If the read index is smaller than the write index, the read index is divided by bufsz to find the read pointer RP, and the branch information is read from the position indicated by the read pointer RP. If the read index is 99991, RP = Mod(99991,10) = 1, and (0x380,0x62) is read from the position where IDX = 1.
[0114] By writing branch information to the position indicated by the write pointer WP and reading the branch information from the position indicated by the read pointer RP, the core 712-1 and the core 712-2 can independently perform writing and reading.
[0115] 23 shows an example of a fourth state of the cyclic buffer 713. When the write index is 100003 and bufsz is 10, the cyclic buffer 713 stores the latest 10 pieces of branch information corresponding to write indexes of 99993 to 100002.
[0116] The read index is 99981, which is smaller than 99993. For this reason, if branch information is read while simply incrementing the read index by 1, (0x380, 0x62) is read from position IDX=1 when the read index is 99981, 99991, and 100001. In this way, if the difference between the write index and the read index is greater than or equal to I and less than I+1 times bufsz (I is a positive integer), the same branch information will be read I+1 times.
[0117] Therefore, in order to prevent the same branch information from being read out more than once, for example, the following intermediate representation code is used as the code 1101 in FIG.
[0118] R11:ridx=read_index[c] R12:widx=write_index[c] R13:if (ridx >= widx) goto empty-entry R14: if (widx >= ridx + bufsz) then ridx=widx-bufsz R15:v=cycle_buff[c][Mod(ridx,bufsz)] R16: read_index[c] = ridx + 1 R17:sip=v.sip R18:tip=v.tip R19:ridx=read_index[c]
[0119] R11 is a process for setting the current read index read_index[c] of the core indicated by the core number c to the variable ridx. R12 is a process for setting the current write index write_index[c] of the core indicated by the core number c to the variable widx.
[0120] R13 is a process for branching to empty-entry if ridx is equal to or greater than widx. empty-entry represents code block 1002-0. R14 is a process for adjusting ridx by setting widx-bufsz to ridx if widx is equal to or greater than ridx+bufsz. If the difference between widx and ridx is equal to or greater than bufsz, ridx is advanced to widx-bufsz to avoid reading duplicate branch information.
[0121] R15 is a process of reading (sip, tip) from the position obtained by adding Mod(ridx, bufsz) to the start position cycle_buff[c] of the cyclic buffer 713 for the core indicated by the core number c, and setting the read value to the variable v.
[0122] Mod(ridx,bufsz) represents the remainder when ridx is divided by bufsz. The position obtained by adding Mod(ridx,bufsz) to cycle_buff[c] is used as the read pointer RP.
[0123] R16 is a process of setting ridx+1 to read_index[c]. R17 is a process of extracting sip from v. R18 is a process of extracting tip from v. R19 is a process of setting read_index[c] to ridx.
[0124] Figure 24 shows an example of the fifth state of the cyclic buffer 713. As shown in Figure 23, when the write index is away from the read index by bufsz or more, the process of R14 is performed to avoid reading duplicate branch information.
[0125] In this example, since widx-bufsz=100003-10=99993, the read index is changed from 99981 to 99993. As a result, the read index will not become 99981 or 99991, and (0x380, 0x62) will not be read twice from the position IDX=1.
[0126] Even if the read index is advanced all the way up to 100000 in one go, the effect of avoiding duplicated reading can be obtained, but the number of pieces of branch information read from the cyclic buffer 713 will decrease. For this reason, it is preferable to advance the read index to a position that is smaller than the write index by bufsz.
[0127] In order to prevent the same branch information from being read out more than once, the following intermediate representation code may be used as the code 1101 in FIG.
[0128] R21:ridx=read_index[c] R22:widx=write_index[c] R23:if (ridx >= widx) goto empty-entry R24:v=VOID R25: swap(v, cycle_buff[c][Mod(ridx,bufsz)]) R26: read_index[c] = ridx + 1 R27:if (v is VOID) goto empty-entry R28:sip=v.sip R29:tip=v.tip
[0129] The processes of R21 to R23 are the same as those of R11 to R13. R24 is a process of initializing a variable v by setting VOID to v. R25 is a process of finding a read position by adding Mod(ridx, bufsz) to the start position cycle_buff[c] of the cyclic buffer 713 for the core indicated by the core number c, and exchanging the branch information stored in the read position with the value of v.
[0130] By the process of R25, the branch information read from the storage area of the cyclic buffer 713 indicated by the read pointer RP is set to v, and a VOID is written to that storage area. When the branch information written in the cyclic buffer 713 is read, the branch information is replaced with a VOID, thereby avoiding the reading of duplicate branch information.
[0131] The process of R26 is the same as that of R16. R27 is a process to branch to an empty-entry if v is VOID. The processes of R28 and R29 are the same as that of R17 and R18.
[0132] When the writing speed of branch information exceeds the reading speed and the cyclic buffer 713 becomes full, the execution of the binary file 725 may be temporarily stopped and resumed after the reading of the branch information has caught up.
[0133] 25 shows an example of the first state of the hash table 1001. "key" represents a key in the hash table 1001, and "code" represents the number k of the code block 1002-k associated with the key.
[0134] If (sip, tip) read from the cyclic buffer 713 is (0x380, 0x62) and its hash value is "0x2", the hash table 1001 is searched using "0x2" as a key, and NULL is obtained as next_ip.
[0135] 26 shows an example of the second state of the hash table 1001. Because next_ip=NULL, an area for a new code block 1002-88 is allocated and the code of any of the code blocks 1002-k is copied to generate the code block 1002-88. The code block 1002-88 is then registered in the hash table 1001 in association with "0x2."
[0136] Thereafter, when (0x380, 0x62) is read from the cyclic buffer 713 by executing any one of the code blocks 1002-k, the hash value "0x2" is used as a key to search the hash table 1001. Then, the start address of the code block 1002-88 is obtained as next_ip, and processing is performed to branch to the code block 1002-88.
[0137] 27 shows an example of an execution sequence of the branch control program 723. The horizontal axis represents the code block 1002-k (k=0, 1, 2, 11), and the vertical axis represents the passage of time. The horizontal dashed lines represent the timing at which the CPU monitor mechanism 714 samples an instruction address, and the sampling result represents the number k of the code block 1002-k to which the sampled instruction address belongs.
[0138] 28 is a flowchart showing an example of conversion processing performed by the conversion unit 716. First, the conversion unit 716 performs tally table generation processing (step 2801), and performs tally processing (step 2802). Next, the conversion unit 716 performs conversion table generation processing (step 2803), and performs instruction address replacement processing (step 2804). Next, the conversion unit 716 performs output processing (step 2805).
[0139] Fig. 29 is a flowchart showing an example of the tally table generation process in step 2801 of Fig. 28. First, conversion unit 716 opens symbol table 727 (step 2901), and checks whether all entries in symbol table 727 have been processed (step 2902).
[0140] If there are any unprocessed entries remaining (step 2902, NO), the conversion unit 716 selects one entry and reads out a set of the code block address, sip, and tip from the selected entry (step 2903). The conversion unit 716 then registers the read out set in the tally table (step 2904) and repeats the processes from step 2902 onwards. The tally table is generated in the storage unit 719.
[0141] If all entries have been processed (step 2902, YES), conversion unit 716 closes symbol table 727 (step 2905).
[0142] Fig. 30 shows an example of an tally table generated from symbol table 727 of Fig. 12. The tally table of Fig. 30 includes a hash table 3001. Hash table 3001 includes entries 3002-0 through 3002-4.
[0143] Hash table 3001 is a table that associates each of a plurality of keys with one of entries 3002-k (k=0 to 4). In this case, five code block addresses in symbol table 727 in Fig. 12 are used as keys. In Fig. 30, "0x5003000" and "0x5004000" are omitted from the five code block addresses.
[0144] Each entry 3002-k includes a sip, a tip, and a tally counter. In the sip and tip of the entry 3002-k corresponding to each code block address, the sip and tip corresponding to the same code block address in the symbol table 727 are registered. The tally counter is set to an initial value of 0.
[0145] Fig. 31 is a flowchart showing an example of the tallying process in step 2802 in Fig. 28. First, the conversion unit 716 opens the performance profile file 729 (step 3101), and checks whether all entries in the performance profile file 729 have been processed (step 3102).
[0146] If there are any unprocessed entries remaining (step 3102, NO), the conversion unit 716 selects one entry and reads the instruction address from the selected entry (step 3103). The conversion unit 716 then checks whether the read instruction address is included in the range of the code block area of the hash table 1001 in the branch control program 723 (step 3104). The range of the code block area is from code_min to code_max.
[0147] If the instruction address is included in the range of the code block area (step 3104, YES), the conversion unit 716 sets the instruction address to the variable code_ip. Then, the conversion unit 716 calculates the start address Addr of the code block 1002-k that includes code_ip by the following formula (step 3105).
[0148] Addr=code_ip -Mod((code_ip-code_min),S) (2)
[0149] S represents the size of the code block 1002-k. Mod((code_ip-code_min),S) represents the remainder when the difference between code_ip and code_min is divided by S.
[0150] Next, conversion unit 716 searches hash table 3001 using Addr as a key (step 3106), and increments the tally counter of entry 3002-k corresponding to Addr by 1 (step 3107). Then, conversion unit 716 repeats the processes from step 3102 onwards.
[0151] If the instruction address is not included in the range of the code block area (step 3104, NO), the conversion unit 716 repeats the processes from step 3102 onwards. If all entries have been processed (step 3102, YES), the conversion unit 716 closes the performance profile file 729 (step 3108).
[0152] According to the counting process of FIG. 31, the number of instruction addresses included in the code block 1002-k corresponding to the pair of sip and tip among the instruction addresses recorded in the performance profile file 729 is recorded in the counting counter corresponding to that pair.
[0153] Fig. 32 shows an example of an aggregation table updated by the aggregation process. The aggregation table in Fig. 32 is generated by updating the aggregation table in Fig. 30 using the performance profile file 729 in Fig. 13. The aggregation counter corresponding to the pair of sip and tip in Fig. 32 indicates the number of instruction addresses included in the code block 1002-k corresponding to that pair, among the instruction addresses recorded in the performance profile file 729 in Fig. 13.
[0154] Fig. 33 is a flowchart showing an example of the conversion table generation process in step 2803 of Fig. 28. First, the conversion unit 716 opens the address correspondence table 726 (step 3301), and checks whether all entries in the address correspondence table 726 have been processed (step 3302).
[0155] If an unprocessed entry remains (step 3302, NO), the conversion unit 716 selects one entry and reads the set of start_addr and post_addr from the selected entry (step 3303). The conversion unit 716 then registers the read set in the conversion table (step 3304) and repeats the processes from step 3302 onwards. The conversion table is generated in the storage unit 719.
[0156] If all entries have been processed (step 3302, YES), the conversion unit 716 closes the address correspondence table 726 (step 3305).
[0157] Fig. 34 shows an example of a conversion table generated from the address correspondence table 726 of Fig. 9. The conversion table of Fig. 34 includes a hash table 3401. The hash table 3401 includes entries 3402-0 to 3402-4.
[0158] The hash table 3401 is a table that associates each of a plurality of keys with one of the entries 3402-k (k=0 to 4). In this case, the five post_addrs in the address correspondence table 726 in FIG.
[0159] Each entry 3402-k includes a start_addr. In the start_addr of the entry 3402-k corresponding to each post_addr, the start_addr corresponding to the same post_addr in the symbol table 727 is registered.
[0160] Fig. 35 is a flow chart showing an example of the instruction address replacement process in step 2804 of Fig. 28. The conversion unit 716 performs the processes of steps 3501 to 3504 for each key registered in the hash table 3001 of the tally table.
[0161] The conversion unit 716 reads the tip from the entry 3002-k corresponding to the key (step 3501), and checks the value of the tip (step 3502).
[0162] If the tip is not 0 (step 3502, NO), the conversion unit 716 searches the conversion table hash table 3401 using the tip as a key, and obtains the start_addr of the entry 3402-k corresponding to the tip (step 3503).The conversion unit 716 then changes the tip of the aggregation table used as the key to the obtained start_addr (step 3504).
[0163] If the tip is 0 (step 3502, YES), the conversion unit 716 does not change the tip.
[0164] 35, the tip registered in the tally table is converted into the start address of the BB in the binary file 721 before binary instrumentation. Therefore, a tally counter can be associated with a pair of a branch source instruction address and a branch destination instruction address in the binary file 721.
[0165] Fig. 36 shows an example of a tally table converted by the instruction address replacement process. The tally table in Fig. 36 is generated by converting the tally table in Fig. 32 using the conversion table in Fig. 34. The tip in Fig. 36 is changed to start_addr in the conversion table in Fig. 34.
[0166] Fig. 37 is a flowchart showing an example of the output process in step 2805 in Fig. 28. At the start of the output process, a set of a sip, a tip, and a tally counter has not yet been recorded in the branch history file 730.
[0167] First, the conversion unit 716 opens the branch history file 730 (step 3701), and performs the processes of steps 3702 to 3704 for each key registered in the hash table 3001 of the tally table.
[0168] The conversion unit 716 reads the tip from the entry 3002-k corresponding to the key (step 3702), and checks the value of the tip (step 3703).
[0169] If the tip is not 0 (step 3703, NO), the conversion unit 716 records the set of the sip, tip, and tally counter of that entry 3002-k in the branch history file 730 (step 3704).
[0170] If the tip is 0 (step 3703 , YES), the conversion unit 716 does not record the set of sip, tip, and tally counter of that entry 3002 - k in the branch history file 730 .
[0171] After the processes of steps 3702 to 3704 are completed for all keys, the conversion unit 716 closes the branch history file 730 (step 3705).
[0172] By the output process of Fig. 37, the branch history file 730 of Fig. 14 is generated from the tally table of Fig. 36. Since entry 3002-0 of the tally table of Fig. 36 is information on a branch operation that does not exist in the binary file 721 before binary instrumentation, that information has been deleted from the branch history file 730 of Fig. 14.
[0173] 28, the performance profile file 729 of the branch control program 723 is converted into a branch history file 730 using an address correspondence table 726 and a symbol table 727. This makes it possible to obtain the branch history of the binary file 721 before binary instrumentation from profile information obtained by simulating the branch operation in the binary file 725 after binary instrumentation.
[0174] Next, specific examples of branch probabilities calculated from the branch history file 730 will be described with reference to FIGS.
[0175] Fig. 38 shows an example of a second branch history file 730. The branch history file 730 in Fig. 38 includes a sip, a tip, and a tally counter, similar to the branch history file 730 in Fig. 14.
[0176] Fig. 39 shows an example of a first branch probability calculated from the branch history file 730 of Fig. 38. The branch probabilities of Fig. 39 represent branch probabilities from the same branch source to different branch destinations.
[0177] A sip represents a sip in the branch history file 730, and a tip of a branch destination m (m=1 to 3) represents the m-th tip associated with the same sip in the branch history file 730.
[0178] The tally counter for each branch destination m represents the value of the tally counter associated with a pair of sip and tip in the branch history file 730. The calculation unit 717 calculates the ratio of the tally counter for branch destination m to the sum of the tally counters for branch destinations 1 to 3 as the branch probability for branch destination m.
[0179] For example, when sip="0x50FA0", the tip of branch destination 1 is "0x41092", the tip of branch destination 2 is "0x43FF0", and the tip of branch destination 3 is "0x40000". The tally counter of branch destination 1 is "3218629", the tally counter of branch destination 2 is "535", and the tally counter of branch destination 3 is "1062147". Therefore, the sum of the tally counters of branch destination 1 to branch destination 3 is "4281311".
[0180] In this case, the branch probability from "0x50FA0" to branch destination 1 is 3218629 / 4281311=0.7518. The branch probability from "0x50FA0" to branch destination 2 is 535 / 4281311=0.0001. The branch probability from "0x50FA0" to branch destination 3 is 1062147 / 4281311=0.2481.
[0181] For other sips, since branch destination 2 and branch destination 3 do not exist, the branch probability of branch destination 1 is 1.0.
[0182] Fig. 40 shows an example of a second branch probability calculated from the branch history file 730 of Fig. 38. The branch probabilities of Fig. 40 represent branch probabilities from different branch sources to the same branch destination.
[0183] A tip represents a tip in the branch history file 730, and a sip of a branch source m (m=1 to 3) represents the mth sip associated with the same tip in the branch history file 730.
[0184] The tally counter of each branch source m represents the value of the tally counter associated with a pair of sip and tip in the branch history file 730. The calculation unit 717 calculates the ratio of the tally counter of branch source m to the sum of the tally counters of branch sources 1 to 3 as the branch probability of branch source m.
[0185] For example, when tip="0x40000", the sip of branch source 1 is "0x50240", the sip of branch source 2 is "0x5482B", and the sip of branch source 3 is "0x50FA0". The tally counter of branch source 1 is "1845144", the tally counter of branch source 2 is "900202", and the tally counter of branch source 3 is "1062147". Therefore, the sum of the tally counters of branch source 1 to branch source 3 is "3807493".
[0186] In this case, the branch probability from branch source 1 to "0x40000" is 1845144 / 3807493 = 0.4846. The branch probability from branch source 2 to "0x40000" is 900202 / 3807493 = 0.2364. The branch probability from branch source 3 to "0x40000" is 1062147 / 3807493 = 0.2790.
[0187] For other tips, since branch source 2 and branch source 3 do not exist, the branch probability of branch source 1 is 1.0.
[0188] Fig. 41 shows an example of the third branch probability calculated from the branch history file 730 of Fig. 38. The branch probabilities of Fig. 41 represent the occurrence probability of each combination among all combinations of sip and tip.
[0189] sip, tip, and the tally counter represent sip, tip, and the tally counter in the branch history file 730. The calculation unit 717 calculates the ratio of the tally counter of each combination to the sum of the tally counters of all combinations of sip and tip as the branch probability. The sum of the tally counters of all combinations of sip and tip is "10831285".
[0190] For example, when the combination of sip and tip is “0x50FA0” and “0x41092”, the tally counter is “3218629.” In this case, the branch probability of the combination of “0x50FA0” and “0x41092” is 3218629 / 10831285=0.29716.
[0191] 7, since a cyclic buffer 713 is provided for each core, mutual exclusion control between the cores is not required. Therefore, the branch history recording process can be easily applied to parallel programs such as multi-threads or multi-processes.
[0192] In addition, since the cyclic buffer 713 is a buffer of finite length, the storage area of the cyclic buffer 713 does not increase indefinitely, and there is no need to interrupt the execution of the binary file 725 in order to read branch information from the cyclic buffer 713.
[0193] When the execution time of the binary file 725 becomes long, the branch probability of the branch instruction may change over time. Even in such a case, the change in the branch probability over time can be detected by generating the branch history file 730 at predetermined intervals based on the cycle counter recorded in the performance profile file 729.
[0194] When performing binary instrumentation on the binary file 721, the instrumentation unit 711 can also extract the branch destination instruction address of a static branch instruction included in the binary file 721 to generate branch destination information.
[0195] In this case, the core 712-2 acquires memory map information immediately before starting execution of the binary file 725, and calculates a hash value of branch information of a static branch instruction based on the branch destination information and memory map information. The core 712-2 then registers the branch destination code block 1002-k in the hash table 1001 in association with the calculated hash value.
[0196] As a result, next_ip=NULL is set in step 1905 only when (sip, tip) of a dynamic branch instruction is read in step 1902 of Fig. 19. When (sip, tip) of a static branch instruction is read, next_ip=NULL is not set, and therefore the frequency with which the processes of steps 1906 to 1909 are performed decreases. As a result, the number of times that a set of next_ip, sip, and tip is recorded in symbol table 727 during execution of branch control program 723 decreases.
[0197] The configuration of the branch history recording system 501 in FIG. 5 is merely an example, and some of the components may be omitted or changed depending on the application or conditions of the branch history recording system 501.
[0198] 7 is merely an example, and some of the components may be omitted or changed depending on the application or conditions of the information processing system 701. For example, when an external device calculates the branch probability, the calculation unit 717 can be omitted.
[0199] The flowcharts of Figures 6, 15, 16, 19, 28, 29, 31, 33, 35, and 37 are merely examples, and some of the processing may be omitted or modified depending on the configuration or conditions of the branch history recording system 501 or the information processing system 701.
[0200] The profile information shown in Fig. 1, the performance profile file shown in Fig. 2, and the performance profile file 729 shown in Fig. 13 are merely examples, and the profile information and the performance profile file change depending on the program being executed. The symbol table shown in Fig. 3 and the tabulation result file shown in Fig. 4 are merely examples, and the symbol table and the tabulation result file change depending on the program being executed.
[0201] 8 is merely an example, and some of the processes may be omitted or changed depending on the configuration or conditions of the information processing system 701. The address correspondence table 726 shown in FIG 9 is merely an example, and the address correspondence table 726 changes depending on the binary file 721.
[0202] The branch control program 723 shown in FIG. 10 and the code block 1002-k shown in FIG. 11 are merely examples, and a branch control program 723 and code block 1002-k of a different structure may be used depending on the configuration or conditions of the information processing system 701.
[0203] 12 is merely an example, and symbol table 727 changes depending on branch control program 723 and binary file 725. Branch history file 730 shown in Figures 14 and 38 is merely an example, and branch history file 730 changes depending on binary file 721. The binary instrumentation process shown in Figure 17 and binary file 725 shown in Figure 18 are merely an example, and the binary instrumentation process and binary file 725 change depending on binary file 721.
[0204] The cyclic buffer 713 shown in Figures 20 to 24 is merely an example, and the branch information of the cyclic buffer 713 changes depending on the binary file 721 and the binary file 725. The hash table 1001 shown in Figures 25 and 26 is merely an example, and the code block 1002-k registered in the hash table 1001 changes depending on the branch information. The execution sequence of the branch control program 723 shown in Figure 27 is merely an example, and the execution sequence changes depending on the branch information.
[0205] 30, 32, and 36 are merely examples, and the aggregation tables change according to the symbol table 727 and the performance profile file 729. The conversion table shown in Fig. 34 is merely an example, and the conversion table changes according to the address correspondence table 726. The branch probabilities shown in Figs. 39 to 41 are merely examples, and the branch probabilities change according to the branch history file 730.
[0206] The formulas (1) and (2) are merely examples, and the information processing system 701 may perform the branch history recording process using other calculation formulas.
[0207] Fig. 42 shows an example of the hardware configuration of an information processing device (computer) used as the branch history recording system 501 of Fig. 5 and the information processing system 701 of Fig. 7. The information processing device of Fig. 42 includes a CPU 4201, a memory 4202, an input device 4203, an output device 4204, an auxiliary storage device 4205, a medium drive device 4206, and a network connection device 4207. These components are hardware, and are connected to each other by a bus 4208.
[0208] The CPU 4201 (processor) includes a CPU monitor mechanism 714 and cores 4211-1 to 4211-L (L is an integer equal to or greater than 2). The CPU monitor mechanism 714 and the cores 4211-1 to 4211-L are hardware.
[0209] 5, and the other core 4211-i operates as the second arithmetic processing unit 513. Any of the cores 4211-i (i=1 to L) may operate as an acquisition unit 514.
[0210] 7. Any of the cores 4211-i may operate as the instrumentation unit 711, the acquisition unit 715, the conversion unit 716, and the calculation unit 717.
[0211] The memory 4202 is, for example, a semiconductor memory such as a ROM (Read Only Memory) or a RAM (Random Access Memory), and stores programs and data used in processing. The memory 4202 may operate as the storage unit 511 in Fig. 5 or the storage unit 719 in Fig. 7. The cyclic buffer 713 in Fig. 7 may be provided in the memory 4202.
[0212] The input device 4203 is, for example, a keyboard, a pointing device, etc., and is used for inputting instructions or information from a user. The output device 4204 is, for example, a display device, a printer, etc., and is used for outputting inquiries or instructions to a user and processing results. The output device 4204 may operate as the output unit 718 in Fig. 7. The processing results may be a branch history file 730 or a branch probability.
[0213] The auxiliary storage device 4205 is, for example, a magnetic disk device, an optical disk device, a magneto-optical disk device, a tape device, or the like. The auxiliary storage device 4205 may be a hard disk drive or an SSD (Solid State Drive). The information processing device can store programs and data in the auxiliary storage device 4205 and load them into the memory 4202 for use. The auxiliary storage device 4205 may operate as the storage unit 719 in FIG. 7.
[0214] The medium drive device 4206 drives the portable recording medium 4209 and accesses the recorded contents. The portable recording medium 4209 is a memory device, a flexible disk, an optical disk, a magneto-optical disk, etc. The portable recording medium 4209 may be a CD-ROM (Compact Disk Read Only Memory), a DVD (Digital Versatile Disk), a USB (Universal Serial Bus) memory, etc. A user can store programs and data in the portable recording medium 4209 and load them into the memory 4202 for use.
[0215] Thus, the computer-readable recording medium that stores the program and data used in the processing is a physical (non-transitory) recording medium such as the memory 4202, the auxiliary storage device 4205, or the portable recording medium 4209.
[0216] The network connection device 4207 is a communication interface circuit that is connected to a communication network such as a WAN (Wide Area Network) or a LAN (Local Area Network) and performs data conversion associated with communication. The information processing device can receive programs and data from an external device via the network connection device 4207 and load them into the memory 4202 for use. The network connection device 4207 may operate as the output unit 718 in FIG. 7.
[0217] It is not necessary for the information processing device to include all of the components in Fig. 42, and some of the components may be omitted or changed depending on the purpose or conditions of the information processing device. For example, when the portable recording medium 4209 or the communication network is not used, the medium drive device 4206 or the network connection device 4207 can be omitted.
[0218] Although the disclosed embodiments and their advantages have been described in detail, it will be appreciated that those skilled in the art may make various modifications, additions and omissions therein without departing from the scope of the invention as clearly set forth in the claims.
[0219] The following notes are further disclosed regarding the embodiment described with reference to FIGS. (Appendix 1) A storage unit; a first arithmetic processing unit that executes a write program to write, into the storage unit, branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation that occurs during execution of the write program; a second arithmetic processing unit that executes a branch control program to read the branch information from the storage unit and branch to a code block corresponding to the branch information among a plurality of code blocks included in the branch control program; an acquisition unit that acquires an instruction address of an executed instruction during execution of the branch control program, and records operation information including the instruction address of the executed instruction; A branch history recording system comprising: (Appendix 2) The branch history recording system of claim 1, wherein the second calculation processing unit calculates a hash value of the branch information, and uses a hash table that associates each of a plurality of hash values with one of the plurality of code blocks to identify the code block associated with the hash value of the branch information as the code block corresponding to the branch information. (Appendix 3) The branch history recording system of claim 2, wherein when a code block corresponding to the branch information is not included in the branch control program, the second calculation processing unit generates a code block corresponding to the branch information by copying a code block included in the branch control program, and registers the code block corresponding to the branch information in the hash table in association with a hash value of the branch information. (Appendix 4) the write program is generated by embedding a code for writing the branch information into the storage unit into the analysis target program; the branch source instruction address is a branch source instruction address in the analysis target program, the branch destination instruction address is a branch destination instruction address in the written program, when a code block corresponding to the branch information is not included in the branch control program, the second processing unit records an address of the code block corresponding to the branch information in code block information in association with the branch information; the branch history recording system further includes a conversion unit that converts the operation information into branch history information based on the code block information and address correspondence information that associates the branch destination instruction address with a branch destination instruction address in the analysis target program; 4. The branch history recording system according to claim 3, wherein the branch history information includes a pair of the branch source instruction address and the branch destination instruction address in the analysis target program. (Appendix 5) the storage unit is a cyclic buffer including a plurality of storage areas; the first arithmetic processing unit writes the branch information to a storage area indicated by a write pointer among the plurality of storage areas; The branch history recording system according to any one of claims 1 to 4, characterized in that the second arithmetic processing unit reads the branch information from a memory area among the plurality of memory areas that is indicated by a read pointer. (Appendix 6) Reading from the storage unit branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation occurring during execution of the written program; branching to a code block corresponding to the branch information among a plurality of code blocks; The process is executed by a computer, the branch information is written into the storage unit by executing the writing program; A branch control program, characterized in that, when the process is executed, an instruction address of an executed instruction is obtained, and operation information including the instruction address of the executed instruction is recorded. (Appendix 7) Calculating a hash value of the branch information; using a hash table that associates each of a plurality of hash values with one of the plurality of code blocks, the code block associated with the hash value of the branch information is identified as the code block corresponding to the branch information; 7. The branch control program according to claim 6, further causing the computer to execute a process. (Appendix 8) if a code block corresponding to the branch information is not included in the branch control program, generating a code block corresponding to the branch information by copying a code block included in the branch control program; registering a code block corresponding to the branch information in the hash table in association with a hash value of the branch information; 8. The branch control program according to claim 7, further causing the computer to execute a process. (Appendix 9) if a code block corresponding to the branch information is not included in the branch control program, causing the computer to further execute a process of recording an address of the code block corresponding to the branch information in code block information in association with the branch information; the write program is generated by embedding a code for writing the branch information into the storage unit into the analysis target program; the branch source instruction address is a branch source instruction address in the analysis target program, the branch destination instruction address is a branch destination instruction address in the written program, The operation information is converted into branch history information based on the code block information and address correspondence information that associates the branch destination instruction address with a branch destination instruction address in the analysis target program; 9. The branch control program according to claim 8, wherein the branch history information includes a pair of the branch source instruction address and the branch destination instruction address in the analysis target program. (Appendix 10) the storage unit is a cyclic buffer including a plurality of storage areas; the branch information is written into a storage area among the plurality of storage areas indicated by a write pointer; A branch control program as described in any one of Appendices 6 to 9, characterized in that the process of reading the branch information from the memory unit includes a process of reading the branch information from a memory area indicated by a read pointer among the multiple memory areas. (Appendix 11) The computer By executing a write program, branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation occurring during execution of the write program is written into a storage unit; By executing a branch control program, the branch information is read from the storage unit, and a process of branching to a code block corresponding to the branch information is executed among a plurality of code blocks included in the branch control program; When the branch control program is executed, an instruction address of the executed instruction is obtained; recording operational information including instruction addresses of the executed instructions; A branch history recording method comprising: (Appendix 12) Calculating a hash value of the branch information; using a hash table that associates each of a plurality of hash values with one of the plurality of code blocks, the code block associated with the hash value of the branch information is identified as the code block corresponding to the branch information; 12. The branch history recording method according to claim 11, further comprising the steps of: (Appendix 13) if a code block corresponding to the branch information is not included in the branch control program, generating a code block corresponding to the branch information by copying a code block included in the branch control program; registering a code block corresponding to the branch information in the hash table in association with a hash value of the branch information; 13. The branch history recording method according to claim 12, further comprising the steps of: (Appendix 14) the write program is generated by embedding a code for writing the branch information into the storage unit into the analysis target program; the branch source instruction address is a branch source instruction address in the analysis target program, the branch destination instruction address is a branch destination instruction address in the written program, if the code block corresponding to the branch information is not included in the branch control program, an address of the code block corresponding to the branch information is recorded in code block information in association with the branch information; converting the operation information into branch history information based on the code block information and address correspondence information that associates the branch destination instruction address with a branch destination instruction address in the analysis target program; The computer further executes the process, 14. The branch history recording method according to claim 13, wherein the branch history information includes a pair of the branch source instruction address and the branch destination instruction address in the analysis target program. (Appendix 15) the storage unit is a cyclic buffer including a plurality of storage areas; the process of writing the branch information to the storage unit includes a process of writing the branch information to a storage area indicated by a write pointer among the plurality of storage areas; A branch history recording method described in any one of Appendices 11 to 14, characterized in that the process of reading the branch information from the memory unit includes a process of reading the branch information from a memory area indicated by a read pointer among the multiple memory areas. [Explanation of symbols]
[0220] 501 Branch History Recording System 511, 719 Storage section 512 First arithmetic processing unit 513 Second arithmetic processing unit 514, 715 Acquisition Department 701 Information Processing Systems 711 Instrumentation Department 712-1, 712-2, 4211-1~4211-L core 713 Cyclic Buffer 714 CPU monitor mechanism 716 Conversion Unit 717 Calculation Department 718 Output section 721, 725 binary files 722 Instrumentation Program 723 Branching Control Program 724 Conversion Program 726 Address Correspondence Table 727 Symbol Table 728 Profile Information 729 Performance Profile File 730 Branch History File 1001, 3001, 3401 hash tables 1002-0~1002-4 Code block 1101~1104 Code 3002-0 to 3002-4, 3402-0 to 3402-4 entries 4201 CPU 4202 Memory 4203 Input Device 4204 Output device 4205 Auxiliary storage device 4206 Media Drive Unit 4207 Network connection device 4208 Bus 4209 Portable recording media
Claims
1. A storage unit; a first arithmetic processing unit that executes a write program to write, into the storage unit, branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation that occurs during execution of the write program; a second arithmetic processing unit that executes a branch control program to read the branch information from the storage unit and branch to a code block corresponding to the branch information among a plurality of code blocks included in the branch control program; an acquisition unit that acquires an instruction address of an executed instruction during execution of the branch control program, and records operation information including the instruction address of the executed instruction; A branch history recording system comprising:
2. The branch history recording system according to claim 1, characterized in that the second calculation processing unit calculates a hash value of the branch information, and uses a hash table that corresponds each of a plurality of hash values to one of the plurality of code blocks to identify the code block that corresponds to the hash value of the branch information as the code block that corresponds to the branch information.
3. The branch history recording system of claim 2, characterized in that when a code block corresponding to the branch information is not included in the branch control program, the second calculation processing unit generates a code block corresponding to the branch information by copying a code block included in the branch control program, and registers the code block corresponding to the branch information in the hash table by associating it with a hash value of the branch information.
4. the write program is generated by embedding a code for writing the branch information into the storage unit into the analysis target program; the branch source instruction address is a branch source instruction address in the analysis target program, the branch destination instruction address is a branch destination instruction address in the written program, when a code block corresponding to the branch information is not included in the branch control program, the second arithmetic processing unit records an address of the code block corresponding to the branch information in code block information in association with the branch information; the branch history recording system further includes a conversion unit that converts the operation information into branch history information based on the code block information and address correspondence information that associates the branch destination instruction address with a branch destination instruction address in the analysis target program; 4. The branch history recording system according to claim 3, wherein the branch history information includes a pair of the branch source instruction address and the branch destination instruction address in the analysis target program.
5. the storage unit is a cyclic buffer including a plurality of storage areas; the first arithmetic processing unit writes the branch information to a storage area indicated by a write pointer among the plurality of storage areas; 5. The branch history recording system according to claim 1, wherein the second processing unit reads the branch information from a storage area, among the plurality of storage areas, that is indicated by a read pointer.
6. Reading from the storage unit branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation occurring during execution of the written program; branching to a code block corresponding to the branch information among a plurality of code blocks; The process is executed by a computer, the branch information is written into the storage unit by executing the writing program; A branch control program, characterized in that, when the process is executed, an instruction address of an executed instruction is obtained, and operation information including the instruction address of the executed instruction is recorded.
7. The computer By executing a write program, branch information including a pair of a branch source instruction address and a branch destination instruction address of a branch operation occurring during execution of the write program is written into a storage unit; By executing a branch control program, the branch information is read from the storage unit, and a process of branching to a code block corresponding to the branch information is executed among a plurality of code blocks included in the branch control program; When the branch control program is executed, an instruction address of the executed instruction is obtained; recording operational information including instruction addresses of the executed instructions; A branch history recording method comprising:
Citation Information
Patent Citations
Compiling processor and its method
JP2000081984A
