System and method for non-real-time system to realize hard real-time in hardware-in-loop simulation

By creating real-time model tasks on a personal computer and automatically setting the number of threads, and utilizing the number of computer processor cores, hard real-time simulation of non-real-time systems was achieved. This solved the problems of high hardware investment and difficulty in signal observation, and improved development and testing efficiency as well as the flexibility of simulation signal observation.

CN121742967APending Publication Date: 2026-03-27SHANGHAI TOSUN TECH LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-19
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Existing technologies require real-time systems in hardware-in-the-loop simulation, which increases hardware investment and deployment costs, and makes it impossible to directly observe simulation signals, affecting development and testing efficiency.

Method used

By creating real-time model tasks on a personal computer and automatically setting the number of threads, and utilizing the number of computer processor cores, hard real-time simulation of non-real-time systems can be achieved. This includes single-threaded and multi-threaded execution mechanisms, avoiding critical section synchronization overhead and ensuring simulation time accuracy.

Benefits of technology

It enables the direct running of a hard real-time environment on a personal computer, reducing hardware investment costs and improving development and testing efficiency as well as the flexibility of simulation signal observation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121742967A_ABST
    Figure CN121742967A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of vehicle software development, and particularly relates to a system and method for a non-real-time system to achieve hard real-time in hardware-in-loop simulation, and the system comprises a computer device, a hardware-in-loop simulation device and a hardware-in-loop simulation device. The computer device is configured to execute a task creating module and a task thread setting module; wherein the task creating module is configured to create a real-time model task and form a task program; the task thread setting module is configured to enable a task program to automatically read computer configuration and judge the number Z of processor cores of the current computer device, when the number Z of the cores does not exceed X, the thread number n is set to be equal to 1 so as to execute a real-time model task, otherwise, the thread number n is set to be equal to (Z-X) / Y so as to execute the real-time model task, wherein Y represents the number of threads of one physical core of the processor.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application of the original application with the application number 202311360358.0 and the filing date of October 19, 2023; the divisional application is entitled "System and computer for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation".

[0002] This application is based on and claims priority to U.S. Patent Application No. 18 / 371,543 filed on September 22, 2023. The entire contents of the above application are incorporated herein by reference. TECHNICAL FIELD

[0003] The present application belongs to the technical field of vehicle software development, and specifically relates to a system and computer for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation. BACKGROUND

[0004] In order to perform the task of hardware-in-the-loop simulation, it is often necessary to rely on a real-time system and deploy the execution of the task in the real-time system. The real-time system is on another computer and not local. Any action needs to be completed by remote calling, which causes problems such as the inability to directly observe the related signals and key signals that determine the algorithm function and performance. SUMMARY

[0005] The purpose of the present application is to provide a system and computer for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation.

[0006] In order to solve the above technical problems, the present application provides a system for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation, which comprises a computer device configured to execute a task creation module and a task thread setting module; wherein

[0007] The task creation module is configured to create a real-time model task and form a task program.

[0008] The task thread setting module is configured to make the task program automatically read the computer configuration and judge the number Z of processor cores of the current computer device. When the number Z of processor cores does not exceed X, the number n of threads is set to 1 to execute the real-time model task, otherwise the number n of threads is set to (Z-X) / Y to execute the real-time model task, wherein

[0009] Y represents the number of threads of one physical core of the processor.

[0010] In another aspect, the present application also provides a computer device for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation, which comprises a processor configured to execute the task creation module and the task thread setting module.

[0011] The beneficial effect of the present application is that the present application realizes that the virtual hardware real-time environment can be directly run in a personal computer when performing a hardware-in-the-loop simulation task to achieve hard real-time, that is, there is no need to purchase a real-time system, and since all operations are performed locally, the development and testing efficiency is greatly improved.

[0012] Other features and advantages of the present application will be set forth in the descriptions that follow, and in part will be apparent from the description, or can be learned by practice of the application. The objects and other advantages of the application will be realized and attained by the structure particularly pointed out in the description and the drawings.

[0013] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the following preferred embodiments are specifically described below, and the accompanying drawings are described in detail as follows. BRIEF DESCRIPTION OF DRAWINGS

[0014] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.

[0015] Figure 1 A step diagram of a method for implementing hard real-time by a non-real-time system in hardware-in-the-loop simulation is shown;

