Method and apparatus for performing time critical processing in a non-real-time operating system
By capturing and preprocessing sampled value messages in a non-real-time operating system, and utilizing double buffers and dedicated real-time threads, the real-time problem of time-critical processing in a non-real-time operating system is solved, achieving a rapid response effect in the power system and improving the convenience of software development and debugging.
Patent Information
- Application Number
- CN202110381445.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-09
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2041-04-09
AI Technical Summary
Non-real-time operating systems struggle to meet the real-time requirements of time-critical processing, especially in power systems where rapid response to emergencies is crucial.
Packet capture tools are used to capture messages from external devices. The messages are analyzed to determine if they are sampled value messages and written to a buffer. After preprocessing, time-critical processing is performed in a dedicated real-time thread. The dual-buffer mechanism and semaphores are used to trigger the dedicated real-time thread to ensure that real-time requirements are met in a non-real-time operating system.
It achieves time-critical processing performance comparable to that of a real-time operating system in a non-real-time operating system, meeting the demand for rapid response in power systems and improving the convenience of software development and debugging.
Smart Images

Figure CN115203007B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to a method and device for performing time-critical processing in a non-real-time operating system, and more particularly, to a method for performing time-critical processing associated with a sampled-value message in a non-real-time operating system of a computing device such as a personal computer, and a device for performing the method. BACKGROUND
[0002] In a power system such as a smart substation, for certain contingencies or specific tasks, it is desirable for the system to be able to handle these events or tasks in real time to minimize the loss. For example, for relay protection in a power system, when a circuit fault is detected, it is desirable for the faulty circuit to be switched off at the first time to reduce the possibility of a major accident. Currently, the response to contingencies or specific tasks is achieved by relying on a real-time operating system (RTOS) in the power system to handle the sampled-value messages of the power system in real time. The software development and debugging of the real-time operating system is usually carried out after the hardware development and debugging including printed circuit board (PCB). However, in some special cases, for example, when the software development or debugging of the real-time operating system cannot be carried out due to the obstruction of hardware development and debugging or due to the lack of test conditions in the field, it is desirable to be able to use a non-real-time operating system to simulate the real-time operating system for software development and debugging. SUMMARY
[0003] In view of this, the purpose of the embodiments of the present disclosure is to provide a method and device capable of handling time-critical processing in a non-real-time operating system, which can better meet the real-time requirement of time-critical processing in a non-real-time operating system.
[0004] One aspect of the present disclosure provides a method for performing time-critical processing in a non-real-time operating system. The method comprises: capturing a message from an external device by a packet capturing tool; analyzing whether the message is a sampled-value message associated with the time-critical processing, and when the message is a sampled-value message associated with the time-critical processing, writing data units contained in the sampled-value message into a first buffer; pre-processing the data units written into the first buffer, the pre-processing comprising arranging and combining bytes of the data units such that bytes indicative of sampled values are located at specific positions; in response to a predetermined number of pre-processed data units in the first buffer being reached, writing the predetermined number of pre-processed data units from the first buffer into a second buffer dedicated to a real-time dedicated thread, while triggering the real-time dedicated thread; and performing the time-critical processing by the real-time dedicated thread reading the pre-processed data units from the second buffer.
[0005] Optionally, writing preprocessed data units from the first buffer to the second buffer includes: writing the preprocessed data units to the second buffer based on the write pointer of the second buffer, and for each write, the offset of the write pointer of the second buffer is the number of data units written; and the real-time dedicated thread reading the preprocessed data units from the second buffer includes: reading the data units from the second buffer based on the read pointer of the second buffer, and for each read, if the processing capability of the non-real-time operating system allows, the offset of the read pointer is determined to be an offset that aligns the read pointer after the read with the current write pointer.
[0006] Optionally, an error message is triggered when the determined offset of the read pointer exceeds a predetermined offset threshold.
[0007] Optionally, the time-critical processing includes sample value acquisition, sample value processing, and protection decision-making, wherein the sample value acquisition is triggered in response to the triggering of the real-time dedicated thread, which is used to acquire the sample value from the data unit from the second buffer; the sample value processing is triggered in response to the completion of the sample value acquisition, which is used to process the sample value to form data for making a protection decision; and the protection decision-making is triggered in response to the sample value processing being executed a predetermined number of times, which is used to make a protection decision based on the data for performing the protection decision.
[0008] Optionally, the method further includes: writing the result data generated by the real-time dedicated thread performing the time-critical processing into a local database.
[0009] Another aspect of this disclosure provides an apparatus for performing time-critical processing in a non-real-time operating system. The apparatus includes: a packet capture module for capturing packets from an external device using a packet capture tool; a packet analysis module for analyzing whether the packets are sampled value packets, and when the packets are sampled value packets, writing data units contained in the sampled value packets into a first buffer; a packet preprocessing module for preprocessing the data units written into the first buffer, the preprocessing including arranging bytes of the data units such that a byte indicating a sampled value is located at a specific position; a real-time dedicated thread triggering module, which, in response to a predetermined number of preprocessed data units in the first buffer reaching a predetermined number, writes the predetermined number of preprocessed data units from the first buffer into a second buffer dedicated to a real-time dedicated thread, and simultaneously triggers the real-time dedicated thread; and a real-time dedicated thread execution module, which reads the preprocessed data units from the second buffer through the real-time dedicated thread to execute the time-critical processing associated with the sampled value packets.
[0010] Optionally, the real-time dedicated thread execution module writes the predetermined number of preprocessed data units into the second buffer based on the write pointer of the second buffer, and for each write, the offset of the write pointer of the second buffer is the number of the written data units; and the reading of the preprocessed data units from the second buffer by the real-time dedicated thread comprises: reading the data units from the second buffer based on the read pointer of the second buffer, and for each read, the offset of the read pointer is determined to be an offset that aligns the read pointer after the read with the current write pointer, if the processing capability of the non-real-time operating system allows.
[0011] Optionally, the device further comprises an error reporting module configured to trigger an error message when the determined offset of the read pointer exceeds a predetermined offset threshold.
[0012] Yet another aspect of the present disclosure provides a device for performing time-critical processing in a non-real-time operating system, comprising a processor and a memory, the memory having stored therein a computer-executable program which, when executed by the processor, causes the device to perform the above-mentioned method for performing time-critical processing in a non-real-time operating system.
[0013] Still another aspect of the present disclosure provides a computer-readable storage medium having stored thereon computer instructions which, when executed by a processor, implement the above-mentioned method for performing time-critical processing in a non-real-time operating system.
[0014] Thus, the method and device according to the embodiments of the present disclosure can perform time-critical processing in a non-real-time operating system, better meeting the real-time requirement of time-critical processing. And in the case that the network transmission rate and computing capability of the current non-real-time operating system computing device are very strong, the effect of performing time-critical processing on a real-time operating system can be achieved. BRIEF DESCRIPTION OF DRAWINGS
[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings used in the description of the embodiments will be briefly introduced. Obviously, the drawings in the following description are only some example embodiments of the present disclosure, and other drawings can be obtained by those of ordinary skill in the art without creative effort based on these drawings.
[0016] Figure 1 is a schematic diagram of performing time-critical processing in a real-time operating system;
[0017] Figure 2 is a schematic diagram of a task scheduling mechanism of a non-real-time operating system;
[0018] Figure 3 is a schematic flowchart of a method of performing time critical processing in a non-real-time operating system according to an embodiment of the present disclosure;
[0019] Figure 4 is another schematic diagram of a method of performing time critical processing in a non-real-time operating system according to an embodiment of the present disclosure;
[0020] Figure 5 is a schematic diagram of writing and reading data units to and from a second buffer according to an embodiment of the present disclosure;
[0021] Figure 6 is a schematic diagram of results obtained from performing a method of performing time critical processing in a non-real-time operating system according to an embodiment of the present disclosure;
[0022] Figure 7 is a schematic block diagram of an apparatus for performing time critical processing in a non-real-time operating system according to an embodiment of the present disclosure;
[0023] Figure 8 is a schematic block diagram of an apparatus for performing time critical processing in a non-real-time operating system according to another embodiment of the present disclosure; and
[0024] Figure 9 is a schematic diagram of a computer readable storage medium according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] The present disclosure will now be described in detail by way of specific example embodiments thereof. However, these embodiments are not intended to limit the scope of the present disclosure, which can be implemented in various forms. The described embodiments are merely provided for the full and complete disclosure of the present disclosure and fully convey the concept of the present disclosure to those skilled in the art. The features of various embodiments described can be combined or replaced with other features unless explicitly excluded or unless such combination or replacement is technically infeasible.
[0026] Unless otherwise defined, technical terms or scientific terms used in the present disclosure shall have the same meaning as those understood by a person of ordinary skill in the art to which the present disclosure belongs. The terms “first”, “second” and similar terms used in the present disclosure do not denote any order, quantity or importance, but are used to distinguish different components.
[0027] In a system under test involving sampling, the sampled values obtained by sampling are delivered to a device or apparatus that can perform processing on the sampled values. If the sampled values are important data for judging the current state of the system under test, making corresponding decisions, or even issuing control commands, it is desirable that the device or apparatus that performs processing on the sampled values can perform processing on the sampled values in real time. The processing associated with the sampled values that needs to be performed in real time is referred to as time-critical processing hereinafter. Time-critical processing means that the processing of the previous batch of input data needs to be completed before the next batch of input data arrives in a real-time operating system.
[0028] Taking a power system (e.g., a smart substation) as an example, the power system uses a mutual inductor to collect voltage and / or current values in the system, and such sampled values can represent the power protection status of the power system, and thus it is desirable to perform time-critical processing associated with the sampled values as quickly as possible. As an example, the time-critical processing can include, for example, sampling value acquisition, sampling value processing (e.g., including resampling and / or filtering), protection decision, RMS calculation, measurement, and / or I / O mapping, etc.
[0029] Figure 1 is a schematic diagram of performing time-critical processing in a real-time operating system.
[0030] A real-time operating system is a preemptive operating system, which is characterized in that as long as a high-priority task is ready, a low-priority task will be interrupted immediately to execute the high-priority task regardless of whether the low-priority task is being executed or in a sleep state. Commonly used real-time operating systems include embedded Linux, embedded Windows, VxWorks, RT-Thread, uCOS, QNX, WinCE, etc.
[0031] Still taking the power system as an example, reference is made to Figure 1 which shows a timing diagram of performing time-critical processing on the sampled values of the power system in a real-time operating system VxWorks, including sampling, resampling, filtering, and protection decision. As shown in the example of Figure 1 , the real-time operating system triggers sampling once every 1 ms by a timer, the end of sampling triggers resampling, the end of resampling triggers filtering, and the protection decision is performed when sampling, resampling, and filtering are performed 5 times. The timer counts from 25.39316 ms to 30.39544 ms, a total of 5 times of sampling, resampling, and filtering are performed, and 1 time of protection decision is performed. In other words, the real-time operating system performs time-critical processing on the sampled values relies on the timer triggering sampling every 1 ms to ensure a sampling interval of 1 ms and a protection interval of 5 ms.
[0032] As mentioned above, in some special cases, it is desired that a non-real-time operating system can be used to simulate a real-time operating system, and it is desired that the time-critical processing for the sample value is performed as timely as possible in the non-real-time operating system.
[0033] Figure 2 is a schematic diagram of a task scheduling mechanism of a non-real-time operating system.
[0034] The non-real-time operating system can be a general-purpose operating system such as Windows, Linux, etc. running on a computing device such as a personal computer, a workstation, a server, etc. Unlike a real-time operating system, a non-real-time operating system is not a preemptive operating system. Its characteristic is that even in the face of the need for a high-priority task to be executed, it will not immediately interrupt a low-priority task to execute the high-priority task, but will wait for the low-priority task to be executed within the current time slice or the current time slice to end before being executed.
[0035] With reference to Figure 2 , the task scheduling mechanism of the non-real-time operating system is a time slice rotation manner, each of the tasks 1, 2 and 3 is forced to pause after being executed for a short period of time, and then the next task is executed, and each task is executed in turn, and the short period of time during which the task is executed is called a time slice. The state when the task is being executed is called a running state, and the paused task is called a ready state to wait for the arrival of the next time slice belonging to it. The advantage of the time slice rotation mechanism is that each task can be executed, and since the short period of time represented by the time slice is very short, the rapid switching between tasks gives the user the experience that multiple tasks are being performed at the same time.
[0036] It can be seen that for the time-critical processing of the sample value, the real-time operating system and the non-real-time operating system differ in sample synchronization. However, the processing power of current non-real-time operating system computing devices is very strong, and the processing frequency is much higher than the expected processing frequency of the to-be-processed task, so that a small time deviation can not greatly affect the real-time performance of the to-be-processed task. For example, the processing frequency of a core of a processor of a current general personal computer reaches several GHz, and usually a processor has several cores. In this case, the present disclosure conceives a technical solution for performing time-critical processing in a non-real-time operating system, which can better achieve the real-time requirement of time-critical processing in a non-real-time operating system.
[0037] Figure 3 is a schematic flowchart of a method for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure.
[0038] As Figure 3As shown, the method 300 for executing time critical processing in a non-real-time operating system according to an embodiment of the present disclosure comprises steps S310-S350.
[0039] In step S310, a packet from an external device is captured by a packet sniffer.
[0040] The external device can be a device that is located externally to the computing device of the non-real-time operating system and is communicatively connected to the computing device via a communication means such as an Ethernet card. The packet can be various packets from a communication path such as Ethernet. In the present disclosure, the sampled values of the system under test are carried in the packet for sending to the computing device where the non-real-time operating system is located.
[0041] The packet sniffer can be, for example, WinPcap under Window operating system or emcek / packet under Linux operating system. They can bypass the protocol stack of the non-real-time operating system to "sniff" the packets transmitted on the network. For example, based on a callback function, whenever an external device delivers a frame of packet, WinPcap is invoked to "sniff" the packet.
[0042] In step S320, it is analyzed whether the captured packet is a sampled value packet associated with time critical processing, and when the captured packet is a sampled value packet associated with time critical processing, the data unit contained in the sampled value packet is written into the first buffer.
[0043] Still taking the power system as an example of the system under test, for example, the power system is operated and maintained according to the communication protocol IEC 61850-9-2, then the sampled value packet is a packet conforming to the frame format specified by the communication protocol IEC 61850-9-2. The sampled value packet is formed after the voltage and / or current sampled values in the power system are merged, synchronized, and packed by a merging unit or other device having equivalent functions of the merging unit, and contains the voltage and / or current sampled values. In this step, it can be analyzed according to the frame format specified by, for example, the communication protocol IEC 61850-9-2, whether the packet is a sampled value packet associated with time critical processing. If so, the data unit contained in the sampled value packet is written into the first buffer.
[0044] In particular, as an example, the frame format of the sampled value message complying with the communication protocol IEC 61850-9-2 includes a preamble field, a start frame delimiter field (SFD), a MAC header (including a destination address and a source address), a priority tag (TPID, TCI), an Ethernet type, an Ethernet type PCU, an application protocol data unit (APDU), optional padding bytes, a frame check sequence, etc. Among them, the APDU can be linked by one or more application service data units ASDU, as shown in the following table.
[0045] Tag Length Number of ASDUs n ASDU1 ASDU2 ………… ASDUn
[0046] In other words, when analyzing the captured message is a sampled value message associated with time-critical processing, the n ASDUs contained therein are written into the first buffer. For example, in the case of a sampling rate of 4000 Hz and a power frequency of 50 Hz, 80 sampling points per cycle, the voltage and / or current sampling values related to a sampling point are carried by an ASDU in the sampled value message, and the number n of ASDUs contained in each sampled value message can be a suitable value matching the sampling rate, such as 1, 2, 4, etc. For example, the number n of ASDUs matching the sampling rate 4000 Hz / 4800 Hz can be 4.
[0047] In step S330, the data units written into the first buffer are preprocessed. The preprocessing in this step can include arranging and combining the bytes in the data units so that the bytes indicating the sampling values are located in a specific position. For example, for the aforementioned example of the power system, the sampled value message is formed by the merging unit from the voltage / current sampling values from each sampling channel after synchronization and packaging, and the mapping relationship between the data representing the voltage / current sampling values in the data units in the sampled value message and each sampling channel needs to be preprocessed to be parsed. In this case, the preprocessing can be an operation of matching the data (e.g., bytes in the data units) indicating the voltage / current sampling values in the data units with each sampling channel, so as to be able to indicate the voltage / current sampling values of each sampling channel.
[0048] In step S340, in response to the preprocessed data units in the first buffer reaching a predetermined number, the predetermined number of preprocessed data units are written from the first buffer to the second buffer dedicated to the real-time dedicated thread, while triggering the real-time dedicated thread.
[0049] The "predetermined number" in this step can be set according to the real-time requirement of the time-critical processing. For example, assuming that the number of ASDUs contained in each sample value message is set to 4, if the real-time requirement of the time-critical processing is high, the "predetermined number" can be set to 4, i.e. the time-critical processing is performed on each ASDU after it is preprocessed in a sample value message, alternatively, if the real-time requirement of the time-critical processing is medium, the "predetermined number" can also be set to 8, i.e. the time-critical processing is performed on two ASDUs after they are preprocessed in a sample value message.
[0050] The real-time dedicated thread is a thread specially used to perform the time-critical processing associated with the sample value message. There can be a real-time dedicated thread pool including one or more real-time dedicated threads, in which case triggering the real-time dedicated thread means triggering one real-time dedicated thread in the real-time dedicated thread pool. The triggering of the real-time dedicated thread can be implemented by, for example, a semaphore (i.e. Semaphore), which is used to limit the number of threads accessing a specific resource at the same time. By using an independent real-time dedicated thread to perform the time-critical processing associated with the sample value message, the time-critical processing of the previous batch of input data is performed as soon as possible before the next batch of input data (e.g. the next batch of sample value messages) arrives, so as to better meet the real-time requirement of the time-critical processing.
[0051] In step S350, the triggered real-time dedicated thread performs the time-critical processing by reading the preprocessed data units from the second buffer.
[0052] Therefore, by receiving the sample value message carrying the sample value through a communication interface such as Ethernet, using the first buffer and the second buffer, and using the real-time dedicated thread specially used to perform the time-critical processing to perform the time-critical processing as soon as possible, the method 300 for performing the time-critical processing in a non-real-time operating system according to the embodiments of the present disclosure can better meet the real-time requirement of the time-critical processing in the non-real-time operating system. In current general-purpose computing devices, the transmission rate of the communication interface is very high (e.g. more than 100 Mbps), and the computing power is very strong (e.g. reaching several GHz), and the present disclosure can achieve a processing effect comparable to or even better than that of a real-time operating system in a non-real-time operating system.
[0053] For example, taking the power system as an example, in the case of a sampling rate of 4000 Hz and a power frequency of 50 Hz, 80 sampling points per cycle, each sampling value message carries the data of 4 sampling points (i.e. 4 ASDUs), 20 sampling value messages are generated corresponding to each cycle (i.e. 20 ms), and the length of each sampling value message is less than 600 bytes. Taking the transmission rate of Ethernet as 100 Mbps, i.e. 12.5 MB / s, the number of sampling value messages that can be transmitted within 1 ms is up to 20, which is much higher than the requirement of transmitting 20 messages within 20 ms. Even if the messages transmitted by Ethernet also include messages other than sampling value messages, the interval between the continuous capture of two sampling value messages will not exceed 1 ms, and the transmission rate of Ethernet has reached the order of Gbps. Moreover, the performance of ordinary computing devices can fully meet the requirement of processing 20 sampling value messages within 20 ms. For example, the inventors of the present disclosure used a CPU Intel Xeon E3-1220 v6 with a processing frequency of 3.00 GHz, 4 cores and 4 threads, and 16 GB of RAM to execute the above method 300, and in the case of a sampling frequency of 4800 Hz and each sampling value message carrying 1 ASDU, the real-time processing of 96 sampling value messages within 20 ms was realized. Higher network transmission performance and higher CPU hardware performance will also be suitable for higher sampling rates.
[0054] To better illustrate Figure 3 the method 300, Figure 4 is another schematic diagram of a method for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure.
[0055] Referring to Figure 4 , the messages from the external device are transmitted to the computing device of the non-real-time operating system via the communication interface, and as a response to the external device, the non-real-time operating system will enable the "interrupt" mode to process the messages, for example, using a packet capture tool to capture the messages. Then, according to the predefined rule (for example, for the aforementioned example of the power system, the predefined rule can be the frame format of the sampling value message specified in the communication protocol IEC 61850-9-2), it is analyzed whether the captured message is a sampling value message associated with time-critical processing, and if so, the data unit of the captured sampling value message is written into a first buffer. Then, the data units in the first buffer are preprocessed, which can include operations such as arranging and combining the bytes in the data units so that the bytes indicating the sampling values are located in a specific position. When the number of preprocessed data units in the first buffer reaches a predetermined number, the predetermined number is written into a second buffer, and at the same time, a real-time dedicated thread is triggered, for example, by a semaphore, to start executing the time-critical processing for the sampling value message.
[0056] As Figure 4As shown, the result data of the time-critical processing performed by the real-time dedicated thread can be written into a local database of the computing device for use by a non-real-time dedicated thread. The non-real-time dedicated thread is relative to the real-time dedicated thread, and is used to perform non-time-critical processing with lower real-time requirement than the time-critical processing in the real-time dedicated thread. For example, for the aforementioned example of the power system, the non-time-critical processing includes, but is not limited to, Human Machine Interface (HMI) update, other processing required to be performed according to the provisions of the communication protocol IEC 61850-9-2, other processing for control, etc., wherein the HMI update generates an updated interface to be shown to a user based on the result data in the local database, which can highly simulate the interface related to the power system to be shown to the user under the real-time operating system.
[0057] Figure 5 is a schematic diagram of writing and reading data units to and from the second buffer according to an embodiment of the disclosure.
[0058] Reference is made to Figure 5 When a predetermined number of pre-processed data units are written from the first buffer to the second buffer (as shown in step S340 in Figure 3 , the pre-processed data units are written into the second buffer based on the write pointer of the second buffer, which points to the address space in the second buffer where the current data unit should be written. For each write, the offset of the write-after write pointer relative to the write-before write pointer is the predetermined number of data units that are written.
[0059] The real-time dedicated thread reads the pre-processed data units from the second buffer through the read pointer of the second buffer. Since the speed of the real-time dedicated thread to process the data units can be affected by the amount of tasks processed by the computing device, it is possible to be slower than the speed of the data units being written into the second buffer. Therefore, in order for the data units in the second buffer to be processed as soon as possible to better achieve real-time, when performing the read operation on the second buffer, the number of data units read each time can be determined to be the offset that aligns the read-after read pointer with the current write pointer, if the processing capability of the non-real-time operating system allows.
[0060] As Figure 5As shown, the second buffer experiences a first write operation, and the number of data units written is 4, so the offset between the write-before-write pointer and the write-after-write pointer is 4. Then, the second buffer experiences a first read operation, and due to the limitation of processing capability, the number of data units read by the real-time dedicated thread is less than 4, only 3, so the offset between the read-after-read pointer and the read-before-read pointer is 3. Then, the second buffer experiences a second write operation, and the number of data units written is still 4, so the offset between the write-before-write pointer and the write-after-write pointer is still 4. Then, the second buffer experiences a second read operation, and at this time, the processing capability allows, in order to improve the processing speed of the data units in the second buffer to better reflect the real-time performance, the offset of the read pointer of the second read operation can be determined to be 5 (i.e. 4+4-3=5) data units, that is, 5 data units are read, and at this time, the read-after-read pointer is aligned with the current write pointer.
[0061] In this way, the read pointer of the second buffer forms a "catch-up" with the write pointer of the second buffer, which can improve the processing speed of the data units in the second buffer, better reflect the real-time performance, and prevent the missing processing of the data units written into the second buffer.
[0062] Generally, under the computing capability of the currently common computing device, the second buffer will not appear the situation that the read pointer "cannot catch up" with the write pointer. However, it cannot be ruled out that such a situation will occur in extreme or certain specific scenarios. For example, for a power frequency of 50 Hz and a sampling rate of 4000 Hz, 80 sampling points per cycle, and each sampling value message carries 4 sampling value information of sampling points, 20 frames of messages will be generated every 20 ms, and if the computing capability of the computing device is lower than such data throughput, the situation that the read pointer in the second buffer "cannot catch up" with the write pointer may occur. Therefore, the present disclosure also contemplates an error reporting mechanism in this case. When the speed of reading data units from the second buffer is slower than the speed of writing data units from the first buffer to the second buffer, the read pointer becomes more and more difficult to "catch up" with the write pointer, until the offset of the read pointer determined at a certain read operation exceeds a predetermined offset threshold (for example, 10 data units, which is not limited by the present disclosure), the real-time dedicated thread cannot read the data units in the second buffer according to the determined offset, at this time, an error message is triggered to inform the user that the time-critical processing cannot be performed due to the mismatch between the read and write speeds of the second buffer.
[0063] The inventors of the present disclosure use 100Mbps Ethernet transmission rate and 3.00GHz processing frequency, 4-core 4-thread CPU Intel Xeon E3-1220 v6 and 16GB RAM to perform the method 300, and in the case of 4800Hz sampling frequency and each sampling value message carrying 1 ASDU, 96 sampling value messages within 20ms can be well achieved.
[0064] Figure 6 is a result diagram obtained by performing the method for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure.
[0065] Still taking the power system as an example, Figure 6 shows the result obtained by performing time-critical processing on the sampling value message of the power system in the Windows operating system. The sampling value message is transmitted via 100Mbps Ethernet to the computing device of the Windows operating system, the data units in the sampling value message are written into the first buffer, when a predetermined number of data units are written into the first buffer, the predetermined number of data units are written into the second buffer, and a real-time dedicated thread is triggered to perform time-critical processing. For example, the time-critical processing includes sampling value acquisition, sampling value processing and protection decision. The sampling value acquisition is triggered in response to the real-time dedicated thread being triggered, which is used to read the data units from the second buffer and acquire the sampling values in the data units. The sampling value processing is triggered in response to the end of the execution of the sampling value acquisition, which is used to process the acquired sampling values to form data that can be used to make a protection decision. The sampling value processing can include a plurality of sub-processes, which can be triggered in turn, such as Figure 6 The sub-processes shown in include resampling and filtering, and the resampling is triggered in response to the end of the execution of the sampling value acquisition, and the filtering is triggered in response to the end of the execution of the resampling, and the present disclosure does not limit the number of sub-processes of the sampling value processing. The protection decision is triggered in response to the sampling value processing having been executed for a predetermined number of times (for example, 5 times), which is used to make a protection decision according to the data that can be used to make a protection decision formed by the sampling value processing.
[0066] Figure 6 T1, T2, T3, T4, T5 in represent the time intervals of triggering the real-time dedicated thread twice in a row, but they are not fixed values, they are related to the Ethernet transmission rate and the computing power of the computing device (as described before). When the inventors of the present disclosure use 100Mbps Ethernet transmission rate and 3.00GHz processing frequency, 4-core 4-thread CPU Intel Xeon E3-1220 v6 and 16GB RAM to perform the method 300, the time intervals T1, T2, T3, T4, T5 and the like are all much less than 1ms, which reaches the requirement ofFigure 1 The real-time operating system in the above-mentioned system is equivalent to the effect of a real-time operating system. For a system under test with a higher sampling rate, a higher Ethernet transmission rate and the computing capacity of the computing device can be configured accordingly.
[0067] The above-mentioned Figures 3 to 6 A method for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure is described below in conjunction with Figure 7 A device for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure is described below in conjunction with
[0068] Figure 7 is a schematic block diagram of a device for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure. The device can be a computing device such as a personal computer, a workstation, a server running, for example, a Windows operating system.
[0069] Reference is made to Figure 7 The device 700 for performing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure comprises at least a packet capturing module 710, a packet analyzing module 720, a packet preprocessing module 730, a real-time dedicated thread triggering module 740 and a real-time dedicated thread executing module 750.
[0070] The packet capturing module 710 can be a tool that can be used to receive raw packets via a communication interface, for example, the WinPcap tool under the Windows operating system.
[0071] The packet analyzing module 720 is configured to analyze whether the packet captured by the packet capturing module 710 is a sampled value packet associated with time-critical processing, and when it is determined that the packet is a sampled value packet associated with time-critical processing, write the data unit contained in the sampled value packet to a first buffer. For example, for the aforementioned example of a power system, the sampled value packet can be, for example, a sampled value packet conforming to the communication protocol IEC 61850-9-2.
[0072] The packet preprocessing module 730 is configured to perform preprocessing on the data unit written in the first buffer. The preprocessing can include an operation of arranging and combining the bytes in the data unit so that the bytes indicating the sampled value are located at a specific position.
[0073] The real-time dedicated thread triggering module 740 is configured to, in response to the preprocessed data units in the first buffer reaching a predetermined number (for example, 4), write the predetermined number of preprocessed data units from the first buffer to a second buffer dedicated to a real-time dedicated thread, and trigger the real-time dedicated thread. For example, the real-time dedicated thread triggering module 740 can trigger the real-time dedicated thread by means of a semaphore.
[0074] The real-time dedicated thread execution module 750 reads data units from the second buffer and performs time-critical processing associated with the sampled-value messages. For example, for the aforementioned example of the power system, the time-critical processing includes, but is not limited to, sampled-value acquisition, sampled-value processing (including resampling, filtering, etc.), protection decision, etc.
[0075] As an example, the real-time dedicated thread triggering module 740 writes the preprocessed data units in the first buffer into the second buffer based on the write pointer of the second buffer, and for each write, the offset of the write pointer is the predetermined number. And the real-time dedicated thread reads the data units from the second buffer based on the read pointer of the second buffer, and for each read, the offset of the read pointer of the second buffer is determined to be an offset that aligns the read pointer with the current write pointer after the read, if the processing capability of the non-real-time operating system allows.
[0076] As an example, the device 700 can further include an error reporting module 760 for issuing an error message when the offset of the read pointer of the second buffer is determined to exceed the predetermined offset threshold.
[0077] As an example, the real-time dedicated thread also writes the result data generated by performing the time-critical processing into a local database for reading and processing by the non-real-time dedicated thread, which performs non-time-critical processing. For example, for the aforementioned example of the power system, the non-time-critical processing includes HMI update, which updates the interface shown to the user based on the result data in the local database, which can highly simulate the interface related to the power system shown to the user under the real-time operating system.
[0078] For the sake of brevity, the detailed description of the detailed details performed by the message capturing module 710, the message analysis module 720, the message preprocessing module 730, the real-time dedicated thread triggering module 740, the real-time dedicated thread execution module 750, and the error reporting module 760 is referred to the above description in connection with Figures 3 to 6 .
[0079] The method 300 and the device 700 for performing time-critical processing in a non-real-time operating system according to the embodiments of the present disclosure can achieve comparable or even better effects of performing time-critical processing in a real-time operating system by triggering the real-time dedicated thread for performing time-critical processing on the sampled-value messages based on the number of data units contained in the captured sampled-value messages reaching a predetermined number, by employing the double buffering mechanism of the first buffer and the second buffer and dedicating the second buffer to the real-time dedicated thread, and by determining the number of data units to be read each time the real-time dedicated thread performs a read operation on the second buffer to avoid missing processing of data units, under the current network transmission rate and the computing capability of computing devices.
[0080] In addition, for example, for the example of the power system described above, from the perspective of production and market, the method 300 and the device 700 for executing time-critical processing in a non-real-time operating system according to the embodiments of the present disclosure can also bring the following benefits: compared with a real-time operating system, it is easier to debug and unit test on a non-real-time operating system such as Windows, thereby bringing great convenience to software developers; the confirmation and verification (Validation and Verification) in software development can be carried out in parallel with hardware development, thereby saving the development cycle; messages can be received directly from the Ethernet without the need for bulky signal generating equipment (for example, the relay protection tester of OMICRON CMC), thereby only one computing device is needed; the non-time-critical processing HMI update can highly simulate the interface related to the power system displayed to the user under the real-time operating system, thereby facilitating the collection of customer feedback and needs during the development and testing stage, reducing the development risk, and being more conducive to maintaining customers.
[0081] The present disclosure, although taking the power system as an example, is obviously not limited to the power system, and can also be applied to other systems to be tested that require real-time processing.
[0082] The above-described embodiments are merely illustrative, for example, although in the above description, the real-time dedicated thread is triggered by taking the message of the sampling value containing a predetermined number of data units as the trigger condition, other trigger conditions such as the number of messages of the sampling value can also be considered to trigger the real-time dedicated thread. For another example, although in the above description, WinPcap is used as the packet capturing tool and the semaphore is used as the tool for triggering the real-time dedicated thread, other tools that can achieve equivalent functions can also be considered.
[0083] Figure 8 is a schematic block diagram of a device for executing time-critical processing in a non-real-time operating system according to another embodiment of the present disclosure.
[0084] The device 800 for executing time-critical processing in a non-real-time operating system according to another embodiment of the present disclosure at least includes a memory for storing computer program instructions and a processor for executing the computer program instructions. When the computer program instructions are loaded and run by the processor, the processor executes the above-described method 300 for executing time-critical processing in a non-real-time operating system.
[0085] Figure 8The device 800 shown to execute time-critical processing in a non-real-time operating system can specifically include a central processing unit (CPU) 801, a graphics processing unit (GPU) 802, and a main memory 803. These units are connected to each other through a bus 804. The central processing unit (CPU) 801 and / or the graphics processing unit (GPU) 802 can be used as the processor described above, and the main memory 803 can be used as the memory described above to store computer program instructions. In addition, the device 800 can further include a communication unit 805, a storage unit 806, an output unit 808, an input unit 808, and an external device 809, which are also connected to the bus 804.
[0086] Figure 9 is a schematic diagram illustrating a computer-readable storage medium according to an embodiment of the present disclosure. As shown, the computer-readable storage medium 900 according to an embodiment of the present disclosure has computer program instructions 901 stored thereon. When the computer program instructions 901 are run by a processor, the method 300 of executing time-critical processing in a non-real-time operating system according to an embodiment of the present disclosure described with reference to the above figures is executed. Figure 9
[0087] The computer-readable storage medium includes, but is not limited to, for example, volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory, etc. The non-volatile memory may, for example, include read-only memory (ROM), a hard disk, a flash memory, an optical disk, a magnetic disk, etc.
[0088] The flowcharts and block diagrams in the drawings show the possible implementation architecture, function and operation of the method, device and computer program product according to an embodiment of the present disclosure. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks can also occur in different order from that noted in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and they can also be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and the combination of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0089] In addition, each functional module in the embodiments of the present disclosure can be integrated together to form a separate part, or each module can exist independently, or two or more modules can be integrated to form a separate part.
[0090] If the functions are implemented 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 this understanding, the technical solutions of the present disclosure, essentially or part of the prior art, or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, and various media that can store program codes.
[0091] The above is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present disclosure, which should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the appended claims and their equivalents.
Claims
1. A method for performing time-critical processing in a non-real-time operating system, comprising: Capture packets from external devices using packet capture tools; Analyze whether the message is a sampled value message associated with the time-critical processing, and when the message is a sampled value message associated with the time-critical processing, write the data units contained in the sampled value message into the first buffer; The data units written to the first buffer are preprocessed, the preprocessing including arranging the bytes of the data units such that the byte indicating the sample value is located in a specific position; In response to the preprocessed data units in the first buffer reaching a predetermined number, the predetermined number of preprocessed data units are written from the first buffer to a second buffer dedicated to a real-time dedicated thread, and the real-time dedicated thread is triggered to start executing the time-critical processing. The real-time dedicated thread is independent of other threads, and The execution of the time-critical processing includes reading the preprocessed data units from the second buffer via the real-time dedicated thread.
2. The method according to claim 1, wherein, Writing preprocessed data units from a first buffer to a second buffer includes: writing the preprocessed data units to the second buffer based on a write pointer of the second buffer, wherein for each write, the offset of the write pointer of the second buffer is the number of data units written; and The real-time dedicated thread reads the preprocessed data unit from the second buffer by: reading the data unit from the second buffer based on the read pointer of the second buffer, and for each read, if the processing capability of the non-real-time operating system allows, the offset of the read pointer is determined to be an offset such that the read pointer is aligned with the current write pointer after the read.
3. The method according to claim 2, wherein, An error message is triggered when the determined offset of the read pointer exceeds a predetermined offset threshold.
4. The method according to claim 1, wherein, The time-critical processing includes sample value acquisition, sample value processing, and protection decision-making. The sample value acquisition is triggered in response to the real-time dedicated thread being triggered, which is used to acquire the sample value in the data unit from the second buffer; The sample value processing is triggered in response to the completion of the sample value acquisition, and is used to process the sample value to form data for making protection decisions; as well as The protection decision is triggered in response to the sampled value processing having been performed a predetermined number of times, and is used to make a protection decision based on the data used to perform the protection decision.
5. The method according to claim 1, further comprising: The result data generated by the time-critical processing performed by the real-time dedicated thread is written to the local database.
6. A device for performing time-critical processing in a non-real-time operating system, comprising: The packet capture module is used to capture packets from external devices using packet capture tools. The message analysis module is used to analyze whether the message is a sampled value message associated with the time-critical processing, and when the message is a sampled value message associated with the time-critical processing, writes the data units contained in the sampled value message into the first buffer. A message preprocessing module is used to preprocess data units written to the first buffer, the preprocessing including arranging and combining the bytes of the data unit so that the byte indicating the sample value is located in a specific position; The real-time dedicated thread triggering module, in response to the predetermined number of preprocessed data units in the first buffer, writes the predetermined number of preprocessed data units from the first buffer into a second buffer dedicated to the real-time dedicated thread, and simultaneously triggers the real-time dedicated thread to start executing the time-critical processing. as well as The real-time dedicated thread execution module is configured to perform the time-critical processing associated with the sampled value message by reading the preprocessed data units from the second buffer through the real-time dedicated thread. The real-time dedicated thread is independent of other threads.
7. The device according to claim 6, wherein, The real-time dedicated thread triggering module writes the predetermined number of preprocessed data units into the second buffer based on the write pointer of the second buffer, and for each write, the offset of the write pointer of the second buffer is the number of data units written. and The real-time dedicated thread reads the preprocessed data unit from the second buffer by: reading the data unit from the second buffer based on the read pointer of the second buffer, and for each read, if the processing capability of the non-real-time operating system allows, the offset of the read pointer is determined to be an offset such that the read pointer is aligned with the current write pointer after the read.
8. The device according to claim 7, further comprising: The error reporting module is used to trigger an error message when the determined offset of the read pointer exceeds a predetermined offset threshold.
9. The device according to claim 6, wherein, The time-critical processing includes sample value acquisition, sample value processing, and protection decision-making. The sample value acquisition is triggered in response to the real-time dedicated thread being triggered, which is used to acquire the sample value in the data unit from the second buffer; The sample value processing is triggered in response to the completion of the sample value acquisition, and is used to process the sample value to form data for making protection decisions; as well as The protection decision is triggered in response to the sampled value processing having been performed a predetermined number of times, and is used to make a protection decision based on the data used to make the protection decision.
10. The device according to claim 6, wherein, The real-time dedicated thread execution module is also used to write the result data generated by the real-time dedicated thread executing the time-critical processing into a local database.
11. A device for performing time-critical processing in a non-real-time operating system, comprising: processor; and A memory storing a computer-executable program that, when executed by the processor, causes the device to perform the method of any one of claims 1-5.
12. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, perform the method according to any one of claims 1-5.
Citation Information
Patent Citations
Method and device for realizing SV message processing based on FPGA on-chip buffering
CN106961396A
Non real-time metrology data management
US20140173630A1