Search

CN-121501286-B - Program real-time compiling method and device for real-time kernel and storage medium

CN121501286BCN 121501286 BCN121501286 BCN 121501286BCN-121501286-B

Abstract

The application provides a program real-time compiling method and device for a real-time kernel and a storage medium. The method comprises the steps of constructing and running an operating system with real-time kernel capability on a target hardware platform, determining a real-time interface library and a real-time equipment driving model of the operating system as compiling and linking dependence, carrying out real-time transformation on a high-level language compiler and a runtime key library to generate a transformed tool chain, introducing the real-time interface library into the construction and linking configuration of the runtime key library, bringing an interface and a data structure of the real-time equipment driving model into the visible range of the runtime key library, setting real-time constraint on a concurrent scheduling and timer mechanism, compiling application source codes by utilizing the transformed tool chain, and introducing the real-time interface library in the linking stage to obtain a real-time application program running on the operating system. The application can realize real-time compiling, unified interface adaptation, cross-architecture multiplexing and deterministic operation of source codes without modification.

Inventors

  • WANG CHAO
  • WANG YANLONG
  • LIU JINGJING
  • AN FEI
  • SUN YAN

Assignees

  • 北京凡书信息技术有限公司

Dates

Publication Date
20260508
Application Date
20251021

Claims (9)

  1. 1. A program real-time compiling method facing to a real-time kernel is characterized by comprising the following steps: constructing and running an operating system with real-time kernel capability on a target hardware platform, and determining a real-time interface library and a real-time equipment driving model of the operating system as the dependence of compiling and linking; Real-time transformation is carried out on a high-level language compiler and a runtime key library to generate a transformed tool chain, wherein the real-time transformation comprises the steps of introducing the real-time interface library into the construction and link configuration of the runtime key library, bringing the interface and the data structure of the real-time equipment driving model into the visible range of the runtime key library, and setting real-time constraint on concurrent scheduling and timer mechanisms; Compiling application source codes by utilizing the modified tool chain, and introducing the real-time interface library in a linking stage to obtain a real-time application running on the operating system; The method comprises the steps that a runtime critical library configures a real-time critical concurrency unit when the runtime critical library is executed, wherein the configuration comprises the steps of assigning priority of a real-time task at the bottom layer for the real-time critical concurrency unit, assigning processor affinity for the real-time critical concurrency unit, and carrying out limited encapsulation on system call generating non-deterministic blocking; the real-time transformation is performed on the high-level language compiler and the runtime key library to generate a transformed tool chain, which comprises the following steps: Introducing the real-time interface library into the construction and link configuration of the key library in the operation, and establishing a call mapping of timing, scheduling and synchronization related calls to the real-time interface library; The interface and the data structure of the real-time equipment driving model are brought into the visible range of the runtime key library, and an equipment access adaptation layer is set for user mode call; setting real-time constraint on concurrent scheduling and a timer mechanism, wherein the real-time constraint comprises the steps of establishing a priority binding relation between a real-time critical concurrent unit and a corresponding real-time task, and setting processor affinity for the real-time critical concurrent unit; Performing limited encapsulation on the system call generating the non-deterministic blocking, and replacing or bypassing the system call by an equivalent interface provided by the real-time interface library; Uniformly configuring timing and awakening paths, and presetting a time base by using a clock and timing service provided by the real-time interface library when compiling and linking the runtime key library; And presetting and linking the real-time interface library and the dependent parameter templates in a compiler option, and outputting a modified tool chain for compiling and linking.
  2. 2. The method of claim 1, wherein said building and running an operating system with real-time kernel capabilities on a target hardware platform, determining a real-time interface library and a real-time device driver model of the operating system as a compilation and linking dependency, comprises: generating and starting an operating environment of a real-time kernel on the target hardware platform by a collaborative kernel construction mode or a compatible construction mode based on a real-time frame; installing a real-time interface library matched with the running environment, and starting a device access interface based on a real-time device driving model; Registering header files, binary and symbol information of the real-time interface library and the real-time equipment driving model as a compiling and linking dependency list, and setting version identification for the compiling and linking dependency list; Performing parameterization setting on a timing source, a preemption and priority strategy and a device access channel, so that the parameterization setting is used as interface configuration of a key library in operation; And completing the availability verification of the real-time interface library and the equipment access interface in the running environment, and externally providing a link configuration and retrieval path called by the compiler and the tool chain.
  3. 3. The method of claim 1, wherein introducing the real-time interface library in the build and link configuration of the runtime critical library creates a call map of timing, scheduling and synchronization related calls to the real-time interface library, comprising: Setting a head file and a library file retrieval path of the real-time interface library in a construction script, and designating the real-time interface library, a dependent link sequence and a symbol analysis priority in a link option; setting a call adaptation layer in a key library in operation, and redirecting the abstract interfaces which are timed, scheduled and synchronized to the equivalent interfaces of the real-time interface library; replacing the universal implementation with the implementation provided by the real-time interface library by means of conditional compiling or linking aliases; Mapping synchronization primitives to a synchronization interface provided by the real-time interface library, mapping thread creation, priority configuration and processor affinity setting to a task and scheduling interface provided by the real-time interface library, and mapping timing and timer creation to a clock and timing interface provided by the real-time interface library.
  4. 4. The method of claim 1, wherein said incorporating the interface and data structure of the real-time device driver model into the visible range of the runtime critical library and setting a device access adaptation layer for user mode invocation comprises: Introducing a header file, type definition and constant declaration of the real-time equipment driving model into the construction configuration of a key library in the running process, and finishing symbol visibility and dependency registration; setting up a device access adaptation layer in a key library in operation, and providing a unified device access interface facing to a user mode; Mapping the equipment interrupt and event notification into an event and timing interface provided by the real-time interface library, and waking up and waiting in a user state in a configurable timeout mode; establishing error code and state code mapping of equipment access, and unifying codes returned by the real-time equipment driving model into error representation of a key library in operation; Generating a configuration list and a link identifier of the device access adaptation layer, wherein the configuration list and the link identifier are referenced by a tool chain when compiling and linking and are integrated with a real-time application program.
  5. 5. The method of claim 1, wherein setting real-time constraints on the concurrency schedule and timer mechanism includes establishing priority binding relationships between real-time critical concurrency units and corresponding real-time tasks, and setting processor affinities for the real-time critical concurrency units, comprising: registering real-time attributes for the real-time key concurrency units in a runtime key library, and generating corresponding real-time tasks when the real-time key concurrency units are created according to the real-time attributes; Setting processor affinity for real-time critical concurrency units in the form of an affinity mask or a processor set, and adopting affinity configuration in task creation and migration control; creating a timer for a real-time critical concurrency unit based on a clock and timing service provided by the real-time interface library, wherein the timer comprises single timing and periodic timing, and performs expiration judgment and awakening on a unified time basis; Mapping event waiting, awakening and overtime processing associated with the concurrency unit into a synchronous and timing interface provided by the real-time interface library, and recording the real-time attribute, the affinity configuration and the timer parameters in a configuration list of a key runtime library so as to be preset and integrated with a real-time application program when compiling and linking.
  6. 6. The method of claim 1, wherein compiling application source code using the modified tool chain, introducing the real-time interface library during a linking phase, and obtaining a real-time application running on the operating system, comprises: selecting a modified compiler at a compiling inlet, and loading a preset parameter template and a link script; Referencing a configuration list of the runtime key library and the device access adaptation layer in the compiling process, and bringing the header file path, the library file path and the symbol analysis rule recorded in the configuration list into a compiling and linking range; linking the real-time interface library and the dependency library according to a preset sequence in a linking stage, and merging calling mapping about timing, scheduling and synchronization in the configuration list; Generating an executable file or loadable target containing the run-time key library and the equipment access adaptation layer, and outputting a corresponding symbol table and a link identifier; For different processor architectures, the matched modified tool chain is invoked to complete the same compiling and linking process, and the constructed modified tool chain and parameter templates are multiplexed under the same processor architecture.
  7. 7. A real-time kernel-oriented program real-time compiling device, comprising: The building module is used for building and running an operating system with real-time kernel capability on a target hardware platform, and determining a real-time interface library and a real-time equipment driving model of the operating system as compiling and linking dependence; The transformation module is used for carrying out real-time transformation on the high-level language compiler and the runtime key library to generate a transformed tool chain, wherein the real-time transformation comprises the steps of introducing the real-time interface library into the construction and link configuration of the runtime key library, bringing the interface and the data structure of the real-time equipment driving model into the visible range of the runtime key library, and setting real-time constraint on a concurrent scheduling and timer mechanism; The system comprises a real-time key concurrency unit, a compiling module, a configuration module, a processing module and a processing module, wherein the real-time key concurrency unit is used for compiling application program source codes by utilizing the modified tool chain, introducing the real-time interface library in a linking stage to obtain a real-time application program running on the operating system, and the configuration comprises the steps of assigning the priority of a bottom real-time task to the real-time key concurrency unit, assigning the processor affinity to the real-time key concurrency unit, and carrying out limited encapsulation on system call generating non-deterministic blocking; The transformation module is used for introducing the real-time interface library into construction and link configuration of a runtime key library, establishing call mapping for timing, scheduling and synchronization related calls to the real-time interface library, bringing an interface and a data structure of the real-time equipment driving model into a visible range of the runtime key library, setting an equipment access adaptation layer for user mode calls, setting real-time constraint on a concurrent scheduling and timer mechanism, comprising establishing a priority binding relation between a real-time key concurrency unit and a corresponding real-time task, setting processor affinity for the real-time key concurrency unit, carrying out limited encapsulation on system call generating non-deterministic blocking, replacing or bypassing an equivalent interface provided by the real-time interface library, carrying out unified configuration on timing and wakeup paths, enabling the runtime key library to be preset with clock and timing services provided by the real-time interface library as time bases when compiling and linking, presetting a parameter template for linking the real-time interface library and relying on in a compiler option, and outputting a transformed tool chain for compiling and linking.
  8. 8. An electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 6 when executing the computer program.
  9. 9. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the steps of the method according to any one of claims 1 to 6.

