RTOS automatic adaptation method and system and storage medium

By extracting shared resource information in the CPU description file and generating save/restore functions, adding hook functions to RTOS, automatically generating execution files to achieve automatic CPU adaptation, solving the problem of low adaptation efficiency of traditional RTOS and improving the software Development efficiency.

CN119225803APending Publication Date: 2024-12-31CHIPEASY TECHNOLOGY (SHANGHAI) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310777162.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The traditional method is inefficient when adapting the embedded processor RTOS after the CPU is designed, requiring repetitive and tedious work, and a lot of code logic is general, which fails to effectively utilize this to improve development efficiency.

Method used

By extracting shared resource information in the CPU description file, generating save/restore functions, and adding hook functions to RTOS, automatically generate execution files to achieve automatic CPU adaptation, and use library functions such as farm_get_regfile_list() and farm_get_inst_list() to obtain registers Information, generate register files and header files, integrate into the operating system, compile and generate execution files to support context switching.

Benefits of technology

It realizes that when the CPU design is completed, the information is automatically parsed through tools and RTOS adaptation code is generated, which improves software development efficiency, reduces duplicate work, and improves adaptation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225803A_ABST
    Figure CN119225803A_ABST
Patent Text Reader

Abstract

The invention discloses an RTOS automatic adaptation method and system and a storage medium, and relates to the field of processor design, and the method comprises the steps: extracting a CPU description file, and determining CPU shared resource information; according to the CPU shared resource information, the ave / store of the corresponding resource is generated; the ave / reset of the resource is used for storing or recovering a shared resource value during context switching; the CPU shared resource information comprises the number of registers, the length of the registers, the name of the registers and abbreviations of the registers; adding a corresponding hook function in the RTOS, and generating an execution file according to the ave / reset of the resource; and automatically adapting to the new CPU by utilizing the execution file. According to the method and the device, RTOS automatic adaptation can be realized, so that the software development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of processor design, and in particular to an RTOS automatic adaptation method, system and storage medium. Background Art

[0002] Currently, there are many EDA design tools that support the design of CPUs with custom instructions, such as FARMStudio. After the CPU is designed, it is necessary to adapt the operating system for the CPU, especially for processors in the embedded field, which often support several RTOS. The traditional approach is to add corresponding processor codes according to the characteristics of various RTOS (FreeRTOS, RT-thread) after the CPU is designed to support new processors.

[0003] According to the characteristics of the operating system, the work of porting and adaptation focuses on how to properly handle the context switching of the CPU during system scheduling. The traditional method is inefficient and requires repeated work for each CPU design. But in fact, many code logics are universal.

[0004] How to solve the inefficiency of traditional methods is a technical problem that needs to be solved urgently. Summary of the invention

[0005] The purpose of the present invention is to provide an RTOS automatic adaptation method, system and storage medium, which can realize RTOS automatic adaptation and thus improve software development efficiency.

[0006] To achieve the above object, the present invention provides the following solutions:

[0007] An RTOS automatic adaptation method, comprising:

[0008] Extract the CPU description file to determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value when the context is switched; the CPU shared resource information includes: the number of registers, the length of registers, the register name and the abbreviation of registers;

[0009] Add the corresponding hook function in RTOS and generate the execution file according to the save / restore of the resource;

[0010] Use executable files to automatically adapt to new CPUs.

[0011] Optionally, extracting the CPU description file to determine the CPU shared resource information; and generating save / restore of corresponding resources according to the CPU shared resource information specifically includes:

[0012] Call the library function farm_get_regfile_list() to obtain CPU shared resource information;

[0013] Call the library function farm_get_inst_list() to obtain the load / store instructions of the corresponding register;

[0014] Generate the save and restore functions of the corresponding register file according to the CPU shared resource information and the load / store instructions of the corresponding register;

[0015] Generate a header file according to the CPU shared resource information; the header file is used to define the number information of register resources;

[0016] Generate C files based on CPU shared resource information and corresponding register load / store instructions;

[0017] Put the header files, C files and assembly files into the source code directory of the corresponding RTOS and integrate them into the operating system.

[0018] Optionally, the adding of a corresponding hook function in the RTOS and generating an execution file according to the save / restore of the resource specifically includes:

[0019] Add a first hook function in the task initialization function in the operating system to allocate memory for the newly added shared hardware resources;

[0020] Add a second hook function to the context switch function corresponding to the RTOS; the second hook function is used to support the context switch of the newly added register;

[0021] Compile the resource save / restore, the first hook function and the second hook function to generate an executable file.

[0022] Optionally, the compilation method is: llvm method.

[0023] Optionally, the method for generating the execution file is: Makefile method.

[0024] An RTOS automatic adaptation system, comprising:

[0025] A code generation module is used to extract the CPU description file and determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value when the context is switched; the CPU shared resource information includes: the number of registers, the length of registers, the register name and the abbreviation of registers;

