Memory resource allocation method and computer device for embedded system

By classifying and dynamically allocating the software modules of embedded systems, the problem of limited memory resources in embedded systems is solved, and efficient memory management and performance improvement is achieved.

CN119781955APending Publication Date: 2025-04-08CHINA GRIDCOM
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411720053.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

In embedded systems, due to the contradiction between hardware limitations and software requirements, it is difficult to load and run multiple software modules at the same time with limited memory space, resulting in poor memory usage efficiency.

Method used

By classifying the software modules of the embedded system, determining the target software module collection and target operation domain, establishing a target loading management table, and dynamically allocating memory resources to ensure that the software modules are loaded into memory only when needed.

Benefits of technology

Effectively utilize limited memory resources, improve the performance and efficiency of embedded systems, reduce the need for manual memory management, and improve execution efficiency and response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781955A_ABST
    Figure CN119781955A_ABST
Patent Text Reader

Abstract

The present application discloses a memory resource allocation method for an embedded system, a computer device, and a computer-readable storage medium. The method comprises: determining a target software module set according to the classification result of the software modules of the embedded system. Determining a target operation domain according to the target software module set. Determining a target loading management table according to the target software module set and the target operation domain. According to the target loading management table, memory resources are allocated to the target software module set to implement memory resource allocation for the embedded system. In this way, by classifying software modules that do not need to be resident in memory at the same time when the program is running, different software modules of the same class use the same operation domain, namely, the target operation domain, thereby effectively utilizing limited memory resources and ensuring that the software modules are loaded into the target operation domain only when needed, thereby improving the performance and efficiency of the embedded system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of electronic engineering technology, and more specifically, to a memory resource allocation method for an embedded system, a computer device, and a computer-readable storage medium. Background Art

[0002] In embedded systems, there is a contradiction between hardware limitations and software requirements. As software functions increase and program size increases, limited memory space may make it difficult to load and run multiple software modules at the same time. This makes the memory usage efficiency of embedded systems poor. Summary of the invention

[0003] The present application provides a memory resource allocation method for an embedded system, a computer device, and a computer-readable storage medium.

[0004] The present application provides a method for allocating memory resources for an embedded system, the method comprising:

[0005] Determining a target software module set according to the classification results of the software modules of the embedded system;

[0006] Determining a target operating domain according to the target software module set;

[0007] Determining a target loading management table according to the target software module set and the target operating domain;

[0008] Memory resources are allocated to the target software module set according to the target loading management table to implement memory resource allocation to the embedded system.

[0009] In this way, the computer device determines the target software module set according to the classification result of the software modules of the embedded system. Then, the computer device determines the target operation domain according to the target software module set. Then, the computer device determines the target loading management table according to the target software module set and the target operation domain. Finally, the computer device allocates memory resources to the target software module set according to the target loading management table to realize the memory resource allocation of the embedded system. In this way, by classifying the software modules that do not need to be resident in the memory at the same time when the program is running, different software modules of the same class use the same operation domain, that is, the target operation domain, so as to effectively utilize the limited memory resources, ensure that the software modules are loaded into the target operation domain only when needed, thereby improving the performance and efficiency of the embedded system. In addition, the target loading management table is determined, through which the computer device can efficiently manage multiple software modules in limited memory resources, automatically optimize memory usage, reduce the need for manual memory management, and improve the execution efficiency and response speed of the embedded system.

[0010] In certain embodiments, the method further comprises:

[0011] The classification result is determined according to the execution sequence of the software modules.

[0012] In this way, the computer device determines the classification result according to the execution timing of the software modules. In this way, according to the execution timing of the software modules, the computer device classifies those software modules that do not need to run at the same time into one category and obtains the classification result, so that the software modules in the embedded system can be effectively organized and managed, so as to utilize limited memory resources and improve the performance and power consumption of the embedded system.

[0013] In some implementations, determining a target software module set according to the classification results of the software modules of the embedded system includes:

[0014] The target software module set is determined according to the preloaded file and the classification result.

[0015] In this way, the computer device determines the target software module set based on the preloaded files and the classification results. In this way, the memory usage and program execution efficiency of the resource-constrained embedded system can be optimized, and the software modules are loaded into the memory only when needed, thereby reducing the memory usage and improving the response speed and efficiency of the system.

[0016] In certain embodiments, the method further comprises:

[0017] Determining a maximum value of memory space according to the target software module set;

[0018] According to the maximum value of the memory space, a storage domain memory value of the target execution domain is determined.

[0019] In this way, the computer device determines the maximum value of the memory space according to the target software module set. Then, the computer device determines the storage domain memory value of the target operation domain according to the maximum value of the memory space. In this way, the computer device ensures that sufficient memory is allocated to each software module set, the embedded system can avoid the problem of insufficient memory, improve the stability and performance of the embedded system, and thus effectively manage memory resources.

[0020] In some implementations, determining a target loading management table according to the target software module set and the target operating domain includes:

[0021] The target loading management table is determined according to the module loading information of the software modules in the target software module set, wherein the module loading information includes the loading address of the software module in the non-volatile storage medium, the memory size of the software module, the target virtual memory address of the software module and / or the target execution domain loading flag of the software module, and the target execution domain loading flag is used to indicate whether the software module is loaded into the target execution domain.

[0022] In this way, the computer device determines the target loading management table according to the module loading information of the software modules in the target software module set, wherein the module loading information includes the loading address of the software module in the non-volatile storage medium, the memory size of the software module, the target virtual memory address of the software module and / or the target operation domain loading flag of the software module, and the target operation domain loading flag is used to indicate whether the software module is loaded into the target operation domain. In this way, the target loading management table is obtained, through which the loading and unloading of the software module can be managed at runtime. When a software module needs to be executed, the system will determine the module loading information of the module according to this target loading management table. When the module is no longer needed, the system can uninstall it from the embedded system to free up memory space for other modules to use, thereby effectively optimizing memory usage and improving system performance and resource utilization.

