Memory allocation method and device, equipment, medium and product

By configuring the mapping between target files and memory spaces and adding code segments to the memory-mapped files, the problem of allocating memory without specifying memory address variables is solved, achieving memory allocation without data consistency issues or performance impact.

CN121050868APending Publication Date: 2025-12-02BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410685053.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2025-12-02

AI Technical Summary

Technical Problem

In AUTOSAR development, variables without specified memory addresses may be allocated to the cache or have their cache disabled, leading to data consistency issues and performance impacts on variables accessed frequently.

Method used

By configuring the mapping between target files and memory spaces, target code segments are added to the memory-mapped files, and these code segments are called during compilation. Variables without specified memory addresses are allocated to the corresponding memory spaces, avoiding allocation to the cache area or disabling the cache area.

Benefits of technology

This effectively avoids data consistency issues and the performance impact of hot access variables, thus improving memory allocation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121050868A_ABST
    Figure CN121050868A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and device, equipment, a medium and a product, and relates to the technical field of vehicles. The memory allocation method comprises the following steps: configuring a corresponding relationship between a target file and a memory space; in the memory mapping file, a target code segment is added, the target code segment is used for distributing a first variable in a target file to a memory space having a corresponding relation with the target file, and the first variable is a variable without a specified memory address; when the target file is compiled, the target code segment in the memory mapping file is called, and the variables are distributed to the memory space. Through the scheme disclosed by the invention, the variable of the non-specified memory address in the target file can be allocated to the memory space having the corresponding relationship with the target file, so that the problem of data consistency and the influence on the access performance of the hotspot access variable are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of vehicle technology, and in particular relates to a memory allocation method, apparatus, device, medium and product. Background Technology

[0002] When developing software components (SWCs) based on the Automotive Open System Architecture (AUTOSAR), a memory mapping (Memmap) header file is typically generated using an SWC modeling tool. In the code, the memory address of the variable to be mapped is specified using the Memmap macro in the Memmap header file to achieve memory allocation for that variable.

[0003] However, in actual engineering development, there may be variables in the code whose memory addresses are not specified using the Memmap macro. When editing the code, these variables may be allocated to the cache area or the nocache area by the editor. When these variables are allocated to the cache area, cross-core access to these variables will cause data consistency problems if the chip hardware cannot guarantee the consistency of cache line data. When these variables are allocated to the nocache area, since the nocache area usually stores frequently accessed variables, this will affect the performance of accessing frequently accessed variables. Summary of the Invention

[0004] This application provides a memory allocation method, apparatus, device, medium, and product that can avoid data consistency problems and affect the access performance of frequently accessed variables.

[0005] In a first aspect, embodiments of this application provide a memory allocation method, including:

[0006] Configure the mapping between target files and memory space;

[0007] In the memory-mapped file, add a target code segment, which is used to allocate the first variable in the target file to a memory space that corresponds to the target file. The first variable is a variable whose memory address is not specified.

[0008] When compiling the target file, the target code segment in the memory-mapped file is called to allocate variables to memory space.

[0009] Secondly, embodiments of this application provide a memory allocation apparatus, comprising:

[0010] The configuration module is used to configure the mapping between target files and memory space;

[0011] The first adding module is used to add a target code segment to the memory-mapped file. The target code segment is used to allocate the first variable in the target file to a memory space that corresponds to the target file. The first variable is a variable whose memory address is not specified.

[0012] The allocation module is used to call the target code segment in the memory-mapped file during the compilation of the target file and allocate variables to memory space.

[0013] Thirdly, embodiments of this application provide an electronic device, the electronic device comprising: a processor and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the memory allocation method provided in embodiments of this application.

[0014] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the steps of the memory allocation method provided in embodiments of this application.

[0015] Fifthly, embodiments of this application provide a computer program product, the computer program product including computer program instructions, which, when executed by a processor, implement the steps of the memory allocation method provided in embodiments of this application.

[0016] In this embodiment, the mapping relationship between target files and memory spaces is configured. A target code segment is added to the memory-mapped file. This target code segment allocates a first variable from the target file to a memory space corresponding to the target file. The first variable is a variable without a specified memory address. When compiling the target file, the target code segment in the memory-mapped file is called to allocate the variable to the memory space. This allows variables without specified memory addresses in the target file to be allocated to a memory space corresponding to the target file, without being allocated to the cache area or no-cache area. This avoids data consistency issues and performance impacts on access to frequently accessed variables. Attached Figure Description

[0017] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart illustrating the memory allocation method provided in an embodiment of this application;

[0019] Figure 2This is a schematic diagram of the structure of the memory allocation device provided in the embodiments of this application;

