Hardware resource allocation method, device and equipment based on Jailhouse
Through an automated hardware resource allocation method, the memory and CPU resource information are determined using the device tree file to allocate resources for the Jailhouse partition, solving the problem of unreasonable manual allocation and improving the efficiency and reliability of hardware devices.
Patent Information
- Application Number
- CN202410979288.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-11-15
AI Technical Summary
Jailhouse hardware resource allocation method relies on developers to manually write cell files, resulting in unreasonable resource allocation and prone to problems such as memory overlap, affecting the efficiency of hardware devices.
Automatically determine memory information and CPU resource information through the device tree file, allocate hardware resources to the cell partition, realize automated memory and CPU resource allocation, and avoid the cumbersomeness and errors of manual allocation.
It improves the rationality of hardware resource allocation, reduces resource waste, avoids the risk of operational crashes, and improves the efficiency and reliability of hardware equipment.
Smart Images

Figure CN118964009A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of virtual machine technology, and in particular to a jailhouse-based hardware resource allocation method, device and equipment. Background Art
[0002] Given the increasing multi-functional requirements of hardware devices, a single device often needs to execute multiple independent programs with different functions at the same time. This is a huge challenge for the hardware architecture and will inevitably affect the efficiency of the hardware devices. In this context, the application of virtual machine technology is very important.
[0003] Jailhouse is a partition management program based on Linux. It can run on bare metal and can configure the virtualization features of the CPU and hardware using a method called "cell". Under Jailhouse, each cell describes a partition, and different partitions can execute different programs or operating systems in parallel. Jailhouse is very simple in design. Once activated, it can run on bare devices, fully control the hardware and require no external support. Compared with other bare device managers, Jailhouse is loaded and configured through the Linux system, and the management interface is based on the Linux architecture, so you need to start Linux first and then enable Jailhouse to divide system resources into additional cells.
[0004] The jailhouse allocates resources by developers manually writing cell files, which allocate memory and CPU resources to each cell. This allocation method is cumbersome, and in some cases there is no basis for allocation, which is prone to problems such as memory overlap and can lead to runtime crashes. Summary of the invention
[0005] In view of this, the present application provides a Jailhouse-based hardware resource allocation method, apparatus and device, which automatically allocates hardware resources to cell partitions according to the memory information and CPU information of the electronic device, making the hardware resource allocation of the cell partitions more reasonable.
[0006] In a first aspect, an embodiment of the present invention provides a Jailhouse-based hardware resource allocation method, comprising:
[0007] Determine whether the cell file has been configured;
[0008] If the cell file is not configured, the memory information and CPU resource information are determined according to the device tree file;
[0009] Allocate memory to the cell partition according to the memory information;
[0010] Allocate CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition;
[0011] Assign cell files according to the memory and CPU resources allocated to the cell partition.
[0012] In some embodiments, the memory information includes: full memory size and reserved memory;
[0013] The allocating memory to the cell partition according to the memory information includes:
[0014] Determining allocatable memory according to the full memory size and the reserved memory;
[0015] Memory is allocated to the cell partition according to the allocatable memory.
[0016] In some embodiments, the reserved memory includes a combination of one or more of the following:
[0017] Kernel reserved memory;
[0018] Each memory is reserved for supporting hardware operation;
[0019] Memory used by the hypervisor.
[0020] In some embodiments, allocating memory to a cell partition according to the allocatable memory includes:
[0021] The number of the cell partitions is multiple;
[0022] The allocatable memory is evenly distributed to each cell partition.
[0023] In some embodiments, the CPU resource information includes: the total number of CPUs;
[0024] The allocating CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition includes:
[0025] The number of CPUs allocated to the cell partition is determined according to the total number of CPUs and the memory size allocated to the cell partition.
[0026] In some embodiments, determining the number of CPUs allocated to the cell partition according to the total number of CPUs and the memory size allocated to the cell partition includes:
[0027] Determine the sum of the memory allocated for the cell partition and the kernel reserved memory;
[0028] Determining a ratio of memory allocated to a cell partition to the sum of the memories;
[0029] The number of CPUs allocated to the cell partition is determined according to the ratio and the total number of CPUs.
[0030] In a second aspect, an embodiment of the present invention provides a Jailhouse-based hardware resource allocation device, including:
[0031] The judgment module is used to judge whether the cell file has been configured;
[0032] A resource allocation module, used for determining memory information and CPU resource information according to a device tree file when a cell file is not configured; allocating memory to a cell partition according to the memory information; and allocating CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition;
[0033] The assignment module is used to assign cell files according to the memory and CPU resources allocated to the cell partition.
[0034] In some embodiments, the memory information includes: full memory size and reserved memory;
[0035] The resource allocation module is specifically used to: determine the allocatable memory according to the complete memory size and the reserved memory; and allocate memory to the cell partition according to the allocatable memory.
[0036] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device executes the method described in the first aspect or any one of the first aspect.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in the first aspect or any one of the first aspects.
[0038] In the embodiment of the present invention, memory information and CPU resource information are determined according to the device tree file, memory can be adaptively allocated to the cell partition according to the memory information, and CPU resources can be allocated to the cell partition according to the memory resources allocated to the cell partition. The embodiment of the present invention allocates memory to the cell partition based on the memory information, and allocates CPU resources to the cell partition based on the memory allocation situation, which solves the drawbacks of the original manual resource allocation to a certain extent and makes the cell resource allocation more reasonable. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 A schematic diagram of a jailhouse provided in an embodiment of the present invention;
[0041] Figure 2 A flowchart of a Jailhouse-based hardware resource allocation method provided in an embodiment of the present invention;
[0042] Figure 3 A flowchart of another Jailhouse-based hardware resource allocation method provided in an embodiment of the present invention;
[0043] Figure 4 A schematic diagram of the structure of a Jailhouse-based hardware resource allocation device provided in an embodiment of the present invention;
[0044] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] In order to better understand the technical solution of the present application, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0046] It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0047] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0048] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0049] See also Figure 1 , is a schematic diagram of a Jailhouse provided by an embodiment of the present invention. Figure 1 As shown in the figure, Jailhouse is a partition management program based on Linux. Jailhouse uses the openness of the Linux system to add one or more real-time operating systems to the Linux system, so that multiple systems can run on a multi-core processor. Jailhouse uses cells to manage each operating system and configures CPU and device resources for each cell. Device resources between different cells cannot be shared. Figure 1 As shown, Jailhouse has a host node, which usually runs a Linux system, but the master node does not have control over all hardware resources. Jailhouse creates new partitions, such as cell 1, cell 2...cell n, through a virtual machine monitor (hypervisor), and divides the relevant hardware resources into corresponding partitions. Among them, the cell file is the basis for the hypervisor to divide the hardware resources into cell partitions. The cell files in the related art are mainly written manually by developers. In order to achieve the rationality of the hardware resource allocation of cell partitions, an embodiment of the present invention provides a method for automatically allocating hardware resources to cell partitions.
[0050] See also Figure 2 , is a flowchart of a Jailhouse-based hardware resource allocation method provided by an embodiment of the present invention. Figure 2 As shown, the processing steps of the method include:
[0051] 101. Determine whether the cell file has been configured.
[0052] This step is mainly used to determine whether the cell file has been manually written by the developer. If the cell file has been configured, the method ends. If the cell file has not been configured, step 102 is executed.
[0053] 102. Determine memory information and CPU resource information according to the device tree file.
[0054] The device tree file (DeviceTreeSource, referred to as DTS) is a file that uses a tree structure to describe the device information on the development board, such as the number of CPUs, memory base addresses, which devices are connected to the IIC interface, which devices are connected to the SPI interface, etc. In an embodiment of the present invention, the memory information and CPU resource information in the electronic device can be determined based on the device tree file. The memory information can include, for example, the complete memory size, reserved memory, etc. Based on the complete memory size and reserved memory, the allocatable memory in the electronic device can be determined, and the allocatable memory is the memory that can be allocated to the cell partition. Memory can be allocated to the cell partition based on the allocatable memory.
[0055] 103. Allocate memory to the cell partition according to the memory information.
[0056] 104. Allocate CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition.
[0057] 105, assigning cell files according to the memory and CPU resources allocated to the cell partition.
[0058] In an embodiment of the present invention, manually written cell files are replaced by automatically generated cell files. When the cell file is automatically generated, the memory information and CPU resource information of the electronic device are determined according to the device tree file, and the memory can be adaptively allocated to the cell partition according to the memory information, and the CPU resources can be allocated to the cell partition according to the memory resources allocated to the cell partition. The embodiment of the present invention allocates memory to the cell partition based on the memory information, and allocates CPU resources to the cell partition based on the memory allocation situation, which solves the drawbacks of the original manual resource allocation to a certain extent and makes the allocation of cell hardware resources more reasonable.
[0059] See also Figure 3 , is a flowchart of another Jailhouse-based hardware resource allocation method provided by an embodiment of the present invention. Figure 3 As shown, the processing steps of the method include:
[0060] 201, determine whether the cell file has been configured. If not, execute step 202; if it has been configured, the method ends.
[0061] 202 , determining a full memory size and a reserved memory of the electronic device according to the device tree file.
[0062] Among them, the complete memory size of the electronic device is represented by M all , the reserved memory can include kernel reserved memory M k , each memory is reserved for supporting hardware operation Mi (i=1,2,3.....), memory M occupied by the virtual machine monitor h A combination of one or more of .
[0063] 203, determine the memory size allocated to the cell partition.
[0064] In some embodiments, the reserved memory of the electronic device includes a kernel reserved memory M. k , each memory is reserved for supporting hardware operation M i (i=1,2,3.....) and the memory M occupied by the virtual machine monitor h , the memory size M allocated for the cell partition can be determined according to the following formula (1): s .
[0065]
[0066] Optionally, if there are multiple cell partitions, M is calculated according to formula (1): s Then, M s Each cell is partitioned. For example, Figure 1 There are n partitions in total, including cell 1, cell 2, ..., cell n. According to formula (1), M is calculated. s After that, the memory size allocated to each cell partition is M s / n.
[0067] 204, assigning values to the memory allocation module in the cell file, including the starting address and memory size of the memory allocated to the cell partition. The starting address of the memory allocated to the cell partition can also be determined according to the device tree file.
[0068] 205 , determining CPU resource information of the electronic device according to the device tree file, where the CPU resource information includes: a total number of CPUs.
[0069] 206, determine the number of CPUs allocated to the cell partition.
[0070] In some embodiments, the number of CPUs allocated to the cell partition may be determined based on the total number of CPUs and the memory size allocated to the cell partition. s And kernel reserved memory M k The sum of the memory of the cell partition is determined by s and the ratio of the total number of CPUs to the total memory; and determining the number of CPUs allocated to the cell partition according to the ratio and the total number of CPUs.
[0071] In an example, the number of CPUs allocated to the cell partition can be determined according to the following formula (2):
[0072] N cs =N c / (M s / (M s +M k )) (2).
[0073] In the above formula (2), N cs Indicates the number of CPUs allocated to the cell partition, M s Indicates the memory size allocated to the cell partition, M k Indicates the kernel reserved memory size.
[0074] 207, assign values to the cpu module in the cell file, including the number of CPUs allocated to the cell partition.
[0075] The embodiment of the present invention provides a specific algorithm for calculating the memory size and the number of CPUs allocated to a cell partition, which can make the allocation of cell hardware resources more reasonable.
[0076] Corresponding to the above method, an embodiment of the present invention provides a hardware resource allocation device based on Jailhouse. Figure 4 As shown, the device comprises:
[0077] A judging module 310 is used to judge whether the cell file has been configured;
[0078] The resource allocation module 320 is used to determine the memory information and the CPU resource information according to the device tree file when the cell file is not configured; allocate memory to the cell partition according to the memory information; allocate CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition;
[0079] The assignment module 330 is used to assign values to the cell files according to the memory and CPU resources allocated to the cell partitions.
[0080] In some embodiments, the memory information includes: a complete memory size and a reserved memory; a resource allocation module 320 is specifically used to: determine the allocatable memory according to the complete memory size and the reserved memory; and allocate memory to the cell partition according to the allocatable memory.
[0081] The Jailhouse-based hardware resource allocation device of the embodiment of the present invention can be the method of the embodiment shown above. For the parts not described in detail in this embodiment, reference can be made to the relevant description of the method embodiment. The execution process and technical effects of the technical solution refer to the description of the embodiment shown in the method, which will not be repeated here.
[0082] Corresponding to the above method, an embodiment of the present invention provides an electronic device. Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, the electronic device 400 may include: a processor 401, a memory 402 and a communication unit 403. These components communicate through one or more buses, and those skilled in the art can understand that the structure of the electronic device shown in the figure does not constitute a limitation on the embodiment of the present invention, it can be a bus structure or a star structure, and can also include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0083] The communication unit 403 is used to establish a communication channel so that the electronic device can communicate with other devices, receive user data sent by other devices or send user data to other devices.
[0084] The processor 401 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It runs or executes software programs, instructions, and / or modules stored in the memory 402, and calls data stored in the memory to perform various functions of the electronic device and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 401 can only include a central processing unit (CPU). In the embodiment of the present application, the CPU includes multiple computing cores.
[0085] The memory 402 is used to store the execution instructions of the processor 401. The memory 402 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0086] When the execution instructions in the memory 402 are executed by the processor 401 , the electronic device 400 can execute part or all of the steps of the Jailhouse-based hardware resource allocation method in the embodiment of the present invention.
[0087] In a specific implementation, the present application also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment of the Jailhouse-based hardware resource allocation method provided in the present application. The storage medium may be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0088] In a specific implementation, the present application also provides a computer program product, wherein the computer program product includes executable instructions, and when the executable instructions are executed on a computer, the computer executes part or all of the steps of the Jailhouse-based hardware resource allocation method provided in the present application.
[0089] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the Jailhouse-based hardware resource allocation method provided by an embodiment of the present invention.
[0090] The above-mentioned non-temporary computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (Read Only Memory; hereinafter referred to as: ROM), an erasable programmable read-only memory (ErasableProgrammable Read Only Memory; hereinafter referred to as: EPROM) or flash memory, optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0091] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0092] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0093] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application or some parts of the embodiments.
[0094] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the device embodiment and the terminal embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
Claims
1. A method for allocating hardware resources based on Jailhouse, characterized in that: include: Determine whether the cell file has been configured; If the cell file is not configured, the memory information and CPU resource information are determined according to the device tree file; Allocate memory to the cell partition according to the memory information; Allocate CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition; Assign cell files according to the memory and CPU resources allocated to the cell partition.
2. The method according to claim 1, characterized in that The memory information includes: full memory size and reserved memory; The allocating memory to the cell partition according to the memory information includes: Determining allocatable memory according to the full memory size and the reserved memory; Memory is allocated to the cell partition according to the allocatable memory.
3. The method according to claim 2, characterized in that The reserved memory includes one or more of the following combinations: Kernel reserved memory; Each memory is reserved for supporting hardware operation; Memory used by the hypervisor.
4. The method according to claim 2, characterized in that: The allocating memory to the cell partition according to the allocable memory includes: The number of the cell partitions is multiple; The allocatable memory is evenly distributed to each cell partition.
5. The method according to claim 1, characterized in that The CPU resource information includes: the total number of CPUs; The allocating CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition includes: The number of CPUs allocated to the cell partition is determined according to the total number of CPUs and the memory size allocated to the cell partition.
6. The method according to claim 5, characterized in that The step of determining the number of CPUs allocated to the cell partition according to the total number of CPUs and the memory size allocated to the cell partition comprises: Determine the sum of the memory allocated for the cell partition and the kernel reserved memory; Determining a ratio of memory allocated to a cell partition to the sum of the memories; The number of CPUs allocated to the cell partition is determined according to the ratio and the total number of CPUs.
7. A Jailhouse-based hardware resource allocation device, characterized in that: include: The judgment module is used to judge whether the cell file has been configured; A resource allocation module, used for determining memory information and CPU resource information according to a device tree file when a cell file is not configured; allocating memory to a cell partition according to the memory information; and allocating CPU resources to the cell partition according to the CPU resource information and the memory allocated to the cell partition; The assignment module is used to assign cell files according to the memory and CPU resources allocated to the cell partition.
8. The device according to claim 7, characterized in that The memory information includes: full memory size and reserved memory; The resource allocation module is specifically used to: determine the allocatable memory according to the complete memory size and the reserved memory; and allocate memory to the cell partition according to the allocatable memory.
9. An electronic device, characterized in that: include: A memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device executes the method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 6.
Citation Information
Cited By
Dynamic modification method and device supporting Jailhouse configuration file
CN120653360A