[0026] The execution file generation module is used to add the corresponding hook function in RTOS and generate the execution file according to the save / restore of resources;

[0027] The automatic adaptation module is used to automatically adapt to the new CPU using the execution file.

[0028] A storage medium stores computer program instructions, which implement the method when the computer program instructions are executed by a processor.

[0029] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0030] The present invention provides an RTOS automatic adaptation method, system and storage medium. All CPU information can be obtained from EDA tools, corresponding hook functions are added in RTOS, and execution files are generated according to save / restore of resources. When the CPU design is completed, the tool can automatically parse the CPU information and generate RTOS adaptation code for the corresponding resources, so as to achieve automatic adaptation. The corresponding code logic of the present invention can be automatically generated, which improves the software development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0032] Figure 1 The present invention provides a flow chart of an RTOS automatic adaptation method. DETAILED DESCRIPTION

[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] The purpose of the present invention is to provide an RTOS automatic adaptation method, system and storage medium, which can realize RTOS automatic adaptation and thus improve software development efficiency.

[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0036] like Figure 1 As shown, the present invention provides an RTOS automatic adaptation method, comprising:

[0037] S101, extract the CPU description file to determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value during context switching; the CPU shared resource information includes: the number of registers, the length of registers, the register name and the abbreviation of the register; all the information of the CPU can be obtained from the EDA tool.

[0038] S101 specifically includes:

[0039] S1.1, call the library function farm_get_regfile_list() to obtain the CPU shared resource information; the library function farm_get_regfile_list() will return all the register file information and status register information contained in the CPU. This function will return a linked list, and each node in the linked list contains the information of a corresponding register group or status register.

[0040] S1.2, call the library function farm_get_inst_list() to obtain the load / store instruction of the corresponding register; call the library function farm_get_inst_list(), this function will return a linked list containing all instruction information in the CPU, by traversing this linked list, check whether the corresponding instruction is the load / store instruction of the register resource obtained in 1.1, and the judged S is:

[0041] 1- Whether the instruction will read or write memory.

[0042] 2-Whether the instruction will operate the corresponding register.

[0043] 3-Whether any of the instruction operands is a general register.

[0044] 4-Whether the instruction has an immediate value.

[0045] Through the above judgment conditions, the corresponding load / store instructions of the register can be automatically derived.

[0046] S1.3, generating the save and restore functions of the corresponding register file according to the CPU shared resource information and the load / store instructions of the corresponding register;

[0047] For example, the CPU adds a set of 128-bit registers VR, the number of registers is 4, and the load instruction of the register is vld, and the store instruction is vst. We can automatically generate save / restore functions:

[0048] asm_func save_VR_context:

[0049] vld v0,0(a0)

[0050] vld v1,16(a0)

[0051] vld v2,32(a0)

[0052] vld v348(a0)

[0053] end_func save_VR_context_

[0054] asm_func restore_VR_context

[0055] vst v0,0(a0)

[0056] vst v1,16(a0)

[0057] vst v2,32(a0)

[0058] vst v3,48(a0)

[0059] asm_func restore_VR_context

[0060] No matter how many newly added register groups there are, we can generate corresponding functions according to this S. At the same time, these generated functions are saved to an assembly file, for example, the saved assembly file is named farm_udl_asm.S.

[0061] S1.4, generating a header file according to the CPU shared resource information; the header file is used to define the number information of register resources;

[0062] For example, the header file name is farm_udl.h, and the content of the header file is as follows:

[0063]

[0064] S1.5, generating a C file according to the CPU shared resource information and the load / store instructions of the corresponding registers;

[0065] Each register resource information will eventually be described as a structure, the definition of this structure is as follows:

[0066]

[0067] By summarizing all CPU information, a C file (for example, the file name is farm_udl.c) can be automatically generated. The C file contains an array with the following content:

[0068]

[0069]

[0070] S1.6, put the header files, C files and assembly files into the source code directory of the corresponding RTOS and integrate them into the operating system.

[0071] Through the above S, three files are obtained:

[0072] Farm_udl.h – contains a macro indicating how many custom register banks there are.

[0073] Farm_udl.c – contains an array containing information about all register groups.

[0074] Farm_udl.S – assembly file, contains save / restore functions corresponding to all register groups.

[0075] S102, add the corresponding hook function in RTOS, and generate an execution file according to the save / restore of the resource; the compiling method is: llvm method, and the method of generating the execution file is: Makefile method.

[0076] S102 specifically includes:

[0077] S2.1, adding a first hook function in the task initialization function in the operating system to allocate memory for the newly added shared hardware resources;

[0078] For example: The following is the specific implementation logic of the first hook function:

[0079] Each RTOS needs to allocate corresponding stack space to the task when it is created, and needs to provide a callback function for the corresponding architecture to initialize the context content of each task when it is first run. In this function, we need to do some special processing. First, reserve a pointer to a memory section to record the information of the current task. The information stored in the memory is as follows:

