Memory initialization method supporting heterogeneous CPUs in Qemu emulator
By initializing the memory of the X86 and Shenwei AI processors separately in the Qemu simulator, the problem of the inability of existing technologies to support heterogeneous CPUs is solved, and effective management of heterogeneous CPUs and high-performance operation of the simulator are achieved.
Patent Information
- Application Number
- CN202210196042.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-02
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2042-03-02
AI Technical Summary
The existing Qemu simulator cannot effectively support memory initialization of heterogeneous CPUs, resulting in the inability to simulate different types of CPUs simultaneously in the same simulator.
By isolating memory ranges, the memory of X86 and Shenwei AI processors is initialized separately, and different memory allocation methods are used to ensure that there is no conflict between the two, thus realizing memory management of heterogeneous CPUs.
Memory initialization for X86 and Shenwei AI processors is implemented in the same Qemu emulator, supporting the coexistence of heterogeneous CPUs and improving the compatibility and performance of the emulator.
Abstract
Description
Technical Field
[0001] The present invention relates to a memory initialization method supporting heterogeneous CPUs in a Qemu simulator, which is used for a domestic AI accelerator card simulator and belongs to the field of computing technology. Background Art
[0002] Qemu (Quick Emulator) is an open-source full-system emulator and virtual machine monitor (VMM) that plays a vital role in hardware and basic software development. Qemu simulates virtual memory, with its core function being to maintain the physical address space of the virtual machine. This address space facilitates Qemu management, providing memory to the virtual machine, and facilitates display and export, providing a memory view to the platform.
[0003] In the current Qemu architecture, memory is initially designed for a single architecture, initializing and allocating memory for a single CPU architecture from 0. Therefore, the existing Qemu emulator's memory management is designed for a single CPU architecture and cannot support heterogeneous CPUs, primarily due to memory layout issues. From Qemu's perspective, the physical address of a virtual machine's memory range (memory_region) in a single architecture starts at 0 and increases in size. In heterogeneous mode, memory ranges must be planned for heterogeneous CPUs without any overlapping conflicts. Summary of the Invention
[0004] The purpose of the present invention is to provide a memory initialization method supporting heterogeneous CPUs in a Qemu simulator, so as to solve the problem of initializing the underlying memory of different types of CPUs when the same Qemu simulator simulates heterogeneous CPUs at the same time.
[0005] To achieve the above object, the present invention provides a memory initialization method that supports heterogeneous CPUs in the Qemu simulator, targeting the heterogeneous model of X86+Shenwei AI, comprising the following steps:
[0006] Step 1. Initialize the memory of the X86 CPU starting from address 0 according to the default initialization method of Qemu. The specific process is as follows:
[0007] Step 11. In pc_init1, analyze the memory to be initialized according to the parameters;
[0008] Step 12. In the function cpu_exec_init_all, call io_mem_init and memory_map_Init to initialize io and memory respectively. io_mem_init is responsible for creating the memory area of io, and memory_map_init is used to create two memory address spaces: address_space_memory and system_memory.
[0009] Step 13: Call pc_memory_init to initialize the memory required in X86;
[0010] Step 2: Analyze the usage of address ranges by X86 and Shenwei architecture. The memory range starts from SW_PHYS_ADDR_START (1<<59) and initializes the memory of Shenwei AI processor. The specific process is as follows:
[0011] Step 21: Create a new memory region (MemoryRegion) type pointer ram;
[0012] Step 22: Assign a name airam-xx to each core group continuous segment memory controller;
[0013] Step 23: Set the address range of each continuous segment memory control;
[0014] Step 24: Call the memory_region_allocate_system_memory function to allocate four consecutive memory regions.
[0015] Step 25: Call the function memory_region_add_subregion to add subregions to the four contiguous memory regions created in step 24.
[0016] Step 26: Complete the allocation of continuous segment memory;
[0017] Step 27: Specify the cross segment name as ram_cross;
[0018] Step 28: Set the address range of the cross-segment memory control;
[0019] Step 29: Call the memory_region_allocate_system_memory function to allocate the cross-segment memory area;
[0020] Step 210: Call the function memory_region_add_subregion to add a subregion to the cross-segment memory region created in step 29;
[0021] Step 211: Complete cross-segment memory allocation.
[0022] Due to the application of the above technical solution, the present invention has the following advantages compared with the prior art:
[0023] The present invention supports a memory initialization method for heterogeneous CPUs in the Qemu simulator. The Qemu simulator is oriented towards the coexistence of X86 and Shenwei AI. It isolates the CPU memories of different architectures by isolating memory ranges and initializes them in different ways, thus realizing memory initialization of heterogeneous CPUs. This lays the foundation for full-system simulation of X86+AI accelerator cards in the same Qemu simulation environment. DETAILED DESCRIPTION
[0024] Example: The present invention provides a memory initialization method supporting heterogeneous CPUs in the Qemu simulator, simulating two large blocks of memory, namely X86 memory and Shenwei AI memory (including cross-segment);
[0025] In the simulator, the X86 memory range (memory_region) uses Qemu's default allocation method starting from address 0. The card memory must be separated from the X86 memory and must not conflict with various IO addresses.
[0026] In order to support both X86 and Sunway AI processors running in the simulator, the memory initialization for the two CPUs is as follows:
[0027] The memory initialization of X86CPU starts from address 0, according to the default initialization method of Qemu:
[0028] 1) In pc_init1, first analyze the memory to be initialized based on the parameters (host_type, ram_size);
[0029] 2) In the function cpu_exec_init_all, io_mem_init and memory_map_Init are called to initialize io and memory respectively;
[0030] 3) io_mem_init is mainly responsible for creating the io memory area (MemoryRegion);
[0031] 4) memory_map_init mainly creates two memory address spaces: address_space_memory and system_memory;
[0032] 5) Finally, call pc_memory_init to initialize the memory required in X86.
[0033] After the X86 CPU memory is initialized according to the default path, the memory of the Shenwei AI processor needs to be initialized. First, after analyzing the usage of the address range of X86 and Shenwei architecture, the memory range of Shenwei AI starts from SW_PHYS_ADDR_START (1<<59). The memory initialization process on the card is as follows:
[0034] 1) Create a new memory region (MemoryRegion) type pointer ram;
[0035] 2) Assign a name airam-xx to each core group continuous segment memory controller;
[0036] 3) Set the address range of each continuous segment memory control;
[0037] 4) Call the memory_region_allocate_system_memory function to allocate four consecutive memory regions;
[0038] 5) Call the function memory_region_add_subregion to add subregions to the newly created four consecutive memory regions, that is, to associate them with the memory controller;
[0039] 6) Complete the allocation of continuous segment memory;
[0040] 7) Specify the cross segment name as ram_cross;
[0041] 8) Set the address range of cross-segment memory control;
[0042] 9) Call the memory_region_allocate_system_memory function to allocate the cross-segment memory area;
[0043] 10) Call the function memory_region_add_subregion to add a subregion to the newly created cross-segment memory region;
[0044] 11) Complete cross-segment memory allocation.
[0045] In the above process, four continuous segments and one cross segment are allocated. In order to facilitate processing, a separate memory segment is allocated to the cross segment. The advantage of this is that the processing is simple and the performance is high. It can also simulate the hardware design well.
[0046] To facilitate a better understanding of the present invention, the following briefly explains the terms used herein:
[0047] Qemu: Quick Emulator, an open source full-system emulator;
[0048] Heterogeneous: Mainly refers to the CPU using different instruction sets and different architectural designs.
[0049] AI: Artificial Intelligence.
[0050] Accelerator card: A processor product specially designed to accelerate algorithm execution. In the AI field, accelerator cards generally use the PCIe interface to connect to the server.
[0051] Management core, main core: In the multi-core architecture, the core that is specifically responsible for management functions among the many processing cores of the CPU is called the management core, also called the main core.
[0052] Computing core and slave core: In a multi-core architecture, the core that is specifically responsible for computing functions among the many processing cores of the CPU is called a computing core, also called a slave core.
[0053] When using the above-mentioned memory initialization method to support heterogeneous CPUs in the Qemu simulator, the Qemu simulator for the coexistence of X86 and Shenwei AI isolates the CPU memory of different architectures by isolating the memory range and initializing them in different ways, realizing the memory initialization of heterogeneous CPUs, laying the foundation for the full-system simulation of X86+AI accelerator card in the same Qemu simulation environment.
[0054] The above embodiments are intended only to illustrate the technical concepts and features of the present invention. Their purpose is to enable those skilled in the art to understand the contents of the present invention and implement them accordingly. They are not intended to limit the scope of protection of the present invention. Any equivalent changes or modifications made in accordance with the spirit of the present invention are intended to be covered by the scope of protection of the present invention.
Claims
1. A memory initialization method supporting heterogeneous CPUs in a Qemu simulator, characterized by: For the heterogeneous model of X86+Shenwei AI, the following steps are included: Step 1. Initialize the memory of the X86 CPU starting from address 0 according to the default initialization method of Qemu. The specific process is as follows: Step 11. In pc_init1, analyze the memory to be initialized according to the parameters; Step 12. In the function cpu_exec_init_all, call io_mem_init and memory_map_Init to initialize io and memory respectively. io_mem_init is responsible for creating the memory area of io, and memory_map_init is used to create two memory address spaces: address_space_memory and system_memory. Step 13: Call pc_memory_init to initialize the memory required in X86; Step 2: Analyze the usage of address ranges by X86 and Sunway architecture. The memory range starts from SW_PHYS_ADDR_START and initializes the memory of Sunway AI processor. The specific process is as follows: Step 21: Create a new memory area type pointer ram; Step 22: Assign a name airam-xx to each core group continuous segment memory controller; Step 23: Set the address range of each continuous segment memory control; Step 24: Call the memory_region_allocate_system_memory function to allocate four consecutive memory regions. Step 25: Call the function memory_region_add_subregion to add subregions to the four contiguous memory regions created in step 24. Step 26: Complete the allocation of continuous segment memory; Step 27: Specify the cross segment name as ram_cross; Step 28: Set the address range of the cross-segment memory control; Step 29: Call the memory_region_allocate_system_memory function to allocate the cross-segment memory area; Step 210: Call the function memory_region_add_subregion to add a subregion to the cross-segment memory region created in step 29; Step 211: Complete cross-segment memory allocation.
Citation Information
Patent Citations
A processing method and device for a memory in a device based on a SW architecture
CN108984427A
KVM-oriented virtualization layer fault injection method
CN109857522A