Serial port para-virtualization method and system of real-time operating system virtual machine

Through shared memory and active frequency conversion polling, the vmexit and blocking problems of real-time operating system virtual machines during serial port data output are solved, efficient serial port data transmission is achieved, and the system's real-time and performance is improved.

CN120256170AInactive Publication Date: 2025-07-04ZHEJIANG UNIV
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510740343.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-07-04
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional vehicle-mounted systems cannot meet the diverse needs of human-computer interaction and real-time vehicle control at the same time. The frequent vmexit and synchronization problems of real-time operating system virtual machines during serial port data output have caused performance impact.

Method used

Using shared memory and active frequency conversion polling, data interaction is organized through a ring queue, the front-end program of the virtual machine in real time judges writability and avoids blockage, and the serial port server actively polls and reads data, using the principle of time localization to balance real-time and performance overhead.

Benefits of technology

It effectively avoids the occurrence of vmexit, reduces the blockage of serial port data output, and improves the operating efficiency and performance of the real-time operating system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256170A_ABST
    Figure CN120256170A_ABST
Patent Text Reader

Abstract

The invention discloses a serial port para-virtualization method and system for a real-time operating system RTOS virtual machine, and the method comprises the steps: configuring a shared memory for the real-time operating system RTOS virtual machine and a serial port server, enabling the real-time operating system RTOS virtual machine to write serial port data into the shared memory, enabling the serial port server to read the data, and printing the data, thereby achieving the para-virtualization of the serial port of the real-time operating system RTOS virtual machine through the data in the shared memory. Whether serial port data can be written or not is judged through a real-time system virtual machine front-end program, if the data cannot be written, other tasks are scheduled firstly, and blocking is avoided; in addition, the serial server further reads the data in the shared memory in an active variable-frequency polling mode, the polling reading mode can avoid vmean in a traditional serial port virtualization mechanism, meanwhile, the variable-frequency polling mode utilizes the temporal locality principle, and the real-time performance of serial port data output and the polling performance overhead are balanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computers, and particularly relates to a serial port para-virtualization method and system for a virtual machine of a real-time operating system. Background Art

[0002] With the intelligent development of automobiles, the task complexity of in-vehicle systems has also increased significantly. On the one hand, general tasks such as human-computer interaction and high-performance computing have requirements for the system ecosystem and computing power. On the other hand, tasks such as vehicle real-time control have strict requirements for the real-time performance of the system. Traditional in-vehicle systems cannot meet the diverse requirements of the above tasks simultaneously. Therefore, virtualization technology is needed to implement a hybrid kernel operating system that can run a real-time operating system (RTOS) and a general-purpose operating system (GPOS) simultaneously to handle the challenges faced by intelligent vehicles.

[0003] Microkernel virtualization is a virtualization technology based on a microkernel. The hybrid kernel system implemented based on this virtualization technology has higher isolation and security. A serial port server is a microkernel process dedicated to printing serial port data. The hybrid kernel system based on the microkernel can achieve serial port virtualization for each virtual machine through the serial port server. In this architecture, for the GPOS virtual machine in the hybrid kernel operating system based on the microkernel architecture, serial port para-virtualization can be performed through the VirtIO para-virtualization standard. For the RTOS virtual machine in this architecture, the impact of virtualization technology on the system real-time performance needs to be considered during the running process.

[0004] During the implementation of serial port para-virtualization, when the real-time operating system virtual machine executes the task of outputting serial port data, it may face the problem that the virtual machine frequently exits vmexit from the current state, and needs to synchronize with the serial port data reading task of the backend program. These problems will seriously affect the running performance of the real-time operating system virtual machine. If the backend program reads serial port data in an active polling manner, the generation of vmexit can be avoided to ensure the efficient operation of the real-time system, but the impact of high-frequency polling needs to be considered at the same time. Summary of the Invention

[0005] To solve the deficiencies of the prior art and achieve the purpose of avoiding frequent generation of vmexit during the running process of the real-time operating system and blocking of the front-end program, the present invention adopts the following technical solutions: A serial port para-virtualization method for a real-time operating system virtual machine, comprising the following steps: Step S1: Configure shared memory for the Real - Time Operating System (RTOS) virtual machine and the serial port server. The RTOS virtual machine writes serial port data into the shared memory, and the serial port server reads the data and prints it. Step S2: The serial port server reads the data in the shared memory by means of active frequency - conversion polling.