[0023] In certain embodiments, the method further comprises:

[0024] In the process of initializing the embedded system, the allocation of the target virtual memory address is determined according to the target loading management table.

[0025] Thus, during the initialization process of the embedded system, the computer device determines the allocation of the target virtual memory address according to the target loading management table. In this way, the computer device can ensure that no memory conflict or cross-boundary access occurs when the embedded system loads software modules at runtime, thereby improving the stability and reliability of the embedded system.

[0026] In some implementations, allocating memory resources to the target software module set according to the target loading management table includes:

[0027] Compiling and linking the target software modules in the target software module set to obtain target module codes;

[0028] Allocating memory resources to the target software module according to the target loading management table;

[0029] The target module code is run according to the result of the memory resource allocation.

[0030] In this way, the computer device compiles and links the target software modules in the target software module set to obtain the target module code. Then, the computer device allocates memory resources to the target software module according to the target loading management table. Finally, the computer device runs the target module code according to the result of the memory resource allocation. In this way, by compiling and linking the target software module set, the target module code is obtained, the target module code occupies a small space and has a faster loading rate. In addition, the embedded system can efficiently manage memory resources to ensure that each software module can run on the correct memory address, thereby ensuring the stability and performance of the embedded system.

[0031] In some implementations, running the target module code according to the result of the memory resource allocation includes:

[0032] Identify the target module code and determine the target operation domain loading flag of the target module code;

[0033] When the target operation domain loading flag is the first loading flag, patch processing is performed on the first target interface corresponding to the target module code based on a preset compiler to determine a second target interface;

[0034] The target execution domain is called according to the second target interface to execute the target module code.

[0035] In this way, the computer device identifies the target module code and determines the target operation domain loading flag of the target module code. Then, when the target operation domain loading flag is the first loading flag, the computer device performs patch processing on the first target interface corresponding to the target module code based on the preset compiler to determine the second target interface. Finally, the target operation domain is called according to the target interface corresponding to the target module code to run the target module code. In this way, in a resource-constrained embedded system, by dynamically loading and unloading software modules when needed, the system can effectively utilize limited memory resources while reducing startup time and power consumption, thereby optimizing memory usage and improving system performance.

[0036] In some implementations, running the target module code according to the result of the memory resource allocation includes:

[0037] When the target operation domain loading flag is the second loading flag, determining the first target interface according to the target loading management table;

[0038] Based on a preset compiler, patch processing is performed on the first target interface to determine the second target interface;

[0039] Calling the target execution domain according to the second target interface to execute the target module code;

[0040] The target execution domain loading flag is updated to the first loading flag.

[0041] In this way, when the target operation domain loading flag is the second loading flag, the computer device determines the first target interface according to the target loading management table. Then, based on the preset compiler, the first target interface is patched to determine the second target interface. Next, the computer device calls the target operation domain according to the second target interface to run the target module code. Finally, the computer device updates the target operation domain loading flag to the first loading flag. In this way, in a resource-constrained embedded system, by dynamically loading and unloading software modules when needed, the system can effectively utilize limited memory resources while reducing startup time and power consumption, thereby optimizing memory usage and improving system performance.

[0042] In certain embodiments, the method further comprises:

[0043] In the case where there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code is cacheable, the target instruction cache corresponding to the target module code in the preset cache device is cleared to ensure the timeliness of the target instruction cache.

[0044] In this way, when there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code is a cacheable attribute, the computer device clears the target instruction cache corresponding to the target module code in the preset cache device to ensure the timeliness of the target instruction cache. In this way, in an embedded system that needs to process a large number of instructions or frequently execute the same instructions, the timeliness of the instruction cache can be ensured, ensuring that the system can always obtain the latest instructions to maintain high efficiency, thereby improving the performance and response speed of the embedded system.

[0045] An embodiment of the present application provides a computer device, which includes a memory, a processor, and a computer program stored in the memory, and is characterized in that the processor executes the computer program to implement the above method.

[0046] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium memory stores a computer program, and when the computer program is executed by one or more processors, the above method is implemented.

[0047] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0049] Figure 1 It is one of the flowcharts of the memory resource allocation method of certain implementation modes of the present application;

[0050] Figure 2 It is a schematic diagram of the compilation and linking process of the software code of certain implementation modes of the present application;

[0051] Figure 3 This is the second flow chart of the memory resource allocation method in some implementation modes of the present application;

[0052] Figure 4 This is the third flow chart of the memory resource allocation method of certain implementation modes of the present application;

[0053] Figure 5 It is a data flow diagram of an example of some embodiments of the present application;

[0054] Figure 6 This is a fourth flowchart of a memory resource allocation method in certain implementation modes of the present application;

[0055] Figure 7 This is a fifth flowchart of a memory resource allocation method in certain implementation modes of the present application;

[0056] Figure 8 This is the sixth flowchart of the memory resource allocation method of certain implementation modes of the present application;

[0057] Fig. 9 This is the seventh flowchart of the memory resource allocation method of certain implementation modes of the present application;

[0058] Fig.10 This is the eighth flowchart of the memory resource allocation method of certain implementation modes of the present application;

[0059] Fig.11 This is a ninth flowchart of a memory resource allocation method according to certain implementation modes of the present application;

[0060] Fig.12 This is the tenth flowchart of the memory resource allocation method of certain implementation modes of the present application. DETAILED DESCRIPTION

[0061] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as limiting the embodiments of the present application.

