An event record generation method, device, apparatus, and storage medium
By combining virtual clocks and shared memory, virtual time values are generated, solving the problem of insufficient timestamp accuracy in event recording in soft PLCs and cloud-based control systems. This achieves accuracy and stability in event recording, supporting reliable accident analysis and fault tracing.
Patent Information
- Application Number
- CN202611276752.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-11-20
AI Technical Summary
In soft PLC or cloud-based control systems, the insufficient accuracy of event timestamp recording may lead to the reversal of the order of event records, making the timestamps unreliable and affecting accident analysis and fault tracing.
Virtual time values are generated using a virtual clock and are periodically updated via shared memory. The virtual time values are calculated from observed time values, hardware feedback data, and historical data, and are obtained directly from shared memory, avoiding the impact of operating system scheduling, and generating event records with time.
It improves the accuracy and stability of event records, enabling them to accurately reflect the sequence of events and provide a reliable basis for accident analysis and fault tracing.
Smart Images

Figure CN123138487A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial control technology, specifically to an event log generation method, apparatus, device, and storage medium. Background Technology
[0002] Sequence of Events (SOE) systems are used to record the temporal sequence of discrete events such as switch changes and protection actions in industrial settings. Their time resolution typically requires millisecond or even microsecond levels to support accident analysis and fault tracing. As industrial control systems evolve towards software-based and virtualized architectures, running software-based programmable logic controllers (PLCs) or cloud-based control systems on general-purpose servers, and acquiring SOE signals via software, has become a trend. Currently, interrupt-based SOE signal acquisition is commonly used. This method involves triggering an interrupt when the hardware detects an event, prompting the acquisition program to respond and read the system clock time value, which is then used to timestamp the event.
[0003] However, in the aforementioned software data acquisition scheme, the acquisition program runs on a general-purpose operating system, and the accuracy of its timestamp recording is affected by the operating system's running state. In actual operation, there is often a non-negligible error between the timestamp recorded by the acquisition program and the actual time of the event, which may cause the order of event recordings to be reversed, making the timestamps unreliable. Summary of the Invention
[0004] This application provides an event log generation method, apparatus, device, and storage medium that can generate event logs with time information, so that the time information in the event logs can reflect the actual chronological order of events, providing a reliable basis for accident analysis and fault tracing.
[0005] A first aspect of this application provides an event log generation method, the method comprising: In response to an interrupt signal received by the operating system kernel, a virtual time value is obtained from shared memory. The interrupt signal is used to indicate that an event has occurred. The shared memory is a memory region that supports direct access by the operating system kernel. The virtual time value stored in the shared memory is periodically updated by a virtual clock. Based on the virtual time value and the associated data of the event, an event record with time is generated; The virtual time value is generated in the following way: A virtual time value is calculated based on the observed time value, hardware feedback data, and historical data. The observed time value is determined using an observed time source. The hardware feedback data characterizes the working status of the transmission link associated with the observed time source. The historical data includes the virtual time value previously calculated and output by the virtual clock and the state vector obtained from the previous calculation. The state vector characterizes the error state between the previously calculated virtual time value and the observed time value used in the previous calculation.
[0006] A second aspect of this application provides an event log generation apparatus, the apparatus comprising: The acquisition module is used to acquire a virtual time value from shared memory in response to an interrupt signal received by the operating system kernel. The interrupt signal is used to indicate that an event has occurred. The shared memory is a memory area that supports direct access by the operating system kernel. The virtual time value stored in the shared memory is periodically updated by a virtual clock. The generation module is used to generate time-stamped event records based on the virtual time value and the associated data of the event; The virtual time generation module is used to calculate a virtual time value based on the observed time value, hardware feedback data, and historical data, and periodically update it to the shared memory. The observed time value is determined using an observed time source, the hardware feedback data represents the working status of the transmission link associated with the observed time source, and the historical data includes the virtual time value output by the virtual clock in the previous calculation and the state vector obtained in the previous calculation. The state vector represents the error state between the virtual time value output by the previous calculation and the observed time value used in the previous calculation.
[0007] A third aspect of this application provides a computing device, the device comprising a processor and a memory: The memory is used to store computer programs; The processor is configured to perform the steps of the event log generation method as described in the first aspect above, according to the computer program.
[0008] A fourth aspect of this application provides a computer-readable storage medium for storing a computer program for performing the steps of the event log generation method described in the first aspect.
[0009] A fifth aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of the event log generation method described in the first aspect.
[0010] As can be seen from the above technical solutions, the embodiments of this application have the following advantages: This application provides an event log generation method, which innovatively proposes a scheme for generating time-based event logs based on a virtual clock and shared memory. The method includes: in response to an interrupt signal, obtaining a virtual time value from shared memory, where the interrupt signal indicates an event has occurred; and generating a time-based event log based on the virtual time value and associated event data. Specifically, the virtual time value is calculated by the virtual clock based on observed time values, hardware feedback data, and historical data, and is periodically updated to the shared memory, rather than directly using the observed time value as the virtual time value. Specifically, the hardware feedback data characterizes the operating status of the transmission link associated with the observed time source, and the historical data includes the virtual time value previously calculated and output by the virtual clock and a previously calculated state vector, which characterizes the error state between the previously output virtual time value and the previously observed time value. Therefore, the calculation of the virtual time value suppresses the impact of fluctuations in single observed time values and can be dynamically adjusted according to the operating status of the transmission link, giving the virtual time value high stability and accuracy. Furthermore, since the virtual time value is periodically updated to shared memory, the latest virtual time value can be directly retrieved from shared memory in response to an interrupt signal. This means the retrieval process does not involve operating system scheduling, resulting in low latency, deterministic timing, and immunity to operating system scheduling jitter. Consequently, the error between the time recorded in the event log generated based on this virtual time value and the actual time of the event is small. This ensures that when multiple event logs are arranged according to their timestamps, they reflect the true chronological order of the events, thus providing a reliable basis for accident analysis and fault tracing. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This application provides an architectural diagram of an event log generation system. Figure 2 This is a schematic diagram illustrating an application scenario of an event log generation method provided in an embodiment of this application; Figure 3 A flowchart illustrating an event log generation method provided in an embodiment of this application; Figure 4A flowchart illustrating a virtual time value generation method provided in an embodiment of this application; Figure 5 A schematic diagram of a multi-source observation and robust anomaly detection process provided for an embodiment of this application; Figure 6 A flowchart illustrating a priority scheduling method provided in an embodiment of this application; Figure 7 This is a schematic diagram of the overall data processing flow of an event log generation method provided in an embodiment of this application; Figure 8 This is a schematic diagram of the structure of an event log generation device provided in an embodiment of this application; Figure 9 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Detailed Implementation
[0013] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0014] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0015] Event sequence recording (SOE) systems are a crucial component of industrial control systems used to record the state changes of field equipment and the sequence of their occurrence. In industrial sites such as power plants, substations, and chemical plants, numerous switches, circuit breakers, and protection devices are deployed. The state changes of these devices, such as switch tripping and protection actions, typically occur discretely. SOE systems need to record the occurrence time of each state change event with millisecond or even microsecond-level time resolution and arrange them in chronological order to form an event timeline.
[0016] Event timelines are the core basis for accident analysis and fault tracing. When a fault occurs in an industrial field, multiple devices may operate in succession within a very short period of time. For example, in the instant of a power grid failure, dozens of switches may trip within milliseconds. Analysts need to use the event timeline to determine which device the fault occurred in first, how the fault gradually propagated, and thus locate the root cause of the fault and develop a repair plan. If the order of events in the timeline is incorrect, the root cause of the fault may be misjudged, or even a faulty device may be mistakenly identified as a faulty device.
[0017] As industrial control systems evolve towards software-based and virtualized architectures, running software PLCs or cloud-based control systems on general-purpose servers and acquiring SOE signals via software has become a trend. Compared to traditional dedicated hardware input / output (IO) cards, software acquisition solutions offer advantages such as lower cost and greater flexibility in expansion. However, software acquisition solutions implementing SOE acquisition on general-purpose servers also face the challenge of insufficient timestamp recording accuracy.
[0018] Currently, in related technologies, soft PLCs or cloud-based control systems typically acquire SOE signals using software. Specifically, when a field switch quantity changes, the communication (COM) card detects this change and sends an interrupt signal to the processor via the peripheral component interconnect express (PCIe) bus. After responding to the interrupt signal, the processor uses the acquisition program to call the system clock to obtain the time value, and then uses the obtained time value as a timestamp to generate an event record along with the event information.
[0019] However, the accuracy of the timestamp in the above methods is affected by two factors.
[0020] On one hand, the system clock itself suffers from frequency drift. Driven by a hardware crystal oscillator, the oscillator's frequency is not absolutely constant due to factors such as temperature and aging, causing the system clock to run too fast or too slow. Although the operating system periodically calibrates the system clock using methods such as network time protocols, the calibration intervals are usually quite long. Between two calibrations, the system clock may have accumulated a non-negligible deviation. Therefore, the time value read from the system clock by the acquisition program may itself deviate from the actual time of the event.
[0021] On the other hand, the process of the acquisition program obtaining the system clock involves random delays. The acquisition program needs to read the system clock through a system call. During the system call, the operating system may be processing other tasks, and the acquisition program needs to wait for the operating system scheduler to allocate processor time slices. The waiting time is uncertain, ranging from a few microseconds to tens of microseconds, and may vary each time. Therefore, even if the system clock itself is accurate, the actual time value read by the acquisition program may lag behind the actual time of the event, and the amount of lag varies randomly.
[0022] The combination of these two factors results in a significant discrepancy between the timestamps in the event logs generated by the data collection program and the actual timestamps of the events. When multiple events occur consecutively within a short period, this error can lead to a discrepancy between the recorded order of events and the actual order in which they occur, rendering the timestamps unreliable.
[0023] To address the aforementioned issues, this application provides an event log generation method. In this method, the virtual time value is calculated by a virtual clock based on observed time values, hardware feedback data, and historical data, and is periodically updated to shared memory. Specifically, the virtual clock estimates the current time based on historical data and corrects this estimate using observed time values provided by the observation time source. Simultaneously, the virtual clock also determines the reliability of the observed time value based on hardware feedback data characterizing the transmission link's operating status and adjusts the correction accordingly. Through this combination of estimation, observation, and dynamic correction, the virtual time value no longer directly depends on the system clock but continuously integrates external calibration information, thereby suppressing the impact of system clock drift and improving the accuracy and stability of the virtual time value. Furthermore, shared memory is a memory region that supports direct access by the operating system kernel. When an event occurs, the operating system kernel responds to an interrupt signal and directly retrieves the virtual time value from shared memory. The retrieval process does not involve operating system scheduling, has low latency, is deterministic, and is unaffected by operating system scheduling.
[0024] In this way, the solution can ensure the accuracy of the virtual time value and ensure that the process of obtaining the virtual time value is not delayed by scheduling, so that the time of the generated event record can reflect the actual order of events.
[0025] The event log generation system of this application embodiment will now be described with reference to the accompanying drawings.
[0026] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of an event log generation system provided in an embodiment of this application. Figure 1The event log generation system 100 is a system architecture used to implement the event log generation method in the embodiments of this application. The event log generation system 100 includes a computing device 110, a virtual clock 120, shared memory 130, a COM card 140, and an observation time source 150.
[0027] The computing device 110 is used to execute the event log generation method provided in the embodiments of this application. The computing device 110 may be, for example, a general-purpose server, an industrial control computer, or a computing node in a cloud-based control platform. The embodiments of this application do not limit the specific form of the computing device 110.
[0028] The computing device 110 runs an operating system. The operating system divides the runtime environment into kernel mode and user mode. Kernel mode is the environment in which the operating system kernel and hardware drivers run, possessing a higher privilege level and the ability to directly access hardware resources. In kernel mode, the processor responds to hardware interrupts and executes the corresponding interrupt handlers. User mode is the environment in which applications run, possessing a lower privilege level. Applications cannot directly access hardware resources and must access system resources through interfaces provided by the operating system.
[0029] Virtual clock 120 runs in user space. Virtual clock 120 is a software module used to generate virtual time values. Instead of directly reading the operating system's system clock, virtual clock 120 periodically calculates virtual time values based on observed time values, hardware feedback data, and historical data. Specifically, virtual clock 120 uses observed time source 150 to determine the observed time values, hardware feedback data characterizes the working status of the transmission link associated with observed time source 150, and historical data is data generated by virtual clock 120 in previous calculations. After generating virtual time values, virtual clock 120 updates the virtual time values in shared memory 130.
[0030] In this embodiment, the virtual clock 120 can be deployed in a virtual controller. The virtual controller is a software module running in user space, used to execute various user-space processing tasks during the event log generation process. In addition to the virtual clock 120, the virtual controller may also include a handler for reading time-bearing event logs from shared memory, and modules for performing subsequent processing such as priority scheduling, software debouncing, and resuming data transmission after network outages.
[0031] Shared memory 130 is a memory region allocated by the operating system in physical memory, located in computing device 110. This shared memory 130 is configured to support direct access by the operating system kernel. Specifically, shared memory 130 is mapped to both user-mode and kernel-mode address spaces, enabling the virtual clock 120 in user mode to write virtual time values to shared memory 130, while interrupt handlers in kernel mode can directly read virtual time values from shared memory 130. Accessing shared memory 130 does not involve operating system scheduling or context switching, resulting in low and deterministic access latency.
[0032] COM card 140 is connected to computing device 110. COM card 140 is a communication card used to connect field devices to computing device 110. Field devices can be, for example, industrial equipment such as switches, circuit breakers, and protection devices. The switching signals from the field devices are connected to the input terminals of COM card 140 via cables. When the state of a field device changes, COM card 140 detects the change and sends a hardware interrupt signal to the processor via the PCIe bus.
[0033] The observation time source 150 provides a calibration reference for the virtual clock 120. The observation time source 150 may include a first observation time source and a second observation time source. The first observation time source may be, for example, a high-precision counter on a COM card 140 or a field-programmable gate array (FPGA). The high-precision counter is a hardware timing circuit driven by an independent crystal oscillator, and its counting process is not affected by operating system scheduling. The second observation time source may be, for example, a network time source that obtains time from a higher-level master clock via a precision time protocol (PTP). Each of the two observation time sources provides an observation time value, and the virtual clock 120 performs a fusion calibration based on the two observation time values.
[0034] Hardware feedback data characterizes the operational status of the transmission link associated with the observation time source 150. For the first observation time source, hardware feedback data may include, for example, the number of retransmissions that occurred during the acquisition of the observation time value, and the variance of the time taken to read the observation time value multiple times. For the second observation time source, hardware feedback data may include, for example, the network round-trip delay variance and the deviation of the PTP time from the local monotonic clock. The hardware feedback data is used to calculate the reliability of the observation time value, thereby determining the degree of trust that the virtual clock 120 has in the observation time value during fusion calibration.
[0035] It should be noted that, Figure 1The quantity and deployment of the computing device 110, virtual clock 120, shared memory 130, COM card 140, and observation time source 150 shown are merely examples. In practical applications, the computing device 110 may include more or fewer components, the virtual clock 120 may be deployed as an independent process or thread, the shared memory 130 may be divided into multiple regions, and the observation time source 150 may be configured according to the actual scenario. This application embodiment does not impose specific limitations in this regard.
[0036] The following is combined with Figure 2 This paper provides an example of the application scenarios for the event log generation method.
[0037] See Figure 2 , Figure 2 This is a schematic diagram illustrating an application scenario of an event log generation method provided in an embodiment of this application. Figure 2 Taking a circuit breaker tripping event as an example, the complete process from the occurrence of the event to the formation of a time-based event record is demonstrated.
[0038] In industrial settings, numerous switching devices are deployed, such as circuit breakers, protective devices, and disconnect switches. Taking a circuit breaker as an example, the circuit breaker is connected to a COM card 140 via a cable, and the COM card 140 is inserted into the PCIe slot of the computing device 110. A virtual clock 120 continuously runs in user mode on the computing device 110, periodically generating virtual time values and writing the latest virtual time value to shared memory 130. Shared memory 130 is a memory area that supports direct access by the operating system kernel.
[0039] When the circuit breaker trips at a certain moment, i.e., changes from the closed state to the open state, the COM card 140 detects the corresponding level change and sends an interrupt signal to the processor via the PCIe bus. After responding to the interrupt signal, the processor suspends the currently executing task and switches to executing the interrupt handler registered in the COM card 140 driver.
[0040] During execution, the interrupt handler directly reads the currently stored virtual time value from shared memory 130. This virtual time value is the one most recently updated in shared memory 130 by virtual clock 120 before the tripping event occurred. Since the calculation cycle of virtual clock 120 is less than the time resolution required by the SOE system, the update interval of the virtual time value in shared memory 130 meets the time accuracy requirements of the event log. Therefore, the read virtual time value is relatively close to the moment the tripping event occurred. Furthermore, since accessing shared memory 130 is not scheduled by the operating system, the time interval between the interrupt signal generation and the acquisition of the virtual time value is extremely small and deterministic. Thus, the event log generated based on this virtual time value can accurately reflect the moment the tripping event occurred and the chronological order of events.
[0041] After obtaining the virtual time value, the interrupt handler also reads the terminal number that tripped and the current voltage level from the hardware registers of COM card 140. The terminal number indicates which circuit breaker tripped, and the voltage level indicates the current open state after the trip. The interrupt handler uses the virtual time value as a timestamp, associates it with the terminal number and voltage level, and generates a timed event log. This event log contains at least three pieces of information: "which device changed," "what state it became," and "when the change occurred."
[0042] Optionally, the interrupt handler can also write the generated timed event records to shared memory 130 for the user-mode handler to read and perform subsequent processing. The subsequent processing performed by the user-mode handler may include, for example, software debouncing, priority scheduling, and batch packaging and sending the event records to a historical database or monitoring client.
[0043] For example, during a power grid fault, multiple switching devices may activate sequentially within milliseconds. The computing device 110 generates a time-based event record for each device's state change. Since the time value in each event record is a virtual time value directly retrieved from shared memory 130, without operating system scheduling, the event records generated based on these virtual time values accurately reflect the sequence of device actions. When analysts arrange these event records by their timestamps, the resulting sequence accurately reflects the actual order of device actions, thus providing a reliable basis for fault tracing.
[0044] It should be understood that Figure 2The application scenarios shown are merely examples. In practical applications, the event log generation method can also be applied to other scenarios that require recording the time sequence of events, such as recording the sequence of communication signaling and recording the time of each financial transaction, etc., without limitation here.
[0045] The following is a detailed description of the event log generation method through method implementation examples.
[0046] See Figure 3 , Figure 3 This is a flowchart illustrating an event log generation method provided in an embodiment of this application. Figure 3 As shown, the method includes the following steps: S301: Retrieves a virtual time value from shared memory in response to an interrupt signal received by the operating system kernel.
[0047] Interrupt signals are used to indicate the occurrence of an event. Specifically, an interrupt signal can be a hardware signal generated by the COM card when it detects a change in the state of a field device. The COM card is connected to the field device via a cable, and the field device's switching signals are connected to the COM card's input terminals. When the state of the field device changes, for example, a circuit breaker changes from closed to open, the COM card detects this change and sends an interrupt signal to the processor via the PCIe bus. Upon receiving the interrupt signal, the operating system kernel suspends the currently executing task and executes the interrupt handler corresponding to that interrupt signal.
[0048] The virtual time value is a time value generated by a virtual clock and pre-updated to shared memory. This virtual time value is used by interrupt handlers to read and serve as the time information for an event when it occurs. Unlike the operating system's system clock, the virtual time value is not read directly from the system clock; instead, it is calculated by the virtual clock based on observed time values, hardware feedback data, and historical data. The virtual clock periodically generates virtual time values and updates the shared memory with the new virtual time value after each generation. Therefore, the virtual time value stored in shared memory is always the time value most recently calculated by the virtual clock.
[0049] For example, the virtual time value can be an absolute time value in the nanosecond range, stored in shared memory as an unsigned 64-bit integer (uint64_t) variable. The address of this variable is pre-defined in the shared memory. Each time the virtual clock completes a calculation, the new virtual time value is overwritten to this address via a memory write operation. The interrupt handler can directly read the variable stored at this address using the pre-established address mapping to obtain the latest virtual time value.
[0050] The process of an interrupt handler reading shared memory does not involve operating system scheduling or context switching, resulting in low and deterministic read latency, unaffected by operating system scheduling. For example, consider a scenario where the virtual time value is at the nanosecond level and shared memory supports access via memory mapping. When the COM card generates an interrupt signal, the processor jumps to the interrupt handler. The interrupt handler directly reads the currently stored virtual time value from shared memory using a pre-established address mapping. Thus, the time interval between the interrupt signal generation and the acquisition of the virtual time value is extremely small and deterministic.
[0051] S302: Generate event records with time based on virtual time values and associated event data.
[0052] The associated data of an event describes the specific content of that event. This associated data can include signal source information and state change information. Signal source information indicates the signal source from which the event occurred; that is, it indicates which field device experienced a state change. State change information indicates the state change of that signal source after the event occurred, for example, the field device changing from a closed state to an open state, or vice versa.
[0053] Specifically, the interrupt handler can read the terminal number where the status change occurred and the current voltage level of that terminal from the hardware registers of the COM card. The terminal number serves as signal source information, uniquely distinguishing different signal input terminals; the voltage level serves as status change information, indicating the state of the device connected to that terminal after the event occurred. After obtaining the virtual time value, the interrupt handler can use this virtual time value as a timestamp, associating it with the signal source information and status change information to generate a timed event record.
[0054] For example, consider a circuit breaker as the field device, changing from a closed to an open state. The COM card detects a change in the input terminal level corresponding to the circuit breaker from high to low, generating an interrupt signal. The interrupt handler reads a virtual time value from shared memory, for example, 17000000000000000000 nanoseconds. The interrupt handler reads from the COM card's hardware register that the terminal number corresponding to this event is "Switch 1," and the current level state is "open." Then, the interrupt handler associates "Switch 1," "open," and "17000000000000000000 nanoseconds" to generate an event record with time. This event record fully reflects three pieces of information: "which device changed," "what state it became," and "when the change occurred."
[0055] Optionally, after generating timed event records, the computing device can also write the timed event records into shared memory for the user-mode processor to read and execute subsequent processing. The user-mode processor can read the timed event records from shared memory and perform software debouncing, priority scheduling, and batch packaging and sending the event records to a historical database or monitoring client, among other subsequent processing. This application embodiment does not limit the processing method after generating timed event records.
[0056] In the event log generation method provided in this application embodiment, the virtual time value is pre-updated to shared memory by a virtual clock. When an event occurs, the operating system kernel responds to an interrupt signal and directly retrieves the virtual time value from shared memory. Since the process of retrieving the virtual time value does not involve operating system scheduling, the retrieval latency is low and deterministic, resulting in a small error between the time carried in the generated event log and the actual time of the event. Simultaneously, because the virtual time value is calculated by the virtual clock based on observed time values, hardware feedback data, and historical data, rather than directly reading the operating system's system clock, the accuracy and stability of the virtual time value itself are also improved. These two aspects work together to ensure that when multiple event logs are arranged according to their timestamps, they reflect the true chronological order of events, providing a reliable basis for accident analysis and fault tracing.
[0057] In one possible implementation, shared memory can be structured as a circular buffer. A circular buffer is a buffer with its ends connected, containing read and write pointers. When either the read or write pointer moves to the end of the buffer, it returns to the beginning of the buffer, thus cyclically using the buffer space.
[0058] Specifically, the shared memory may also include a preset address location for storing virtual time values. The virtual clock writes the virtual time value to this preset address location. The interrupt handler reads the virtual time value from this preset address location. A circular buffer can also be used for transmitting time-based event records. The interrupt handler writes the time-based event record to the circular buffer, and the user-mode handler reads the event record from the circular buffer.
[0059] The read and write pointers of a circular buffer can be managed by comparing and swapping instructions to avoid the context switching overhead of using mutexes, thereby improving the efficiency of concurrent access.
[0060] Therefore, by implementing shared memory as a structure including preset address locations and a circular buffer, and using comparison and swap instructions to manage read and write pointers, we can ensure the safety of concurrent access while avoiding the context switching overhead caused by mutex locks, and further improve the efficiency of transferring virtual time values and event records between user mode and kernel mode.
[0061] The following section provides a detailed explanation of how virtual time values are generated.
[0062] See Figure 4 , Figure 4 This is a flowchart illustrating a virtual time value generation method provided in an embodiment of this application. This process is executed periodically by a virtual clock. Each execution of this process by the virtual clock completes one round of virtual time value calculation. For ease of description, the following uses the k-th calculation by the virtual clock as an example to illustrate a complete generation process of the virtual time value. The previous calculation data used in the k-th calculation refers to the historical data obtained and retained in the (k-1)-th calculation. Figure 4 As shown, the process includes the following steps: S401: Acquire observation time values, hardware feedback data, and historical data.
[0063] The observation time value is a time value determined using an observation time source. In this embodiment, the observation time value can be a two-dimensional observation vector, including a first observation value and a second observation value. The first observation value is determined using a first observation time source, and the second observation value is determined using a second observation time source, wherein the first and second observation time sources are different observation time sources.
[0064] For example, the first observation time source is a hardware counter. The hardware counter can be a high-precision counter on a COM card or FPGA. The count value of the high-precision counter can be read via direct memory mapping and converted into a time value, which is then used as the first observation value. The second observation time source is a network time synchronization source. A timestamp can be obtained from the upstream master clock via PTP, and the obtained timestamp is used as the second observation value. The first and second observation values constitute a two-dimensional observation vector, which is the observation time value calculated in the kth iteration. , represented as: ; in, This represents the first observation determined by the hardware counter in the k-th calculation; This represents the second observation determined by the network time source in the k-th calculation.
[0065] Hardware feedback data characterizes the operational status of the transmission link associated with the observation time source. For the first observation time source, hardware feedback data may include the number of retransmissions during the acquisition of the observation time value, and the variance of the time consumed by each read of the observation time value. For the second observation time source, hardware feedback data may include the network round-trip delay variance and the deviation of the PTP time from the local monotonic clock. Hardware feedback data is used to calculate the reliability of the observation time values.
[0066] Historical data refers to the data generated and retained by the virtual clock in the previous calculation. In the k-th calculation, historical data specifically includes the virtual time value output from the previous calculation. and the state vector obtained in the previous calculation Among them, the state vector The virtual time value representing the output of the previous calculation The error state between the observed time values and those used in the previous calculation. Historical data is used to calculate the estimated time value for the k-th calculation and to determine the reliability of the estimated time value.
[0067] S402: Calculate the estimated time value based on historical data.
[0068] The virtual clock first uses the state vector from historical data. Based on the state transition equation, the predicted state vector corresponding to the k-th calculation is obtained. .
[0069] In this embodiment, the virtual clock may include an extended state observer that estimates the state of the virtual clock using a state vector and a state transition equation.
[0070] The state vector characterizes the error state between the virtual clock and the observed time value. In this embodiment, the state vector includes four components: phase deviation, frequency deviation, transmission delay, and jitter variance. Specifically, the state vector can be represented as: ; in, This represents the phase deviation of the virtual clock during the k-th calculation, characterizing the time difference between the virtual time value output by the virtual clock and the observed time value; This represents the frequency deviation of the virtual clock during the k-th calculation, characterizing the rate of change of the virtual time value relative to the observed time value; This represents the signal transmission delay on the PCIe bus during the k-th calculation, i.e., the time difference between the occurrence of the event and the receipt of the interrupt signal; This indicates the degree of fluctuation in the time interval for obtaining the observation time value during the k-th calculation.
[0071] The state transition equation describes the evolution of the state vector over time. For example, the state transition equation can be expressed as: ; Among them, in the state transition equation This is the predicted state vector calculated in the kth iteration, also denoted as [vector name missing] in this application. A represents the state transition matrix, which is constructed based on the synchronization cycle interval; This represents the process noise between the (k-1)th and the kth calculations, used to characterize the frequency random walk caused by crystal oscillator aging and temperature changes. Corresponding to a process noise covariance matrix .
[0072] In one possible implementation, the state transition matrix A can have the following form: ; in, This represents the time interval between two consecutive calculations, i.e., the synchronization period interval. This matrix indicates that the phase deviation is calculated as "the phase deviation from the previous calculation + the frequency deviation from the previous calculation". The frequency deviation, transmission delay, and jitter variance remain essentially constant between two adjacent calculations, with their variations caused by process noise. describe.
[0073] Process noise covariance matrix Used to characterize process noise The statistical characteristics. For example, It can be a diagonal matrix, where each diagonal element corresponds to the random fluctuation variance of a state component between two adjacent calculations. The specific values of the diagonal elements can be preset based on prior information such as crystal oscillator aging characteristics and temperature variation range, or adjusted based on the actual operating data of the virtual clock. This application's embodiment... The specific form is not limited.
[0074] The previously calculated state vector Substituting into the state transition equation, we can calculate the predicted state vector corresponding to the k-th calculation. For ease of description, in this application... This represents the estimated value of the corresponding vector. This represents the estimated state vector in the k-th calculation before the k-th observation time value has been fused. This represents the updated state vector after incorporating the time values from the kth observation in the kth calculation. (Predicted state vector) This represents the predicted result of the error between the virtual clock and the observed time value at the k-th calculation, which is derived from the state vector calculated in the previous calculation.
[0075] Then, the virtual clock is based on the virtual time value calculated and output previously. and the predicted state vector The estimated time value for the k-th calculation is obtained. Specifically, the virtual time value output from the previous calculation can be... With the predicted state vector The phase deviation components are added together to obtain the estimated time value.
[0076] S403: Determine the correction gain based on hardware feedback data and historical data.
[0077] First, the reliability of the observation time values is calculated based on the hardware feedback data. The reliability of the observation time values is used to characterize the degree of trustworthiness of the observation time values.
[0078] When the observation time source is a hardware counter, the reliability of the observed time value can be determined based on the number of retries and the variance of read time consumption in the hardware feedback data. The number of retries refers to the number of retransmissions that occur on the transmission link during the acquisition of the observed time value; the variance of read time consumption is the variance of the time consumed by each read of the observed time value. A higher number of retries and a larger variance of read time consumption indicate a more unstable transmission link and lower reliability of the observed time value. For example, the reliability of the observed time value can be calculated as follows: ; in, This represents the noise variance of the observation time values determined by the hardware counter; This represents the variance of the time taken for N consecutive register reads; This indicates the PCIe retry counter reading; and These are adjustable weighting coefficients.
[0079] When the observation time source is a network time source, the reliability of the observed time value can be determined based on the network round-trip delay variance and the deviation between the PTP time and the local monotonic clock. For example, the reliability of the observed time value can be calculated as follows: ; in, This represents the noise variance of the observation time values determined based on the network time source; This represents the variance of network round-trip delay; Indicates PTP time; Indicates a local monotonic clock; and These are adjustable weighting coefficients.
[0080] The reliability of the estimated time value is calculated based on historical data and noise parameters. The reliability of the estimated time value characterizes the degree of uncertainty of the estimated time value. In one possible implementation, the reliability of the estimated time value can be obtained recursively through covariance based on the previously calculated state vector and noise parameters. Specifically, the prior covariance matrix can be calculated first based on the previously calculated covariance matrix and state transition matrix. , and then As a quantitative indicator of the reliability of estimated time values.
[0081] After determining the reliability of the observed time values and the reliability of the estimated time values, a correction gain is calculated based on these two reliability values. The correction gain is used to determine the confidence allocation between the observed time values and the estimated time values when fusing them.
[0082] For example, the corrected gain can be calculated as follows: ; in, This represents the correction gain calculated in the kth iteration; This represents the prior covariance matrix corresponding to the estimated time values, which is determined based on the reliability of the estimated time values. Represents the observation matrix; This represents the noise covariance matrix corresponding to the observation time values, which is determined based on the reliability of the observation time values. for matrix; for diagonal matrix; for matrix.
[0083] In one possible implementation, when both observations directly observe the phase deviation, the observation matrix... It can be represented as: ; It can be represented as: ; S404: Calculate the virtual time value calculated in the kth calculation based on the observed time value, the estimated time value, and the correction gain.
[0084] Based on the observed time value, estimated time value, and correction gain calculated in the kth iteration, the estimated state vector is corrected to obtain the updated state vector. Then, the virtual time value calculated in the kth iteration is determined based on the updated state vector.
[0085] The observation time value calculated in the k-th iteration includes the first observation value and the second observation value. The first deviation between the first observation value and the estimated time value, and the second deviation between the second observation value and the estimated time value are calculated respectively. The first deviation and the second deviation constitute the innovation vector calculated in the k-th iteration. , represented as: ; in, This represents the estimated time value for the k-th calculation; , These represent the first and second observations, respectively.
[0086] If the deviation corresponding to the first observation or the deviation corresponding to the second observation exceeds the threshold, the observation will be downweighted or removed. For details, please refer to [link to relevant documentation]. Figure 5 The multi-source observation and robust anomaly detection process is shown.
[0087] According to the new information vector Correction gain For the predicted state vector After making corrections, the updated state vector is obtained. , represented as: ; in, This represents the updated state vector after the k-th computation; This represents the predicted state vector calculated in the k-th iteration; This represents the correction gain calculated in the kth iteration; This represents the new information calculated in the kth iteration.
[0088] Based on the updated state vector Determine the virtual time value for the kth calculation. Specifically, the updated state vector The phase deviation component in the calculation represents the time difference between the virtual time value output by the virtual clock and the observed time value in the k-th calculation. Based on this time difference, the virtual time value can be determined. .
[0089] Furthermore, after updating the state vector, the covariance matrix can also be updated for the next round of calculation. For example, the covariance update can be represented as: ; in, This represents the updated covariance matrix after the k-th calculation; Represents the identity matrix. The updated covariance matrix. With the updated state vector Together they will serve as historical data for the next round of calculations.
[0090] S405: Smooth the virtual time value of the kth calculation and apply monotonicity constraints.
[0091] Before outputting the virtual time value, the virtual clock can also perform smoothing and monotonicity constraints on the virtual time value. Smoothing is used to eliminate possible step jumps in the virtual time value during the correction process; monotonicity constraints are used to ensure that the virtual time value obtained in the later calculation is greater than the virtual time value obtained in the previous calculation.
[0092] For example, smoothing can be achieved using piecewise cubic spline interpolation. Discrete multi-round virtual time values are used as interpolation nodes, and cubic spline interpolation is used to generate a continuous virtual time curve, thereby eliminating possible step jumps between adjacent rounds.
[0093] The monotonicity constraint can be expressed as: ; in, This represents the virtual time value obtained from the nth calculation; This represents the virtual time value obtained in the (n-1)th calculation; Indicates the preset step size; This represents the original virtual time value obtained from the nth calculation. This constraint guarantees that the virtual time value written to shared memory is strictly monotonically increasing.
[0094] S406: Update the virtual time value calculated in the kth iteration to the shared memory.
[0095] After calculating the virtual time value for the kth calculation, the virtual time value is updated in shared memory, so that the virtual time value stored in shared memory is the most recently calculated time value. This way, when a subsequent event occurs, the interrupt handler in kernel mode can directly read the latest virtual time value from shared memory.
[0096] Therefore, through the aforementioned virtual time value generation method, based on observed time values, hardware feedback data, and historical data, high-precision virtual time values are periodically generated through estimation, gain correction calculation, fusion calculation, smoothing processing, and monotonicity constraints, and then updated to shared memory. This process does not directly rely on the operating system's system clock, thus suppressing the impact of system clock drift. Simultaneously, the reliability of the observed time values can be dynamically adjusted based on hardware feedback data, thereby adjusting the correction gain. This allows the calculation of virtual time values to adapt to changes in the transmission link's operating state, ensuring the accuracy and stability of the virtual time values.
[0097] To facilitate understanding, the following explanation uses a set of simplified numerical values to illustrate the complete generation process of virtual time values.
[0098] After the (k-1)th calculation, the virtual clock retains the following historical data: The virtual time value output from the previous calculation 10,000 nanoseconds; The state vector obtained from the previous calculation The phase deviation is 20 nanoseconds, the frequency deviation is 0.2, the transmission delay is 5 nanoseconds, and the jitter variance is 4 nanoseconds². Set synchronization period interval 100 nanoseconds; state transition matrix Adopting the form shown above, that is: ; In the k-th calculation, perform the following operations: Step 1: Calculate the predicted state vector.
[0099] The previously calculated state vector Substituting into the state transition equation, we obtain the predicted state vector for the k-th calculation: ; The phase deviation component in the predicted state vector is 40 nanoseconds.
[0100] Step 2: Calculate the estimated time value.
[0101] Based on the virtual time value output from the previous calculation And by calculating the phase deviation component in the predicted state vector, the predicted time value for the k-th calculation is obtained: nanosecond; Step 3: Obtain the observation time value and calculate the innovation vector.
[0102] Assume that in the k-th calculation, the first observation is 10060 nanoseconds and the second observation is 10030 nanoseconds. Then the observation time value is: ; The innovation vector is obtained by calculating the deviations between the two observed values and the estimated time values respectively. ; Step 4: Update the state vector based on the corrected gain.
[0103] For ease of demonstration, we assume that the corrected gain is calculated from the prior covariance matrix and the observation noise covariance matrix according to the formula above. for: ; According to the modified gain and new information vector The predicted state vector is corrected to obtain the updated state vector: ; ; The phase deviation component in the updated state vector is 35 nanoseconds.
[0104] Step 5: Determine the virtual time value for the kth calculation.
[0105] Based on the phase deviation component in the updated state vector and the virtual time value output from the previous calculation, determine the virtual time value for the k-th calculation: nanosecond; Step 6: Smooth the process, apply monotonicity constraints, and write to shared memory.
[0106] The virtual time value for the kth calculation Nanoseconds are smoothed and monotonicity is constrained. A minimum step size is defined. It is 1 nanosecond. Because... nanosecond, and Since the nanosecond is greater than 10001 nanoseconds, the monotonicity constraint holds, and no further adjustments are needed. Adjustments were made. After smoothing, the virtual time value of 10035 nanoseconds was updated to the shared memory.
[0107] At this point, the virtual time value for the k-th calculation is complete. The virtual time value currently stored in shared memory is 10035 nanoseconds. When a subsequent event occurs, the interrupt handler in kernel mode can directly read this virtual time value from shared memory.
[0108] It should be understood that the above values and the values of the correction gain are shown only for the convenience of understanding the embodiments of this application, and do not constitute a specific limitation on the technical solution of this application.
[0109] Below, in conjunction with Figure 5 This paper provides a detailed explanation of multi-source observation and robust anomaly detection.
[0110] See Figure 5 , Figure 5 This is a schematic flowchart illustrating a multi-source observation and robust anomaly detection method provided in an embodiment of this application. In one possible implementation, the observation time values include a first observation value and a second observation value. The first observation value is determined using the first observation time source, and the second observation value is determined using the second observation time source.
[0111] For example, the first observation time source is a hardware counter, and the second observation time source is a network time synchronization source. The first observation time source is the primary reference source, and the second observation time source is a redundant backup source. The initial value of the observation noise variance corresponding to the primary reference source can be smaller than the initial value of the observation noise variance corresponding to the redundant backup source, thereby giving the observations corresponding to the primary reference source higher confidence during the filtering process.
[0112] In another possible implementation, the first and second observation time sources can also be two observation time sources of the same type. For example, the first observation time source is a first hardware counter, and the second observation time source is a second hardware counter. The two hardware counters are deployed on different hardware devices, and observation values are provided by two independent hardware counters, further improving the redundancy of the observation values.
[0113] When calculating the virtual time value based on the observed time value, the estimated time value, and the correction gain, the virtual clock calculates the deviation between the first observed value and the estimated time value, and the deviation between the second observed value and the estimated time value. When the deviation corresponding to the first observed value exceeds a threshold, the reliability of the first observed value in calculating the virtual time value is reduced, or the first observed value is discarded; when the deviation corresponding to the second observed value exceeds a threshold, the reliability of the second observed value in calculating the virtual time value is reduced, or the second observed value is discarded.
[0114] The reliability of each observation in the observation time value is characterized by its corresponding observation noise variance. To reduce the reliability of an observation, the observation noise variance corresponding to that observation can be increased; to remove an observation, the observation noise variance corresponding to that observation can be set to a maximum value, so that the observation is not included in the calculation of the virtual time value of the current round.
[0115] For example, when the deviation corresponding to the first observation exceeds the threshold but has not yet met the removal condition, the observation noise variance corresponding to the first observation can be increased to reduce the reliability of the first observation; when the deviation corresponding to the first observation exceeds the removal condition, the observation noise variance corresponding to the first observation can be set to the maximum value, which is equivalent to removing the first observation so that the first observation does not participate in the calculation of the virtual time value of the current round.
[0116] Specifically, the new information corresponding to the first observation can be calculated separately. The new information corresponding to the second observation .when When the adaptive threshold is exceeded, it indicates that the first observation may be an outlier caused by electromagnetic interference. In this case, the reliability of the first observation should be reduced, or the first observation should be directly discarded so that it does not participate in the calculation of the virtual time value of the current round; when If the adaptive threshold is exceeded, it indicates that the second observation may be an outlier caused by a network storm. In this case, similar processing should be performed on the second observation. The adaptive threshold can be calculated based on 3 times the standard deviation of historical information. The criterion is that the adaptive threshold can be set to 3 times the standard deviation of historical information.
[0117] In another possible implementation, the threshold can also be a preset fixed value, without requiring dynamic calculation based on the standard deviation of historical information. For example, the threshold can be preset to a fixed value based on the maximum time deviation allowed by the SOE system. If the deviation corresponding to an observation exceeds this fixed value, the observation is considered abnormal.
[0118] In one possible implementation, when the deviations corresponding to the first and second observations both exceed a threshold, the virtual clock may no longer correct the estimated state vector based on the observed time value in this round, but instead use the estimated time value as the virtual time value.
[0119] In another possible implementation, when the deviations corresponding to the first and second observations both exceed the threshold, a PTP forced resynchronization request can be directly triggered, and the correction of the virtual time value in this round can be suspended, waiting for the next round to reacquire the observation time value.
[0120] For example, assuming the standard deviation of historical updates is 10 nanoseconds, the adaptive threshold is 30 nanoseconds. If the update corresponding to the first observation is 50 nanoseconds, exceeding 30 nanoseconds, the first observation is considered an outlier, its reliability is reduced, or it is discarded. If the update corresponding to the second observation is 5 nanoseconds, not exceeding 30 nanoseconds, the second observation participates normally in this round of calculation. It should be understood that this value is only an example.
[0121] Therefore, through the aforementioned multi-source observation and robust anomaly detection, when acquiring observations from two different observation time sources simultaneously, anomaly detection can be performed on both observations separately. If an observation is abnormal, its reliability can be reduced or it can be removed, preventing a single abnormal observation from contaminating the virtual time value and ensuring its accuracy and stability. Furthermore, since the two observation time sources serve as backups for each other, when one observation time source experiences an anomaly, the other can still provide a calibration reference, improving the system's fault tolerance.
[0122] In one possible implementation, the virtual clock can also be detected for loss of lock, and a degradation process can be performed when the lock is lost.
[0123] Specifically, when the information updates exceed the adaptive threshold for multiple consecutive rounds, the virtual clock determines that it has lost its lock. At this point, the generation of event records with time based on virtual time values is paused, and event records with relative timestamps are generated instead, with the time marked as unreliable. Here, the relative timestamp refers to the time interval relative to the occurrence time of the previous event.
[0124] Simultaneously, a PTP forced resynchronization request is triggered to restore the accuracy of the virtual clock as quickly as possible. Once the information has recovered to within the adaptive threshold, the virtual clock resumes generating time-based event records based on the virtual time value.
[0125] For example, the number of rounds in which the adaptive threshold is exceeded consecutively can be preset to M times, and the specific value of M can be configured according to the actual scenario.
[0126] Therefore, through lockout detection and degradation processing, during the period when the virtual clock is locked out, unreliable absolute time values will not continue to be output. Instead, events will be recorded with relative timestamps, and the time will be explicitly marked as unreliable. In this way, even if the virtual clock is briefly locked out, it will not mislead accident analysis due to the output of incorrect time values. At the same time, the system can actively attempt to recover, and resume the absolute timestamp recording after the virtual clock converges again, thus improving the system's fault tolerance and reliability.
[0127] Below, in conjunction with Figure 6 This section provides a detailed explanation of the priority scheduling of event logging.
[0128] See Figure 6 , Figure 6 This is a flowchart illustrating a priority scheduling method provided in an embodiment of this application. In one possible implementation, after generating time-stamped event records, priority scheduling can also be performed on these time-stamped event records.
[0129] First, after timed event logs are generated, they can be stored in a high-speed memory buffer. This buffer temporarily stores timed event logs to smooth out peak traffic spikes. This high-speed memory buffer can be an internal cache area of the virtual controller, unlike the shared memory used for data transfer between user and kernel modes. When a large number of switching devices operate sequentially within a short period, event logs are generated in a concentrated manner. By storing these logs in the high-speed memory buffer first, overflow during subsequent classification and scheduling processes due to excessive instantaneous traffic can be avoided, ensuring that event logs are not lost.
[0130] Then, the time-sensitive event records are assigned to their respective priority queues according to their priority. Different event records can correspond to different priorities. Specifically, different priorities can be pre-configured for different signal sources; the higher the priority of a signal source, the more priority its event records need to be processed. For example, the priority of "general accident signal" can be higher than that of "normal switch". For instance, three priority queues can be set up: a high-priority queue, a medium-priority queue, and a low-priority queue. High-priority event records are assigned to the high-priority queue, medium-priority event records to the medium-priority queue, and low-priority event records to the low-priority queue.
[0131] In another possible implementation, the number of priority queues may be more than three or less than three; this application does not limit the specific number of priority queues. For example, two queues, four queues, or more queues may be set up depending on the number and importance of the signal sources.
[0132] During scheduling, the queue depth and processor utilization of each priority queue are monitored in real time, and these parameters are used as system load indicators. Based on these system load indicators, the scheduling weights of each priority queue and the time windows for batch submission of timed event records are dynamically adjusted.
[0133] In another possible implementation, the event record generation rate can be further incorporated as a basis for adjusting the batch submission time window. For example, when the event record generation rate continuously exceeds a preset generation rate threshold, the batch submission time window of the high-priority queue can be shortened in advance, even if the depth of each priority queue has not yet exceeded the preset threshold.
[0134] Specifically, when the queue depth of a high-priority queue exceeds a preset threshold, the scheduling weight of the high-priority queue is increased, and the batch submission time window of the high-priority queue is shortened, for example, from 1 millisecond to 0.5 milliseconds, so that high-priority event records are submitted and processed faster. When the queue depth of a high-priority queue does not exceed the preset threshold and the processor utilization rate is below the safe level, the scheduling weight and batch submission time window of each priority queue can be maintained unchanged to ensure the overall processing efficiency of the system. When the processor utilization rate is high, the scheduling frequency of low-priority queues can be reduced, and the batch submission time window of low-priority queues can be extended to ensure that critical high-priority event records can still receive priority processing resources when the system is overloaded.
[0135] In another possible implementation, the scheduling weight can be adjusted by changing the processor time slice ratio corresponding to the priority queue. For example, the processor time slice ratio corresponding to the high-priority queue can be increased, and the processor time slice ratio corresponding to the low-priority queue can be decreased.
[0136] Finally, when the number of event records in a priority queue reaches the corresponding submission threshold for that queue, or when the batch submission time window for that queue arrives, the event records in that priority queue are packaged in batches and sent to the historical database or monitoring client.
[0137] Therefore, by using the above priority scheduling method, when a large number of event records are generated concurrently, the scheduling strategy can be dynamically adjusted according to the event priority and system load, ensuring that high-priority event records are processed first, avoiding the loss of critical event records due to system overload, and improving the reliability and real-time performance of the system in high-concurrency scenarios.
[0138] In one possible implementation, software debouncing can also be applied to time-based event logs. The contacts of field devices may experience mechanical bouncing during operation, causing the COM card to detect multiple level changes within a short period, thus generating multiple false event logs. Software debouncing filters out millisecond-level glitches caused by contact bouncing, ensuring that the generated event logs correspond to genuine state changes.
[0139] For example, after detecting a change in signal state, a preset time window can be waited for. If the signal state remains in the changed state within the time window, the event record is considered a valid event record; if the signal state returns to its original state within the time window, the event record is discarded as a glitch. For example, the preset time window can be 5 milliseconds.
[0140] Therefore, by using software debouncing, false event records caused by contact bounce can be filtered out, ensuring that the event records correspond to real state changes and avoiding interference with subsequent event analysis and fault tracing due to false event records.
[0141] In one possible implementation, during the process of sending timed event records to a historical database or monitoring client, network interruption resumption and consistency verification can also be performed.
[0142] Specifically, when the memory queue is full or a system malfunction occurs, event records are temporarily stored in local high-speed storage and retransmitted after the network is restored. A monotonically increasing sequence number can be generated for each event record. The receiving end automatically requests the missing event records from the computing device by verifying the continuity of the sequence numbers, ensuring the integrity of the event records.
[0143] In another possible implementation, the sequence number can carry a sender identifier. The receiver uses the sender identifier and the sequence number to jointly determine the source and continuity of the event record, thereby supporting scenarios where multiple senders send event records to the same receiver.
[0144] In another possible implementation, local high-speed storage can be a memory-mapped file. By temporarily storing event records in a memory-mapped file, persistent data storage can be achieved while maintaining write speeds close to those in memory.
[0145] Therefore, through network interruption resumption and consistency verification, even if network interruption or system anomaly causes event logs to be temporarily unable to be sent, the event logs will not be lost. After the network is restored, the system can automatically retransmit the temporarily stored event logs and ensure that the receiving end obtains a complete set of event logs through sequence number verification, further improving the reliability of event logs.
[0146] To facilitate a more intuitive understanding of the overall process of the event log generation method provided in the embodiments of this application, the following is a detailed explanation. Figure 7 A general example is provided.
[0147] See Figure 7 , Figure 7 This is a schematic diagram of the overall data processing flow of an event log generation method provided in an embodiment of this application. Figure 7 The various processing steps involved in the embodiments of this application are summarized in the order of data flow.
[0148] During the operation of the event logging generation system, the virtual clock continuously performs state estimation in user mode, periodically generates virtual time values, and updates the latest virtual time values to shared memory. Internally, the virtual clock performs state estimation through an extended state observer. Simultaneously, the COM card monitors the state changes of field devices in real time.
[0149] When a field device experiences a status change, such as a circuit breaker tripping, the COM card detects this change and generates a hardware interrupt. This hardware interrupt is then transmitted to the virtual clock via the driver. The virtual clock determines how to generate an event log based on whether the filter has converged. When the virtual clock is in a convergent state, the interrupt handler reads the virtual time value from shared memory and combines it with signal source information and state change information to generate a timed event record. The interrupt handler then writes this timed event record into a circular buffer in shared memory.
[0150] When the virtual clock is unlocked, the system enters degraded mode. In degraded mode, the computing device no longer generates timed event records based on the virtual time value, but instead records events with relative timestamps and marks the time as unreliable.
[0151] Timed event records written to the shared memory circular buffer are read by a handler in user space. This handler, also known as the SOE acquisition thread, reads the timed event records from the circular buffer in a lock-free manner. The handler manages the read and write pointers of the circular buffer by comparing and exchanging instructions, thus achieving a lock-free operation and avoiding the context switching overhead introduced by mutexes.
[0152] The user-space processing program performs software debouncing on the time-varying event records, filtering out millisecond-level glitches caused by touch bounce. Then, the event records are allocated to high-priority, medium-priority, or low-priority queues according to event priority. The scheduling module dynamically adjusts the scheduling weights and batch submission time windows based on the queue depth and processor utilization of each priority queue, dynamically batching the event records in each queue. The computing device sends the packaged event records to the historical database or monitoring client, as well as to a local persistent cache. The local persistent cache is used to temporarily store event records in the event of network interruption or system anomaly, and retransmit them after network recovery, thus achieving resume transmission after network outage.
[0153] thus, Figure 7 This document fully illustrates the entire data flow process from event occurrence, virtual time value generation, time-inclusive event log generation, exception handling, priority scheduling, to event log output. This process combines two main threads: "accurate generation of virtual time values" and "rapid acquisition of virtual time values," ensuring that the time in the final output event log reflects the true chronological order of events, providing a reliable basis for accident analysis and fault tracing.
[0154] Based on the event log generation method provided in the preceding embodiments, this application also provides an event log generation apparatus. The following, in conjunction with... Figure 8 To explain, Figure 8 This is a schematic diagram of the structure of an event log generation device 800 provided in an embodiment of this application. The device includes: The acquisition module 801 is used to acquire a virtual time value from shared memory in response to an interrupt signal received by the operating system kernel. The interrupt signal is used to indicate that an event has occurred. The shared memory is a memory area that supports direct access by the operating system kernel. The virtual time value stored in the shared memory is periodically updated by a virtual clock. The generation module 802 is used to generate time-based event records based on the virtual time value and the associated data of the event; The virtual time generation module 803 is used to calculate a virtual time value based on the observed time value, hardware feedback data, and historical data, and periodically update it to the shared memory. The observed time value is determined using an observed time source, the hardware feedback data represents the working status of the transmission link associated with the observed time source, and the historical data includes the virtual time value output by the virtual clock in the previous calculation and the state vector obtained in the previous calculation. The state vector represents the error state between the virtual time value output by the previous calculation and the observed time value used in the previous calculation.
[0155] In one possible implementation, the virtual time generation module 803 is specifically used for: Calculate the estimated time value based on the historical data; The correction gain is determined based on the hardware feedback data and the historical data; The virtual time value is calculated based on the observed time value, the estimated time value, and the correction gain.
[0156] In one possible implementation, the virtual time generation module 803 is specifically used for: Using the previously calculated state vector and state transition equation from the historical data, a predicted state vector is calculated, wherein the state transition equation is used to describe the evolution of the state vector. The estimated time value is calculated based on the virtual time value previously calculated and output by the virtual clock in the historical data and the estimated state vector. The state vector includes at least phase deviation and frequency deviation. The phase deviation represents the time difference between the virtual time value output by the virtual clock in its previous calculation and the observation time value used in the previous calculation of the virtual clock. The frequency deviation represents the rate of change of the virtual time value output by the virtual clock in its previous calculation relative to the observation time value used in the previous calculation of the virtual clock.
[0157] In one possible implementation, the state vector further includes a transmission delay and a jitter variance, wherein the transmission delay indicates the time difference between the occurrence of the event and the receipt of the interrupt signal, and the jitter variance indicates the degree of fluctuation in the time interval between two consecutive acquisitions of the observation time value.
[0158] In one possible implementation, the virtual time generation module 803 is specifically used for: The reliability of the observation time value is calculated based on the hardware feedback data. The reliability of the estimated time value is calculated based on the historical data and noise parameters. The correction gain is calculated based on the reliability of the observed time value and the reliability of the estimated time value.
[0159] In one possible implementation, the observation time value includes a first observation value and a second observation value; the first observation value is determined using a first observation time source, and the second observation value is determined using a second observation time source, wherein the first observation time source and the second observation time source are different observation time sources.
[0160] In one possible implementation, the virtual time generation module 803 is specifically used for: Calculate the deviation between the first observed value and the estimated time value, and the deviation between the second observed value and the estimated time value; When the deviation corresponding to the first observation exceeds the threshold, the reliability of the first observation in calculating the virtual time value is reduced, or the first observation is removed. When the deviation corresponding to the second observation exceeds the threshold, the reliability of the second observation in calculating the virtual time value is reduced, or the second observation is removed.
[0161] In one possible implementation, the device further includes: The scheduling module is used to allocate the time-stamped event records to the corresponding priority queues according to their priority after the event records are generated; and to adjust the scheduling weight of each priority queue and the time window for batch submission of the time-stamped event records according to the queue depth and processor utilization of each priority queue.
[0162] It should be understood that the event log generation apparatus 800 in this application embodiment can be implemented by a central processing unit (CPU), an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). The PLD can be a complex programmable logic device (CPLD), an FPGA, a generic array logic (GAL), or any combination thereof. It can also be implemented in software. Figures 3 to 7 In the event log generation method shown, the event log generation device 800 and its various modules can also be software modules.
[0163] Since the event record generation device 800 corresponds to the aforementioned event record generation method, the specific implementation of the event record generation device 800 and its technical effects can be found in the relevant descriptions in the foregoing embodiments, and will not be repeated here.
[0164] This application also provides a computing device. See [link to relevant documentation]. Figure 9 , Figure 9 This is a schematic diagram of the structure of a computing device 900 provided in an embodiment of this application. Figure 9As shown, the computing device 900 includes a bus 904, a processor 901, a memory 902, and a communication interface 903. The processor 901, memory 902, and communication interface 903 communicate via the bus 904. The bus 904 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus 904 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, Figure 9 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0165] It should be understood that in the embodiments of this application, the processor 901 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), ASICs, FPGAs, or other programmable logic devices, discrete gate or transistor logic devices, discrete device assemblies, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0166] The memory 902 may include read-only memory and random access memory, and provides instructions and data to the processor 901. The memory 902 may also include non-volatile random access memory. For example, the memory 902 may also store device type information.
[0167] The memory 902 can be volatile memory or non-volatile memory, or it can include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus RAM (DRRAM).
[0168] It should be understood that the computing device 900 according to the embodiments of this application may correspond to the event log generation device 800 in the embodiments of this application, and may correspond to the execution of the device according to the embodiments of this application. Figures 3 to 7 The corresponding entities in the illustrated method, and the aforementioned and other operations and / or functions implemented by the computing device 900, are respectively for the purpose of implementing... Figures 3 to 7 For the sake of brevity, the corresponding processes of each method in the code will not be elaborated here.
[0169] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0170] In the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially by using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units.
[0171] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that there can be three relationships. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist simultaneously. A and B can be singular or plural.
[0172] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for generating event logs, characterized in that, The method includes: In response to an interrupt signal received by the operating system kernel, a virtual time value is obtained from shared memory. The interrupt signal is used to indicate that an event has occurred. The shared memory is a memory region that supports direct access by the operating system kernel. The virtual time value stored in the shared memory is periodically updated by a virtual clock. Based on the virtual time value and the associated data of the event, an event record with time is generated; The virtual time value is generated in the following way: A virtual time value is calculated based on the observed time value, hardware feedback data, and historical data. The observed time value is determined using an observed time source. The hardware feedback data characterizes the working status of the transmission link associated with the observed time source. The historical data includes the virtual time value previously calculated and output by the virtual clock and the state vector obtained from the previous calculation. The state vector characterizes the error state between the previously calculated virtual time value and the observed time value used in the previous calculation.
2. The method according to claim 1, characterized in that, The calculation of the virtual time value based on the observed time value, hardware feedback data, and historical data includes: Calculate the estimated time value based on the historical data; The correction gain is determined based on the hardware feedback data and the historical data; The virtual time value is calculated based on the observed time value, the estimated time value, and the correction gain.
3. The method according to claim 2, characterized in that, The step of calculating the estimated time value based on the historical data includes: Using the previously calculated state vector and state transition equation from the historical data, a predicted state vector is calculated, wherein the state transition equation is used to describe the evolution of the state vector. The estimated time value is calculated based on the virtual time value previously calculated and output by the virtual clock in the historical data and the estimated state vector. The state vector includes at least phase deviation and frequency deviation. The phase deviation represents the time difference between the virtual time value output by the virtual clock in its previous calculation and the observation time value used in the previous calculation of the virtual clock. The frequency deviation represents the rate of change of the virtual time value output by the virtual clock in its previous calculation relative to the observation time value used in the previous calculation of the virtual clock.
4. The method according to claim 2, characterized in that, The step of determining the correction gain based on the hardware feedback data and the historical data includes: The reliability of the observation time value is calculated based on the hardware feedback data. The reliability of the estimated time value is calculated based on the historical data and noise parameters. The correction gain is calculated based on the reliability of the observed time value and the reliability of the estimated time value.
5. The method according to claim 2, characterized in that, The observation time value includes a first observation value and a second observation value; the first observation value is determined using a first observation time source, and the second observation value is determined using a second observation time source, wherein the first observation time source and the second observation time source are different observation time sources.
6. The method according to claim 5, characterized in that, The step of calculating the virtual time value based on the observed time value, the estimated time value, and the correction gain includes: Calculate the deviation between the first observed value and the estimated time value, and the deviation between the second observed value and the estimated time value; When the deviation corresponding to the first observation exceeds the threshold, the reliability of the first observation in calculating the virtual time value is reduced, or the first observation is removed. When the deviation corresponding to the second observation exceeds the threshold, the reliability of the second observation in calculating the virtual time value is reduced, or the second observation is removed.
7. The method according to claim 1, characterized in that, After generating the time-stamped event record, the process also includes: The time-based event records are assigned to the corresponding priority queues according to their priority. Based on the queue depth and processor utilization of each priority queue, adjust the scheduling weight of each priority queue and the time window for batch submission of the timed event records.
8. An event log generation device, characterized in that, include: The acquisition module is used to acquire a virtual time value from shared memory in response to an interrupt signal received by the operating system kernel. The interrupt signal is used to indicate that an event has occurred. The shared memory is a memory area that supports direct access by the operating system kernel. The virtual time value stored in the shared memory is periodically updated by a virtual clock. The generation module is used to generate time-stamped event records based on the virtual time value and the associated data of the event; The virtual time generation module is used to calculate a virtual time value based on the observed time value, hardware feedback data, and historical data, and periodically update it to the shared memory. The observed time value is determined using an observed time source, the hardware feedback data represents the working status of the transmission link associated with the observed time source, and the historical data includes the virtual time value output by the virtual clock in the previous calculation and the state vector obtained in the previous calculation. The state vector represents the error state between the virtual time value output by the previous calculation and the observed time value used in the previous calculation.
9. A computing device, characterized in that, The device includes a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the event record generation method according to any one of claims 1 to 7 according to the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program that, when executed by an electronic device, implements the event log generation method according to any one of claims 1 to 7.