[0006] Further, in Step S1, the front - end program in the RTOS virtual machine writes data, and the back - end program in the serial port server reads the data and prints it. The front - end and back - end programs organize data in a circular queue structure based on the shared memory for interaction.

[0007] Further, in the RTOS virtual machine, create a front - end program for writing serial port data. The front - end program is used for printing tasks with a low printing task priority. When the printing task is called, first perform a writable judgment. If it is writable, read data from the memory space storing serial port data and store it in the queue in the shared memory; otherwise, end the call of this printing task and call a task with a higher priority to avoid blocking during the printing of serial port data.

[0008] Further, the front - end program judges whether the circular queue is writable through the head and tail pointers of the circular queue. If the modulus of the tail pointer plus one and the queue length is not equal to the head pointer, it is considered that there is free space in the circular queue, write the data into the circular queue and modify the tail pointer accordingly; otherwise, it is considered that there is no free space in the circular queue and no data writing is performed.

[0009] Further, in Step S2, judge whether there is data in the circular queue by checking the positions of the head pointer and the tail pointer. If the position of the head pointer is not equal to the position of the tail pointer, it means that there is data, and the serial port server reads the data and modifies the head pointer accordingly.

[0010] Further, the reading and modification of the head and tail pointers are implemented by atomic operations.

[0011] Further, the implementation of frequency - conversion polling in Step S2 depends on the current delay variable current_delay, the maximum delay variable max_delay, the minimum delay variable min_delay, and the growth factor x (x > 1); In the initialization stage, the current delay variable current_delay is set to the maximum delay variable max_delay, and then the serial port server will set the current delay variable current_delay as the next check interval; In each polling judgment, if data is found in the queue of the shared memory, the current delay variable current_delay is assigned the minimum delay variable min_delay. If no data is found in the queue, the product of the current value and the growth factor is compared with the maximum delay variable max_delay, and the minimum value is assigned to the current delay variable current_delay.

[0012] The serial port para-virtualization system of the real-time operating system virtual machine includes a real-time operating system RTOS virtual machine, a serial port server, and a microkernel. The real-time operating system RTOS virtual machine virtualizes the microkernel and configures shared memory for the real-time operating system RTOS virtual machine and the serial port server according to the serial port para-virtualization method of the real-time operating system virtual machine. The real-time operating system RTOS virtual machine writes serial port data into the shared memory. The serial port server reads the data in the shared memory by means of active variable-frequency polling and prints the data.

[0013] The advantages and beneficial effects of the present invention are as follows: The present invention organizes the data in the shared memory using a circular queue. The front-end program of the real-time system virtual machine can determine whether serial port data can be written by the head and tail pointers in the circular queue. If the data cannot be written, other tasks are scheduled first to avoid blocking. The back-end program in the serial port server actively reads the data in the circular queue by means of variable-frequency polling. The polling reading method can avoid the occurrence of vmexit in the traditional serial port virtualization mechanism. At the same time, the variable-frequency polling method utilizes the principle of temporal locality to balance the real-time performance of serial port data output and the performance overhead of polling. Brief Description of the Drawings

[0014] Figure 1 It is a schematic diagram of the hybrid kernel system structure based on the microkernel in the prior art.

[0015] Figure 2 It is an architecture diagram of the serial port para-virtualization system of the real-time operating system virtual machine in the embodiment of the present invention.

[0016] Figure 3 It is a flowchart of the serial port para-virtualization method of the real-time operating system virtual machine in the embodiment of the present invention.

[0017] Figure 4 It is a flowchart of the implementation of variable-frequency polling in the embodiment of the present invention. Detailed Embodiments

[0018] The following will describe in detail the specific embodiments of the present invention with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for the purpose of illustrating and explaining the present invention, and are not intended to limit the present invention.