[0016] Figure 2 A principle block diagram of a system for implementing hard real-time by a non-real-time system in hardware-in-the-loop simulation is shown;

[0017] Figure 3 A principle block diagram of an electronic device is shown. DETAILED DESCRIPTION

[0018] In order to make the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of the present application will be described clearly and completely in the following with reference to the drawings. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the present application.

[0019] At present, when the same kind of software performs a hardware-in-the-loop simulation task, it generally achieves hard real-time through a real-time system, which needs to increase hardware investment and deployment cost, and the method for implementing hard real-time by a non-real-time system in hardware-in-the-loop simulation of some embodiments does not need to additionally increase a real-time system, and can also achieve hard real-time in a non-real-time system.

[0020] Specifically, some embodiments provide a method for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation, comprising: creating a real-time model task and forming a task program; the task program automatically reads computer configuration and judges the number Z of processor cores of the current computer device, when the number Z of processor cores does not exceed X, setting the number n of threads to 1 to execute the real-time model task, otherwise setting the number n of threads to (Z-X) / Y to execute the real-time model task, wherein Y represents the number of threads of one physical core of the processor.

[0021] The method for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation according to some embodiments realizes that when executing a hardware-in-the-loop simulation task, a virtual hard real-time environment can be directly run in a personal computer to achieve hard real-time, that is, there is no need to purchase a real-time system, and because all operations are performed locally, the development and testing efficiency is greatly improved, and the flexibility of simulation signal observation and modification is increased. For example, if it is desired to observe a local variable, the local program code can be modified at any time to add functions such as printing information, observation information, and curve drawing signal information, and the modified code can be immediately run after local compilation, which is efficient. In the traditional approach, an input and output interface needs to be designed for the local variable, the simulation model interface table needs to be updated, the entire code program needs to be compiled, the real-time system software needs to be redeployed, the simulation model needs to be remotely run, and then observation can be performed.

[0022] Various non-limiting implementations of the embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.

[0023] As shown in FIG. 1, some embodiments provide a method for implementing hard real-time in non-real-time system in hardware-in-the-loop simulation, comprising: Figure 1

[0024] Step S101, creating a real-time model task and forming a task program;

[0025] Step S102, the task program automatically reads computer configuration and judges the number Z of processor cores of the current computer device, when the number Z of processor cores does not exceed X, setting the number n of threads to 1 to execute the real-time model task, otherwise setting the number n of threads to (Z-X) / Y to execute the real-time model task, wherein

[0026] Y represents the number of threads of one physical core of the processor.

[0027] Specifically, the real-time model task is a timing program, and the real-time model task is created by first creating a timer. After creating the timer, the period of the timer is set, for example, 500 microseconds. Then the step function of the model is called according to this period, and the task program formed is a code module for simulating the real-time model task.

[0028] ​The number of processor cores Z is determined by the processor model. Different processor models have completely different numbers of cores Z. For example, the Intel Xeon Platinum 9282 has 56 cores Z, while the Intel Core i5-2520M has 2 cores Z.

[0029] When Z does not exceed X, it indicates that the current computer performance is weak and it is not suitable to use multiple threads to execute the simulation. Otherwise, it will cause the local computer to freeze. In this case, it is suitable to execute the real-time model task with a single thread, that is, set the number of threads n=1 to execute the real-time model task.

[0030] When Z exceeds X, in order to prevent multi-threaded simulation execution under weak computer performance, it is necessary to limit the minimum value of X, that is, to limit the minimum value of the number of computer cores Z for multi-threaded simulation tasks. In the extreme case X=0, the number of threads n=Z / Y is exactly equal to the number of real physical cores. When X is non-zero, it means that X / Y real physical cores are reserved as proprietary cores. These proprietary cores do not participate in the simulation, thus ensuring the smooth operation of the software system and other software.

[0031] As one implementation of some embodiments, setting the number of threads to n=1 to execute real-time model tasks includes:

[0032] Define the real-time interval m for the execution of the real-time model task;

[0033] The thread obtains the current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next.

[0034] When t > t_next, then t_next = t_next + m, and the real-time model task is executed simultaneously.

[0035] It should be noted that when the real-time model task is executed for the first time, t_next = m, t = 0.