[0062] In embedded systems, there is a contradiction between hardware limitations and software requirements. The memory resources of embedded systems are usually very limited. As software functions are enhanced and the size of software programs increases, the limited memory space may be difficult to meet software requirements. For example, the random access memory (RAM) located inside the processor chip has a very fast access speed, usually within a few clock cycles. However, due to cost constraints, the capacity of RAM is relatively small and the cost is high. As a result, it is difficult for RAM to load and run multiple software modules at the same time, and it cannot meet user needs.

[0063] In the related art, virtual memory management technology and position-independent code (PIC) dynamic library technology are usually used to automatically load the executed program into RAM before running and enable fast execution.

[0064] Virtual memory management technology implements virtual memory management through MMU, which can effectively expand the available memory space and allow the system to run programs that are larger than the physical memory capacity. When a page fault exception occurs during program execution, the system will load the necessary program segments into RAM for execution, thereby improving memory usage efficiency. However, virtual memory management will increase the overhead of memory access because address translation is required through the MMU hardware unit. Without the MMU hardware unit, virtual memory management cannot be performed. In addition, frequent page fault exception handling may affect system performance.

[0065] Position-independent code dynamic library technology allows programs to run at any location in memory without specifying specific memory addresses during compilation. The PIC dynamic library is loaded into a certain address of RAM by the loader, and the symbol address is obtained through the global offset table (GOT) and the procedure link table (PLT) at runtime, which can achieve more efficient use of memory resources and improve the flexibility and portability of the system. However, PIC technology may increase the runtime overhead of the program because it is necessary to perform address resolution through GOT and PLT. In addition, the dynamic library that needs to be compiled is an executable and linkable format (ELF) file, and the ELF file is large in size, occupies too much non-volatile storage media, and may also require a file system to save the file, and a complex resident loader program is required to parse and load the ELF library file. The symbol address needs to be located in a table during runtime, and the execution efficiency is low.

[0066] The global offset table refers to a data structure used to store the addresses of global variables and functions. The procedure linkage table refers to a data structure used to store the call addresses of external functions.

[0067] Based on the above questions, please refer to Figure 1 The present application embodiment provides a memory resource allocation method for an embedded system, the method comprising:

[0068] 01: Determine the target software module set based on the classification results of the software modules of the embedded system;

[0069] 02: Determine the target operating domain based on the target software module set;

[0070] 03: Determine the target loading management table according to the target software module set and the target operation domain;

[0071] 04: According to the target loading management table, memory resources are allocated to the target software module set to realize memory resource allocation for the embedded system.

[0072] The embodiment of the present application also provides a computer device, including a memory and a processor. The memory resource allocation method of the embodiment of the present application can be implemented by the computer device of the embodiment of the present application. Specifically, a computer program is stored in the memory, and the processor is used to determine the target software module set according to the classification results of the software modules of the embedded system. And determine the target operating domain according to the target software module set. The processor is also used to determine the target loading management table according to the target software module set and the target operating domain. And according to the target loading management table, memory resources are allocated to the target software module set to realize memory resource allocation for the embedded system.

[0073] The embodiment of the present application also provides a resource allocation device. The memory resource allocation method of the embodiment of the present application can be implemented by the resource allocation device of the embodiment of the present application. Specifically, the resource allocation device includes a determination module and an allocation module. The determination module is used to determine the target software module set according to the classification results of the software modules of the embedded system. The determination module is also used to determine the target operating domain according to the target software module set. The determination module is also used to determine the target loading management table according to the target software module set and the target operating domain. The allocation module is used to allocate memory resources to the target software module set according to the target loading management table to realize memory resource allocation for the embedded system.

[0074] Specifically, an embedded system refers to a special-purpose computer system that is designed to perform a specific task and is usually embedded in a larger device or system. Compared to general-purpose computers, embedded systems usually have limited memory size and storage space.

[0075] The software module of an embedded system refers to the independent components or parts that make up the embedded system software. Each software module is responsible for implementing a specific function or sub-function of the system.

[0076] The classification result refers to the result obtained by classifying the software modules of the embedded system into different categories according to certain rules.

[0077] The target software module set refers to a software module set consisting of software modules of the same category.

[0078] The target operation domain refers to the memory address used to run each software module in the target software module set, which is usually readable and writable. In the implementation of the present application, for the convenience of explanation, the random access memory (RAM) located inside the processor chip is taken as an example to illustrate the memory resource allocation method for the embedded system provided by the implementation of the present application.

[0079] The target load management table refers to a data structure used to manage the loading and unloading of software modules in an embedded system, including detailed information of each software module in the embedded system, such as the loading address, loading domain size, and running address of the software module. The main function of the target load management table is to guide the memory management unit (MMU) or similar hardware / software components of the embedded system to dynamically load the module from the non-volatile memory to the RAM at runtime. Through the target load management table, the embedded system can efficiently manage multiple software modules in limited memory resources. These software modules can share the same RAM memory area and are only loaded into the RAM when needed, thereby reducing memory usage. It should be noted that the loading address, loading domain size, and running address of each software module in the target load management table are all determined when the software module is compiled and linked. All software codes (including software modules) are compiled and linked into an image file, which will have a loading address and a running address. The loading address can be considered as a storage address and is stored in the non-volatile memory. The running address can be considered as a memory address and is stored in the RAM. Please refer to Figure 2 , Figure 2 Schematic diagram of the software code compilation and linking process.

[0080] In the implementation manner of the present application, for the convenience of explanation, the memory resource allocation method for an embedded system provided in the implementation manner of the present application is explained by taking the flash memory Flash located outside the processor chip as a non-volatile memory.

[0081] The following is an example to illustrate the method of the implementation mode of the present application. In the example of the present application, the embedded system includes multiple software modules such as A1, A2, A3, B1, B2, C1, C2, C3 and C4. Among them, A1, A2 and A3 are a class, called dynamic software module set A. B1 and B2 are a class, called dynamic software module set B. C1, C2, C3 and C4 are a class, called dynamic software module set C. The computer device is an overlay loading manager (Automatic Overlay Manager, AOM).

