Method and system for realizing hard real-time in a non-real-time system in HILS
By creating a real-time model task and dynamically adjusting thread counts based on processor cores, the method achieves hard real-time execution in HILS without a separate real-time system, reducing costs and improving efficiency and flexibility.
Patent Information
- Application Number
- JP2023203444
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2023-10-19
- Filing Date
- 2023-11-30
- Publication Date
- 2025-06-09
- Estimated Expiration
- 2043-11-30
AI Technical Summary
Existing Hardware-in-the-Loop Simulation (HILS) systems require a real-time system to execute tasks, which leads to increased hardware and deployment costs, and limits the ability to directly observe and modify simulation signals.
A method is introduced to realize hard real-time in a non-real-time system within HILS by creating a real-time model task and automatically adjusting the number of threads based on the number of processor cores, allowing for efficient execution without the need for a separate real-time system.
This approach enables hard real-time execution in a non-real-time system, reducing hardware costs and improving development and test efficiency, while also enhancing the flexibility of simulation signal observation and modification.
Smart Images

Figure 0007689760000001 
Figure 0007689760000002 
Figure 0007689760000003
Abstract
Description
Technical Field
[0001] This application claims priority based on Chinese Patent Application No. 202311360067.1 filed on October 19, 2023, and US Patent Application No. 18 / 371,543 filed on September 22, 2023, the entire contents of which are incorporated herein by reference. The present invention belongs to the technical field of vehicle software development, and specifically relates to a method and system for realizing hard real-time in a non-real-time system in Hardware-in-the-Loop Simulation (HILS).
Background Art
[0002] In order to execute the tasks of Hardware-in-the-Loop Simulation, it is always necessary to rely on a real-time system to arrange the execution of tasks in the real-time system. The real-time system is in another computer, not local, and all operations need to be completed by remote calls, which causes problems such as the key signals of the related signals that determine the algorithm function and performance cannot be directly observed.
Summary of the Invention
[0003] The present invention relates to a method for realizing hard real-time in a non-real-time system in HILS. This method includes the following. Create a real-time model task to form a task program. The task program automatically reads the computer configuration to determine the number Z of kernels of the current computer device's processor. When the number Z of kernels is X or less, the number of threads n is set to 1 and the real-time model task is executed. When the number Z of kernels exceeds X, the number of threads n is set to (Z - X) / Y and the real-time model task is executed. Y represents the number of threads of one physical core of the processor.
[0004] In a second aspect, the present invention further provides a computer-readable (readable) storage medium. A computer-readable command is stored in this storage medium, and when executed by at least one processor, it causes the method for realizing hard real-time in a non-real-time system in the HILS to be executed.
[0005] In a third aspect, the present invention further provides an electronic device. This electronic device includes a processor, a readable storage medium, a communication bus, and a communication interface. Here, the above-mentioned processor, the above-mentioned readable storage medium, and the above-mentioned communication interface realize communication with each other via the above-mentioned communication bus. The above-mentioned readable storage medium is used to store a program for executing the method for realizing hard real-time in a non-real-time system in the HILS. The above program causes the processor to execute operations corresponding to the method for realizing hard real-time in a non-real-time system in the HILS.
[0006] In a fourth aspect, the present invention further provides a system for realizing hard real-time in a non-real-time system in the HILS. This system includes a computer device, and the above computer device is configured to execute a task creation module and a task thread setting module. The task creation module is configured to create a real-time model task and form a task program. The task thread setting module is configured such that the task program automatically reads the computer configuration to determine the number of processor cores Z of the current computer device. When the number of cores Z is X or less, the number of threads n is set to 1 and the real-time model task is executed. When the number of cores Z exceeds X, the number of threads n is set to (Z - X) / Y and the real-time model task is executed. Y indicates the number of threads of one physical core of the processor.
[0007] In a fifth aspect, the present invention further provides a computer program product. This product includes a computer-readable storage medium in which computer-readable program code is stored. The computer-readable program code includes commands that cause at least one processor or at least one computer device to execute a method for realizing hard real-time in a non-real-time system in the HILS.
[0008] Other features and advantages of the present invention are described in the following specification, and some will be apparent from the specification or understood by implementing the present invention. The objects and other advantages of the present invention are realized and obtained by the structures specifically pointed out in the specification and drawings.
[0009] To make the above objects, features, and advantages of the present invention more understandable, the following provides preferred embodiments and, in conjunction with the accompanying drawings, will be described in detail. To more clearly explain the specific embodiments of the present invention or the technical solutions of the prior art, the following briefly describes the drawings that need to be used in the description of the specific embodiments or the prior art. The drawings described in the following description are some embodiments of the present invention, and it is obvious that those skilled in the art can obtain other drawings from these drawings without creative effort.
Brief Description of the Drawings
[0010]
Figure 1
Figure 2
Figure 3
DETAILED DESCRIPTION OF THE INVENTION
[0011] To make the objectives, technical aspects, and advantages of the embodiments of the present invention clearer, the technical aspects of the present invention will be clearly and completely described below in connection with the accompanying drawings. It is obvious that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the invention, all other embodiments obtained on the premise that those skilled in the art do not perform creative labor belong to the protection scope of the invention.
[0012] When current similar software executes HILS tasks, it generally reaches hard real-time by a real-time system, which requires an increase in hardware investment and deployment costs. The method for realizing hard real-time in a non-real-time system in HILS according to some embodiments can realize hard real-time in a non-real-time system without the need to separately increase a real-time system.
[0013] Specifically, some embodiments provide a method for realizing hard real-time in a non-real-time system in HILS, including the following. Create a real-time model task to form a task program. The task program automatically reads the computer configuration to determine the number of processor cores Z of the current computer device. When the number of cores Z is less than or equal to X, set the number of threads n = 1 and execute the real-time model task. When the number of cores Z exceeds X, set the number of threads n = (Z - X) / Y and execute the real-time model task. Y represents the number of threads of one physical core of the processor.
[0014] In HILS according to some embodiments, a method for a non-real-time system to realize hard real-time is, when executing a HILS task, directly execute a virtual hard real-time environment on a personal computer 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 test efficiency is greatly improved, and the flexibility of simulation signal observation and modification is improved. For example, when it is desired to observe a certain local variable, the local program code can be modified at any time, functions such as print information, observation information, and curve drawing signal information can be added, and it can be executed immediately after being compiled locally, which is highly efficient. In the conventional method, it is necessary to design input and output interfaces for this local variable, update the simulation model interface table, compile the entire code program, relocate the real-time system software, remotely execute the simulation model, and then observe it.
[0015] Various non-limiting embodiments of the examples of the present disclosure will be described in detail below in connection with the drawings. As shown in FIG. 1, some embodiments provide a method for realizing hard real-time in a non-real-time system in HILS. This method includes the following. Create a real-time model task to form a task program. The task program automatically reads the computer configuration to determine the number of processor cores Z of the current computer device. When the number of cores Z is less than or equal to X, the number of threads n is set to 1, and the real-time model task is executed. When the number of cores Z exceeds X, the number of threads n is set to (Z - X) / Y, and the real-time model task is executed. Y represents the number of threads of one physical core of the processor.
[0016] Specifically, the real-time model task is a timing program. First, a timer is created to create the real-time model task. After creating the timer, the period of the timer is set, for example, 500 microseconds. Subsequently, the step function of the model is called at the timing according to this period. The formed task program is a code module for real-time model task simulation.
[0017] The number of processor cores Z is determined by the processor model, and different processor models result in completely different numbers of cores Z. For example, the number of cores Z of Intel Xeon Platinum 9282 is 56, and the number of cores Z of Intel Core i5-2520M is 2.
[0018] When Z is less than or equal to X, the current computer performance is weak and not suitable for performing simulations by dividing into multiple threads. When the number of cores Z exceeds X, it may cause the local computer to freeze, and at this time, it is suitable to execute the real-time model task with a single thread, that is, set the number of threads n = 1 and execute the real-time model task.
[0019] On the one hand, when Z exceeds X, in order to prevent the simulation from being executed in a multi-threaded manner when the computer performance is weak, it is necessary to limit the minimum value of X. That is, limit the minimum value of the number of cores Z of the computer that executes the simulation task in a multi-threaded manner. When taking the limit situation X = 0, the number of threads n = Z / Y is equal to the number of true physical cores. When X is not zero, it indicates reserving X / Y true physical cores as self-cores, and these self-cores do not participate in the simulation, thereby ensuring the smooth operation of the software system and other software.
[0020] As an implementation situation of some embodiments, setting the number of threads n = 1 to execute the real-time model task includes the following. Define the real-time time interval m for the execution of the real-time model task. The above 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, t_next = t_next + m, and the real-time model task is executed.
[0021] When the real-time model task is executed for the first time, t_next = m and t = 0. Specifically, the execution method of the real-time model task when n = 1 will be described in detail with examples. Set X = 4, and when the processor model of the computer device is Intel Core i5-2520M, the number of cores Z = 2, which is less than 4, and the current computer performance is weak, so it is not suitable to execute the simulation by dividing into multiple threads. Otherwise, it will cause a phrase of the local computer. At this time, it is suitable to execute the real-time model task in a single thread, that is, set the number of threads n = 1 to execute the real-time model task.
[0022] Only one thread executes the real-time model task. During the execution, since there is no preemption in the multi-thread environment, there is no need to perform thread synchronization using means such as critical sections, and thus the performance cost caused by introducing critical sections can be reduced. However, the defects of the single thread itself are also becoming apparent. When the processor time slice of the single thread is deprived by the OS scheduling, the processor may start a new time slice, which will reduce the lock accuracy of the time t_next, that is, the execution time accuracy level of locking the next time will decrease.
[0023] When executing the real-time mode task in a single thread, set the real-time time interval m for executing the real-time mode task to 500 microseconds. The pseudo-code for the thread to execute the real-time model task is as follows. m = 0.00005; while (is_running) { t = get_current_time_stamp_us(); if (t > t_next){ t_next_ = t_next + m; run_model_task(); } other_task(); } Here, "is_running" is the simulation execution enable flag. When the simulation is terminated by the user or exits naturally, this flag is false, and the algorithm does not execute the while loop. "get_current_time_stamp_us()" is an internal function of the Windows system, which is used to obtain the time stamp of the current time, and the unit is microseconds. "run_model_task()" is an internal function of the Windows system, which is used to periodically call the step function of the model. "other_task()" is another task of the Windows system. For example, Sleep(1) can be executed here to reduce the consumption of the current processor's processor time.
[0024] In another implementation scenario of some embodiments, when the number of threads n = (Z - X) / Y, it shows that when the number of cores Z exceeds X, the processor of the current computer device is suitable for starting a multi-threaded simulation. The method for executing the real-time model task includes the following. Define the real-time time interval m for the execution of the real-time model task. Each thread simultaneously obtains the corresponding current time t in real time and determines in real time whether the corresponding current time t is greater than the next execution time t_next. When at least one thread recognizes that t > t_next, the thread attempts to enter the critical section. At this time, other threads are blocked from entering the critical section. After the thread successfully enters the critical section, the flag determined by the previous thread as t > t_next becomes invalid. Therefore, the thread that successfully enters the critical section executes the following content in the critical section. Repeatedly obtain the current time t and determine whether the current time t is greater than the next execution time t_next. If so, t_next = t_next + m, and at the same time, the real-time model task is executed, and the thread exits from the critical section. If not, the thread directly exits from the critical section.
[0025] Specifically, the execution method of the real-time model task when n = (Z - X) / Y will be described in detail with examples. When X = 2, Y = 2, and the processor model of the computer device is Intel Core i7-8700, the number of cores Z = 6. When it is greater than 2, the number of threads n = (Z - X) / Y = (6 - 2) / 2 = 2 is set to execute the real-time model task.
[0026] Define the two threads as the 0th thread and the 1st thread respectively. When defining the real-time time interval m = 500 microseconds for the execution of the real-time model task, the pseudo-code for each thread to execute the model task is as follows. m = 0.00005; while (is_running) { t = get_current_time_stamp_us(); if (t > t_next){ EnterCriticalSection(FSection); t = get_current_time_stamp_us(); if (t > t_next){ t_next_ = t_next + m; run_model_task(); } LeaveCriticalSection(FSection); } other_task(); } Here, "is_running" is the simulation execution enable flag. When the simulation is terminated by the user or exits naturally, this flag is false, and the algorithm does not execute the while loop. "get_current_time_stamp_us()" is an internal function of the Windows system, which is used to obtain the time stamp of the current time, and the unit is microseconds. "EnterCriticalSection" is an API function of the Windows system, and its role is to enter the critical section. "FSection" is a critical section object shared by multiple threads. "LeaveCriticalSection" is a Windows API function that works to exit the critical section. "run_model_task()" is an internal function of the Windows system, which is used to periodically call the step function of the model. "other_task()" is another task of the Windows system. For example, Sleep(1) can be executed here to reduce the consumption of the current processor's processor time.
[0027] The above pseudo-code effectively alleviates the situation of the reduction in simulation time accuracy caused by a single thread being deprived of processor time by system scheduling, that is, effectively guarantees the simulation time accuracy by the above method, thereby guaranteeing the simulation real-time performance.
[0028] Threads that do not successfully enter the critical section are blocked from entering the critical section and start the next attempt after the thread that has entered the critical section exits the critical section.
[0029] Also, taking as an example the method of setting the number of threads n = 2 as described above and executing real-time model tasks, if the 0th thread fails to timely determine the next execution time t_next for system scheduling, the probability that the 1st thread determines the next execution time t_next is very high, and when it recognizes that t > t_next, it successfully enters the critical section, thereby preferentially executing the model task. At this time, the 0th thread is blocked at the code line entering the critical section. After the 1st thread executes the real-time model task and completes and exits the critical section, the 0th thread begins to determine whether the current time t is greater than the next execution time t_next. At this time, after the 0th thread successfully enters the critical section, it updates the current time t again, that is, repeatedly obtains the current time t, and if it determines that the current time t is less than the next execution time t_next (the next execution time t_next is updated by the 1st thread), the 0th thread does not execute the real-time model task, immediately exits the critical section, and waits for the next determination.
[0030] The thread successfully entering the critical section is determined by the critical section itself. That is, the thread that successfully enters the critical section is randomly determined by the Windows system.
[0031] t_next is a common global variable for each thread. That is, multiple threads can access the same variable simultaneously. Each thread can share and access the same variable. In this way, when any thread first discovers that the current time t is greater than the next execution time t_next, it immediately tries to enter the critical section. This effectively alleviates the situation where the simulation time accuracy decreases due to a single thread being deprived of processor time by system scheduling, and effectively guarantees the simulation time accuracy.
[0032] Each set thread occupies one physical core of a processor, including that the index of the processor physical core occupied by each thread is equal to the value obtained by performing a modulo operation on the corresponding thread index and the total number of processor physical cores.
[0033] Each set thread occupies one physical core of a processor and can exhibit the optimal performance of the computer device.
[0034] For example, if a total of 10 threads are set and the total number of processor physical cores is 8, the index of the processor physical core occupied by thread 0 is equal to the value obtained by performing a modulo operation on 0 and 8, and this value is 0. The index of the processor physical core occupied by thread 9 is equal to the value obtained by performing a modulo operation on 9 and 8, and this value is 1.
[0035] In the HILS of the present disclosure, the method for a non-real-time system to achieve hard real-time is to directly execute a virtual hard real-time environment on a personal computer when executing HILS tasks 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 test efficiency is greatly improved, and the degree of freedom for observing and modifying simulation signals is increased.
[0036] As shown in FIG. 2, some embodiments further provide a system for a non-real-time system to achieve hard real-time in HILS, including a computer device. The computer device is configured to execute a task creation module and a task thread setting module. The task creation module is configured to create real-time model tasks and form task programs. The task thread setting module is configured such that the task program automatically reads the computer configuration to determine the number Z of processor cores of the current computer device. When the number Z of cores is less than or equal to X, the number of threads n = 1 is set to execute the real-time model task. When the number Z of cores exceeds X, the number of threads n = (Z - X) / Y is set to execute the real-time model task. Y represents the number of threads of one physical core of the processor.
[0037] In some embodiments, the functions executed by the task creation module and the task thread setting module are realized in the computer device. Specifically, reference can be made to the specific description of the method for a non-real-time system to achieve hard real-time in the aforementioned HILS, and the description is omitted here.
[0038] The following describes the electronic device in some embodiments from the perspective of hardware processing. As shown in FIG. 3, some embodiments of the present disclosure do not limit the specific implementation of the electronic device. When the above-mentioned processor executes the above program, it realizes the steps in an embodiment of a method for realizing hard real-time in a non-real-time system in the HILS shown in FIG. 1 above, for example, steps S101 and S102 shown in FIG. 1. Alternatively, when the processor executes a computer program, it realizes the functions of each module or unit in the embodiments of the above-mentioned respective devices.
[0039] In some embodiments, the processor is specifically used to realize the following steps. Create a real-time model task to form a task program. The task program automatically reads the computer configuration to determine the number Z of processor cores of the current computer device. If the number of cores Z is less than or equal to X, set the number of threads n = 1 and execute the real-time model task. If the number of cores Z exceeds X, set the number of threads n = (Z - X) / Y and execute the real-time model task. Y represents the number of threads of one physical core of the processor.
[0040] Optionally, as a possible implementation form, the processor can further be used to realize the following steps. Setting the number of threads n = 1 and executing the real-time model task includes the following. Define the real-time time interval m for the execution of the real-time model task. The above 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. If t > t_next, then t_next = t_next + m, and at the same time, execute the real-time model task.
[0041] Optionally, as a possible implementation form, the processor can further be used to realize the following steps. When the real-time model task is executed for the first time, t_next = m and t = 0.
[0042] Optionally, as a possible embodiment, the processor can further be used to implement the following steps. To execute real-time model tasks, set the number of threads to n = (Z - X) / Y, including the following. Define the real-time time interval m for real-time model task execution. Each thread simultaneously obtains the corresponding current time t in real time and determines in real time whether the corresponding current time t is greater than the next execution time t_next. If at least one thread recognizes that t > t_next, the thread attempts to enter the critical section, and the thread that successfully enters the critical section executes the following content in the critical section. Repeatedly obtain the current time t and determine whether the current time t is greater than the next execution time t_next. If so, t_next = t_next + m, and at the same time execute the real-time model task, and the thread exits the critical section. If not, the thread directly exits the critical section.
[0043] Optionally, as a possible embodiment, the processor can further be used to implement the following steps. Threads that do not enter the critical section normally are blocked from entering the critical section, and after the thread that has entered the critical section exits the critical section, the next attempt is started.
[0044] Optionally, as a possible embodiment, the processor can further be used to implement the following steps. Threads that enter the critical section normally are determined by the critical section itself.
[0045] Optionally, as a possible embodiment, the processor can further be used to implement the following steps. t_next is a common global variable for each thread.
[0046] Optionally, as a possible embodiment, the processor can further be used to implement the following steps. Each set thread occupies a physical core of one processor and includes the following. The physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation on the corresponding thread number index and the total number of physical cores of the processor.
[0047] Some embodiments provide a computer-readable storage medium storing computer-readable commands that, when executed by at least one processor, implement a method for realizing hard real-time in a non-real-time system in the HILS of the above embodiments.
[0048] Some embodiments provide a computer program product including a computer-readable storage medium storing computer-readable program code including commands that cause at least one processor or at least one computer device to execute a method for realizing hard real-time in a non-real-time system in any of the possible HILSs described above.
[0049] In other embodiments, the computer device, industrial computer can also be a type of electronic device.
[0050] Note that the configuration shown in FIG. 3 does not limit the electronic device, and it can include fewer or more components than shown in the figure, some components can be combined, or different components can be arranged.
[0051] In some embodiments, the communication interface may be a communication interface connectable to an external bus adapter, such as RS232, RS485, a USB port, and a TYPE port. A wired or wireless network interface may also be included, and the network interface may optionally include wired and / or wireless interfaces (e.g., a WI-FI interface, a Bluetooth® interface, etc.) typically used to establish a communication connection between the computer device and other electronic devices. The memory module, readable storage medium, or computer-readable storage medium includes at least one type of memory. The memory includes flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, it may be an internal storage unit of the computer device, such as a hard disk of the computer device. In other embodiments, the memory may be an external storage device of the computer device, such as a plug-in hard disk equipped in the computer device, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Further, the memory may include both an internal storage unit and an external storage device of the computer device. The memory stores various data such as application software installed in the computer device and the code of computer programs, and is also used to temporarily store output data and data to be output.
[0052] In some embodiments, the processor may execute program code stored in the memory or process data, and may be, for example, a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip for executing a computer program.
[0053] In some embodiments, the communication bus may be an input / output bus that can be, for example, a Peripheral Component Interconnect (PCI) bus or an Enhanced Industry Standard Architecture (EISA) bus. This bus can be divided into an address bus, a data bus, a control bus, and the like.
[0054] Optionally, the computer device may further include a user interface. The user interface can include input units such as a display and a keyboard, and optionally, the user interface can also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display or display module may be an LED display, a liquid crystal display, a touch liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. In this case, the display or display module is also referred to as a display screen or a display unit for displaying the information processed within the computer device and for displaying the visualized user interface.
[0055] In some embodiments provided by the present invention, naturally, the disclosed apparatus and method can also be implemented in other ways. The embodiments of the apparatus described above are merely illustrative. For example, the flowcharts and block diagrams in the drawings show the possible architectures, functions, and operations of an apparatus, method, and computer program product according to multiple embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code. The above module, program segment, or part of code includes executable instructions for implementing one or more predetermined logical functions. It should be noted that in some alternative implementation ways, the functions represented by the blocks may occur in an order different from the order shown in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel and, depending on the related functions, can sometimes be executed in the reverse order. Also, each block of the block diagram and / or flowchart, as well as combinations of the blocks of the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing a predetermined function or operation, or may be implemented by a combination of dedicated hardware and computer instructions.
[0056] In addition, each functional module in each embodiment of the present invention may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0057] When the above functions are realized in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art or a part of the technical solution, can be represented in the form of a software product. The computer software product is stored in the storage medium and includes a plurality of instructions to cause a computer device (which may be a personal computer, a server, a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention.
[0058] Inspired by the preferred embodiments of the present invention described above, those skilled in the art can make various changes and modifications without departing from the technical idea of the present invention from the above description. The technical scope of the present invention is not limited to the content of the specification, and its technical scope must be determined based on the scope of the claims.
Claims
1. A method for realizing hard real-time in a non-real-time system in HILS, comprising: creating a real-time model task to form a task program; when the task program automatically reads the computer configuration to determine the number of processor cores Z of the current computer device, taking the maximum number of threads supported by one physical core of the processor as Y, and when X is set such that (Z - X) / Y is a natural number and the number of self-cores not participating in HILS is X / Y, if the number of cores Z is less than or equal to X, setting the number of threads n assigned to the real-time model task to 1 and executing the real-time model task, and if the number of cores Z exceeds X, setting the number of threads n assigned to the real-time model task to (Z - X) / Y and executing the real-time model task; A method for realizing hard real-time in a non-real-time system in HILS, characterized by the above.
2. Setting the number of threads to n = 1 and executing the real-time model task includes: defining the real-time time interval m for real-time model task execution; the thread obtaining the current time t in real time and determining in real time whether the current time t is greater than the next execution time t_next; when t > t_next, setting t_next = t_next + m and simultaneously executing the real-time model task. A method for realizing hard real-time in a non-real-time system in HILS according to Claim 1, characterized by the above.
3. When the real-time model task is first executed, t_next = m and t = 0. A method for realizing hard real-time in a non-real-time system in HILS according to Claim 2, characterized by the above.
4. Setting the number of threads to n = (Z - X) / Y and executing the real-time model task includes: defining the real-time time interval m for real-time model task execution; each thread simultaneously obtaining the corresponding current time t in real time and determining in real time whether the corresponding current time t is greater than the next execution time t_next; When at least one thread recognizes that t > t_next, the thread attempts to enter the critical section, and the thread that successfully enters the critical section, within the critical section, (1) repeatedly obtains the current time t and determines whether the current time t is greater than the next execution time t_next, (2) if it is greater, set t_next = t_next + m, execute the real-time model tasks simultaneously, and exit the critical section, (3) if it is not greater, including directly exiting from the critical section, A method for realizing hard real-time in a non-real-time system in the HILS according to claim 1, characterized in that.
5. A method for realizing hard real-time in a non-real-time system in the HILS according to claim 4, characterized in that a thread that has not normally entered the critical section is prevented from entering the critical section, and after the thread that has entered the critical section exits the critical section, the next attempt is started.
6. A method for realizing hard real-time in a non-real-time system in the HILS according to claim 5, characterized in that a thread that normally enters the critical section is determined by the critical section itself.
7. A method for realizing hard real-time in a non-real-time system in the HILS according to claim 4, characterized in that t_next is a common global variable for each thread.
8. Each set thread occupies a physical core of one processor, A method for realizing hard real-time in a non-real-time system in the HILS according to claim 1, characterized in that the physical core index of the processor occupied by each thread is equal to the value obtained by performing a modulo operation with the corresponding thread number index as the dividend and the total number of physical cores of the processor as the divisor.
9. A computer-readable storage medium, A computer-readable command is stored, and when executed by at least one processor, a method for realizing hard real-time in a non-real-time system in the HILS according to any one of claims 1 to 8 is executed. A computer-readable storage medium characterized by this.
10. An electronic device, comprising a processor, a readable storage medium, a communication bus, and a communication interface, wherein the processor, the readable storage medium, and the communication interface realize communication with each other via the communication bus, the readable storage medium is configured to store a program of a method for realizing hard real-time in a non-real-time system in the HILS according to any one of claims 1 to 8, and the program is configured to cause the processor to execute operations corresponding to the method for realizing hard real-time in the non-real-time system in the HILS. An electronic device characterized by this.
11. A system for realizing hard real-time in a non-real-time system in HILS, including a computer device, the computer device being configured to execute a task creation module and a task thread setting module, the task creation module is configured to create a real-time model task and form a task program, the task thread setting module is configured to cause the task program to automatically read the computer configuration to determine the number Z of processor cores of the current computer device. Let the maximum number of threads supported by one physical core of the processor be Y. When X is set such that (Z - X) / Y is a natural number and the number of self-cores not participating in HILS is X / Y, if the number of cores Z is less than or equal to X, set the number of threads n assigned to the real-time model task to 1 and execute the real-time model task; otherwise, set the number of threads n assigned to the real-time model task to (Z - X) / Y and execute the real-time model task. A system for realizing hard real-time in a non-real-time system in HILS, characterized by this.
12. The computer device is configured to execute the task creation module and the task thread setting module by the method according to any one of claims 2 to 8. A system for realizing hard real-time in a non-real-time system in the HILS according to claim 11, characterized by this. A computer program, characterized in that at least one processor or at least one computer device is caused to execute a method for realizing hard real-time in a non-real-time system in the HILS according to any one of claims 1 to 8.
Citation Information
Patent Citations
Rail transit network passenger flow parallel simulation method
CN117634189A