[0036] Specifically, let's explain in detail, with examples, how to execute real-time model tasks when n=1:

[0037] With X=4, when the computer device's processor model is Intel Core i5-2520M, the number of cores Z=2, which is less than 4. This indicates that the current computer performance is weak and it is not suitable to use multiple threads to execute the simulation. Otherwise, it will cause the computer to freeze. In this case, it is suitable to execute the real-time model task with a single thread, that is, set the number of threads n=1 to execute the real-time model task.

[0038] Since only one thread executes the real-time model task, the operation of determining whether the current time t is greater than the next execution time t_next does not involve multi-threaded preemption. Therefore, there is no need to use critical sections or other means for thread synchronization, which can reduce the performance overhead caused by introducing critical sections. However, the inherent defects of single-threaded operation are also apparent. When the processor time slice of this thread is preempted due to operating system scheduling, the locking precision of the time t_next will decrease.

[0039] When executing a real-time model task in a single thread, the real-time time interval for the task is set to m = 500 microseconds. The pseudocode for this thread executing the real-time model task is as follows:

[0040]

[0041]

[0042] Among them, "is_running" is the simulation running enable flag. When the simulation is terminated by the user or exits naturally, this flag is false and the algorithm will no longer execute the while loop; "get_current_time_stamp_us()" is an internal function of the simulation system used to obtain the current time stamp in microseconds.

[0043] "run_model_task()" is an internal function of the simulation system used to periodically call the model's step function; "other_task()" is another task of the Windows system, in which Sleep(1) can be executed to reduce the current processor's consumption of processor time.

[0044] As another implementation of some embodiments, when the number of threads is n = (ZX) / Y, and the number of cores Z exceeds X, it indicates that the processor of the current computer device is suitable for enabling multi-threaded simulation. The method for executing real-time model tasks includes:

[0045] Define the real-time interval m for the execution of the real-time model task;

[0046] Each thread simultaneously obtains its current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next;

[0047] When at least one thread detects that t > t_next, that thread attempts to enter the critical section. At this time, other threads are blocked from entering the critical section. Once the thread successfully enters the critical section, the flag indicating that t > t_next is invalidated. Therefore, the thread that successfully entered the critical section will execute the following content within the critical section:

[0048] Repeatedly retrieve the current time t and determine if the current time t is greater than the next execution time t_next:

[0049] If so, then t_next = t_next + m, and simultaneously execute the real-time model task and exit the critical section;

[0050] If not, the thread will exit the critical section directly.

[0051] Specifically, let's explain in detail, with examples, how to execute real-time model tasks when n = (ZX) / Y:

[0052] Given X=2 and Y=2, when the computer device's processor is an Intel Core i7-8700, the number of cores Z=6, which is greater than 2. Therefore, the number of threads n=(ZX) / Y=(6-2) / 2=2 to execute the real-time model task.

[0053] Define two threads, thread 0 and thread 1.

[0054] If the real-time time interval for executing the real-time model task is defined as m = 500 microseconds, then the pseudocode for each thread executing the model task is as follows:

[0055]

[0056]

[0057] Among them, "is_running" is the simulation running enable flag. When the simulation is terminated by the user or exits naturally, this flag is false, and the algorithm no longer executes the while loop; "get_current_time_stamp_us()" is an internal function of the simulation system, used to obtain the current time stamp in microseconds; "EnterCriticalSection" is a Windows system API function, used to enter the critical section; "FSection" is a critical section object shared by multiple threads; "LeaveCriticalSection" is a Windows API function, used to exit the critical section; "run_model_task()" is an internal function of the simulation system, used to periodically call the model's step function; "other_task()" is other tasks of the Windows system, such as executing Sleep(1) to reduce the current processor's time consumption.

[0058] The above pseudocode effectively alleviates the situation where simulation time accuracy decreases due to a single thread being deprived of processor time by system scheduling. In other words, the above method effectively ensures simulation time accuracy, thereby guaranteeing simulation real-time performance.

[0059] Threads that fail to enter the critical section are blocked from entering the critical section until the thread that entered the critical section leaves the critical section, at which point the next attempt will begin.