[0082] The overlay loading manager determines that the target software module set to be managed is the dynamic software module set A according to the classification result of the software modules of the embedded system. It should be noted that the dynamic software module set B or the dynamic software module set C also needs to be used as the target software module set for the subsequent steps of the memory resource allocation method.

[0083] Next, the overlay load manager determines the target execution domain, i.e., the RAM memory area where the dynamic software module A will be loaded and executed, based on the software modules A1, A2, and A3 in the dynamic software module A. Then, in order to effectively manage the loading and unloading of software modules, the overlay load manager determines a global overlay load management table, i.e., a target load management table, based on the target software module set and the target execution domain.

[0084] Finally, the overlay loading manager allocates memory resources to the dynamic software module set A according to the global overlay loading management table, that is, according to the information in the global overlay loading management table, the software modules in the dynamic software module set A are loaded into the specified location in the RAM so that these software modules can be executed.

[0085] In summary, in the memory resource allocation method and computer device for embedded systems of the embodiment of the present application, the computer device determines the target software module set according to the classification result of the software module of the embedded system. Then, the computer device determines the target operation domain according to the target software module set. Then, the computer device determines the target loading management table according to the target software module set and the target operation domain. Finally, the computer device allocates memory resources to the target software module set according to the target loading management table to realize the memory resource allocation of the embedded system. In this way, by classifying the software modules that do not need to be resident in the memory at the same time when the program is running, different software modules of the same class use the same operation domain, that is, the target operation domain, so as to effectively utilize the limited memory resources and ensure that the software modules are loaded into the target operation domain only when needed, thereby improving the performance and efficiency of the embedded system. In addition, the target loading management table is determined, through which the computer device can efficiently manage multiple software modules in limited memory resources, automatically optimize memory usage, reduce the need for manual memory management, and improve the execution efficiency and response speed of the embedded system.

[0086] See also Figure 3 In some embodiments, the method further comprises:

[0087] 05: Determine the classification result based on the execution sequence of the software module.

[0088] In some implementations, the determination module is further configured to determine the classification result based on the execution sequence of the software module.

[0089] In some embodiments, the processor is further configured to determine a classification result based on an execution sequence of the software module.

[0090] Specifically, execution timing refers to the execution timing of each software module in the embedded system, that is, they do not need to be executed at the same time in terms of function. For example, different audio codec algorithms such as MP3, AAC and WAV, each of which is designed for specific application scenarios and needs, has its own unique compression and decompression mechanism, as well as different sound quality and compression ratio. At the same time, users can only choose one audio codec algorithm to compress and decompress audio files. Or, different image codec algorithms such as JPEG, PNG and WebP can all be used to compress and decompress image data to reduce storage space and transmission bandwidth requirements, but have different application scenarios.

[0091] The computer device determines the classification result according to the execution sequence of the software modules. By classifying the software modules that do not need to be executed at the same time, the computer device can dynamically load and unload these modules at runtime instead of keeping all the software modules resident in the memory.

[0092] Continuing with the above example, the overlay loading manager determines the classification result according to the execution sequence of software module A1, software module A2, software module A3, software module B1, software module B2, software module C1, software module C2, software module C3 and software module C4 in the embedded system. That is, software module A1, software module A2 and software module A3 that do not need to be executed simultaneously in terms of function are classified into dynamic software module set A. Software module B1 and software module B2 that do not need to be executed simultaneously in terms of function are classified into dynamic software module set B. Software module C1, software module C2, software module C3 and software module C4 that do not need to be executed simultaneously in terms of function are classified into dynamic software module set C.

[0093] In this way, according to the execution timing of the software modules, the computer device classifies those software modules that do not need to run simultaneously into one category, and obtains the classification result, so as to effectively organize and manage the software modules in the embedded system, so as to utilize limited memory resources and improve the performance and power consumption of the embedded system.

[0094] See also Figure 4 In some implementations, step 01 (determining a target software module set according to the classification results of the software modules of the embedded system) includes:

[0095] 011: Determine the target software module set based on the preloaded files and classification results.

[0096] In some implementations, the determination module is further configured to determine a target software module set based on the preloaded files and the classification results.

[0097] In some implementations, the processor is further configured to determine a target software module set based on the preloaded files and the classification results.

[0098] Specifically, the preload file refers to a pre-set scatter-loading file (scatter-loading file), which describes the information required by the ARM connector to generate an ARM image file. The scatter-loading file also includes the starting address (load address) and maximum size (maxsize) of each load region when loading, the attributes of each load region, the runtime domain separated from each load region, the execution starting address (execution address) and maximum size (max size) of each runtime region (execution region), the storage access characteristics of each runtime region, the attributes of each runtime region and the input segments contained in each runtime region, etc. The OVERLAY keyword is used to indicate that these modules will be loaded into the same virtual memory address (Virtual Memory Address, VMA) overlay loading area at runtime. It can be used to guide the memory management unit or similar hardware / software components of the embedded system to dynamically load the software module from Flash to a specific memory address in RAM at runtime so that these software modules can be executed. It should be noted that if the user does not provide a preload file, the ARM connector will generate the ARM image file in the default way.

[0099] ARM image files refer to executable files, including bin or hex formats. ARM image files are generally composed of domains, and domains are composed of up to three output segments (RO, RW, ZI), and output segments are composed of input segments.

[0100] Domain refers to the area where the entire bin format image file is located, which is divided into loading domain and running domain. Loading domain is the working area where the ARM image file is statically stored. Generally speaking, the address space where the entire bin format image file in Flash is located is the loading domain. However, the programs in the ARM image file are generally not placed in Flash for execution, but are generally moved to RAM for operation. The address space where they are moved to RAM for operation is the running domain.

