Address conversion method and device, electronic equipment and storage medium
By obtaining the address to be translated in the code cache space of the binary translator, and using the direct address mapping window and the secondary translation back-up buffer for conversion, the problem of low address conversion efficiency in the binary translator is solved, and different to-be-translated addresses are realized. Efficient processing of addresses.
Patent Information
- Application Number
- CN202410659129.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-24
- Publication Date
- 2024-08-30
AI Technical Summary
The binary translator has the problem of poor address translation efficiency in the running code space, especially when dealing with multiple different addresses to be translated.
The address to be translated is obtained from the code cache space of the client's binary translator, and is directly converted to the host virtual address when the direct address mapping window matches it. When it does not match, the secondary translation back-up buffer is used for conversion, using different conversion method to improve efficiency.
The efficiency of address translation is improved, appropriate translation methods can be used for different addresses to be translated, and the address translation performance in the code cache space is improved.
Smart Images

Figure CN118568014A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an address conversion method, device, electronic equipment and storage medium. Background Art
[0002] Binary translation technology enables a program of one instruction set architecture (ISA) (client architecture) to run correctly in another instruction set architecture (host architecture), thereby realizing cross-ISA program simulation operation.
[0003] In the related technology, during the operation of the binary translator, it obtains the addresses to be translated from the running code space, converts these addresses to be translated into host addresses using a preset address correspondence, and translates the client memory access instructions corresponding to the addresses to be translated into target memory access instructions for the host, and then executes the target memory access instructions corresponding to the host addresses in the host.
[0004] However, the code space in which the binary translator is running usually contains a variety of different addresses to be translated, and the above method has the problem of poor address conversion efficiency. Summary of the invention
[0005] In view of the above problems, an embodiment of the present invention is proposed to provide an address conversion method that overcomes the above problems or at least partially solves the above problems, thereby improving the efficiency of address conversion.
[0006] Correspondingly, an embodiment of the present invention further provides an address conversion device, an electronic device, and a storage medium to ensure the implementation and application of the above method.
[0007] In a first aspect, an embodiment of the present invention discloses an address conversion method, the method comprising:
[0008] Obtaining a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer;
[0009] When the first address to be translated matches the mapping address of the direct address mapping window, converting the first address to be translated into a host virtual address based on the direct address mapping window;
[0010] When the first address to be translated does not match the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the secondary translation lookaside buffer.
[0011] Optionally, after obtaining the first address to be translated, the method further includes:
[0012] Obtaining high-order address information of a preset length in the first address to be translated;
[0013] When the high-order information of the address matches the preset high-order information, it is determined that the first address to be translated matches the mapping address of the direct address mapping window.
[0014] Optionally, before obtaining the first address to be translated, the method further includes:
[0015] Replacing the address high-bit information of the host machine virtual address of the binary translator's own memory access instruction by preset high-bit information to obtain a first to-be-translated address corresponding to the own memory access instruction;
[0016] The first address to be translated corresponding to the native memory access instruction is stored in the code cache space.
[0017] Optionally, before obtaining the first address to be translated, the method further includes:
[0018] Writing an address mapping relationship between the mapping address and the host machine virtual address corresponding to the mapping address into the window configuration space to configure the direct address mapping window,
[0019] Alternatively, preset high-bit information is written into the window configuration space to configure the direct address mapping window.
[0020] Optionally, after obtaining the first address to be translated, the method further includes:
[0021] Obtaining a second address to be translated from the binary translator's own code space;
[0022] The second address to be translated is converted into a host virtual address based on the secondary translation lookaside buffer, or the second address to be translated is determined as a host virtual address.
[0023] Optionally, before converting the first address to be translated into a host virtual address based on the secondary translation lookaside buffer, the method further includes:
[0024] In the case where the first address to be translated does not match the mapping address of the direct address mapping window, filling the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer;
[0025] When the second address to be translated is obtained, a second mapping relationship between the first host machine virtual address and the second host machine virtual address is filled into the secondary translation lookaside buffer.
[0026] Optionally, before obtaining the second address to be translated, the method further includes:
[0027] Obtaining an address space identifier for indicating a code space in which the binary translator is running;
[0028] In a case where the address space identifier matches the first preset identifier, determining that the running code space is a code cache space;
[0029] When the address space identifier matches the second preset identifier, it is determined that the running code space is the own code space.
[0030] Optionally, before obtaining the second address to be translated, the method further includes:
[0031] Obtaining the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state;
[0032] When the hardware paging mechanism is in the on state, determining that the code space in which the binary translator is running is a code cache space;
[0033] When the hardware paging mechanism state is the closed state, it is determined that the running code space is the own code space.
[0034] Optionally, the binary translator runs in a virtual machine mode, and after converting the first address to be translated into a host virtual address based on a secondary translation lookaside buffer, the method further comprises:
[0035] In response to a system call to the host machine, switching the operating mode of the binary translator from a virtual machine mode to a user mode;
[0036] Executing the system call in the user mode;
[0037] The operation mode of the binary translator is switched from the user mode to the virtual machine mode.
[0038] Optionally, the first address to be translated includes a memory access address corresponding to a source memory access instruction of a client program of the client, and after converting the first address to be translated into a host virtual address based on a secondary translation lookaside buffer, the method further includes:
[0039] Performing binary translation on the source memory access instruction to obtain a target memory access instruction;
[0040] Based on the host machine virtual address corresponding to the first address to be translated, the target memory access instruction is executed in the host machine, so that the host machine operates on the data stored in the host machine physical address corresponding to the host machine virtual address based on the target memory access instruction.
[0041] In a second aspect, an embodiment of the present invention discloses an address conversion device, the device comprising:
[0042] A first address to be translated module, used for obtaining a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer;
[0043] A first conversion module, configured to convert the first address to be translated into a host virtual address based on the direct address mapping window when the first address to be translated matches a mapping address of the direct address mapping window;
[0044] The second conversion module is configured to convert the first address to be translated into a host machine virtual address based on a secondary translation lookaside buffer when the first address to be translated does not match a mapping address of a direct address mapping window.
[0045] Optionally, the device further comprises:
[0046] An address high-bit information module, used to obtain address high-bit information of a preset length in the first address to be translated;
[0047] The high-order information matching module is used to determine that the first address to be translated matches the mapping address of the direct address mapping window when the high-order information of the address matches the preset high-order information.
[0048] Optionally, the device further comprises:
[0049] A first address to be translated generating module, used for replacing the address high-bit information of the host machine virtual address of the own memory access instruction of the binary translator by preset high-bit information, so as to obtain a first address to be translated corresponding to the own memory access instruction;
[0050] The first address to be translated storage module is used to store the first address to be translated corresponding to the own memory access instruction into the code cache space.
[0051] Optionally, the device further comprises:
[0052] A configuration module is used to write an address mapping relationship between the mapping address and the host virtual address corresponding to the mapping address in the window configuration space to configure the direct address mapping window, or to write preset high-bit information in the window configuration space to configure the direct address mapping window.
[0053] Optionally, the device further comprises:
[0054] A second address to be translated module, used for obtaining a second address to be translated from the binary translator's own code space;
[0055] The third conversion module is used to convert the second address to be translated into a host virtual address based on the secondary translation backup buffer, or determine the second address to be translated as a host virtual address.
[0056] Optionally, the device further comprises:
[0057] A first mapping relationship module, configured to fill the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer when the first address to be translated does not match the mapping address of the direct address mapping window;
[0058] The second mapping relationship module is used to fill the second mapping relationship between the first host machine virtual address and the second host machine virtual address into the secondary translation backup buffer when the second address to be translated is obtained.
[0059] Optionally, the device further comprises:
[0060] An address space identification module, used to obtain an address space identification for indicating a code space in which the binary translator is running;
[0061] A first code cache space determination module, configured to determine that the running code space is a code cache space when the address space identifier matches a first preset identifier;
[0062] The first own code space determination module is used to determine that the running code space is the own code space when the address space identifier matches the second preset identifier.
[0063] Optionally, the device further comprises:
[0064] A hardware paging mechanism state module, used to obtain the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state;
[0065] A second code cache space determination module, configured to determine, when the hardware paging mechanism state is the enabled state, that the code space in which the binary translator is running is the code cache space;
[0066] The second own code space determination module is used to determine that the running code space is the own code space when the hardware paging mechanism state is the closed state.
[0067] Optionally, the binary translator runs in a virtual machine mode, and the device further comprises:
[0068] A first mode switching module, configured to switch the operation mode of the binary translator from a virtual machine mode to a user mode in response to a system call to the host machine;
[0069] A system call processing module, used for executing the system call in the user mode;
[0070] The second mode switching module is used to switch the operating mode of the binary translator from the user mode to the virtual machine mode.
[0071] Optionally, the first address to be translated includes a memory access address corresponding to a source memory access instruction of a client program of the client, and the apparatus further includes:
[0072] A target memory access instruction module, used for performing binary translation on the source memory access instruction to obtain a target memory access instruction;
[0073] A target memory access instruction execution module is used to execute the target memory access instruction in the host machine based on the host machine virtual address corresponding to the first address to be translated, so that the host machine operates on the data stored in the host machine physical address corresponding to the host machine virtual address based on the target memory access instruction.
[0074] In the third aspect, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of any of the address conversion methods described above.
[0075] In a fourth aspect, an embodiment of the present invention discloses a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, any address conversion method described in the embodiment of the present invention can be implemented.
[0076] The address conversion method, device, electronic device, and storage medium provided by the embodiments of the present invention have the following advantages:
[0077] When performing address conversion loading, the embodiment of the present invention obtains a first address to be translated from the code cache space of the binary translator of the client; the client runs in the host; when the first address to be translated matches the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the direct address mapping window; when the first address to be translated does not match the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the secondary translation backup buffer. The present invention uses direct address mapping to perform address conversion for the first address to be translated that can match the direct address mapping window, and uses the secondary translation backup buffer to perform address conversion for the remaining first addresses to be translated, and can use different conversion methods for different addresses to be translated in the code cache space, which helps to improve the efficiency of address conversion. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] Figure 1 is a flowchart of the steps of an embodiment of an address conversion method of the present invention;
[0079] Figure 2 is a flowchart of another embodiment of an address conversion method of the present invention;
[0080] Figure 3 It is a context switching schematic diagram of a binary translator of the present invention;
[0081] Figure 4 This is a first address conversion schematic diagram of the present invention;
[0082] Figure 5 It is a schematic diagram of address conversion of the present invention;
[0083] Figure 6 is a flowchart of another embodiment of an address conversion method of the present invention;
[0084] Figure 7 is another context switching schematic diagram of a binary translator of the present invention;
[0085] Figure 8 is a structural block diagram of an embodiment of an address conversion device of the present invention;
[0086] Fig. 9 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0087] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0088] The terms "first", "second", etc. in the specification and claims of the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable when appropriate, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of the present invention, the term "multiple" refers to two or more, and other quantifiers are similar.
[0089] Figure 1 A flowchart of an address conversion method embodiment of the present invention is shown, and the method may include the following steps:
[0090] Step 101, obtaining a first address to be translated from a code cache space of a binary translator of a client computer; the client computer runs in a host computer.
[0091] A host is a physical server or computer that runs one or more virtual machines (VMs). The host provides hardware resources such as CPU, memory, storage space, and network connections, which are virtualized and allocated to the virtual machines running on it. The host is responsible for managing and allocating these resources to ensure that the virtual machines can run and perform the required operations.
[0092] The client can run in the host machine, and each client can be regarded as an independent computer with its own operating system and application program. The client can run on the binary translator of the host machine, and the binary translator provides virtualization support. In an embodiment of the present invention, the architecture of the host machine and the client machine can be different, and application programs of different instruction set architectures can be run. For example, the host machine can run an operating system that complies with the X86 architecture rules, and the client machine can run an operating system that complies with the ARM architecture rules.
[0093] The address conversion method provided by the embodiment of the present invention can be applied to a host machine or a client machine running a binary translator, and the binary translator can translate the to-be-translated address generated in the client machine into the host machine virtual address of the host machine. Specifically, the binary translator can translate the to-be-translated address corresponding to the memory access instruction issued by the client machine, and obtain the corresponding host machine virtual address, so that the memory access instruction issued by the client machine can be correctly executed on the host machine hardware, and the host machine can be compatible with heterogeneous operating systems and heterogeneous applications running in clients with different instruction set architectures from its own. According to the different levels of the simulated program, it can be classified into user-level binary translators and system-level binary translators. User-level binary translators support the running of client applications, and system-level binary translators support the running of complete client operating systems, thereby realizing the running of any client application.
[0094] The code cache space of the binary translator is a memory area located in the host's memory, which is used to store the target code generated by the binary translator. When the binary translator translates the code of the source architecture (client architecture) into the code of the target architecture (host architecture), the translated target code can be stored in the code cache space for further execution. Since the code cache space stores the translated code, when the translated code needs to be executed again, the translated code can be directly loaded from the code cache space to avoid repeated translation, thereby significantly improving the execution speed.
[0095] In the embodiment of the present invention, the address to be translated stored in the code cache space may be referred to as the first address to be translated, so that the binary translator may obtain the first address to be translated from the code cache space of the binary translator of the client. The first address to be translated may be included in the memory access instruction issued by the client and stored in the code cache space in binary form.
[0096] Step 102: When the first address to be translated matches the mapping address of the direct address mapping window, convert the first address to be translated into a host virtual address based on the direct address mapping window.
[0097] A direct memory window (DMW) is a technology for mapping an address of a specific address segment to a specific target address, which can be supported by host hardware. The direct memory window contains a continuous segment of mapping addresses that can be mapped, and contains target addresses corresponding to each mapping address. In an embodiment of the present invention, the mapping address in the direct address mapping window and the target address corresponding to the mapping address can be of the same address type, for example, both can be host virtual addresses.
[0098] In the code cache space, two types of addresses may be included, one is the host virtual address (HVA) corresponding to the memory access instruction of the binary translator itself, and the other is the guest virtual address (GVA) corresponding to the memory access instruction generated by the operating system or other applications in the client, that is, the address corresponding to the memory access instruction translated by the binary translator. Among them, the host virtual address corresponding to the memory access instruction of the binary translator itself can be mapped by the direct address mapping window, that is, each host virtual address corresponding to the memory access instruction of the binary translator itself is the same as a mapping address of the direct address mapping window; the guest virtual address corresponding to the memory access instruction generated by the operating system or other applications in the client will not be mapped by the direct address mapping window, that is, each guest virtual address corresponding to the memory access instruction generated by the operating system or other applications in the client is different from all the mapping addresses of the direct address mapping window.
[0099] In an embodiment of the present invention, in order to improve the address conversion efficiency, a direct address mapping window for converting the address carried by the binary translator's own memory access instruction into a host virtual address can be configured in the host. After obtaining a first address to be translated, the first address to be translated can be matched with the mapping address of the direct address mapping window. If the first address to be translated can be successfully matched with the mapping address of the direct address mapping window, it means that the first address to be translated is the host virtual address corresponding to the memory access instruction of the binary translator itself. The host virtual address can be directly converted through the direct address mapping window to obtain the converted host virtual address, thereby bypassing the address conversion process based on the translation backup buffer and improving the address conversion efficiency. It should be noted that since the direct address mapping window processes the first address to be translated directly generated by the binary translator, these first addresses to be translated may already be host virtual addresses, so the host virtual address obtained after conversion by the direct address mapping window can be the same as the host virtual address before conversion. In some cases, such as when the hardware of the host machine on which the binary translator runs changes or when the binary translator runs on a host machine with a different architecture, the binary translator may need to use a different host machine virtual address to execute its memory access instructions. In order to reduce the modification of the binary translator's own code, the target address in the direct address mapping window may be adjusted so that the host machine virtual address obtained after conversion through the direct address mapping window may be different from the host machine virtual address before conversion, thereby reducing the difficulty of porting and improving the compatibility of the binary translator. The embodiments of the present invention do not make specific limitations on this.
[0100] Exemplarily, there is a direct address mapping window that can map addresses from 0x80000000 to 0x80000004. The address mapping relationship contained in the direct address mapping window can be shown in the following Table 1:
[0101] Mapping Address Target address 0x80000000 0x80000000 0x80000001 0x80000001 0x80000002 0x80000002 0x80000003 0x80000003
[0102] Table 1
[0103] If the first address to be translated obtained from the code cache space of the binary translator is 0x80000002, the first address to be translated successfully matches the mapping address shown in the above Table 1, which means that the first address to be translated is the host virtual address corresponding to the memory access instruction of the binary translator itself. The first address to be translated can be directly translated into the host virtual address, that is, 0x80000002, according to the direct address mapping window.
[0104] In the embodiment of the present invention, it can be determined whether the first address to be translated matches the direct address mapping window by using the window start address and window end address of the direct address mapping window. Since the mapping address of the direct address mapping window is usually a continuous address, its window start address is the lower limit of its mapping address, and its window end address is the upper limit of its mapping address.
[0105] Exemplarily, if the mapping address range of the direct address mapping window is (0x80000000-0x8FFFFFFF), the window start address of the direct address mapping window is 0x80000000, and the window end address is 0x8FFFFFFF.
[0106] After obtaining the window start address and the window end address, the first address to be translated can be matched with the window start address and the window end address respectively. If the matching result shows that the first address to be translated is greater than or equal to the window start address and less than the window end address, it means that the first address to be translated can be mapped by the direct address mapping window, which means that the first address to be translated is the address of the memory access instruction directly generated by the binary translator, and the direct address mapping window can be used to directly convert it into the corresponding host virtual address.
[0107] Continuing with the above example, if the first address to be translated is 0x80000009, since 0x80000009 is greater than the window start address 0x80000000 and less than the window end address 0x8FFFFFFF, it can be determined that the first address to be translated matches the direct address mapping window.
[0108] Optionally, in an embodiment of the present invention, in order to perform address conversion through a direct address mapping window, a window configuration space may be set in a host register or a host memory, and the direct address mapping window may be configured by writing an address mapping relationship between a mapping address and a host virtual address (i.e., the above-mentioned target address) corresponding to the mapping address in the window configuration space, thereby enabling address conversion to be performed using a direct address mapping window based on the address mapping relationship in the window configuration space.
[0109] Step 103: When the first address to be translated does not match the mapping address of the direct address mapping window, convert the first address to be translated into a host virtual address based on the secondary translation lookaside buffer.
[0110] Accordingly, the first address to be translated can be matched with the window start address and the window end address respectively. If the matching result shows that the first address to be translated is smaller than the window start address, or larger than the window end address, it means that the first address to be translated cannot be mapped by the direct address mapping window, which means that the first address to be translated is the address of the memory access instruction translated by the client's operating system or other application programs, and a secondary translation backup buffer can be used to convert it into a host virtual address.
[0111] Continuing with the above example, if the first address to be translated is 0x70000000, since 0x70000000 is less than the window start address 0x80000000, it can be determined that the first address to be translated does not match the direct address mapping window.
[0112] If the first address to be translated does not match the mapping address of the direct address mapping window, it means that the first address to be translated is a client virtual address corresponding to the memory access instruction generated by the operating system or other application in the client, and a secondary translation backup buffer can be used to convert the first address to be translated into a host virtual address.
[0113] Wherein, secondary translation lookaside buffer (Second Level Translation Lookaside Buffer, SLTLB) is a kind of hardware mechanism used in virtualization environment, is intended to accelerate the memory address conversion process in client. Second level translation lookaside buffer can also be called secondary TLB, nested TLB, hardware secondary translation lookaside buffer etc. In virtualization environment, client runs on host machine, each client has its own virtual address space, for the client virtual address of client, can be converted by secondary translation lookaside buffer, can first client virtual address be converted to client physical address (Guest Physical Address, GPA), then client physical address is converted to host virtual address, can also directly client virtual address be converted to host virtual address, the embodiment of the present invention is not specifically limited, can flexibly adjust conversion process according to the different mapping relations of filling in secondary translation lookaside buffer.
[0114] Typically, a client running on a host machine is provided with virtualization services and managed by the host machine's binary translator, and the binary translator can simultaneously manage a secondary translation lookaside buffer. The binary translator can use the secondary translation lookaside buffer to convert a first address to be translated to obtain a corresponding host machine virtual address.
[0115] Continuing with the above example, if the first address to be translated obtained from the code cache space of the binary translator is 0x80000006, the first address to be translated does not match the mapping address shown in the above Table 1, which means that the first address to be translated is the client virtual address corresponding to the memory access instruction generated by the operating system or other application programs in the client, and the first address to be translated can be converted into a host virtual address through the secondary translation backup buffer.
[0116] The binary translator can send a host virtual address to the host, and the host system and hardware convert it into a corresponding host physical address based on the host translation backup buffer and actually execute the corresponding memory access instruction according to the host physical address.
[0117] In summary, in the process of address conversion, the embodiment of the present invention obtains the first address to be translated from the code cache space of the binary translator of the client; the client runs in the host; when the first address to be translated matches the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the direct address mapping window; when the first address to be translated does not match the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the secondary translation backup buffer. The present invention uses direct address mapping to perform address conversion for the first address to be translated that can match the direct address mapping window, and uses the secondary translation backup buffer to perform address conversion for the remaining first addresses to be translated. Different conversion methods can be used for different addresses to be translated in the code cache space, which helps to improve the efficiency of address conversion.
[0118] Reference Figure 2 , Figure 2 FIG. 4 shows a flow chart of another embodiment of an address conversion method provided by an embodiment of the present invention. Figure 2 As shown, the specific steps include:
[0119] Step 201, obtaining an address space identifier for indicating a code space in which the binary translator is running.
[0120] In the embodiment of the present invention, the binary translator can run in different contexts, can run in the code cache space, process the code in the code cache space, and can also run in its own code space to process its own code. That is, the binary translator can jump in different code spaces, and process the code in the code space it is currently in. The above code space can include the code cache space and the own code space.
[0121] The binary translator's own code space refers to the memory area occupied by the binary translator program itself, which includes the running code of the binary translator. The binary translator's code cache space refers to the memory area used to store the translated instruction codes, which are generated by translating the original instructions of the client when the binary translator is running.
[0122] In an embodiment of the present invention, corresponding address space identifiers (ASIDs) can be set for different code spaces of the binary translator. When the binary translator switches the running code space, the address space identifier can be synchronously adjusted. When the binary translator switches the running context to the code cache space, the address space identifier can be set to a first preset identifier. When the binary translator switches the running context to its own code space, the address space identifier can be set to a second preset identifier. Therefore, when obtaining the address to be translated in the code space where the binary translator is running, the current address space identifier can be read at the same time, and the specific type of this code space can be judged according to the address space identifier, thereby determining the type of the obtained address to be translated.
[0123] Reference Figure 3 , Figure 3 FIG. 4 shows a context switching diagram of a binary translator provided by an embodiment of the present invention. Figure 3 As shown, after the binary translator is started, the address space identifier is initialized to 0, and the binary translator runs in its own code space to perform operations such as search and translation (the address space identifier is 0). After the operation in its own code space is completed, a context switch is performed to enter the code cache space for operation, and the address space identifier is set to 1. When running in the code cache space, the address space identifier is kept at 1. After the operation in the code cache space is completed, a context switch is performed again to enter its own code space for operation, and the address space identifier is set to 0.
[0124] Step 202: When the address space identifier matches the first preset identifier, determine that the running code space is a code cache space.
[0125] In an embodiment of the present invention, the binary translator will perform context switching during operation. The binary translator will obtain the address to be translated from the code space in which it is running. If the current address space identifier matches the first preset identifier, it means that the code space in which the binary translator is running is the code cache space, and the address to be translated obtained from the code cache space is the first address to be translated.
[0126] Step 203, obtaining a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer.
[0127] This step can refer to the above-mentioned step 101, and will not be described in detail in this embodiment of the present invention.
[0128] Optionally, the first address to be translated by the binary translator itself can be generated and stored in the code cache space in the following manner:
[0129] Step S11, replacing the address high-bit information of the host machine virtual address of the binary translator's own memory access instruction with preset high-bit information, to obtain a first to-be-translated address corresponding to the own memory access instruction.
[0130] In an embodiment of the present invention, the mapping address of the direct address mapping window may include an address whose high-bit information is the same as the preset high-bit information, so that the first address to be translated generated by the binary translator itself can be mapped through the direct address mapping window. The high-bit information represents the highest N-bit address information in the address, and N is the number of bits of the preset high-bit information. For example, if there is an address of 0x12000001, when the preset high-bit information is 8 binary bits, the high-bit information of the first address can be 0x12.
[0131] After obtaining the address high-bit information of the first address to be translated, the address high-bit information can be matched with the preset high-bit information, which is the high-bit information filled in the generated first address to be translated by the binary translator. If the address high-bit information matches the preset high-bit information, it means that the first address to be translated matches the mapping address of the direct address mapping window. The address high-bit information represents the highest N-bit address information in the first address to be translated, and N is the number of bits of the preset high-bit information.
[0132] Referring to Table 2, Table 2 shows an address mapping relationship included in a direct address mapping window provided by an embodiment of the present invention:
[0133] Mapping Address Target address 0x12000001 0x00000001 0x12000002 0x00000002 0x12000003 0x00000003 …… …… 0x12009999 0x00009999
[0134] Table 2
[0135] Among them, the mapping address in Table 2 can be obtained by combining the preset high-order information 0x12 with the host virtual address, and the target address can be the host virtual address. For example, the preset high-order information 0x12 is used to fill the high order of the host virtual address 0x00000002 to obtain the first address to be translated 0x12000002.
[0136] Step S12: storing the first address to be translated corresponding to the own memory access instruction into the code cache space.
[0137] In order to improve the efficiency of the binary translator repeatedly running its own memory access instructions, the binary translator can also store its own memory access instructions and its corresponding first address to be translated in the code cache space. In the embodiment of the present invention, the first address to be translated corresponding to the binary translator's own memory access instructions matches the direct address mapping window, that is, the addresses to be translated corresponding to its own memory access instructions are all located between the window start address and the window end address of the direct address mapping window, so that the source of the first to be translated in the code cache space can be identified based on the mapping address of the direct address mapping window.
[0138] By setting the first address to be translated of the memory access instruction generated by the binary translator itself within the mapping range of the direct address mapping window, the source of the first address to be translated stored in the code cache space can be identified based on the direct address mapping window so as to adopt different strategies for address conversion, which helps to improve the address conversion efficiency.
[0139] Step 204: Obtain high-order address information of a preset length in the first address to be translated.
[0140] In order to improve the matching efficiency between the first address to be translated and the direct address mapping window, the address to be translated stored in the code cache space by the binary translator itself can contain specific address high-bit information. That is to say, in the embodiment of the present invention, all addresses to be translated from the binary translator itself in the code cache space can contain the same address high-bit information. Since the processor and the operating system usually cannot fully utilize all address bits to address the memory, the binary bits in the address to be translated are usually not exhausted, and the address high-bit information of the first address to be translated generated by other applications is usually 0 or 1.
[0141] The above preset length can be flexibly adjusted by the technician according to the number of address bits that need to be converted. A 64-bit address usually has a larger addressing space, and the number of unused bits is usually more, so a larger preset length can be set, such as 16; while a 32-bit address usually has a smaller addressing space, and the number of unused bits is usually less, so a smaller preset length can be set, such as 8.
[0142] In an embodiment of the present invention, the address high-bit information of the preset length of the first address to be translated can be obtained. For example, if there is a 64-bit first address to be translated of 0x8765000022222222, and the preset length is 16, then the high 16 binary bits of the first address to be translated are obtained to obtain the address high-bit information 0x8765.
[0143] Step 205 : when the high-order information of the address matches the preset high-order information, it is determined that the first address to be translated matches the mapping address of the direct address mapping window.
[0144] By obtaining the high-order address information of a preset length of the first address to be translated, and determining that the first address to be translated matches the mapping address of the direct address mapping window when the high-order address information matches the preset high-order information, the efficiency of matching the first address to be translated and the direct address mapping window can be effectively improved. Moreover, since the first address to be translated generated by the binary translator itself has the preset high-order information added, even if the low-order information of the first address to be translated generated by the binary translator itself and the first address to be translated generated by the client application are repeated, the two first addresses to be translated can be effectively identified, thereby avoiding conflicts between the two addresses, thereby enabling the present solution to support the complete client address space.
[0145] Step 206: When the first address to be translated matches the mapping address of the direct address mapping window, convert the first address to be translated into a host machine virtual address based on the direct address mapping window.
[0146] This step can refer to the above-mentioned step 102, and will not be described in detail in this embodiment of the present invention.
[0147] Optionally, in an embodiment of the present invention, the configuration of the direct address mapping window can be completed by only writing preset high-bit information in the window configuration space. At this time, the actual mapping address of the direct address mapping window is the address of the high-bit information and the preset high-bit information, and the target address actually corresponding to each mapping address is the address after the high-bit information of the mapping address is all set to 0. When performing address conversion based on the direct mapping window, the high-bit information of the first address to be translated can be directly set to 0 to obtain the conversion result.
[0148] Exemplarily, if the preset high-order information 0x12 is used, the preset high-order information 0x12 can be written into the window configuration space. For a first address to be translated 0x12000002, the address high-order information 0x12 of the first address to be translated 0x12000002 can be matched with the preset high-order information 0x12 in the window configuration space. If the match is successful, it means that the first address to be translated belongs to the mapping address of the direct address mapping window, and its address high-order information 0x12 can be directly set to zero to obtain the converted host virtual address 0x00000002.
[0149] By configuring the direct address mapping window as described above, it is possible to avoid configuring a complete address mapping relationship in the direct address mapping window, thereby reducing the required window configuration space size and improving configuration efficiency and conversion efficiency of the direct address mapping window.
[0150] Step 207, when the first address to be translated does not match the mapping address of the direct address mapping window, fill the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer, and convert the first address to be translated into the host virtual address based on the secondary translation lookaside buffer.
[0151] In an embodiment of the present invention, if the first address to be translated does not match the mapping address of the direct address mapping window, it means that the first address to be translated is the client virtual address of the client's memory access instruction, and the first mapping relationship between the client virtual address and the host virtual address can be filled into the secondary translation lookaside buffer, and the first address to be translated is converted into the host virtual address based on the secondary translation lookaside buffer.
[0152] In an embodiment of the present invention, the first address to be translated includes a memory access address corresponding to a source memory access instruction of the client. By converting the first address to be translated into a host virtual address, the source memory access instruction can be executed on the host based on the host virtual address. The specific process can be as follows: Steps S21 to S22:
[0153] Step S21, performing binary translation on the source memory access instruction to obtain a target memory access instruction.
[0154] For source memory access instructions, a binary translator can be used to translate them, translating the source memory access instructions of the client architecture into target memory access instructions of the host architecture, and storing the target memory access instructions in the code cache space so that the target memory access instructions can be executed.
[0155] Exemplarily, a client program such as an operating system or an application of the client generates a source memory access instruction C1, and the client program stores the source memory access instruction C1 and its corresponding first address to be translated in the client virtual memory. The first address to be translated corresponding to the source memory access instruction C1 is 0x70000001. The binary translator intercepts the source memory access instruction C1, obtains the source memory access instruction C1 from the above-mentioned virtual memory, and translates the source memory access instruction C1 into a target memory access instruction C2 of the host architecture, and stores the target memory access instruction C2 and the corresponding first address to be translated in the code cache space.
[0156] Step S22, based on the host virtual address corresponding to the first address to be translated, executing the target memory access instruction in the host, so that the host operates the data stored in the host physical address corresponding to the host virtual address based on the target memory access instruction.
[0157] In an embodiment of the present invention, in order to execute the target memory access instruction, the above method can be used to convert the first address to be translated corresponding to the target memory access instruction stored in the code cache space to obtain the corresponding host virtual address, and the binary translator can execute the corresponding target memory access instruction based on the host virtual address in the host, thereby realizing the execution of the source memory access instruction corresponding to the target memory access instruction. When the host system executes the target memory access instruction, the host virtual address can be converted into a host physical address through the host TLB of the host system, and the physical memory of the host can be operated according to the host physical address to execute the target memory access instruction.
[0158] Continuing with the above example, the binary translator translates the first address to be translated 0x70000001 to obtain the corresponding host virtual address 0x43880033, and executes the target memory access instruction C2 in the host system based on the host virtual address 0x43880033 to implement the execution of the source memory access instruction C1 in the virtualized environment.
[0159] For example, refer to Figure 4 , Figure 4 A schematic diagram of a first address conversion to be translated provided by an embodiment of the present invention is shown. Figure 4 As shown, the client application or client operating system issues a source memory access instruction, and the binary translator intercepts the source memory access instruction to obtain the source memory access instruction and the corresponding first address to be translated. Since the first address to be translated is issued by the client application or the client operating system, the first address to be translated can be a client virtual address. The binary translator can first convert the client virtual address into a client physical address through the client operating system, and the binary translator then converts the client physical address into a host virtual address. Then the client sends a host virtual address to the host, and the host operating system converts the host virtual address into a host physical address. Finally, the host physical address is handed over to the host processor, and the host processor implements the execution of the source memory access instruction based on the host physical address. It should be noted that the client application, the client operating system and the binary translator can all run in the virtual machine mode of the host.
[0160] By converting the first address to be translated in the manner of the present invention, different methods can be used for converting different types of first addresses to be translated, thereby improving the efficiency of converting the first address to be translated to obtain the corresponding host virtual address. The host virtual address converted in the above manner executes the target memory access instruction, which can improve the execution efficiency of the target memory access instruction to a certain extent.
[0161] In the embodiment of the present invention, when the binary translator is running in its own code space, the second address to be translated in its own code space may be processed based on the following steps 208 to 211:
[0162] Step 208: When the address space identifier matches the second preset identifier, determine that the running code space is the own code space.
[0163] Correspondingly, if the address space identifier of the code space in which the binary translator is running matches the second preset identifier, it means that the binary translator is running in its own code space, and the address to be translated obtained from its running space is the second address to be translated.
[0164] Exemplarily, an address space identifier for identifying a storage space can be set in a memory, or a hardware register bit for identifying an address space identifier can be set in the host hardware, so that the hardware-level secondary translation backup buffer can directly determine the address mapping relationship (such as the first mapping relationship and the second mapping relationship) to be used when performing address conversion through the hardware register bit, and the embodiment of the present invention does not make specific limitations. When the binary translator switches the running context to the code cache space, the first preset identifier "1" is written in the identification storage space, and when the binary translator switches the running context to its own code space, the first preset identifier "1" in the identification storage space is replaced with the second preset identifier "0". When obtaining the address to be translated, the address space identifier in the identification storage space can be read, and the read address space identifier is matched with the second preset identifier. If the address space identifier is equal to the second preset identifier "0", the second address to be translated is obtained from the binary translator's own code space. It should be noted that the above-mentioned first preset identifier and the second preset identifier can be flexibly set by technical personnel, and the embodiment of the present invention does not make specific limitations.
[0165] In an embodiment of the present invention, it is possible to obtain an address space identifier for indicating the code space in which the binary translator is running, and determine whether the binary translator is currently running in the code cache space or its own code space based on the address space identifier, thereby distinguishing between a first address to be translated and a second address to be translated, and adopting different methods to process different addresses to be translated, thereby improving address translation efficiency.
[0166] Step 209: Obtain a second address to be translated from the binary translator's own code space.
[0167] When the running context of the binary translator is in its own code space, it is necessary to translate the address in its own code space, and the second address to be translated can be obtained from its own code space.
[0168] Step 210: when the second address to be translated is obtained, fill the second mapping relationship between the first host virtual address and the second host virtual address into the secondary translation lookaside buffer.
[0169] If the address to be translated is obtained from the own code space, the obtained address to be translated is the second address to be translated. For the second address to be translated, the second mapping relationship between the first host virtual address and the second host virtual address can be filled into the secondary translation lookaside buffer, and then the second address to be translated is converted based on the secondary translation lookaside buffer. The first host virtual address represents the address that needs to be converted by the secondary translation lookaside buffer, which matches the second address to be translated, and the second host virtual address represents the address obtained after the secondary translation lookaside buffer performs address conversion on the second address to be translated.
[0170] In the embodiment of the present invention, since the second address to be translated represents the address of the binary translator's own code space, the binary translator is an application of the host architecture, and the memory access address in its own code space can be set according to the host architecture on which it needs to run when writing the binary translator program. Therefore, the second address to be translated in the binary translator's own code space can be a host virtual address. However, due to the design limitations of the system and architecture, it is also necessary to use a secondary transfer backup buffer for address conversion. The second mapping relationship between the first host virtual address and the second host virtual address is filled in the secondary translation backup buffer. The second host virtual address mapped to the first host virtual address in the above second mapping relationship can be the same, so as to ensure that the address before conversion is consistent with the address after conversion, avoid changing the address during the conversion process and affecting the normal operation of the binary translator, and improve the operational stability of the binary translator.
[0171] It should be noted that in some cases, such as changes in the host machine hardware on which the binary translator runs, running the binary translator on a host machine with a different architecture, etc., the second address to be translated of the binary translator may not be executed as a host machine virtual address, and the second address to be translated needs to be adjusted to adapt to different host machine hardware. Usually, the code of the binary translator needs to be adjusted. In an embodiment of the present application, in order to reduce the modification of the binary translator's own code, the above-mentioned second mapping relationship can be adjusted so that the second host machine virtual address mapped to the first host machine virtual address in the above-mentioned second mapping relationship is different, thereby achieving adaptation of the binary translator's operation in different host machine hardware, thereby reducing the difficulty of porting and improving the compatibility of the binary translator.
[0172] In addition, by filling different mapping relationships in the secondary translation lookaside buffer, a secondary translation lookaside buffer can support different types of address conversions, so that different types of first addresses to be translated and second addresses to be translated generated by the binary translator can be converted, which can reduce the number of secondary translation lookaside buffers that need to be set up to a certain extent, helping to reduce implementation costs.
[0173] Step 211: convert the second address to be translated into a host virtual address based on the secondary translation lookaside buffer.
[0174] After obtaining the second address to be translated, the second address to be translated can be converted into a host virtual address based on the secondary translation backup buffer. It should be noted that since the binary translator is designed for the host architecture, the memory access address in its own code space can be adapted to the host architecture, that is, the second address to be translated obtained from its own code space can be a host virtual address. Therefore, when converting the second address to be translated into a host virtual address through the secondary translation backup buffer, the second mapping relationship can be filled in the corresponding secondary translation backup buffer so that the host virtual address obtained by converting the second address to be translated remains unchanged with the second address to be translated.
[0175] By identifying the first address to be translated and the second address to be translated, and filling the corresponding mapping relationship in the secondary translation backup buffer in a targeted manner according to the translation requirements of the first address to be translated and the second address to be translated, different mapping relationships can be used to convert different addresses to be translated, which helps to improve the accuracy of address conversion.
[0176] Reference Figure 5 , Figure 5 A schematic diagram of address conversion provided by an embodiment of the present invention is shown. Figure 5As shown, when the binary translator runs in the code cache space in the memory, the address space identifier ASID=1. At this time, the first address to be translated is obtained from the code space where the binary translator runs, and the first address to be translated is matched with the direct address mapping window. If it matches, it means that the first address to be translated is directly generated by the binary translator and can be converted into a host virtual address using the direct address mapping window. If it does not match, the first address to be translated is generated by other programs in the client. The first mapping relationship corresponding to the address space identifier 1 can be filled in the secondary translation backup buffer, and it is converted into a host virtual address through the secondary translation backup buffer; when the binary translator runs in its own code space in the memory, the address space identifier ASID=0. At this time, the second address to be translated is obtained from the code space where the binary translator runs, and the second mapping relationship corresponding to the address space identifier 0 can be filled in the secondary translation backup buffer, and it is converted into a host virtual address through the secondary translation backup buffer.
[0177] Optionally, in some operating systems, the host hardware can provide a hardware secondary TLB that can directly convert the host virtual address into the host physical address. Privileged instructions are required to call the hardware secondary TLB. After the binary translator is started, it is usually in user mode and may not have the authority to use privileged instructions. Therefore, after the binary translator is started, the operation mode of the binary translator can be converted to the virtual machine mode of the host, so that the binary translator can directly execute privileged instructions to operate the virtualization resources of the hardware, thereby using the secondary TLB provided by the host hardware to convert the first address to be translated generated by the client into a host physical address. In the user mode, the binary translator runs directly in the host operating system as an application of the host, and in the virtual machine mode, the binary translator can directly operate the hardware resources of the kernel virtual machine in which it is located, but is managed by the host operating system.
[0178] Exemplarily, in the case where the operating system of the host machine is Linux, the above-mentioned running of the binary translator in the virtual machine mode can mean running the binary translator in the kernel virtual machine in Linux. The kernel virtual machine interface provided by the host machine can be called to deploy itself in the kernel virtual machine instance to achieve operation in the virtual machine mode. Among them, the kernel virtual machine can include but is not limited to the KVM kernel virtual machine (Kernel-based Virtual Machine), and the kernel virtual machine can provide various functional interfaces (such as kernel virtual machine instance creation interface, kernel virtual machine instance startup interface, etc.), and the binary translator can be deployed in the kernel virtual machine by calling these functional interfaces to enter the virtual machine mode.
[0179] like Figure 3As shown, the binary translator runs in user mode after startup. During initialization, the kernel virtual machine parameters can be configured to start the kernel virtual machine, initialize the direct address mapping window, and initialize the address space identifier to 0. Then, it deploys itself to the kernel virtual machine, enters the virtual machine mode, runs in its own code space, and performs operations such as search and translation.
[0180] It should be noted that if the binary translator runs in user mode, the binary translator's own memory access instructions can be understood as issued by the host machine's application, that is, at this time the binary translator's own memory access instructions can be equivalent to the memory access instructions of the application in the host machine; if the binary translator runs in virtual machine mode, the binary translator's own memory access instructions can be forwarded via the kernel virtual machine on which it runs.
[0181] Optionally, when the binary translator runs in the virtual machine mode, if the binary translator needs to initiate a system call (syscall) for the host machine to the host machine, it can be processed in the following steps S31 to S33:
[0182] Step S31, in response to a system call to the host machine, switching the operation mode of the binary translator from the virtual machine mode to the user mode.
[0183] In actual application scenarios, the binary translator may also generate system calls for the host machine, such as calls generated by operations such as applying for and adjusting the host machine's physical memory that the binary translator can use. These system calls need to be initiated and executed normally by the host machine's application when the binary translator is in user mode. Since the binary translator can run in virtual machine mode, due to the limitations of the virtualization operating mechanism, the binary translator running in virtual machine mode may not be able to directly initiate system calls to the host machine. In order to handle these system calls, the binary translator's operating mode can be switched from virtual machine mode to user mode, that is, the binary translator can be directly run as a host machine application.
[0184] Step S32: executing the system call in the user mode.
[0185] When the binary translator switches to user mode, the binary translator runs as an application of the host machine and can directly initiate system calls to the operating system of the host machine.
[0186] Step S33, switching the operation mode of the binary translator from the user mode to the virtual machine mode.
[0187] After the execution of the system call is completed, or after the system call is issued to the host operating system, the operation mode of the binary translator can be switched from the user mode to the virtual machine mode again to continue to translate the memory access address.
[0188] In an embodiment of the present invention, by making the binary translator run in virtual machine mode, the binary translator can operate the hardware secondary TLB to complete the conversion of the address to be translated, which helps to improve the translation efficiency. The binary translator can also switch between virtual machine mode and user mode, so that the binary translator can initiate system calls to the host machine, thereby supporting the normal operation of the binary translator itself as an application of the host machine, which helps to improve the operating stability and application scope of the present solution.
[0189] In summary, in the process of address conversion, the embodiment of the present invention can obtain the high-order address information of the preset length of the first address to be translated, and determine that the first address to be translated matches the mapping address of the direct address mapping window when the high-order address information matches the preset high-order information, which can effectively improve the efficiency of matching the first address to be translated with the direct address mapping window, and because the first address to be translated generated by the binary translator itself adds the preset high-order information, even if the low-order information of the first address to be translated generated by the binary translator itself and the first address to be translated generated by the client application are repeated, the two first addresses to be translated can be effectively identified, avoiding conflicts between the two addresses, so that the present solution can support a complete client address space. By setting the first address to be translated of the memory access instruction generated by the binary translator itself within the mapping range of the direct address mapping window, the source of the first address to be translated stored in the code cache space can be identified based on the direct address mapping window, so that different strategies can be adopted for address conversion, which helps to improve the efficiency of address conversion. By identifying the first address to be translated and the second address to be translated, and filling the corresponding mapping relationship in the secondary translation backup buffer in a targeted manner according to the translation requirements of the first address to be translated and the second address to be translated, different mapping relationships can be used to convert different addresses to be translated, which helps to improve the accuracy of address conversion. It is possible to obtain an address space identifier for indicating the code space in which the binary translator is running, and determine whether the binary translator is currently running in the code cache space or its own code space according to the address space identifier, thereby distinguishing the first address to be translated and the second address to be translated, and using different methods to process different addresses to be translated, thereby improving the efficiency of address translation.
[0190] Reference Figure 6 , Figure 6 FIG. 4 shows a flow chart of another embodiment of an address conversion method provided by an embodiment of the present invention. Figure 6 As shown, the specific steps include:
[0191] Step 301, obtaining the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state.
[0192] In an embodiment of the present invention, the code space in which the binary translator is running can also be judged by the hardware paging mechanism state of the kernel virtual machine where the binary translator is located, and the conversion method adopted for the address to be translated that currently needs to be converted can be determined. Specifically, the binary translator can synchronously adjust the hardware paging mechanism state of the kernel virtual machine where it is located when switching the running context. When the hardware paging mechanism is closed, it is considered that the binary translator is running in its own code space, and the address to be translated obtained is the second address to be translated. The second address to be translated can be directly regarded as the host machine physical address without any address conversion. When the hardware paging mechanism is turned on, it is considered that the binary translator is running in the code cache space, and the address to be translated obtained is the first address to be translated. The address to be translated can be converted based on the secondary translation backup buffer, or based on the direct address mapping window. Wherein, the kernel virtual machine where the binary translator is located represents the kernel virtual machine where the binary translator is located when it runs under the virtual machine model.
[0193] It should be noted that for host machines of different architectures, the above-mentioned hardware paging mechanism state can be set in different ways, and the embodiments of the present invention do not make specific limitations. Exemplarily, whether the hardware paging mechanism of the kernel virtual machine is enabled can be controlled by combining the A flag and the B flag in the memory synchronization device control register (Control Register for Memory-synchronized Device, CRMD) in the control and status register (Control Status Register, CSR) of the kernel virtual machine. When the A flag is 1 and the B flag is 0, the hardware paging mechanism is turned off, and when the A flag is 0 and the B flag is 1, the hardware paging mechanism is turned on. Among them, the A flag may include a direct address mapping flag (DA flag), and the B flag may include a paging mechanism flag (PG flag). It should be noted that the number and type of flags used to turn on and off the hardware paging mechanism can be flexibly set by technicians, and the embodiments of the present invention do not make specific limitations.
[0194] Reference Figure 7 , Figure 7 FIG. 4 shows another context switching schematic diagram of a binary translator provided by an embodiment of the present invention. Figure 7As shown, after the binary translator is started, DA is initialized to 1 and PG is 0. The binary translator runs in its own code space and performs operations such as search and translation (DA is 1 and PG is 0). After the operation in its own code space is completed, the context is switched to enter the code cache space for operation, and DA is set to 0 and PG is set to 1. When running in the code cache space, DA is kept at 0 and PG is 1. After the operation in the code cache space is completed, the context is switched again to enter its own code space for operation, and DA is set to 1 and PG is set to 0.
[0195] Step 302: When the hardware paging mechanism is in the on state, determine that the code space in which the binary translator is running is a code cache space.
[0196] Since the hardware paging mechanism state of the kernel virtual machine is set by the binary translator when switching contexts, the code space that the binary translator is currently running can be determined through the hardware paging mechanism state. In an embodiment of the present invention, when the hardware paging mechanism state is on, it can be determined that the running code space is the code cache space, and a first address to be translated can be obtained from the code cache space. A direct address mapping window or a secondary translation backup buffer can be used to convert the first address to be translated into a host virtual address, and a memory access instruction can be issued to the host based on the host virtual address.
[0197] Step 303, obtaining a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer.
[0198] This step can refer to the above-mentioned step 203, and will not be described in detail in this embodiment of the present invention.
[0199] Step 304: When the first address to be translated matches the mapping address of the direct address mapping window, convert the first address to be translated into a host virtual address based on the direct address mapping window.
[0200] This step can refer to the above-mentioned step 206, and will not be described in detail in this embodiment of the present invention.
[0201] Step 305, when the first address to be translated does not match the mapping address of the direct address mapping window, fill the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer, and convert the first address to be translated into the host virtual address based on the secondary translation lookaside buffer.
[0202] This step can refer to the above-mentioned step 207, and will not be described in detail in this embodiment of the present invention.
[0203] Step 306: When the hardware paging mechanism state is the closed state, determine that the running code space is the own code space.
[0204] In the embodiment of the present invention, when the hardware paging mechanism is in the off state, it can be determined that the running code space is the binary translator's own code space, and the second address to be translated can be obtained from the own code space.
[0205] Step 307: Obtain a second address to be translated from the binary translator's own code space.
[0206] This step can refer to the above-mentioned step 209, and will not be described in detail in this embodiment of the present invention.
[0207] Step 308: determine the second address to be translated as a host machine virtual address.
[0208] In an embodiment of the present invention, since the hardware paging mechanism of the kernel virtual machine is in a closed state at this time, the kernel virtual machine will not convert the second address to be translated, and directly uses the second address to be translated as the host virtual address to issue a memory access instruction to the host machine, thereby further improving the address conversion efficiency.
[0209] In summary, in the process of address conversion, the embodiment of the present invention can obtain the hardware paging mechanism status of the kernel virtual machine where the binary translator is located; when the hardware paging mechanism status is in the on state, the code space in which the binary translator is running is determined to be the code cache space. When the hardware paging mechanism status is in the off state, the running code space is determined to be its own code space. From the code cache space of the binary translator of the client, a first address to be translated is obtained. When the first address to be translated does not match the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the secondary translation backup buffer. From the binary translator's own code space, a second address to be translated is obtained. The second address to be translated is determined as the host virtual address.
[0210] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0211] Reference Figure 8 , shows a structural block diagram of an embodiment of an address conversion device of the present invention, the device comprising:
[0212] A first address to be translated module 401 is used to obtain a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer;
[0213] A first conversion module 402 is configured to convert the first address to be translated into a host virtual address based on the direct address mapping window when the first address to be translated matches a mapping address of the direct address mapping window;
[0214] The second conversion module 403 is configured to convert the first address to be translated into a host virtual address based on a secondary translation lookaside buffer when the first address to be translated does not match the mapping address of the direct address mapping window.
[0215] Optionally, the device further comprises:
[0216] An address high-bit information module, used to obtain address high-bit information of a preset length in the first address to be translated;
[0217] The high-order information matching module is used to determine that the first address to be translated matches the mapping address of the direct address mapping window when the high-order information of the address matches the preset high-order information.
[0218] Optionally, the device further comprises:
[0219] A first address to be translated generating module, used for replacing the address high-bit information of the host machine virtual address of the own memory access instruction of the binary translator by preset high-bit information, so as to obtain a first address to be translated corresponding to the own memory access instruction;
[0220] The first address to be translated storage module is used to store the first address to be translated corresponding to the own memory access instruction into the code cache space.
[0221] Optionally, the device further comprises:
[0222] A configuration module is used to write an address mapping relationship between the mapping address and the host virtual address corresponding to the mapping address in the window configuration space to configure the direct address mapping window, or to write preset high-bit information in the window configuration space to configure the direct address mapping window.
[0223] Optionally, the device further comprises:
[0224] A second address to be translated module, used for obtaining a second address to be translated from the binary translator's own code space;
[0225] The third conversion module is used to convert the second address to be translated into a host virtual address based on the secondary translation backup buffer, or determine the second address to be translated as a host virtual address.
[0226] Optionally, the device further comprises:
[0227] A first mapping relationship module, configured to fill the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer when the first address to be translated does not match the mapping address of the direct address mapping window;
[0228] The second mapping relationship module is used to fill the second mapping relationship between the first host machine virtual address and the second host machine virtual address into the secondary translation backup buffer when the second address to be translated is obtained.
[0229] Optionally, the device further comprises:
[0230] An address space identification module, used to obtain an address space identification for indicating a code space in which the binary translator is running;
[0231] A first code cache space determination module, configured to determine that the running code space is a code cache space when the address space identifier matches a first preset identifier;
[0232] The first own code space determination module is used to determine that the running code space is the own code space when the address space identifier matches the second preset identifier.
[0233] Optionally, the device further comprises:
[0234] A hardware paging mechanism state module, used to obtain the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state;
[0235] A second code cache space determination module, configured to determine, when the hardware paging mechanism state is the enabled state, that the code space in which the binary translator is running is the code cache space;
[0236] The second own code space determination module is used to determine that the running code space is the own code space when the hardware paging mechanism state is the closed state.
[0237] Optionally, the binary translator runs in a virtual machine mode, and the device further comprises:
[0238] A first mode switching module, configured to switch the operation mode of the binary translator from a virtual machine mode to a user mode in response to a system call to the host machine;
[0239] A system call processing module, used for executing the system call in the user mode;
[0240] The second mode switching module is used to switch the operating mode of the binary translator from the user mode to the virtual machine mode.
[0241] Optionally, the first address to be translated includes a memory access address corresponding to a source memory access instruction of a client program of the client, and the apparatus further includes:
[0242] A target memory access instruction module, used for performing binary translation on the source memory access instruction to obtain a target memory access instruction;
[0243] A target memory access instruction execution module is used to execute the target memory access instruction in the host machine based on the host machine virtual address corresponding to the first address to be translated, so that the host machine operates on the data stored in the host machine physical address corresponding to the host machine virtual address based on the target memory access instruction.
[0244] The address conversion device of the embodiment of the present invention comprises: a first address module to be translated, used for obtaining a first address to be translated from the code cache space of the binary translator of the client; the client runs in the host; a first conversion module, used for converting the first address to be translated into a host virtual address based on the direct address mapping window when the first address to be translated matches the mapping address of the direct address mapping window; a second conversion module, used for converting the first address to be translated into a host virtual address based on the secondary translation backup buffer when the first address to be translated does not match the mapping address of the direct address mapping window. The present invention adopts the direct address mapping method to perform address conversion for the first address to be translated that can match the direct address mapping window, and adopts the secondary translation backup buffer to perform address conversion for the remaining first addresses to be translated, and can adopt different conversion methods for different addresses to be translated in the code cache space, which helps to improve the efficiency of address conversion.
[0245] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0246] Reference Fig. 9 , is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Fig. 9As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the address conversion method of the aforementioned embodiment.
[0247] An embodiment of the present invention provides a non-temporary computer-readable storage medium. When instructions in the storage medium are executed by a program or processor of a terminal, the terminal is enabled to perform the steps of the address conversion method of the aforementioned embodiment.
[0248] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0249] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0250] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0251] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0252] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0253] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0254] Specific examples are used herein 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. An address conversion method, characterized in that: The method comprises: Obtaining a first address to be translated from a code cache space of a binary translator of the client; When the first address to be translated matches the mapping address of the direct address mapping window, converting the first address to be translated into a host virtual address based on the direct address mapping window; When the first address to be translated does not match the mapping address of the direct address mapping window, the first address to be translated is converted into a host virtual address based on the secondary translation lookaside buffer.
2. The method according to claim 1, characterized in that After obtaining the first address to be translated, the method further includes: Obtaining high-order address information of a preset length in the first address to be translated; When the high-order information of the address matches the preset high-order information, it is determined that the first address to be translated matches the mapping address of the direct address mapping window.
3. The method according to claim 1, characterized in that Before obtaining the first address to be translated, the method further includes: Replacing the address high-bit information of the host machine virtual address of the binary translator's own memory access instruction by preset high-bit information to obtain a first to-be-translated address corresponding to the own memory access instruction; The first address to be translated corresponding to the native memory access instruction is stored in the code cache space.
4. The method according to claim 1, characterized in that: Before obtaining the first address to be translated, the method further includes: Writing an address mapping relationship between the mapping address and the host machine virtual address corresponding to the mapping address into the window configuration space to configure the direct address mapping window, Alternatively, preset high-bit information is written into the window configuration space to configure the direct address mapping window.
5. The method according to claim 1, characterized in that After obtaining the first address to be translated, the method further includes: Obtaining a second address to be translated from the binary translator's own code space; The second address to be translated is converted into a host virtual address based on the secondary translation lookaside buffer, or the second address to be translated is determined as a host virtual address.
6. The method according to claim 5, characterized in that Before converting the first address to be translated into a host virtual address based on the secondary translation lookaside buffer, the method further includes: In the case where the first address to be translated does not match the mapping address of the direct address mapping window, filling the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer; When the second address to be translated is obtained, a second mapping relationship between the first host machine virtual address and the second host machine virtual address is filled into the secondary translation lookaside buffer.
7. The method according to claim 5, characterized in that Before obtaining the second address to be translated, the method further includes: Obtaining an address space identifier for indicating a code space in which the binary translator is running; In a case where the address space identifier matches the first preset identifier, determining that the running code space is a code cache space; When the address space identifier matches the second preset identifier, it is determined that the running code space is the own code space.
8. The method according to claim 5, characterized in that Before obtaining the second address to be translated, the method further includes: Obtaining the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state; When the hardware paging mechanism is in the on state, determining that the code space in which the binary translator is running is a code cache space; When the hardware paging mechanism state is the closed state, it is determined that the running code space is the own code space.
9. The method according to any one of claims 1 to 8, characterized in that: The binary translator runs in a virtual machine mode, and after converting the first address to be translated into a host virtual address based on a secondary translation lookaside buffer, the method further includes: In response to a system call to the host machine, switching the operating mode of the binary translator from a virtual machine mode to a user mode; Executing the system call in the user mode; The operation mode of the binary translator is switched from the user mode to the virtual machine mode.
10. The method according to any one of claims 1 to 8, characterized in that: The first address to be translated includes a memory access address corresponding to a source memory access instruction of a client program of the client. After converting the first address to be translated into a host virtual address based on a secondary translation lookaside buffer, the method further includes: Performing binary translation on the source memory access instruction to obtain a target memory access instruction; Based on the host machine virtual address corresponding to the first address to be translated, the target memory access instruction is executed in the host machine, so that the host machine operates on the data stored in the host machine physical address corresponding to the host machine virtual address based on the target memory access instruction.
11. An address conversion device, characterized in that: The device comprises: A first address to be translated module, used for obtaining a first address to be translated from a code cache space of a binary translator of a client computer running in a host computer; A first conversion module, configured to convert the first address to be translated into a host virtual address based on the direct address mapping window when the first address to be translated matches a mapping address of the direct address mapping window; The second conversion module is configured to convert the first address to be translated into a host machine virtual address based on a secondary translation lookaside buffer when the first address to be translated does not match a mapping address of a direct address mapping window.
12. The device according to claim 11, characterized in that The device also includes: An address high-bit information module, used to obtain address high-bit information of a preset length in the first address to be translated; The high-order information matching module is used to determine that the first address to be translated matches the mapping address of the direct address mapping window when the high-order information of the address matches the preset high-order information.
13. The device according to claim 11, characterized in that The device also includes: A first address to be translated generating module, used for replacing the address high-bit information of the host machine virtual address of the own memory access instruction of the binary translator by preset high-bit information, so as to obtain a first address to be translated corresponding to the own memory access instruction; The first address to be translated storage module is used to store the first address to be translated corresponding to the own memory access instruction into the code cache space.
14. The device according to claim 11, characterized in that The device also includes: A configuration module is used to write an address mapping relationship between the mapping address and the host virtual address corresponding to the mapping address in the window configuration space to configure the direct address mapping window, or to write preset high-bit information in the window configuration space to configure the direct address mapping window.
15. The device according to claim 11, characterized in that The device also includes: A second address to be translated module, used for obtaining a second address to be translated from the binary translator's own code space; The third conversion module is used to convert the second address to be translated into a host virtual address based on the secondary translation backup buffer, or determine the second address to be translated as a host virtual address.
16. The device according to claim 15, characterized in that The device also includes: A first mapping relationship module, configured to fill the first mapping relationship between the client virtual address and the host virtual address into the secondary translation lookaside buffer when the first address to be translated does not match the mapping address of the direct address mapping window; The second mapping relationship module is used to fill the second mapping relationship between the first host machine virtual address and the second host machine virtual address into the secondary translation backup buffer when the second address to be translated is obtained.
17. The device according to claim 15, characterized in that The device also includes: An address space identification module, used to obtain an address space identification for indicating a code space in which the binary translator is running; A first code cache space determination module, configured to determine that the running code space is a code cache space when the address space identifier matches a first preset identifier; The first own code space determination module is used to determine that the running code space is the own code space when the address space identifier matches the second preset identifier.
18. The device according to claim 15, characterized in that The device also includes: A hardware paging mechanism state module, used to obtain the hardware paging mechanism state of the kernel virtual machine where the binary translator is located; wherein the hardware paging mechanism state includes an on state and a off state; A second code cache space determination module, configured to determine, when the hardware paging mechanism state is the enabled state, that the code space in which the binary translator is running is the code cache space; The second own code space determination module is used to determine that the running code space is the own code space when the hardware paging mechanism state is the closed state.
19. The device according to any one of claims 11 to 18, characterized in that The binary translator runs in a virtual machine mode, and the device further comprises: A first mode switching module, configured to switch the operation mode of the binary translator from a virtual machine mode to a user mode in response to a system call to the host machine; A system call processing module, used for executing the system call in the user mode; The second mode switching module is used to switch the operating mode of the binary translator from the user mode to the virtual machine mode.
20. The device according to any one of claims 11 to 18, characterized in that The first address to be translated includes a memory access address corresponding to a source memory access instruction of a client program of the client, and the device further includes: A target memory access instruction module, used for performing binary translation on the source memory access instruction to obtain a target memory access instruction; A target memory access instruction execution module is used to execute the target memory access instruction in the host machine based on the host machine virtual address corresponding to the first address to be translated, so that the host machine operates on the data stored in the host machine physical address corresponding to the host machine virtual address based on the target memory access instruction.
21. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the address conversion method according to any one of claims 1 to 10.
22. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the address conversion method according to any one of claims 1 to 10 are implemented.
Citation Information
Cited By
Method and device for increasing storage information density of translation bypass cache, electronic equipment and computer program product
CN121029643A