[0060] Taking the aforementioned method of executing real-time model tasks with n=2 threads as an example, when thread 0 fails to determine the next execution time t_next in time due to system scheduling, thread 1 has a high probability of determining the next execution time t_next. Upon recognizing t > t_next, it successfully enters the critical section and prioritizes the execution of the model task. At this point, thread 0 will be blocked in the code line entering the critical section. Only after thread 1 completes the real-time model task and exits the critical section will thread 0 begin determining whether the current time t is greater than the next execution time t_next. If thread 0 successfully enters the critical section at this point, it will update the current time t again (i.e., repeatedly obtain the current time t) and determine that the current time t is already less than the next execution time t_next (which has already been updated by thread 1). In this case, thread 0 will not execute the real-time model task but will immediately exit the critical section, waiting for the next determination.

[0061] The number of threads that successfully enter the critical section is determined by the critical section itself. In other words, the number of threads that successfully enter the critical section is randomly determined by the Windows system.

[0062] `t_next` is a shared global variable across all threads. This means multiple threads can access the same variable simultaneously. The fact that each thread can share access to the same variable ensures that if any thread detects that the current time `t` is greater than the next execution time `t_next`, it can immediately attempt to enter the critical section. This effectively mitigates the situation where a single thread is deprived of processor time due to system scheduling, thus preventing a decrease in simulation time accuracy and effectively guaranteeing simulation time precision.

[0063] Each thread occupies one physical core of the processor, including:

[0064] The physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation between the corresponding thread number index and the total number of physical cores of the processor.

[0065] Each thread can occupy one physical core of the processor to achieve the best performance of the computer device.

[0066] For example, if there are 10 threads and the total number of physical cores of the processor is 8, then the physical core index of the processor occupied by thread 0 is equal to the value obtained by performing a modulo operation between 0 and 8, which is 0; the physical core index of the processor occupied by thread 9 is equal to the value obtained by performing a modulo operation between 9 and 8, which is 1.

[0067] The method disclosed herein for achieving hard real-time in a non-real-time system during hardware-in-the-loop simulation enables the execution of hardware-in-the-loop simulation tasks by directly running a virtual hard real-time environment on a personal computer, thus achieving hard real-time performance without the need to purchase a real-time system. Furthermore, since all operations are performed locally, it greatly improves development and testing efficiency and increases the flexibility of observing and modifying simulation signals.

[0068] like Figure 2 As shown, some embodiments also provide a system for implementing hard real-time in a non-real-time system during hardware-in-the-loop simulation, including a computer device configured to execute a task creation module and a task thread setting module; wherein

[0069] The task creation module is configured to create real-time model tasks and form task programs;

[0070] The task thread setting module is configured to enable the task program to automatically read the computer configuration and determine the number of processor cores Z of the current computer device. When the number of cores Z does not exceed X, the number of threads n = 1 is set to execute the real-time model task; otherwise, the number of threads is set to n = (ZX) / Y to execute the real-time model task.

[0071] Y represents the number of threads in one physical core of the processor.

[0072] In some embodiments, the functions performed by the task creation module and the task thread setting module are implemented in a computer device. For details, please refer to the specific description of the method for implementing hard real-time in a non-real-time system in the aforementioned hardware-in-the-loop simulation, which will not be repeated here.

[0073] The electronic devices in some embodiments are described below from the perspective of hardware processing:

[0074] Some embodiments disclosed herein do not limit the specific implementation of the electronic device.

[0075] like Figure 3 As shown, this electronic device includes: a processor, a readable storage medium, a communication bus, and a communication interface; wherein the processor, the readable storage medium, and the communication interface communicate with each other through the communication bus; the readable storage medium is used to store a program for executing the method of implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation as described in this embodiment, the program causing the processor to execute the operation corresponding to the method of implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation.

[0076] In other embodiments, computer devices and industrial control computers can also be used as a type of electronic device.

[0077] Figure 3The structure shown does not constitute a limitation on the electronic device and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0078] In some embodiments, the communication interface may be RS232, RS485, USB, or TYPE, and can be connected to an external bus adapter. It may also include a wired or wireless network interface, which may optionally include a wired interface and / or a wireless interface (such as a Wi-Fi interface, Bluetooth interface, etc.), typically used to establish communication connections between the computer device and other electronic devices.