Description

Program real-time compiling method and device for real-time kernel and storage medium Technical Field The present application relates to the field of computer technologies, and in particular, to a method and apparatus for compiling a program in real time for a real-time kernel, and a storage medium. Background The industrial Internet of things scene puts higher requirements on the certainty and low jitter of end-side software, and the common practice is to realize protocol stacks, control and driving in low-level languages such as C language on a system with a real-time kernel. Although the path can meet the time limit, the development efficiency is low, the learning cost is high, and the non-compatible interface, clock and interrupt model are required to be modified when different processor architectures or different real-time operating systems are transplanted, so that the burden is heavy. The Go language which is rising in recent years has the advantages of simple grammar, concurrency, friendly property, ecological abundance and the like, industrial protocol and edge application resources are sufficient, engineering efficiency can be remarkably improved, but the original compiling products are influenced by scheduling and garbage recycling in running, system calling and timing precision are limited by a general kernel, and hard real-time requirements are difficult to directly meet. Xenomai provides a real-time interface library and device driver model that supports deterministic scheduling and high precision timing. However, the prior art lacks a system method for compiling Go language application into real-time application without modifying source code at the tool chain and runtime level, lacks a unified scheme for mapping real-time interfaces, adapting device access and multiplexing across architectures, resulting in insufficient real-time development and migration efficiency and decentralized deterministic guarantee means. Disclosure of Invention In view of the above, the embodiments of the present application provide a method, an apparatus, and a storage medium for real-time compiling a program for a real-time kernel, so as to solve the problems in the prior art that development and migration efficiency is low, deterministic real-time constraint is difficult to satisfy without changing source codes, and a unified real-time interface and device access compiling link adaptation mechanism is lacking. The embodiment of the application provides a program real-time compiling method for a real-time kernel, which comprises the steps of constructing and running an operating system with real-time kernel capability on a target hardware platform, determining a real-time interface library and a real-time equipment driving model of the operating system as compiling and linking dependence, carrying out real-time transformation on a high-level language compiler and a runtime key library to generate a transformed tool chain, wherein the real-time transformation comprises the steps of introducing the real-time interface library into the construction and linking configuration of the runtime key library, bringing an interface and a data structure of the real-time equipment driving model into the visible range of the runtime key library, setting real-time constraint on a concurrent scheduling and timer mechanism, compiling application source codes by utilizing the transformed tool chain, introducing the real-time interface library in a linking stage to obtain a real-time application program running on the operating system, configuring a real-time key concurrency unit during execution, and configuring a real-time concurrency unit comprises the priority of a real-time concurrency unit, designating a processor affinity for the real-time concurrency unit, and carrying out non-blocking system call generation, and carrying out configuration during the compiling and limiting the system in the running and the critical application program. The second aspect of the embodiment of the application provides a program real-time compiling device for a real-time kernel, which comprises a building module, a compiling module, a modifying module and a compiling module, wherein the building module is used for building and running an operating system with real-time kernel capability on a target hardware platform, determining a real-time interface library and a real-time equipment driving model of the operating system as compiling and linking dependence, the modifying module is used for carrying out real-time modification on a high-level language compiler and a run-time key library to generate a modified tool chain, the real-time modification comprises the steps of introducing the real-time interface library into the building and linking configuration of the run-time key library, bringing an interface and a data structure of the real-time equipment driving model into the visible range of the run-time key library, setting real-time constraint o