[0019] The existing hybrid kernel operating system architecture based on the microkernel architecture is as Figure 1 shown. In the embodiments of the present invention, the CAmkES framework is used to implement the construction of a hybrid kernel system based on the seL4 microkernel. This system is implemented based on an 8-core CPU of the ARMv8 architecture. Among them, the GPOS virtual machine occupies 4 cores, and the RTOS virtual machine occupies 4 cores. The serial port server shares the CPU cores bound by the GPOS for scheduling. In the serial port para-virtualization of the real-time operating system RTOS virtual machine, due to frequent vmexit during data transmission, the system operation is affected. Therefore, the present invention proposes a serial port para-virtualization system for the real-time operating system virtual machine, as Figure 2 shown, which includes a real-time operating system RTOS virtual machine, a serial port server, a microkernel, and a virtualization manager.

[0020] The real-time operating system RTOS virtual machine virtualizes the microkernel. The serial port server is a microkernel process for printing serial port data to implement the serial port virtualization of the virtual machine. In the system initialization stage, the shared memory of the real-time operating system RTOS virtual machine and the serial port server is configured, and the circular queue is initialized. The front-end program in the real-time operating system RTOS virtual machine writes data and puts the serial port data into the shared memory circular queue. The back-end program in the serial port server reads the data and prints the data. The front-end and back-end programs are based on the shared memory and organize the data in a circular queue structure for interaction.

[0021] The circular queue is obtained by constructing a head pointer head_ptr, a tail pointer tail_ptr, and a queue queue with a length of LEN. The head pointer head_ptr is used for read operations, and the tail pointer tail_ptr is used for write operations.

[0022] The back-end program in the serial port server reads the serial port data from the circular queue in the shared memory in an active polling manner. By checking the positions of the head pointer head_ptr and the tail pointer tail_ptr to determine whether there is data, if head_ptr is not equal to tail_ptr, it means there is data, and the data is taken out and head_ptr is modified.

[0023] Based on the above serial port para-virtualization system, the present invention proposes a serial port para-virtualization method for the real-time operating system virtual machine, as Figure 3 shown, which includes the following steps: Step S1: The Real-Time Operating System (RTOS) virtual machine puts serial port data into the shared memory circular queue. The front-end and back-end programs organize data in a circular queue structure based on the shared memory for interaction. During the system initialization phase, the shared memory between the virtual machine and the serial port server is configured, and the queue is initialized. The front-end program in the virtual machine writes data, and the back-end program in the serial port server reads and prints the data. The circular queue structure is as follows: struct ring { / / Construct the circular queue ring int head_ptr; / / Define the head pointer head_ptr int tail_ptr; / / Define the tail pointer tail_ptr char queue[LEN] / / Construct the queue queue with length LEN } Among them, the head pointer head_ptr is used for read operations, the tail pointer tail_ptr is used for write operations, and LEN is the queue length.

[0024] The front-end driver program in the RTOS virtual machine determines whether the circular queue is writable through the head and tail pointers and performs specific operations, which specifically include the following steps: Step S1.1: The front-end program determines whether the queue is writable. If (tail_ptr + 1) % LEN is not equal to head_ptr, it means there is free space, and proceed to step S1.2; if there is no free space, proceed to step S1.3; Step S1.2: Put the data into the queue and modify the tail pointer tail_ptr; Step S1.3: End this call; In the real-time operating system, a front-end program for writing serial port data is created. This program is a task dedicated to printing, and its priority is lower than that of other major real-time tasks. During the initialization of the real-time system, a memory space for storing serial port data is configured; when the printing task is called, a writability check is first performed. The printing task determines whether data can be written through the pointers in the circular queue. If it is writable, the data is read from the memory space and stored in the circular queue in the shared memory. Both the read and write operations of this shared memory are implemented as atomic operations. If it is not writable, the call to this printing task is ended, and a task with a higher priority is called to avoid blocking during the printing of serial port data.

[0025] Step S2: The serial port server reads data through active variable-frequency polling. The back-end program in the serial port server actively polls the circular queue in the shared memory and processes the data through the head and tail pointers. Among them, the reading of the head and tail pointers and the modification of the head pointer are implemented as atomic operations. It specifically includes the following steps: Step S2.1: The serial port server data processing program is awakened; Step S2.2: Determine whether there is data in the queue. If head_ptr is not equal to tail_ptr, it means there is data, and go to Step S2.3; if not, go to Step S2.4; Step S2.3: Retrieve the data and modify head_ptr; Step S2.4: Set the next polling wake-up time and end the current data processing; Among them, the implementation of variable-frequency polling depends on the current delay variable current_delay, the maximum delay variable max_delay, the minimum delay variable min_delay, and the growth factor x (x > 1).