[0020] Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0021] To better understand the above-mentioned objectives, features, and advantages of this application, the solution of this application will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.

[0022] Many specific details are set forth in the following description in order to provide a full understanding of this application, but this application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of this application, and not all embodiments.

[0023] The memory allocation method, apparatus, device, medium, and product provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.

[0024] Figure 1 This is a flowchart illustrating the memory allocation method provided in an embodiment of this application. Figure 1 As shown, memory allocation methods may include:

[0025] Step 101: Configure the mapping between target files and memory space;

[0026] In some possible implementations of the embodiments of this application, the memory space in the embodiments of this application can be a kernel (core) private area.

[0027] In some possible implementations of the embodiments of this application, the correspondence between the target file and the memory space can be configured through JavaScript Object Notation (JSON). JSON is a lightweight data exchange format that uses a text format that is completely independent of programming languages ​​to store and represent data.

[0028] For example, the format for configuring the mapping between target files and memory spaces using JSON is as follows:

[0029]

[0030] In this format, A is the filename of the target file, FilePath represents the storage path of file A, and CoreId represents the identifier of the kernel private area.

[0031] Step 102: In the memory-mapped file, add a target code segment, where the target code segment is used to allocate the first variable in the target file to a memory space that corresponds to the target file. The first variable is a variable whose memory address is not specified.

[0032] In some possible implementations of the embodiments of this application, the memory mapping file in the embodiments of this application can be the memory mapping file linker_ghs.ld modified by the JSON configuration in Auto_MemMap_Cfg.json.

[0033] In some possible implementations of embodiments of this application, step 102 may include: using JSON to add the target code segment to the memory-mapped file.

[0034] In this embodiment, the code segments added via JSON have a concise and clear hierarchical structure, making them easy for users to read and modify, and also easier for computers to parse, thereby improving memory allocation efficiency.

[0035] In some possible implementations of embodiments of this application, step 102 may include adding a target code segment before the code segment in the memory-mapped file used to wildcard the variables of the Block Started by Symbol (BSS) segment and the data segment.

[0036] The BSS segment, also known as the zero initial (ZL) segment, is a memory area used to store uninitialized or initialized global and static variables in the program; the data segment, also known as the data area, static data area, or static area, is a memory area used to store initialized global variables in the program.

[0037] The code segment used to wildcard BSS segment variables is, for example, “*(.bss.*)”; the code segment used to wildcard data segment variables is, for example, “*(.data.*)”.

[0038] In the embodiments of this application, by adding the target code segment before the code segment used to wildcard variables of the BSS segment and data segment in the memory-mapped file, it can be guaranteed that variables in the target file that do not specify memory addresses will be allocated to the memory space that corresponds to the target file, and will not be allocated to the cache area or the nocache area.

[0039] In some possible implementations of the embodiments of this application, before step 102, the memory allocation method provided in the embodiments of this application may further include: generating a target code segment using a code segment generation template and a correspondence, wherein the code segment generation template is used to generate a variable allocation code segment, and the variable allocation code segment is used to allocate a second variable in the file to a memory space that has a correspondence with the file, wherein the second variable is a variable for which no memory address is specified.

[0040] For example, the format of the code segment generation template provided in this application embodiment is as follows:

[0041]

[0042] Where x is the value of CoreId in the correspondence between file and memory space, IRAM_COREx is defined as the kernel private area in the memory-mapped file; ALIGN(32) instructs the compiler to align variables on 32-byte boundaries.

[0043] Taking the above JSON configuration target file and memory space correspondence as an example, the generated target code segment is as follows:

[0044]

[0045]

[0046] In some possible implementations of the embodiments of this application, before step 101, the memory allocation method provided in the embodiments of this application may further include: adding a section suffix (--section_suffix) compilation option to a file used to control compilation rules, wherein the section suffix compilation option is used to add a suffix of a preset format to variables during the compilation stage.

[0047] In some possible implementations of the embodiments of this application, the file used to control the compilation rules can be a makefile used for developing SWC. The makefile describes the compilation, linking, and other rules for the entire SWC development project. These include: which source files in the project need to be compiled and how to compile them, which library files need to be created and how to create them, and how to generate the executable file.

[0048] In some possible implementations of the embodiments of this application, the preset format can be set according to actual needs, for example, .folder_name_file_name.

[0049] In this embodiment of the application, by adding the compilation option --section_suffix to the file that controls the compilation rules, the target code segment can be made effective during the compilation process, which can ensure that variables in the target file that do not specify memory addresses are allocated to memory spaces that correspond to the target file, and are not allocated to the cache area or the nocache area.