[0079] The readable storage medium or computer-readable storage medium includes at least one type of memory, such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, it can be an internal storage unit of a computer device, such as the hard disk of the computer device. In other embodiments, the memory can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device. Furthermore, the memory can include both internal storage units and external storage devices of the computer device. The memory can be used not only to store application software and various types of data installed on the computer device, such as computer program code, but also to temporarily store data that has been output or will be output.

[0080] In some embodiments, a processor may be a processor, controller, microcontroller, microprocessor, or other data processing chip for running program code stored in memory or processing data, such as executing computer programs.

[0081] In some embodiments, the communication bus can also be an input / output bus, which may be a Peripheral Component Interconnect (PCI) bus or an Enhanced Industry Standard Architecture (EISA) bus, etc. This bus can be divided into address bus, data bus, control bus, etc.

[0082] Optionally, the computer device may also include a user interface, which may include a display, an input unit such as a keyboard, and optionally, a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the computer device and to display a visual user interface.

[0083] When the processor executes the program, it implements the above. Figure 1 The steps in the embodiment of the method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation shown are as follows: Figure 1 The steps S101 to S102 are shown. Alternatively, the processor executes the computer program to implement the functions of each module or unit in the above-described device embodiments.

[0084] In some embodiments, the processor is specifically configured to implement the following steps:

[0085] Create real-time model tasks and form task programs;

[0086] The task program automatically reads the computer configuration and determines the number of processor cores Z of the current computer device. If the number of cores Z does not exceed X, the number of threads n = 1 is set to execute the real-time model task; otherwise, the number of threads is set to n = (ZX) / Y to execute the real-time model task.

[0087] Y represents the number of threads in one physical core of the processor.

[0088] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0089] Setting the number of threads to n=1 to execute real-time model tasks includes:

[0090] Define the real-time interval m for the execution of the real-time model task;

[0091] The thread obtains the current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next.

[0092] When t > t_next, then t_next = t_next + m, and the real-time model task is executed simultaneously.

[0093] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0094] When the real-time model task is executed for the first time, t_next = m, t = 0.

[0095] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0096] Setting the number of threads to n = (ZX) / Y to execute real-time model tasks includes:

[0097] Define the real-time interval m for the execution of the real-time model task;

[0098] Each thread simultaneously obtains its current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next;

[0099] When at least one thread detects that t > t_next, that thread attempts to enter the critical section. A thread that successfully enters the critical section will execute the following within the critical section:

[0100] Repeatedly retrieve the current time t and determine if the current time t is greater than the next execution time t_next:

[0101] If so, then t_next = t_next + m, and simultaneously execute the real-time model task and exit the critical section;

[0102] If not, the thread will exit the critical section directly.

[0103] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0104] Threads that fail to enter the critical section are blocked from entering the critical section until the thread that entered the critical section leaves the critical section, at which point the next attempt will begin.

[0105] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0106] The number of threads that successfully enter the critical section is determined by the critical section itself.

[0107] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0108] t_next is a shared global variable for all threads.

[0109] Optionally, as one possible implementation, the processor can also be used to implement the following steps:

[0110] Each thread occupies one physical core of the processor, including:

[0111] The physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation between the corresponding thread number index and the total number of physical cores of the processor.

[0112] Some embodiments also provide a computer-readable storage medium configured to store a program for executing the method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation as described in the preceding embodiments. When executed by a processor, the program can implement the specific steps of the method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation. Please refer to the detailed description of the method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation, which will not be repeated here.

[0113] Some embodiments also provide a computer program product, including a computer program or instructions, wherein when the computer program or instructions are executed on a computer, the computer is able to perform any of the above-described methods for implementing hard real-time systems in a non-real-time system in a hardware-in-the-loop simulation.

[0114] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0115] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0116] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0117] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A system for implementing hard real-time operation in a non-real-time system during hardware-in-the-loop simulation, characterized in that, Includes a computer device configured to execute a task creation module and a task thread setting module; in The task creation module is configured to create real-time model tasks and form task programs; The task thread setting module is configured to enable the task program to automatically read the computer configuration and determine the number of processor cores Z of the current computer device. When the number of cores Z exceeds X, the number of threads is set to n = (ZX) / Y to execute the real-time model task. Y represents the number of threads in one physical core of the processor, and Z is set to be greater than X, and X is not equal to 0.