[0101] For example, define OVERLAY_A1 and OVERLAY_A2 in the scatter-loading file, and the corresponding VMA overlay loading area address is 0x10000, and the size is 16KB. The corresponding code in the scatter-loading file is as follows:

[0102]

[0103] Among them, ROM_LOAD 0x0 0x40000 means loading a ROM area of ​​0x40000 (ie, 256KB) in size starting from address 0x0 in the Flash. The ROM area is used to preload the software modules in the embedded system in the Flash, that is, in the non-volatile storage medium.

[0104] ROM_EXEC+0 0x10000 means loading an executable code area of ​​size 0x10000 starting from address 0x0 in RAM. This executable code area is used to run the software module in the embedded system in RAM, that is, the storage area inside the processor chip.

[0105] In addition, it can be found that in OVERLAY_A1 0x10000 OVERLAY 0x4000 and OVERLAY_A2 0x10000 OVERLAY 0x4000, the virtual memory address (VMA) is 0x10000 and the size is 0x4000 (i.e. 16KB), which indicates that software module A1 and software module A2 are running in the internal storage area of ​​the same processor chip, and can load both the read-only part of a1.lib and the read-only part of a2.lib. In other words, software module A1 and software module A2 share the same VMA address 0x4000, but they will not be loaded at the same time during runtime, but will be loaded to this address as needed.

[0106] See also Figure 5 , Figure 5 This is a schematic diagram of the data flow of software modules in embedded systems. Figure 5 The left side is the loading domain, which is usually composed of Flash, and has image code segments, dynamic modules M1, dynamic modules M2, dynamic modules M3, dynamic modules N1, dynamic modules N2 and image data segments. Dynamic modules M1, dynamic modules M2 and dynamic modules M3 are the same type of software modules, and dynamic modules N1 and dynamic modules N2 are the same type of software modules. Figure 5 The right side is the running domain, which is usually composed of RAM. It can be found that the same software module has only one running domain.

[0107] Based on the preloaded files and the classification results, the computer device determines a target software module set.

[0108] In this way, the computer device can optimize the memory usage and program execution efficiency of resource-constrained embedded systems by loading software modules into the memory only when needed, thereby reducing memory usage and improving the system's responsiveness and efficiency.

[0109] See also Figure 6In some embodiments, the method further comprises:

[0110] 06: Determine the maximum memory space based on the target software module set;

[0111] 07: Determine the storage domain memory value of the target running domain based on the maximum value of the memory space.

[0112] In some implementations, the determination module is further configured to determine a maximum memory space value according to the target software module set, and to determine a storage domain memory value of the target execution domain according to the maximum memory space value.

[0113] In some implementations, the processor is further configured to determine a maximum memory space value according to the target software module set, and determine a storage domain memory value of the target execution domain according to the maximum memory space value.

[0114] Specifically, the computer device analyzes the memory requirements of each module in the target software module set and finds the software module that requires the largest memory space. The memory space required by this module is defined as the maximum memory space. Then, once the maximum memory space is determined, the computer device determines the storage domain memory value of the target operating domain based on this value. The storage domain memory value refers to the memory size allocated to the target operating domain, which must be at least equal to the maximum memory space to ensure that all modules can run normally in memory.

[0115] Continuing with the above example, the memory requirements of software module A1, software module A2 and software module A3 in dynamic software module set A are 10KB, 16KB and 12KB respectively. The overlay loading manager determines that the maximum value of the memory space is 16KB based on the memory requirements of each software module in dynamic software module set A, and uses the maximum value of the memory space 16KB as the storage domain memory value of the target execution domain, that is, the storage domain memory value of each software module in the dynamic software module set A in RAM.

[0116] In this way, the computer device ensures that sufficient memory is allocated for each set of software modules, the embedded system can avoid the problem of insufficient memory, improve the stability and performance of the embedded system, and thus effectively manage memory resources.

[0117] See also Figure 7 In some implementations, step 03 (determining a target loading management table according to a target software module set and a target operating domain) includes:

[0118] 031: Determine a target loading management table according to the module loading information of the software modules in the target software module set.

[0119] In some implementations, the determination module is further configured to determine a target loading management table according to module loading information of software modules in the target software module set.

[0120] In some implementations, the processor is further configured to determine a target loading management table according to module loading information of software modules in the target software module set.

[0121] Specifically, the loading address of the software module in the non-volatile storage medium refers to the memory address used to preload the software module in the embedded system.

[0122] The memory size of a software module refers to the size of the physical memory address required to run the software module in the internal address of the processor chip.

[0123] The target virtual memory address of a software module refers to the virtual memory address size and location area required to run the software module in the internal address of the processor chip.

[0124] The target execution domain loading flag of the software module is used to indicate whether there are any instructions loaded into the software module, and includes a first loading flag and a second loading flag.

[0125] The computer device collects module loading information for each software module in the target software module set. The module loading information includes the loading address (LMA) of the software module in the non-volatile storage medium, that is, the location of the software module in the storage medium such as Flash. The module loading information also includes the memory size of the software module, that is, the size of the space required when the software module runs in RAM. The module loading information also includes the target virtual memory address (VMA) of the software module, that is, the expected running address of the software module in RAM. The module loading information also includes the target running domain loading flag of the software module.

[0126] Based on the collected module loading information, the computer device determines a target loading management table to instruct how to load and unload modules at runtime.

[0127] Continuing with the above example, the overlay loading manager will collect module loading information of each software module in dynamic software module A. If the target software module set is dynamic software module B or dynamic software module C, the overlay loading manager will collect module loading information of each software module in dynamic software module B or dynamic software module C accordingly.

[0128] Next, the module loading information of the software module A1, the software module A2 and the software module A3 is recorded in the global coverage loading management table.