[0050] Step 103: When compiling the object file, call the object code segment in the memory-mapped file to allocate the variables to memory space.

[0051] In some possible implementations of the embodiments of this application, in step 103, a script can be written to identify the code segment of the memory-mapped file, and then, when compiling the target file, the target code segment in the memory-mapped file is called to allocate variables to memory space.

[0052] In some possible implementations of the embodiments of this application, the memory space in the embodiments of this application can be a kernel private area with cache.

[0053] In this embodiment of the application, the efficiency of accessing variables can be improved by using the kernel private area cache.

[0054] The process of the memory allocation method provided in the embodiments of this application will be described below with specific examples.

[0055] First, add the compilation option `--section_suffix` to the Makefile. This option specifies the format of the suffix to be added, for example, `.folder_name_file_name`.

[0056] Next, set the code snippet generation template. For example, the code snippet generation template is set as follows:

[0057]

[0058] When you want to allocate a variable with an unspecified memory address in file A, which is stored at path "B\\C", to the kernel private area marked with 1, the Makefile uses the mapping between the JSON configuration file A and the kernel private area marked with 1. The mapping between the configured file A and the kernel private area marked with 1 is as follows:

[0059]

[0060] Based on the mapping between the configured file A and the kernel private area marked as 1, and the code segment generation template, the following target code segment is generated:

[0061]

[0062] Add the generated code snippet to the JSON configuration file linker_ghs.ld in Auto_MemMap_Cfg.json.

[0063] When editing file A, the linker_ghs.ld file is identified, and the target code segment generated above and added to the linker_ghs.ld file is called to allocate variables in file A that do not specify memory addresses to the kernel private area marked as 1.

[0064] In this embodiment, the mapping relationship between target files and memory spaces is configured. A target code segment is added to the memory-mapped file, whereby the target code segment allocates a first variable from the target file to a memory space corresponding to the target file. The first variable is a variable without a specified memory address. During the compilation of the target file, the target code segment in the memory-mapped file is called to allocate the variable to the memory space. This allows variables without specified memory addresses in the target file to be allocated to a memory space corresponding to the target file, without being allocated to the cache area or no-cache area. This avoids data consistency issues and performance impacts on access to frequently accessed variables.

[0065] Corresponding to the above-described method embodiments, this application also provides a memory allocation apparatus. For example... Figure 2 As shown, Figure 2 This is a schematic diagram of the structure of the memory allocation device provided in an embodiment of this application. The memory allocation device 200 may include:

[0066] Configuration module 201 is used to configure the correspondence between target files and memory space;

[0067] The first adding module 202 is used to add a target code segment to the memory-mapped file. The target code segment is used to allocate a first variable in the target file to a memory space that corresponds to the target file. The first variable is a variable whose memory address is not specified.

[0068] The allocation module 203 is used to call the target code segment in the memory-mapped file and allocate variables to memory space when compiling the target file.

[0069] In this embodiment, the mapping relationship between target files and memory spaces is configured. A target code segment is added to the memory-mapped file. This target code segment allocates a first variable from the target file to a memory space corresponding to the target file. The first variable is a variable without a specified memory address. When compiling the target file, the target code segment in the memory-mapped file is called to allocate the variable to the memory space. This allows variables without specified memory addresses in the target file to be allocated to a memory space corresponding to the target file, without being allocated to the cache area or no-cache area. This avoids data consistency issues and performance impacts on access to frequently accessed variables.

[0070] In some possible implementations of the embodiments of this application, the first adding module 202 may specifically be used for:

[0071] Add the target code segment before the code segment in the memory-mapped file that is used to wildcard variables in the BSS segment and data segment.

[0072] In the embodiments of this application, by adding the target code segment before the code segment used to wildcard variables of the BSS segment and data segment in the memory-mapped file, it can be guaranteed that variables in the target file that do not specify memory addresses will be allocated to the memory space that corresponds to the target file, and will not be allocated to the cache area or the nocache area.

[0073] In some possible implementations of the embodiments of this application, the memory allocation device provided in the embodiments of this application may further include:

[0074] The generation module is used to generate target code segments using code segment generation templates and their corresponding relationships. The code segment generation template is used to generate variable allocation code segments, which are used to allocate the second variable in the file to a memory space that has a corresponding relationship with the file. The second variable is a variable whose memory address is not specified.

[0075] In some possible implementations of the embodiments of this application, the memory allocation device provided in the embodiments of this application may further include:

[0076] The second module is used to add segment suffix compilation options to the file used to control compilation rules. These segment suffix compilation options are used to add suffixes of a preset format to variables during the compilation phase.