[0080] structtask_context_info{

[0081] void*context[CONTEXT_MODULE_CNT]; / / Memory for each group of resources.

[0082] };

[0083] This function also needs to allocate corresponding memory for each task to store the task's register data, and save the memory addresses one by one to the context array of the above structure member. In this way, the memory address of the corresponding register data can be extracted with the same index when the task is switched. CONTEXT_MODULE_CNT is defined in farm_udl.h.

[0084] S2.2, add a second hook function to the context switch function corresponding to the RTOS; the second hook function is used to support the context switch of the newly added register.

[0085] The second hook function implements the following functions:

[0086] Automatically scan the C files generated by S1.5 to obtain the save / restore function pointers of resources.

[0087] If the task needs to be switched out, the save function is called and the memory address of the corresponding register group resource is obtained from the stack.

[0088] If the task needs to be switched in, call the restore function to restore the task context.

[0089] The hook function code is:

[0090]

[0091]

[0092] S2.3, compile the save / restore of the resource, the first hook function and the second hook function to generate an execution file.

[0093] S103, automatically adapting to the new CPU using the execution file.

[0094] Usually, RTOS needs to add corresponding support code to support new processors after the processor is designed, according to the actual resource situation of the processor. These codes are usually the code for processing CPU context switching logic. Most current processor designs will add some resources for computing acceleration based on an existing architecture (riscv, arm), and these CPUs are usually completed using some kind of automated EDA tools. All CPU information can be obtained from the EDA tool. The corresponding code logic can be automatically generated, which improves software development efficiency.

[0095] As another specific embodiment, the present invention provides an RTOS automatic adaptation system, including:

[0096] The code generation module is used to extract the CPU description file and determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value during context switching; the CPU shared resource information includes: the number of registers, the length of registers, the name of registers and the abbreviation of registers.

[0097] The execution file generation module is used to add corresponding hook functions in RTOS and generate execution files based on the save / restore of resources.

[0098] The automatic adaptation module is used to automatically adapt to the new CPU using the execution file.

[0099] In order to execute the methods corresponding to the above embodiments to achieve corresponding functions and technical effects, a storage medium is provided, on which computer program instructions are stored, characterized in that the described methods are implemented when the computer program instructions are executed by a processor.

[0100] Based on the above description, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods of various embodiments of the present invention. The aforementioned computer storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk, or an optical disk.

[0101] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0102] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. An RTOS automatic adaptation method, characterized in that: include: Extract the CPU description file to determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value when the context is switched; The CPU shared resource information includes: the number of registers, the length of registers, the name of registers and the abbreviation of registers; Add the corresponding hook function in RTOS and generate the execution file according to the save / restore of the resource; Use executable files to automatically adapt to new CPUs.

2. The RTOS automatic adaptation method according to claim 1, characterized in that: The CPU description file is extracted to determine the CPU shared resource information; and the save / restore of the corresponding resources is generated according to the CPU shared resource information, specifically including: Call the library function farm_get_regfile_list() to obtain CPU shared resource information; Call the library function farm_get_inst_list() to obtain the load / store instructions of the corresponding register; Generate the save and restore functions of the corresponding register file according to the CPU shared resource information and the load / store instructions of the corresponding register; Generate a header file according to the CPU shared resource information; the header file is used to define the number information of register resources; Generate C files based on CPU shared resource information and corresponding register load / store instructions; Put the header files, C files and assembly files into the source code directory of the corresponding RTOS and integrate them into the operating system.

3. The RTOS automatic adaptation method according to claim 1, characterized in that: The corresponding hook function is added in RTOS, and the execution file is generated according to the save / restore of the resource, specifically including: Add a first hook function in the task initialization function in the operating system to allocate memory for the newly added shared hardware resources; Add a second hook function to the context switch function corresponding to the RTOS; the second hook function is used to support the context switch of the newly added register; Compile the resource save / restore, the first hook function and the second hook function to generate an executable file.

4. The RTOS automatic adaptation method according to claim 1, characterized in that: The compilation method is: llvm method.

5. The RTOS automatic adaptation method according to claim 1, characterized in that: The method to generate an executable file is: Makefile method.

6. An RTOS automatic adaptation system, characterized in that: include: A code generation module is used to extract the CPU description file and determine the CPU shared resource information; and generate the save / restore of the corresponding resource according to the CPU shared resource information; the save / restore of the resource is used to save or restore the shared resource value when the context is switched; The CPU shared resource information includes: the number of registers, the length of registers, the name of registers and the abbreviation of registers; The execution file generation module is used to add the corresponding hook function in RTOS and generate the execution file according to the save / restore of resources; The automatic adaptation module is used to automatically adapt to the new CPU using the execution file.

7. A storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.