[0129] In this way, the target loading management table is obtained, through which the loading and unloading of software modules can be managed at runtime. When a software module needs to be executed, the system will determine the module loading information of the module according to this target loading management table. When the module is no longer needed, the system can unload it from the embedded system to free up memory space for other modules to use, thereby effectively optimizing memory usage and improving system performance and resource utilization.

[0130] See also Figure 8 In some embodiments, the method further comprises:

[0131] 08: During the initialization process of the embedded system, the allocation of the target virtual memory address is determined according to the target loading management table.

[0132] In some implementations, the determination module is further configured to determine the allocation of the target virtual memory address according to the target loading management table during the process of initializing the embedded system.

[0133] In some implementations, the processor is further configured to determine the allocation of the target virtual memory address according to the target loading management table during the process of initializing the embedded system.

[0134] Specifically, the target virtual memory address refers to a logical address allocated to the target software module set in the RAM, which is jointly managed by the operating system and hardware and can be used to run the software modules in the target software module set.

[0135] When the embedded system is initialized, the computer device will traverse each table entry in the target load management table and check the module VMA allocation in each table entry to ensure that the VMA address ranges of no two modules overlap and no module's VMA address exceeds the memory space range of the embedded system.

[0136] Continuing with the above example, when the embedded system is initialized, the overlay load manager will traverse each entry in the global overlay load management table. The purpose is to check the module VMA allocation in each entry to ensure that no two modules have overlapping VMA address ranges and no module's VMA address exceeds the system's memory space range.

[0137] In this way, the computer device can ensure that no memory conflict or out-of-bounds access occurs when the embedded system loads software modules at runtime, thereby improving the stability and reliability of the embedded system.

[0138] See also Fig. 9 In some implementations, step 04 (allocating memory resources for the target software module set according to the target loading management table) includes:

[0139] 041: compile and link the target software modules in the target software module set to obtain target module codes;

[0140] 042: Allocate memory resources to the target software module according to the target loading management table;

[0141] 043: Run the target module code according to the result of memory resource allocation.

[0142] In some embodiments, the allocation module is further used to compile and link the target software modules in the target software module set to obtain the target module code, and to allocate memory resources to the target software modules according to the target loading management table, and to run the target module code according to the result of the memory resource allocation.

[0143] In some embodiments, the processor is further configured to compile and link the target software modules in the target software module set to obtain the target module code, allocate memory resources to the target software modules according to the target loading management table, and run the target module code according to the result of the memory resource allocation.

[0144] Specifically, the compilation and linking process refers to the process of combining the target code generated by compiling the target software module, other necessary target codes such as the code in the library file, and the resources provided by the embedded system to generate a complete executable file. In this process, a linker is needed, which is responsible for resolving symbol references in the target code and binding them to the addresses in other target codes or library files that define these symbols. The compilation and linking process also includes the allocation and relocation of address space to ensure that the executable file can be correctly loaded and executed in memory.

[0145] The computer device compiles and links the target software modules in the target software module set, converts the source code into machine code, and resolves the references and dependencies between the target software module and other target codes, thus generating a binary image file, namely the target module code, which contains the executable code and data of all modules. Then, the computer device allocates memory resources to the target software module according to the target loading management table.

[0146] Once the memory resource allocation is completed, the computer device will run the target module code according to the result of the memory resource allocation, that is, load the target software module from Flash to the corresponding VMA in RAM and start executing the instructions in the target module code.

[0147] Continuing with the above example, according to the requirements, software module A1 needs to be run. The overlay loading manager first compiles and links the software module A1 and other necessary codes to obtain the module code a1. Then, the overlay loading manager obtains the data information such as the load address (LMA), memory size, target virtual memory address (VMA) and target operation domain load flag of the software module A1 according to the global overlay loading management table. Subsequently, based on this data information, the overlay loading manager allocates memory resources to the software module A1. Finally, the overlay loading manager runs the module code a1 according to the result of the memory resource allocation.

[0148] In this way, by compiling and linking the target software module set, the target module code is obtained, which takes up less space and has a faster loading rate. In addition, the embedded system can efficiently manage memory resources to ensure that each software module can run on the correct memory address, thereby ensuring the stability and performance of the embedded system.

[0149] See also Fig.10 In some embodiments, step 043 (running the target module code according to the result of memory resource allocation) includes:

[0150] 0431: Identify and process the target module code, and determine the target operation domain loading flag of the target module code;

[0151] 0432: When the target operation domain loading flag is the first loading flag, based on a preset compiler, patch processing is performed on a first target interface corresponding to the target module code to determine a second target interface;

[0152] 0433: Call the target running domain according to the second target interface and run the target module code.

[0153] In some embodiments, the resource allocation device further includes an operation module, and the determination module is further used to identify the target module code and determine the target operation domain loading flag of the target module code. When the target operation domain loading flag is the first loading flag, based on the preset compiler, the first target interface corresponding to the target module code is patched to determine the second target interface. The operation module is further used to call the target operation domain according to the second target interface and run the target module code.

[0154] In some embodiments, the processor is further configured to identify the target module code and determine the target operation domain loading flag of the target module code. When the target operation domain loading flag is the first loading flag, based on the preset compiler, patch the first target interface corresponding to the target module code to determine the second target interface. And call the target operation domain according to the second target interface to run the target module code.

[0155] Specifically, the first loading flag is used to indicate that there is instruction information of the target module code in the VMA in the RAM, that is, it indicates that the target module code corresponding to the target software module was last run in the VMA. The judgment process of the target operation domain loading flag can be as follows: when the resident code calls the overlay loading target software module interface, the control right will be handed over to the overlay loading manager. The overlay loading manager determines that the target software module has been loaded into the VMA, and then the target operation domain loading flag of the target software module is considered to be the first loading flag.