[0077] In this embodiment of the application, by adding the compilation option --section_suffix to the file that controls the compilation rules, the target code segment can be made effective during the compilation process, which can ensure that variables in the target file that do not specify memory addresses are allocated to memory spaces that correspond to the target file, and are not allocated to the cache area or the nocache area.

[0078] In some possible implementations of the embodiments of this application, the first adding module 202 may specifically be used for:

[0079] Using JSON, add the target code segment to the memory-mapped file.

[0080] In some possible implementations of embodiments of this application, the memory space includes:

[0081] A kernel private region with cache.

[0082] Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application.

[0083] The electronic device may include a processor 301 and a memory 302 storing computer program instructions.

[0084] Specifically, the processor 301 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0085] Memory 302 may include mass storage for data or instructions. For example, and not limitingly, memory 302 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where suitable, memory 302 may include removable or non-removable (or fixed) media. Where suitable, memory 302 may be internal or external to an electronic device. In some specific embodiments, memory 302 is a non-volatile solid-state memory.

[0086] In some specific embodiments, the memory may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Therefore, generally, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the memory allocation method according to this application.

[0087] The processor 301 implements the steps of the memory allocation method provided in the embodiments of this application by reading and executing computer program instructions stored in the memory 302.

[0088] In some examples, the electronic device may also include a communication interface 303 and a bus 310. For example, Figure 3 As shown, the processor 301, memory 302, and communication interface 303 are connected through bus 310 and complete communication with each other.

[0089] The communication interface 303 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.

[0090] Bus 310 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 310 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.

[0091] The electronic device can execute the memory allocation method provided in the embodiments of this application, thereby achieving the corresponding technical effects of the memory allocation method provided in the embodiments of this application.

[0092] In addition, in conjunction with the memory allocation method in the above embodiments, this application also provides a computer-readable storage medium for implementation. This computer-readable storage medium stores computer program instructions; when executed by a processor, these computer program instructions implement the steps of the memory allocation method provided in this application. Examples of computer-readable storage media include non-transitory computer-readable media, such as ROM, RAM, magnetic disks, or optical disks.

[0093] This application also provides a computer program product, which includes computer program instructions. When the computer program instructions are executed by a processor, they implement the steps of the memory allocation method provided in this application and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0094] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the term "comprising" or any other variations thereof is 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. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A memory allocation method, characterized in that, The method includes: Configure the mapping between target files and memory space; In the memory-mapped file, a target code segment is added, wherein the target code segment is used to allocate a first variable in the target file to a memory space that corresponds to the target file, and the first variable is a variable for which no memory address is specified; When compiling the target file, the target code segment in the memory-mapped file is called to allocate the variable to the memory space.

2. The method as described in claim 1, characterized in that, Adding the target code segment to the memory-mapped file includes: Add the target code segment before the code segment in the memory-mapped file that is used to wildcard the variables of the BSS segment and the data segment.

3. The method as described in claim 1, characterized in that, Before adding the target code segment to the memory-mapped file, the method further includes: The target code segment is generated using a code segment generation template and the corresponding relationship. The code segment generation template is used to generate a variable allocation code segment, which is used to allocate a second variable in the file to a memory space that has a corresponding relationship with the file. The second variable is a variable for which no memory address is specified.

4. The method as described in claim 3, characterized in that, Before establishing the mapping between the target file and memory space, the method further includes: In the file used to control compilation rules, add a segment suffix compilation option, wherein the segment suffix compilation option is used to add a suffix of a preset format to variables during the compilation phase.

5. The method as described in claim 1, characterized in that, Adding the target code segment to the memory-mapped file includes: Using a JavaScript object, the target code segment is added to the memory-mapped file.

6. The method as described in claim 1, characterized in that, The memory space includes: A kernel private region with cache.

7. A memory allocation device, characterized in that, The device includes: The configuration module is used to configure the mapping between target files and memory space; The first adding module is used to add a target code segment to a memory-mapped file, wherein the target code segment is used to allocate a first variable in the target file to a memory space that corresponds to the target file, and the first variable is a variable whose memory address is not specified. The allocation module is used to call the target code segment in the memory-mapped file during the compilation of the target file to allocate the variable to the memory space.

8. An electronic device, characterized in that, The electronic device includes: a processor and a memory storing computer program instructions; The processor reads and executes the computer program instructions to implement the steps of the memory allocation method as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed by a processor, implement the steps of the memory allocation method as described in any one of claims 1-6.

10. A computer program product, characterized in that, The computer program product includes computer program instructions that, when executed by a processor, implement the steps of the memory allocation method as described in any one of claims 1-6.