[0026] In this embodiment, max_delay is 50ms, min_delay is 1ms, and the growth factor x is 1.5.

[0027] As Figure 4 shown, in the initialization stage, current_delay is set to max_delay, and then the serial port server will set current_delay as the next check interval; in each polling judgment, if data is detected, current_delay is assigned min_delay; if no data exists, current_delay is assigned the minimum value of the product of the current value and the coefficient compared with max_delay, that is, min(current_delay * x, max_delay).

[0028] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. Serial semi-virtualization method for real-time operating system virtual machines, characterized in that The steps are as follows: Step S1: Configure shared memory for the real-time operating system RTOS virtual machine and the serial server. The real-time operating system RTOS virtual machine writes serial data into the shared memory, and the serial server reads the data and prints it; Step S2: The serial server reads the data in the shared memory by means of active variable-frequency polling.

2. The serial port para-virtualization method of the real-time operating system virtual machine according to claim 1, characterized in that: In the said Step S1, the front-end program in the real-time operating system RTOS virtual machine writes data, and the back-end program in the serial server reads the data and prints it. The front-end and back-end programs organize data in a circular queue structure based on the shared memory for interaction.

3. The serial port para-virtualization method of the real-time operating system virtual machine according to claim 2, characterized in that: In the real-time operating system RTOS virtual machine, a front-end program for writing serial data is created. The front-end program is used for printing tasks, and the printing task has a low priority. When the printing task is called, a writability check is first performed. If it is writable, data is read from the memory space storing serial data and stored in the queue in the shared memory. Otherwise, the call of the current printing task ends to call a task with a higher priority.

4. The serial port para-virtualization method of the real-time operating system virtual machine according to claim 2, characterized in that: The front-end program determines whether the circular queue is writable through the head and tail pointers of the circular queue. If the modulus of the tail pointer plus one and the queue length is not equal to the head pointer, it is considered that there is free space in the circular queue, and the data is written into the circular queue and the tail pointer is modified accordingly. Otherwise, it is considered that there is no free space in the circular queue and no data is written.

5. The serial port para-virtualization method of the real-time operating system virtual machine according to claim 4, characterized in that: In the said Step S2, it is judged whether there is data in the circular queue by checking the positions of the head pointer and the tail pointer. If the position of the head pointer is not equal to the position of the tail pointer, it means that there is data, and the serial server reads the data and modifies the head pointer accordingly.

6. The serial port para-virtualization method of the real-time operating system virtual machine according to claim 5, characterized in that: The reading and modification of the head and tail pointers are implemented by atomic operations.

7. The serial port paravirtualization method of the real-time operating system virtual machine according to claim 1, characterized in that: The implementation of variable-frequency polling in the said Step S2 depends on the current delay variable, the maximum delay variable, the minimum delay variable, and the growth factor; In the initialization stage, the current delay variable is set to the maximum delay variable, and then the serial server sets the current delay variable as the next check interval; In each polling judgment, if it is detected that there is data in the queue of the shared memory, the current delay variable is assigned the minimum delay variable. If there is no data in the queue, the product of the current value and the growth factor is compared with the maximum delay variable, and the minimum value is assigned to the current delay variable.

8. Serial port para-virtualization system for real-time operating system virtual machines, including a real-time operating system RTOS virtual machine, a serial port server, and a microkernel. The real-time operating system RTOS virtual machine virtualizes the microkernel, and is characterized in that: According to the serial semi-virtualization method of the real-time operating system virtual machine described in Claim 1, configure shared memory for the real-time operating system RTOS virtual machine and the serial server; The real-time operating system RTOS virtual machine writes serial data into the shared memory; The serial server reads the data in the shared memory by means of active variable-frequency polling and prints the data.

Citation Information

Patent Citations

  • Data asynchronization storage and access mechanism applied to industrial control system

    CN103514261A

  • Para-virtualized serial port method, device and system and storage medium

    CN116244036A

  • Data interaction method and system based on direct memory access

    CN117290268A

  • Data transmission method and system between virtual machine and host machine

    CN118069390A

  • KR20230121421A