[0156] A pre-compiler is a tool that converts high-level programming language source code into machine code.

[0157] Patch processing refers to a mechanism provided by the preset compiler, which allows relevant technicians to modify the target module interface directly during the development phase without modifying the original code, and then compile and link it to obtain an image file. When executing the image file, the target module interface is changed from the original interface to the required application interface. For example, OVERLAY_A1 has an interface foo(), and a new interface $Sub$$foo() is defined. The preset compiler will modify the call to the original interface foo() in the program to $Sub$$foo(), and $Super$$foo() represents the original interface foo(). Therefore, we can first call the overlay loading manager in $Sub$$foo(), and then call $Super$$foo() to enter the original interface foo(). In this way, when calling the dynamic software module interface, the control can be handed over to the overlay loading manager without modifying the original interface implementation of the module. The relevant code is as follows:

[0158] void$Sub$$foo()

[0159] {

[0160] overlay_manager(m1); / / Overlay loading manager processing

[0161] $Super$$foo(); / / Original interface processing

[0162] }

[0163] The target interface refers to the interface used in embedded systems to move target software modules from non-volatile storage media to internal storage addresses of processor chips.

[0164] The computer device will identify the target module code to check the target operation domain loading flag of the target module code. This flag is used to indicate whether the module has been loaded into the target operation domain. If the target operation domain loading flag is the first loading flag, it means that the module has been loaded and the instruction information related to the target module code has not been cleared in the target operation domain.

[0165] If the target operation domain loading flag is the first loading flag, the computer device will perform patch processing on the first target interface corresponding to the target module code based on the preset compiler to determine the second target interface. That is, when it is confirmed that the target operation domain loading flag is the first loading flag, the call to the first target interface in the original program is modified to the second target interface through a specific code segment, and then the second target interface can be used to implement the function of the original first target interface.

[0166] Subsequently, the computer device calls the second target interface and runs the target module code in the target running domain to implement the function of the target module code.

[0167] Continuing with the above example, when the resident code calls the first target interface corresponding to the module code a1, the overlay loading manager will first identify the module code a1 and determine the target runtime domain loading flag of the module code a1. If the module code a1 has been run in the previous round, the target runtime domain loading flag of the module code a1 is considered to be the first loading flag. When the target runtime domain loading flag of the module code a1 is the first loading flag, the overlay loading manager patches the original interface foo() corresponding to the module code a1 based on the preset compiler and determines $Sub$$foo(). Then, the overlay loading manager directly calls $Sub$$foo() to run the module code a1 in the target runtime domain.

[0168] Thus, in resource-constrained embedded systems, by dynamically loading and unloading software modules when needed, the system can effectively utilize limited memory resources while reducing startup time and power consumption, thereby optimizing memory usage and improving system performance.

[0169] See also Fig.11 In some embodiments, step 043 (running the target module code according to the result of memory resource allocation) includes:

[0170] 0434: when the target operation domain loading flag is the second loading flag, determining the first target interface according to the target loading management table;

[0171] 0435: Based on a preset compiler, patch processing is performed on the first target interface to determine a second target interface;

[0172] 0436: calling the target running domain according to the second target interface to run the target module code;

[0173] 0437: Update the target running domain loading flag to the first loading flag.

[0174] In some embodiments, the resource allocation device further includes a processing module, and the determination module is further used to determine the first target interface according to the target loading management table when the target operation domain loading flag is the second loading flag. And based on the preset compiler, the first target interface is patched to determine the second target interface. The operation module is further used to call the target operation domain according to the second target interface and run the target module code. The processing module is used to update the target operation domain loading flag to the first loading flag.

[0175] In some embodiments, the processor is further configured to determine the first target interface according to the target loading management table when the target operation domain loading flag is the second loading flag. And based on the preset compiler, the first target interface is patched to determine the second target interface. The processor is further configured to call the target operation domain according to the second target interface to run the target module code. And the target operation domain loading flag is updated to the first loading flag.

[0176] Specifically, the second loading flag is used to indicate that there is no instruction information of the target module code in the RAM, that is, it indicates that the software module last run in the VMA is not the target module code corresponding to the target software module. The judgment process of the target operation domain loading flag can be as follows: when the resident code calls the overlay loading target software module interface, the control right will be handed over to the overlay loading manager. The overlay loading manager determines that the target software module is not loaded into the VMA, and then considers that the target operation domain loading flag of the target software module is the second loading flag.

[0177] When the target operation domain loading flag is the second loading flag, the computer device first needs to determine the first target interface according to the target loading management table. Then, based on the preset compiler, the first target interface is patched to determine the second target interface. Next, the computer device calls the target operation domain according to the second target interface to run the target module code. Finally, the computer device updates the target operation domain loading flag from the second loading flag to the first loading flag.

[0178] Continuing with the above example, the manager first checks the global overlay loading management table to determine whether the required software module has been loaded into its VMA. If the module code a1 is running in the VMA in the RAM for the first time, or if the module code a2 corresponding to the software module A2 has been run before running the module code a1, the target running domain loading flag of the module code a1 is confirmed to be the second loading flag. In this case, the overlay loading manager first obtains the original interface foo() of the module code a1 from the global overlay loading management table. Subsequently, the overlay loading manager patches the original interface foo() corresponding to the module code a1 based on the preset compiler and determines $Sub$$foo(). Then, the overlay loading manager directly calls $Sub$$foo() to load the module code a1 from its LMA to the VMA, that is, reads the module data from the Flash and stores it to the specified address in the RAM. Finally, the overlay loading manager updates the corresponding table entry in the global overlay loading management table and updates the target running domain loading flag to the first loading flag.

