A method for allocating system memory-mapped input / output resources and an electronic device
By determining the system startup type and making differentiated adjustments using historical resource allocation information, the MMIO resource allocation is dynamically optimized, solving the problem of low efficiency in system memory-mapped input/output resource allocation and improving startup efficiency and resource utilization.
Patent Information
- Application Number
- CN202511405016.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2045-09-29
AI Technical Summary
In existing technologies, the allocation efficiency of system memory-mapped input/output resources is low and the utilization rate is poor. Furthermore, there are problems of repeated calculations and extended startup time when the system is not booted for the first time.
By determining whether the system is starting for the first time, historical resource allocation information is used to make differentiated adjustments, dynamically optimizing MMIO resource allocation and avoiding full scans and redundant calculations.
It improves system startup efficiency, reduces maintenance difficulty, enhances resource utilization and scalability, and shortens non-first-time startup time.
Smart Images

Figure CN120929269B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of resource allocation technology, and in particular to a method and electronic device for allocating system memory-mapped input / output resources. Background Technology
[0002] In computer hardware systems, memory-mapped input / output (MMIO) resources are the critical address space for data interaction between the central processing unit (CPU) and peripheral devices (such as peripheral component interconnect express devices (PCIe devices), internal accelerators, etc.). The rationality of its allocation directly affects system performance, stability, and resource utilization.
[0003] Currently, related technologies typically employ "average allocation" or "fixed-ratio allocation" strategies. This means dividing the total MMIO space evenly based on the number of hardware stacks or allocating it to different devices according to a preset ratio. This approach ignores the differences in actual hardware requirements, resulting in wasted MMIO space. Furthermore, these technologies perform a full resource scan and allocation process regardless of whether the system is booting for the first time: each boot re-identifies the number of CPUs, hardware group types, and device mounting status, recalculating the allocation scheme from scratch. This leads to a large amount of repetitive calculations during subsequent boots, prolonging system startup time, especially in complex systems with multiple CPUs and devices, where the efficiency loss is more pronounced.
[0004] Therefore, the related technologies suffer from technical problems such as low efficiency and poor utilization of system memory-mapped input / output resources. Summary of the Invention
[0005] This application provides a method and electronic device for allocating system memory-mapped input / output resources, so as to at least solve the problems of low allocation efficiency and poor utilization of system memory-mapped input / output resources in related technologies.
[0006] This application provides a method for allocating system memory-mapped input / output resources, including:
[0007] When the system starts up, the system startup information is determined; wherein, the startup information indicates whether the system is starting for the first time or not.
[0008] When the system is not starting for the first time, the historical resource allocation information of the system is determined; wherein, the historical resource allocation information includes: the memory-mapped input / output resource information that the system previously allocated to the hardware stack;
[0009] Based on the historical resource allocation information, resource adjustment information for at least one hardware stack is determined;
[0010] Based on the resource adjustment information, the historical resource allocation information is adjusted to obtain target resource allocation information for at least one hardware stack; wherein, the target resource allocation information includes: memory-mapped input / output resources that need to be allocated to at least one hardware stack in the system;
[0011] Memory-mapped input / output resources are allocated to at least one hardware stack according to the target resource allocation information.
[0012] This application also provides a system memory-mapped input / output resource allocation device, including:
[0013] The first determining unit is used to determine the system startup information when the system starts up; wherein, the startup information is whether the system is starting for the first time or not starting for the first time;
[0014] The second determining unit is used to determine the historical resource allocation information of the system when the system is not starting for the first time; wherein, the historical resource allocation information includes: memory-mapped input / output resource information allocated by the system to the hardware stack in the last time;
[0015] The third determining unit is used to determine resource adjustment information for at least one hardware stack based on the historical resource allocation information.
[0016] An adjustment unit is configured to adjust the historical resource allocation information based on the resource adjustment information to obtain target resource allocation information for at least one hardware stack; wherein, the target resource allocation information includes: memory-mapped input / output resources that need to be allocated to at least one hardware stack in the system;
[0017] The allocation unit is used to allocate memory-mapped input / output resources to at least one hardware stack according to the target resource allocation information.
[0018] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the allocation method of any of the above-described system memory-mapped input / output resources when executing the computer program.
[0019] This application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of any of the above-described system memory-mapped input / output resource allocation methods.
[0020] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described system memory-mapped input / output resource allocation methods.
[0021] This application achieves the following: When the system starts, it acquires hardware configuration information and determines whether it is the first startup. If the system is not starting for the first time, it determines the historical resource allocation information from the previous startup and, in conjunction with the hardware configuration information, determines the resource adjustment information for each hardware stack. Based on this adjustment information, the historical resource allocation information is adjusted to obtain the target resource allocation information for each hardware stack, and then resources are allocated to the hardware stacks according to the target resource allocation information. By determining whether the system is starting for the first time and executing different allocation strategies based on different startup information, this application reduces the difficulty of system maintenance and allows for rapid identification of problematic areas during subsequent iterations or troubleshooting. Furthermore, when the system is not starting for the first time, it directly reuses historical resource allocation information, making only partial adjustments to historical data based on resource adjustment information, rather than recalculating from scratch. This eliminates the need for repeated hardware scanning and full calculation of allocation schemes, significantly shortening startup time. Therefore, this application, through different allocation strategies, dynamically adjusts the allocation of MMIO resources, solving the resource waste problem of traditional fixed allocation and improving system startup efficiency and scalability. Attached Figure Description
[0022] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 One of the flowcharts for a method of allocating system memory-mapped input / output resources provided in this application embodiment;
[0024] Figure 2 A second schematic flowchart illustrating a method for allocating system memory-mapped input / output resources, provided in an embodiment of this application;
[0025] Figure 3 A third flowchart illustrating a method for allocating system memory-mapped input / output resources provided in this application embodiment;
[0026] Figure 4 This is a schematic diagram of a system memory-mapped input / output resource allocation device provided in an embodiment of this application. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0028] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0029] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0030] This application provides a method for allocating system memory-mapped input / output resources. The method is described in detail below, along with its execution flow. Figure 1 The diagram shown illustrates the flowchart of the system memory-mapped input / output resource allocation method provided in this application. The specific steps include the following:
[0031] S101. Determine the system startup information when the system starts up.
[0032] The startup information indicates whether the system is starting for the first time or not.
[0033] When the system starts, it is determined whether the system is starting for the first time. If the system is not starting for the first time, S102 is executed.
[0034] For example, the boot type is determined by checking whether a "first boot flag (e.g., FirstBootFlag)" or "historical MMIO resource allocation variables" exist in the non-volatile random-access memory (NVRAM). If there is no flag, no variable, or the variable is empty in the NVRAM, the system is considered to be booting for the first time; if complete historical variables exist, it is considered to be booting for the second time.
[0035] It should be noted that NVRAM is a type of memory that retains data even when power is off, and it is often used to store critical system configurations. The "first-time boot flag" is a status flag used when writing to NVRAM.
[0036] This application embodiment determines whether the system is being started for the first time, providing a differentiated decision-making basis for subsequent resource allocation. This avoids the drawbacks of traditional indiscriminate full processing from the root and solves the problem of low efficiency in traditional allocation schemes.
[0037] S102. When the system is not starting for the first time, determine the system's historical resource allocation information.
[0038] The historical resource allocation information includes: the memory-mapped input / output resources that the system last allocated to the hardware stack.
[0039] Specifically, the above S102 can be further refined into the following steps 1021 and 1022:
[0040] Step 1021: When the system is not starting for the first time, obtain historical configuration parameters.
[0041] Specifically, historical configuration parameters may include at least: MMIO resource allocation variables, the base address and limit of each hardware stack, and the total MMIO space occupied by all hardware stacks on all CPUs. For example, historical configuration parameters can be obtained from information stored in NVRAM. This is merely an example and does not limit the specific method for obtaining historical configuration parameters.
[0042] Step 1022: Integrate historical configuration parameters to determine historical resource allocation information.
[0043] After obtaining the historical configuration parameters in step S1021 above, all historical configuration parameters are integrated to determine the historical resource allocation information.
[0044] This application embodiment solves the problems of repetitive calculation, configuration fluctuations, and large resource overhead in traditional methods by directly obtaining historical configuration parameters, without rescanning all hardware and calculating the allocation scheme from scratch.
[0045] S103. Based on historical resource allocation information, determine resource adjustment information for at least one hardware stack.
[0046] Specifically, the above S103 can be further refined into the following steps 1031 to 1036:
[0047] Step 1031: Based on historical resource allocation information, determine the preliminary resource allocation information of the hardware stack.
[0048] Specifically, the target base address of the hardware stack is calculated based on historical resource allocation information. This historical resource allocation information includes the base addresses of each hardware stack and the total occupied space (TotalOccupiedSize) allocated in the last time. The system adjusts the target base address based on this data.
[0049] For example, if the total historical memory usage is 500M, a new target base address can be calculated based on the new memory mapping rules (e.g., base address offset) during this startup (e.g., adjusted from the original 0x10000000 to 0x12000000) to ensure that the address range is compatible with the current system memory layout.
[0050] After calculating the target base address, the upper limit address is determined based on the target base address and the resource requirements of each hardware stack. The upper limit address is the end address of the allocatable resources, also known as the resource range limit. The upper limit address must not exceed the total range of allocatable resources in the system.
[0051] For example, suppose the target base address of a certain hardware stack is 0x12000000, and its historical resource requirement is 100M (0x6400000), then the upper limit address is 0x12000000 + 0x6400000 = 0x18400000.
[0052] After determining the upper limit address, the initial resource allocation information of the hardware stack is determined based on the target base address and the upper limit address.
[0053] Specifically, the preliminary resource allocation information is a "transfer adjustment" of the historical resource allocation information, that is, keeping the resource usage of each hardware stack unchanged, and only updating the address range according to the new target base address and upper limit address.
[0054] For example, if the address range of a certain hardware stack in the past was 0x10000000-0x10640000 (64M), and the target base address is adjusted to 0x12000000, then the initial allocation information is updated to 0x12000000-0x12640000, and the resource size remains 64M.
[0055] Step 1032: Perform an incremental comparison between the historical resource allocation information and the preliminary resource allocation information to determine at least one hardware stack that differs from the allocation information between the two.
[0056] Specifically, the historical resource allocation information is incrementally compared with the preliminary resource allocation information. The incremental comparison only compares the changed parts, thereby identifying at least one hardware stack with different allocation information between the two.
[0057] For example, a hardware stack that was previously allocated 64M of resources may now require 128M due to the addition of a new device. This difference in allocation will cause the stack to be marked as a differential hardware stack.
[0058] By identifying the differences in the hardware stack, and triggering reallocation only for the differences, rather than covering the entire stack, the computational overhead of the system is significantly reduced.
[0059] Step 1033: Determine the actual resource requirements of the different hardware stacks.
[0060] Specifically, the system can accurately calculate the actual resource requirements of each hardware stack by cyclically scanning all CPUs' external hardware stacks and their attached PCIe devices.
[0061] Step 1034: Perform difference processing on the allocated resources corresponding to the differential hardware stacks in the preliminary resource allocation information and the actual required resources to determine the resource difference of the differential hardware stacks.
[0062] Specifically, the actual required resources are subtracted from the allocated resources in the preliminary resource allocation information to accurately calculate the difference between the actual required resources and the allocated resources in the preliminary resource allocation information for each hardware stack, thus obtaining the resource difference.
[0063] For example, suppose the actual resource requirement is 200M, and the initial resource allocation information allocates 150M. Then the resource difference is 200M - 150M = 50M.
[0064] Step 1035: Determine the allocation type of the differential hardware stack based on the resource difference.
[0065] Specifically, when the resource difference is less than a preset difference, the corresponding differential hardware stack is determined to be the first allocation type; when the resource difference is greater than or equal to the preset difference, the corresponding differential hardware stack is determined to be the second allocation type. The allocation type can include at least the first allocation type and the second allocation type. The first allocation type indicates that the differential hardware stack lacks memory-mapped input / output resources, that is, the differential hardware stack with insufficient resources. The second allocation type indicates that the differential hardware stack has idle resources, that is, the differential hardware stack with redundant resources.
[0066] For example, when the calculated resource difference is negative, it indicates that the resources currently allocated to the differential hardware stack are insufficient, and the differential hardware stack is marked as the first allocation type; when the calculated resource difference is positive, it indicates that the resources currently allocated to the differential hardware stack are redundant, and the differential hardware stack is marked as the second allocation type.
[0067] Step 1036: Determine resource adjustment information based on the allocation type and idle resources of the different hardware stacks.
[0068] Specifically, after determining the allocation type of the differential hardware stack, the idle resources of the second allocation type differential hardware stack are dynamically allocated to the first allocation type differential hardware stack according to the hardware stack type, giving priority to meeting the needs of the high-demand differential hardware stack (for example, if one hardware stack is short of 64M and another hardware stack is short of 32M, then the former is given priority), that is, determining the resource adjustment information.
[0069] After determining the resource adjustment information, in order to ensure data consistency, the base address and upper limit address of the different hardware stacks are stored.
[0070] This application embodiment accurately identifies the hardware stacks that have changed by incrementally comparing historical and preliminary resource allocation information. Furthermore, it analyzes the difference between the resource requirements and the allocated amount to dynamically distinguish whether the hardware stack is in a state of resource shortage or resource idleness. This enables the intelligent generation of targeted resource adjustment strategies, effectively improving the accuracy and utilization efficiency of system resource allocation, avoiding blind adjustments, and storing the adjustment content corresponding to the adjustment strategy in a timely manner to ensure data consistency.
[0071] S104. Based on the resource adjustment information, adjust the historical resource allocation information to obtain the target resource allocation information for at least one hardware stack.
[0072] The target resource allocation information includes: memory-mapped input / output resources that need to be allocated to at least one hardware stack in the system.
[0073] Specifically, based on the resource adjustment information determined in S103 above, the historical allocation of each hardware stack is adjusted, and the target resource allocation information corresponding to each hardware stack is determined, so as to achieve the purpose of utilizing idle resources and avoiding resource redundancy and waste.
[0074] S105. Perform memory-mapped input / output resource allocation on at least one hardware stack according to the target resource allocation information.
[0075] Specifically, to ensure that resource allocation is implemented effectively, memory-mapped input / output resources are allocated to at least one hardware stack according to the target resource allocation information.
[0076] This application achieves the following: When the system starts, it acquires hardware configuration information and determines whether it is the first startup. If the system is not starting for the first time, it determines the system's previous historical resource allocation information and, in conjunction with the hardware configuration information, determines the resource adjustment information for each hardware stack. Based on this adjustment information, the historical resource allocation information is adjusted to obtain the target resource allocation information for each hardware stack, and then resources are allocated to the hardware stacks according to the target allocation information. By determining whether the system is starting for the first time and executing different allocation strategies based on different startup information, this application reduces the difficulty of system maintenance and allows for rapid identification of problematic areas during subsequent iterations or troubleshooting. Furthermore, when the system is not starting for the first time, it directly reuses historical resource allocation information, making only partial adjustments to historical data using resource adjustment information, rather than recalculating from scratch. This eliminates the need for repeated hardware scanning and full calculation of allocation schemes, significantly shortening startup time. Therefore, this application solves the resource waste problem of traditional fixed allocation by dynamically adjusting the allocation of MMIO resources through different allocation strategies, while also improving system startup efficiency and scalability.
[0077] As an extension and refinement of the above embodiments, refer to Figure 2 As shown, this application also provides a method for allocating system memory-mapped input / output resources, the specific steps of which include the following:
[0078] S201. When the system is booting for the first time, obtain the base address and hardware configuration information.
[0079] The base address is the system's default starting address for allocating memory-mapped input / output resources. The hardware configuration information includes information related to the allocation of memory-mapped input / output resources for at least one hardware stack in the system (e.g., the total number of CPUs and the types of each stack).
[0080] When the system is booting for the first time, the system's basic resources are initialized, and the base address and hardware configuration information are obtained.
[0081] For example, it reads the system's default ≤4GB MMIO base address configuration; it counts the total number of CPUs, hardware stack types (e.g., internal accelerator stack, peripheral component interconnect express input / output stack (PCIe I / O stack), out-of-band modem system manager stack (OOBMSM stack)) and the status of each stack (e.g., number and type of mounted devices). It should be noted that this is only an example and does not limit the specific content of obtaining base address and hardware configuration information.
[0082] This application embodiment improves the accuracy of resource allocation by obtaining the base address and hardware configuration information to ensure that subsequent allocation matches the actual hardware environment.
[0083] S202. Determine the system's allocable resources and fixed configuration information.
[0084] The allocable resources are the total memory-mapped input / output resources available to the system, also known as the total MMIO available space (TotalMMIOSize). Fixed configuration information can be the allocation of a fixed MMIO space for a specific hardware stack according to the CPU manufacturer's specifications (for example, the manufacturer specifies that a certain accelerator stack must occupy a fixed 100M space).
[0085] S203. Based on the base address and fixed configuration information, determine the fixed resource requirements corresponding to at least one hardware stack.
[0086] Specifically, the system allocates fixed required resources to the special hardware stack specified by the manufacturer based on the base address and fixed configuration information, that is, a fixed MMIO space or a fixed address range.
[0087] For example, assuming the base address is 0x10000000, the fixed configuration information of the internal accelerator hardware stack is that 0x1000000 (16M) space needs to be allocated starting from the base address; then the fixed resource requirement of the internal accelerator hardware stack is 0x10000000-0x10FFFFFF.
[0088] S204. Perform a difference calculation between the allocable resources and the fixed demand resources to obtain the remaining allocable resources.
[0089] Specifically, once the fixed-requirement resources corresponding to the special hardware stacks specified by all manufacturers have been allocated, the difference between the allocable resources and the fixed-requirement resources is processed to obtain the remaining allocated resources.
[0090] For example, if the allocable resources are 1GB (0x40000000) and the total fixed resource requirement is 200M, then the remaining allocable resources are 1GB-200M=824M.
[0091] S205. Determine the actual required resources corresponding to the remaining hardware stack in the hardware configuration information.
[0092] The remaining hardware stack includes: hardware stacks with undetermined fixed resource requirements, also known as PCIe stack.
[0093] Specifically, the actual resource requirements corresponding to the remaining hardware stacks for resource allocation are determined from the hardware configuration information, thereby enabling resource allocation on demand.
[0094] For example, suppose the remaining hardware stack A has 3 hard drives connected, and the remaining hardware stack B has only 1 network card connected; then the remaining hardware stack A with 3 hard drives may need 500M, while the remaining hardware stack B with 1 network card may only need 100M. That is, the actual resource requirement of the remaining hardware stack A is 500M, and the actual resource requirement of the remaining hardware stack B is 100M.
[0095] S206. Based on actual resource requirements, determine the target resource allocation information corresponding to the remaining hardware stack from the remaining allocated resources, and allocate memory-mapped input / output resources to at least one hardware stack according to the target resource allocation information.
[0096] Based on the actual resource requirements determined in S205 above, the resources allocated to the remaining hardware stack are determined from the remaining allocated resources, that is, the target resource allocation information.
[0097] This application's embodiments, by prioritizing the fulfillment of the manufacturer's specified fixed resource requirements for the hardware stack, allocate remaining resource space to the remaining hardware stack according to demand. This solves the problem of resource waste caused by traditional average allocation, while avoiding the failure of core hardware to function properly due to insufficient resource allocation or address conflicts.
[0098] As an extension and refinement of the above embodiments, refer to Figure 3 As shown, this application also provides another method for allocating system memory-mapped input / output resources, the specific steps of which include the following:
[0099] S301. After the hardware stack allocates memory-mapped input / output resources, the memory-mapped input / output resources currently allocated by the hardware stack are compared with the actual required resources.
[0100] Specifically, the fine-grained resource allocation completion judgment involves real-time verification after allocation for each hardware stack, comparing the memory-mapped input / output resources currently allocated to the hardware stack with the actual required resources to identify redundant resources.
[0101] S302. When the memory-mapped input / output resources allocated by the current hardware stack are greater than the actual required resources, adjust and store the base address and upper limit address of the next hardware stack.
[0102] When the memory-mapped input / output resources allocated to the current hardware stack are greater than the actual required resources, it indicates that the hardware stack has redundant or idle resources. Based on this, the base address and upper limit address of the next hardware stack are automatically adjusted, and the adjusted addresses are stored to avoid the resource redundancy of the previous stack causing the address of the subsequent stack to be shifted, thereby reducing the waste of total MMIO space and improving the overall utilization rate.
[0103] S303. When the system has no resources to allocate, end the resource allocation and determine the resource allocation status of the hardware stack.
[0104] Specifically, if after allocating resources to a certain hardware stack, it is found that the allocable resources have been exhausted, the system will not continue to adjust parameters, but will directly enter the allocation completion judgment to determine the resource allocation status of the hardware stack and check whether all hardware stacks that need to be allocated resources have obtained enough resources.
[0105] S304. Determine if there are any unallocated resources in the hardware stack.
[0106] If there are unallocated resources in the hardware stack, execute S305; if there are no unallocated resources in the hardware stack, execute S308.
[0107] S305. The system recalculates the actual resource requirements of the hardware stack and re-optimizes the target resource allocation information.
[0108] When there are unallocated hardware stacks (e.g., a newly added hardware stack has not obtained enough space), the system does not restart directly. Instead, it rescans the actual needs of these hardware stacks (e.g., changes in device type or quantity), adjusts the allocation strategy based on the current remaining resource situation (e.g., other hardware stacks may have previously released idle resources), and repeatedly attempts to allocate resources to optimize the target resource allocation information. This continues until all hardware stacks are allocated resources, at which point S308 is executed. If, after repeatedly adjusting the target resource allocation information, there are still hardware stacks without allocated memory-mapped input / output resources, S306 is executed.
[0109] This application embodiment avoids invalid resource scheduling loops by introducing a fast termination mechanism for resource allocation failures. By triggering real-time demand recalculation of unallocated resource hardware stacks and re-optimization of global resource allocation strategies, it achieves graceful degradation and dynamic adaptation of the system in scenarios with extremely scarce resources, thereby ensuring the continuity of key functions and improving the overall resource utilization efficiency and robustness of the system.
[0110] S306. Store the current target resource allocation information and restart the system.
[0111] If, after the system has repeatedly adjusted the target resource allocation information, there are still unallocated memory-mapped input / output resources on the hardware stack, the exception handling mechanism is triggered to store the current target resource allocation information and restart the system.
[0112] S307. When the system restarts, it will prioritize reallocating target resources according to the previously stored target resource allocation information.
[0113] Specifically, when the system restarts, it first reuses the information stored last time (e.g., the allocated address range), and only retryes the unallocated portion.
[0114] In this embodiment, the system stores the current target resource allocation information and restarts to avoid the complete loss of allocation results and improve the recovery success rate.
[0115] S308. Keep the system in the startup state.
[0116] Once all hardware resources are available, the system can continue with subsequent startup steps without any additional operations, avoiding unnecessary interruptions.
[0117] In related technologies, the default MMIO base address and CPU and hardware stack resources are first initialized, and a fixed MMIO space is allocated to a specific hardware stack according to the manufacturer's rules. Then, the total available MMIO space is calculated, and after deducting the fixed resources, the remaining space is evenly distributed to the PCIe hardware stack. Next, the MMIO configuration variables in NVRAM are read and compared with the currently pre-allocated resources. If they match, the process jumps to the BDS stage. If they do not match, a reallocation is attempted, but there is no dynamic optimization. Then, the PCIe devices are scanned cyclically to record their requirements. If the requirements are met, the resources are allocated. If not, the stack is marked and an attempt is made to compress fixed resources from other stacks to release space. Finally, the adjusted resources are written to NVRAM. If the allocation is incomplete or an OOR is triggered, a forced restart can only be performed.
[0118] As can be seen from the above, the remaining MMIO space in the relevant technologies is evenly distributed to the PCIe hardware stack without taking into account the differences in actual device needs, which easily leads to uneven distribution and low efficiency in recycling compressed fixed resources. Secondly, there is a lack of dynamic optimization mechanism when NVRAM variable comparisons do not match, which easily leads to resource conflicts. Furthermore, the lack of version control or difference recording mechanism may result in configuration chaos. At the same time, when the allocation is incomplete or an exception handling mechanism is triggered, it cannot be dynamically repaired and can only be forcibly restarted, affecting system stability and efficiency.
[0119] However, this application dynamically allocates resources according to the actual needs of each hardware stack, improving resource utilization. Secondly, by reading historical configuration parameters in NVRAM and incrementally comparing them with the initial allocation information, it identifies the differing hardware stacks and allocates redundant resources to the hardware stacks that need them, avoiding conflicts caused by full reallocation and improving dynamic adaptation capabilities. At the same time, when writing to NVRAM, it only records the differences from historical data, rather than overwriting the entire data. It also retains historical allocation records, reducing NVRAM storage overhead and avoiding full data conflicts. By tracing the differences, it ensures that the configuration is clear and traceable, preventing confusion. Finally, this application forces a restart but carries the historical allocation data stored in NVRAM. After restarting, it prioritizes reusing valid configurations based on historical experience and only retryes the unallocated parts, significantly improving the recovery success rate and reducing invalid interruptions.
[0120] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0121] Embodiments of this application also provide a system memory-mapped input / output resource allocation device, which corresponds one-to-one with the method claims. Figure 4 This is a schematic diagram of the structure of a system memory-mapped input / output resource allocation device 400 provided in this disclosure, as shown below. Figure 4 As shown, the device 400 of this embodiment includes:
[0122] The first determining unit 41 is used to determine the system startup information when the system starts up; wherein, the startup information is whether the system is starting for the first time or not starting for the first time;
[0123] The second determining unit 42 is used to determine the historical resource allocation information of the system when the system is not starting for the first time; wherein, the historical resource allocation information includes: the memory-mapped input / output resource information allocated by the system to the hardware stack in the last time;
[0124] The third determining unit 43 is used to determine resource adjustment information for at least one hardware stack based on historical resource allocation information.
[0125] The adjustment unit 44 is used to adjust the historical resource allocation information based on the resource adjustment information to obtain the target resource allocation information of at least one hardware stack; wherein, the target resource allocation information includes: the memory-mapped input / output resources that need to be allocated to at least one hardware stack in the system;
[0126] Allocation unit 45 is used to allocate memory-mapped input / output resources to at least one hardware stack according to target resource allocation information.
[0127] As an optional implementation of this application, the third determining unit 43 is specifically configured to: determine preliminary resource allocation information of the hardware stack based on the historical resource allocation information; perform incremental comparison between the historical resource allocation information and the preliminary resource allocation information to determine at least one differential hardware stack with different allocation information; determine the actual resource requirement of the differential hardware stack; perform difference processing between the allocated resources corresponding to the differential hardware stack in the preliminary resource allocation information and the actual resource requirement to determine the resource difference of the differential hardware stack; determine the allocation type of the differential hardware stack based on the resource difference; determine the resource adjustment information based on the allocation type and idle resources of the differential hardware stack; and store the base address and upper limit address of the differential hardware stack.
[0128] As an optional implementation of this application, the third determining unit 43 is further configured to calculate the target base address of the hardware stack based on the historical resource allocation information; determine the upper limit address of the hardware stack based on the target base address; wherein the upper limit address is the end address of the allocatable resources; and determine the preliminary resource allocation information of the hardware stack based on the target base address and the upper limit address.
[0129] As an optional implementation of this application, the third determining unit 43 is further configured to determine the allocation type of the corresponding differential hardware stack as a first allocation type when the resource difference is less than a preset difference; wherein the first allocation type indicates that the differential hardware stack lacks memory-mapped input / output resources; and to determine the allocation type of the corresponding differential hardware stack as a second allocation type when the resource difference is greater than or equal to the preset difference; wherein the second allocation type indicates that the differential hardware stack has idle resources.
[0130] As an optional implementation of this application embodiment, the system memory-mapped input / output resource allocation device 400 further includes:
[0131] The storage unit is used to store the base address and upper limit address of the differential hardware stack.
[0132] As an optional implementation of this application, the third determining unit 43 is specifically used to obtain historical configuration parameters when the system is not starting for the first time; integrate the historical configuration parameters to determine historical resource allocation information.
[0133] As an optional implementation of this application embodiment, the system memory-mapped input / output resource allocation device 400 further includes:
[0134] The acquisition unit is used to acquire the base address and hardware configuration information when the system is booting for the first time. The base address is the default starting address for allocating memory-mapped input / output resources. The hardware configuration information includes information related to the allocation of memory-mapped input / output resources for at least one hardware stack in the system.
[0135] The fourth determining unit is used to determine target resource allocation information based on the base address and hardware configuration information, and to perform memory-mapped input / output resource allocation on at least one hardware stack according to the target resource allocation information.
[0136] As an optional implementation of this application, the hardware configuration information includes at least fixed configuration information, which includes memory-mapped input / output resources that at least one hardware stack of the system needs to be allocated. The fourth determining unit is further configured to determine the allocatable resources and fixed configuration information of the system; wherein, the allocatable resources are the total memory-mapped input / output resources available in the system; based on the base address and fixed configuration information, determine the fixed demand resources corresponding to at least one hardware stack; perform difference processing on the allocatable resources and the fixed demand resources to obtain the remaining allocated resources; determine the actual demand resources corresponding to the remaining hardware stacks in the hardware configuration information; wherein, the remaining hardware stacks include: hardware stacks whose fixed demand resources have not been determined; and determine the target resource allocation information corresponding to the remaining hardware stacks from the remaining allocated resources according to the actual demand resources.
[0137] As an optional implementation of this application embodiment, the system memory-mapped input / output resource allocation device 400 further includes:
[0138] The comparison unit is used to compare the memory-mapped input / output resources currently allocated by the hardware stack with the actual required resources after the hardware stack allocates memory-mapped input / output resources.
[0139] The first adjustment unit is used to adjust and store the base address and upper limit address of the next hardware stack when the memory-mapped input / output resources allocated by the current hardware stack are greater than the actual required resources.
[0140] As an optional implementation of this application, after adjusting and storing the base address and upper limit address of the next hardware stack, the system memory-mapped input / output resource allocation device 400 further includes:
[0141] The termination unit is used to terminate resource allocation and determine the resource allocation status of the hardware stack when the system has no resources available for allocation.
[0142] The optimization unit is used to recalculate the actual resource requirements of the hardware stack and re-optimize the target resource allocation information when there are unallocated resources in the hardware stack.
[0143] A holding unit is used to keep the system in the startup state when there are no unallocated resources in the hardware stack.
[0144] As an optional implementation of this application embodiment, the system memory-mapped input / output resource allocation device 400 further includes:
[0145] The restart unit is used to store the current target resource allocation information and restart the system when there are still unallocated memory-mapped input / output resources in the hardware stack after the system has repeatedly adjusted the target resource allocation information.
[0146] The first allocation unit is used to reallocate resources according to the previously stored target resource allocation information when the system restarts.
[0147] For a description of the features in the embodiment corresponding to the system memory-mapped input / output resource allocation device, please refer to the relevant description in the embodiment corresponding to the system memory-mapped input / output resource allocation method, which will not be repeated here.
[0148] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above embodiments of the system memory-mapped input / output resource allocation method.
[0149] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above embodiments of the system memory-mapped input / output resource allocation method when running.
[0150] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0151] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above embodiments of the system memory-mapped input / output resource allocation method.
[0152] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above embodiments of the system memory-mapped input / output resource allocation method.
[0153] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0154] The foregoing has provided a detailed description of a method and apparatus for allocating system memory-mapped input / output resources. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A method for allocating system memory-mapped input / output resources, characterized in that, include: When the system starts up, the system startup information is determined; wherein, the startup information indicates whether the system is starting for the first time or not. When the system is not starting for the first time, the historical resource allocation information of the system is determined; wherein, the historical resource allocation information includes: the memory-mapped input / output resource information that the system previously allocated to the hardware stack; Based on the historical resource allocation information, resource adjustment information for at least one hardware stack is determined; Based on the resource adjustment information, the historical resource allocation information is adjusted to obtain target resource allocation information for at least one hardware stack; wherein, the target resource allocation information includes: memory-mapped input / output resources that need to be allocated to at least one hardware stack in the system; Memory-mapped input / output resources are allocated to at least one hardware stack according to the target resource allocation information; The step of determining resource adjustment information for at least one hardware stack based on the historical resource allocation information includes: determining preliminary resource allocation information for the hardware stack based on the historical resource allocation information; incrementally comparing the historical resource allocation information with the preliminary resource allocation information to determine at least one differing hardware stack with different allocation information; determining the actual resource requirement of the differing hardware stack; performing difference processing between the allocated resources corresponding to the differing hardware stack in the preliminary resource allocation information and the actual resource requirement to determine the resource difference of the differing hardware stack; determining the allocation type of the differing hardware stack based on the resource difference; determining the resource adjustment information based on the allocation type and idle resources of the differing hardware stack; and storing the base address and upper limit address of the differing hardware stack.
2. The method according to claim 1, characterized in that, The step of determining preliminary resource allocation information for the hardware stack based on the historical resource allocation information includes: Based on the historical resource allocation information, calculate the target base address of the hardware stack; Based on the target base address, the upper limit address of the hardware stack is determined; wherein, the upper limit address is the end address of the allocatable resources; Based on the target base address and the upper limit address, the preliminary resource allocation information of the hardware stack is determined.
3. The method according to claim 1, characterized in that, The step of determining the allocation type of the differential hardware stack based on the resource difference includes: When the resource difference is less than a preset difference, the allocation type of the corresponding differential hardware stack is determined to be the first allocation type; wherein, the first allocation type indicates that the differential hardware stack lacks memory-mapped input / output resources; When the resource difference is greater than or equal to the preset difference, the allocation type of the corresponding differential hardware stack is determined to be the second allocation type; wherein, the second allocation type indicates that the differential hardware stack has idle resources.
4. The method according to claim 1, characterized in that, When the system is not starting for the first time, the historical resource allocation information of the system is determined, including: When the system is not starting for the first time, retrieve historical configuration parameters; The historical configuration parameters are integrated to determine the historical resource allocation information.
5. The method according to claim 1, characterized in that, The method further includes: When the system is booting for the first time, it obtains the base address and hardware configuration information; wherein, the base address is the default starting address for allocating memory-mapped input / output resources in the system, and the hardware configuration information includes: information related to the allocation of memory-mapped input / output resources for at least one hardware stack in the system; Based on the base address and the hardware configuration information, target resource allocation information is determined, and memory-mapped input / output resources are allocated to at least one hardware stack according to the target resource allocation information.
6. The method according to claim 5, characterized in that, The hardware configuration information includes at least fixed configuration information, which includes memory-mapped input / output resources that the system's at least one hardware stack needs to be allocated. The determination of target resource allocation information based on the base address and the hardware configuration information includes: Determine the allocatable resources of the system and the fixed configuration information; wherein, the allocatable resources are the total memory-mapped input / output resources available to the system; Based on the base address and the fixed configuration information, determine the fixed resource requirements corresponding to at least one hardware stack. The remaining allocated resources are obtained by performing a difference calculation between the allocable resources and the fixed demand resources. Determine the actual required resources corresponding to the remaining hardware stack in the hardware configuration information; wherein, the remaining hardware stack includes: hardware stacks for which the fixed required resources have not been determined; Based on the actual resource requirements, the target resource allocation information corresponding to the remaining hardware stack is determined from the remaining allocated resources.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: After the hardware stack allocates memory-mapped input / output resources, the memory-mapped input / output resources currently allocated by the hardware stack are compared with the actual required resources; When the memory-mapped input / output resources allocated by the current hardware stack are greater than the actual required resources, the base address and upper limit address of the next hardware stack are adjusted and stored.
8. The method according to claim 7, characterized in that, After adjusting and storing the base address and upper limit address of the next hardware stack, the method further includes: When the system has no resources available for allocation, resource allocation ends, and the resource allocation status of the hardware stack is determined. When there are unallocated resources in the hardware stack, the system recalculates the actual resource requirements of the hardware stack and re-optimizes the target resource allocation information; When there are no unallocated resources in the hardware stack, the system remains in the startup state.
9. The method according to claim 8, characterized in that, The method further includes: If, after the system has repeatedly adjusted the target resource allocation information, there are still hardware stacks without allocated memory-mapped input / output resources, the current target resource allocation information is stored and the system is restarted. When the system restarts, the target resource allocation information stored previously will be used for reallocation.
Citation Information
Patent Citations
System and method thereof for dynamically distributing MMIO resources
CN106648878A
Coroutine stack resource configuration method and device, equipment and storage medium
CN114721829A