2. The system according to claim 1, characterized in that, Setting the number of threads to n = (ZX) / Y to execute real-time model tasks includes: Define the real-time interval m for the execution of the real-time model task; Each thread simultaneously obtains its current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next; When at least one thread detects that t > t_next, that thread attempts to enter the critical section. A thread that successfully enters the critical section will execute the following within the critical section: Repeatedly retrieve the current time t and determine if the current time t is greater than the next execution time t_next: If so, then t_next = t_next + m, and simultaneously execute the real-time model task and exit the critical section; If not, the thread will exit the critical section directly. Each thread occupies one physical core of the processor.

3. The system according to claim 1, characterized in that, Also includes: The number of threads is set to n=1 to execute real-time model tasks, which include: Define the real-time interval m for the execution of the real-time model task; The thread obtains the current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next. When t > t_next, then t_next = t_next + m, and the real-time model task is executed simultaneously.

4. The system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 3, characterized in that, When the real-time model task is executed for the first time, t_next = m, t = 0.

5. The system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 1, characterized in that, Threads that fail to enter the critical section are blocked from entering the critical section until the thread that entered the critical section leaves the critical section, at which point the next attempt will begin.

6. The system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 5, characterized in that, The number of threads that successfully enter the critical section is determined by the critical section itself.

7. The system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 1, characterized in that, t_next is a shared global variable for all threads.

8. The system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 1, characterized in that, Each thread occupies one physical core of the processor, including: The physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation between the corresponding thread number index and the total number of physical cores of the processor.

9. A computer device, characterized in that, A system for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation as described in any one of claims 1-8, comprising a processor configured to execute the task creation module and the task thread setting module.

10. A method for implementing hard real-time in a non-real-time system during hardware-in-the-loop simulation, characterized in that, include: Create real-time model tasks and form task programs; The task program automatically reads the computer configuration and determines the number of processor cores Z of the current computer device. When the number of cores Z does not exceed X, the number of threads n = 1 is set to execute the real-time model task; that is... Define the real-time interval m for the execution of the real-time model task; The thread obtains the current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next. When t > t_next, then t_next = t_next + m, and the real-time model task is executed simultaneously.

11. The method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 10, characterized in that, When the real-time model task is executed for the first time, t_next = m, t = 0.

12. The method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 10, characterized in that, When the number of kernels Z exceeds X, the number of threads is set to n = (ZX) / Y to execute real-time model tasks, where Y represents the number of threads in one physical core of the processor, and Z is set to be greater than X, and X is not equal to 0; Setting the number of threads to n = (ZX) / Y to execute real-time model tasks includes: Define the real-time interval m for the execution of the real-time model task; Each thread simultaneously obtains its current time t in real time and determines in real time whether the current time t is greater than the next execution time t_next; When at least one thread detects that t > t_next, that thread attempts to enter the critical section. A thread that successfully enters the critical section will execute the following within the critical section: Repeatedly retrieve the current time t and determine if the current time t is greater than the next execution time t_next: If so, then t_next = t_next + m, and simultaneously execute the real-time model task and exit the critical section; If not, the thread will exit the critical section directly. Each thread occupies one physical core of the processor, including: The physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation between the corresponding thread number index and the total number of physical cores of the processor.

13. The method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 10, characterized in that, Threads that fail to enter the critical section are blocked from entering the critical section until the thread that entered the critical section leaves, at which point a second attempt will begin; and The number of threads that successfully enter the critical section is determined by the critical section itself.

14. The method for implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation according to claim 10, characterized in that, t_next is a shared global variable for all threads.

15. A computer-readable storage medium, characterized in that, The computer-readable storage medium is configured to store a program for implementing a method for hard real-time systems in a hardware-in-the-loop simulation as described in any one of claims 10-14.

16. A processor, characterized in that, The processor is configured to execute a program for implementing a method for hard real-time systems in hardware-in-the-loop simulation as described in any one of claims 10-14.

17. An electronic device comprising: Processor, readable storage medium, communication bus and communication interface; The processor, the readable storage medium, and the communication interface communicate with each other via the communication bus. The readable storage medium is used to store a program for executing the method of implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation as described in any one of claims 10-14, the program causing a processor to execute operations corresponding to the method of implementing hard real-time in a non-real-time system in hardware-in-the-loop simulation.