[0179] Thus, in resource-constrained embedded systems, by dynamically loading and unloading software modules when needed, the system can effectively utilize limited memory resources while reducing startup time and power consumption, thereby optimizing memory usage and improving system performance.

[0180] See also Fig.12 In some embodiments, the method further comprises:

[0181] 09: In the case where there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code is cacheable, the target instruction cache corresponding to the target module code in the preset cache device is cleared to ensure the timeliness of the target instruction cache.

[0182] In some embodiments, the processing module is also used to clear the target instruction cache corresponding to the target module code in the preset cache device when there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code has a cacheable attribute, so as to ensure the timeliness of the target instruction cache.

[0183] In some embodiments, the processor is also used to clear the target instruction cache corresponding to the target module code in the preset cache device when there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code has a cacheable attribute, so as to ensure the timeliness of the target instruction cache.

[0184] Specifically, the preset cache device refers to a fast memory located between the CPU and the main memory, which can be used to temporarily store recently or frequently used data and instructions. To facilitate the description of the memory resource allocation method for an embedded system provided in the embodiment of the present application, the following description is made using a hardware cache as the preset cache device.

[0185] The cacheable attribute refers to the attribute that the virtual memory address of the software module can be cached in the hardware cache. When the VMA of the software module is marked as cacheable, when the processor accesses these addresses, the data or instructions may be automatically stored in the hardware cache.

[0186] In the case where there is a hardware cache in the embedded system and the target virtual memory address corresponding to the target module code is cacheable, the computer device will identify the target instruction cache corresponding to the target module code. The target instruction cache is the most recently executed instructions corresponding to the target module code stored in the hardware cache inside the processor. Once the target instruction cache is identified, the computer device will clear it, that is, clear the old instructions in the cache to make room for new instructions. After clearing the instruction cache, when the processor executes the program, it will not be able to find the required instructions from the hardware cache, so it will obtain the latest instructions from the main memory, ensuring that the processor can execute the instructions in the newly loaded software module instead of the old instructions.

[0187] In this way, in embedded systems that need to process a large number of instructions or frequently execute the same instructions, the timeliness of the instruction cache can be ensured, ensuring that the system can always obtain the latest instructions to maintain high efficiency, thereby improving the performance and response speed of the embedded system.

[0188] The present application also provides a computer-readable storage medium containing a computer program. When the computer program is executed by one or more processors, the one or more processors execute the method of the present application.

[0189] It is understood that a computer program includes computer program code. The computer program code may be in source code form, object code form, executable file or some intermediate form. Computer readable storage media may include: any entity or device capable of carrying computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), and software distribution medium.

[0190] In the description of this specification, the descriptions with reference to the terms "specifically", "further", "particularly", "understandably", etc. are intended to mean that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms are not intended to refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.

[0191] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0192] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A memory resource allocation method for an embedded system, characterized in that: The method comprises: Determining a target software module set according to the classification results of the software modules of the embedded system; Determining a target operating domain according to the target software module set; Determining a target loading management table according to the target software module set and the target operating domain; Memory resources are allocated to the target software module set according to the target loading management table to implement memory resource allocation to the embedded system.

2. The method according to claim 1, characterized in that The method further comprises: The classification result is determined according to the execution sequence of the software modules.

3. The method according to claim 1, characterized in that The step of determining a target software module set according to the classification results of the software modules of the embedded system comprises: The target software module set is determined according to the preloaded file and the classification result.

4. The method according to claim 1, characterized in that: The method further comprises: Determining a maximum value of memory space according to the target software module set; According to the maximum value of the memory space, a storage domain memory value of the target execution domain is determined.

5. The method according to claim 1, characterized in that The step of determining a target loading management table according to the target software module set and the target operating domain includes: The target loading management table is determined according to the module loading information of the software modules in the target software module set, wherein the module loading information includes the loading address of the software module in the non-volatile storage medium, the memory size of the software module, the target virtual memory address of the software module and / or the target execution domain loading flag of the software module, and the target execution domain loading flag is used to indicate whether the software module is loaded into the target execution domain.

6. The method according to claim 5, characterized in that The method further comprises: In the process of initializing the embedded system, the allocation of the target virtual memory address is determined according to the target loading management table.

7. The method according to claim 5, characterized in that The allocating memory resources to the target software module set according to the target loading management table includes: Compiling and linking the target software modules in the target software module set to obtain target module codes; Allocating memory resources to the target software module according to the target loading management table; The target module code is run according to the result of the memory resource allocation.

8. The method according to claim 7, characterized in that The step of running the target module code according to the result of the memory resource allocation includes: Identify the target module code and determine the target operation domain loading flag of the target module code; When the target operation domain loading flag is the first loading flag, patch processing is performed on the first target interface corresponding to the target module code based on a preset compiler to determine a second target interface; The target execution domain is called according to the second target interface to execute the target module code.

9. The method according to claim 8, characterized in that The step of running the target module code according to the result of the memory resource allocation includes: When the target operation domain loading flag is the second loading flag, determining the first target interface according to the target loading management table; Based on a preset compiler, patch processing is performed on the first target interface to determine the second target interface; Calling the target execution domain according to the second target interface to execute the target module code; The target execution domain loading flag is updated to the first loading flag.

10. The method according to claim 7, characterized in that The method further comprises: In the case where there is a preset cache device in the embedded system and the target virtual memory address corresponding to the target module code is cacheable, the target instruction cache corresponding to the target module code in the preset cache device is cleared to ensure the timeliness of the target instruction cache.

11. A computer device, characterized in that: The computer device comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium memory stores a computer program, and when the computer program is executed by one or more processors, the method according to any one of claims 1 to 10 is implemented.

Citation Information

Cited By

  • Software algorithm module dynamic reloading method based on static redirection table

    CN121209927A

  • Method for dynamic reloading of software algorithm modules based on static redirection table

    CN121209927B