CN110032435B - Method and device for managing threads in control system - Google Patents

Method and device for managing threads in control system Download PDF

Info

Publication number
CN110032435B
CN110032435B CN201910228811.XA CN201910228811A CN110032435B CN 110032435 B CN110032435 B CN 110032435B CN 201910228811 A CN201910228811 A CN 201910228811A CN 110032435 B CN110032435 B CN 110032435B
Authority
CN
China
Prior art keywords
thread
cycle
running
control system
period
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910228811.XA
Other languages
Chinese (zh)
Other versions
CN110032435A (en
Inventor
王新忠
朱爱华
廖亮
邢佳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Hollysys Co Ltd
Original Assignee
Beijing Hollysys Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Hollysys Co Ltd filed Critical Beijing Hollysys Co Ltd
Priority to CN201910228811.XA priority Critical patent/CN110032435B/en
Publication of CN110032435A publication Critical patent/CN110032435A/en
Application granted granted Critical
Publication of CN110032435B publication Critical patent/CN110032435B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a method and a device for managing threads in a control system. The method comprises the following steps: acquiring a cycle thread running in the current running cycle T in the control system; determining the maximum timeout time Tdead of each period thread in the operation period T, wherein the maximum timeout time Tdead is a determined time; and managing the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to the running cycle T of each cycle thread.

Description

Method and device for managing threads in control system
Technical Field
The present application relates to the field of information processing, and more particularly, to a method and apparatus for managing threads in a control system.
Background
In train control systems such as high-speed railways and urban rail transit, along with the increasing bulkiness of train control system functions, the train control systems gradually start to be realized based on real-time operating systems. The real-time operating system schedules the threads based on the priority, and has the problems that the threads with low priority cannot be scheduled in time, the threads are blocked and the like. Because the train control system has high requirements on safety and real-time performance, effective measures need to be taken to find whether the scheduling of the periodic threads in the system has problems or not in time, so that the train control system can adopt necessary measures to ensure the safety under the condition that the periodic threads are not scheduled in time.
A train control system implemented based on a real-time operating system usually includes a plurality of different cycle threads, which are respectively used to implement different functions, and the cycle and priority of each thread are different. Fig. 1 is a diagram illustrating an example of a periodic thread in a train control system according to the related art. The threads shown in fig. 1 include an IO thread, a communication thread, and a diagnostic thread, which all have different cycles and priorities, where the IO thread has a small cycle and a high priority; the communication thread cycle is medium, and the priority is medium; the diagnosis detection thread period is long, and the priority is the lowest.
In the related art, the monitoring of the periodic thread scheduling adopts a method of roll calling all threads through a common periodic monitoring thread, the periodic thread scheduling is considered normal as long as the periodically monitored threads answer within a certain time, and errors can be introduced into each period of answer delay, so that accumulated errors can be generated, and the system is unreliable in operation during long-time operation. And the method can clear the fault count after the thread scheduling fault is recovered, and monitor whether the periodic thread scheduling is normal again. The method has a large safety risk when being used in a train control system with high real-time requirement.
Disclosure of Invention
In order to solve the above technical problem, the present application provides a method and an apparatus for managing threads in a control system, which can improve the security of thread management.
To achieve the objective of the present application, the present application provides a method for managing threads in a control system, comprising:
acquiring a cycle thread running in the current running cycle T in the control system;
determining the maximum timeout time Tdead of each period thread in the operation period T, wherein the maximum timeout time Tdead is a determined time;
and managing the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to the running cycle T of each cycle thread.
In an exemplary embodiment, before the obtaining of the cycle thread running in the current running cycle T in the control system, the method further includes:
and creating a cycle monitoring thread, setting the priority of the cycle monitoring thread in the whole control system to be the highest, and setting the execution cycle to be the minimum.
In an exemplary embodiment, the determining the maximum timeout time Tdead that the thread runs in each cycle within the running period T includes:
determining the execution time Tschedul corresponding to each cycle thread in the control system in the operation cycle T according to the executed cycle duration and the executed accumulated times of each cycle thread;
and calculating the maximum timeout time Tdead corresponding to the running period T of each periodic thread according to the execution time Tschedul and the preset maximum timeout duration delta T.
In an exemplary embodiment, the managing, according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, a periodic thread running in the running period T includes:
in the operation period T, comparing the current time Tn with the maximum timeout time Tdead of each period thread operated in the operation period T to obtain a comparison result;
selecting a target cycle thread with the current time Tn being greater than the maximum timeout time Tdead from the comparison result;
and performing exception handling on the target period thread.
In an exemplary embodiment, before the obtaining of the cycle thread running in the current running cycle T in the control system, the method further includes:
judging whether the current output operation period of the clock source of the control system is accurate or not;
and if the current output running period of the clock source is accurate, allowing to obtain the cycle thread running in the current running period T in the control system.
In an exemplary embodiment, the determining whether the operation cycle of the current output of the clock source of the control system is accurate includes:
acquiring a first time length of a clock beat currently output by a CPU in the control system;
calculating the difference value between the first time length and a second time length of a pre-acquired reference clock beat;
judging whether the difference value meets a preset difference value judgment strategy or not;
and if the difference value accords with the difference value judgment strategy, determining that the operation cycle of the clock source output of the control system is accurate, otherwise, determining that the operation cycle of the clock source output of the control system is inaccurate.
In an exemplary embodiment, the reference clock beat is output by an independent crystal oscillator module independent from the CPU, and the second duration of the reference clock beat is determined according to the clock beat output by the CPU in a normal operating state.
In an exemplary embodiment, after the managing, according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, a periodic thread running in the running period T, the method further includes:
detecting the working state of the periodic monitoring thread according to a preset detection period;
and if the detection signal of the periodic monitoring thread is not received in the detection period, continuing to wait for a preset waiting time length, and if the detection signal is not received, stopping the running of the periodic thread in the control system.
In an exemplary embodiment, the detecting the working state of the periodic monitoring thread according to a preset detection period includes:
acquiring the working state of the periodic monitoring thread from a CPU (central processing unit) of a control system according to the execution period of the periodic monitoring thread;
the stopping of the running of the periodic thread in the control system comprises:
and sending a control signal, wherein the control signal is used for stopping the running of a CPU in the control system.
In order to solve the above technical problem, the present application provides an apparatus for managing threads in a control system, including a processor and a memory, where the memory stores a computer program, and the processor is configured to call the computer program in the memory to implement any one of the above methods.
According to the technical scheme provided by the embodiment of the application, the periodic threads running in the current running period T in the control system are obtained, the maximum timeout time Tdead of each periodic thread running in the running period T is determined, and the periodic threads running in the running period T are managed according to the maximum timeout time Tdead corresponding to each periodic thread in the running period T, so that the detection of the running state of each periodic thread is realized by taking the periodic threads as a time unit according to the maximum timeout time, the detection accuracy of the periodic threads is improved, and the purpose of improving the safety of thread management is achieved.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
The accompanying drawings are included to provide a further understanding of the claimed subject matter and are incorporated in and constitute a part of this specification, illustrate embodiments of the subject matter and together with the description serve to explain the principles of the subject matter and not to limit the subject matter.
Fig. 1 is a diagram illustrating an example of a periodic thread in a train control system according to the related art;
FIG. 2 is a flow chart of a method for managing threads in a control system provided herein;
FIG. 3 is a schematic diagram of a three-level monitoring system provided by an embodiment provided herein;
fig. 4 is a schematic diagram of an external independent crystal oscillator module generating tick interrupt according to an embodiment of the present application;
fig. 5 is a flowchart of tick interrupt processing function processing of the CPU according to the embodiment of the present application;
fig. 6 is a flowchart of a method for periodically monitoring threads according to an embodiment of the present disclosure;
FIG. 7 is a diagram illustrating a cycle monitoring thread monitoring 3 cycle threads according to an embodiment of the present disclosure;
fig. 8 is a schematic diagram of interaction between a coprocessor soft watchdog module and a cycle monitoring thread according to an embodiment of the present application.
Detailed Description
To make the objects, technical solutions and advantages of the present application more apparent, embodiments of the present application will be described in detail below with reference to the accompanying drawings. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
The steps illustrated in the flow charts of the figures may be performed in a computer system such as a set of computer-executable instructions. Also, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
Fig. 2 is a flowchart of a method for managing threads in a control system according to the present application. The method shown in fig. 2 comprises:
step 201, obtaining a cycle thread running in a current running cycle T in a control system;
the control system may be a system comprising one or at least two threads that are executed periodically; such as a train control system, etc.
The period of each cycle thread is different, and the cycle thread running in the current running period is determined according to the length of the cycle in which the cycle thread is executed in the control system.
In an exemplary embodiment, the monitored time granule of the cycle thread is a running cycle, the running cycle is a clock cycle of system output, wherein the execution cycle of the cycle thread in the whole control system is N times of the running cycle, wherein N is a real number greater than 0; therefore, the running state of the cycle thread is acquired by taking the running cycle as the detection cycle, and the purpose of managing the cycle thread based on the fixed cycle is achieved.
Step 202, determining the maximum timeout time Tdead of each periodic thread in the operating period T, wherein the maximum timeout time Tdead is a determined time;
the Tdead of each cycle thread in the running cycle T is a determined moment, is not influenced by interruption of other cycle threads, is not influenced by the last cycle execution delay of the cycle thread, namely, an accumulated error is not introduced, the executed moment of the cycle thread in the current running cycle T is ensured to be a specific moment which is not influenced by the outside, and an accurate judgment basis is provided for the judgment of the abnormal running of the cycle thread.
In an exemplary embodiment, the determining the maximum timeout time Tdead that the thread runs in each cycle within the running period T includes:
determining the execution time Tschedul corresponding to each cycle thread in the control system in the operation cycle T according to the executed cycle duration and the executed accumulated times of each cycle thread;
and calculating the maximum timeout time Tdead corresponding to the running period T of each periodic thread according to the execution time Tschedul and the preset maximum timeout duration delta T.
In the present exemplary embodiment, the duration of the executed cycle is fixed for each cycle thread, and the cumulative number of times of execution can be obtained by recording the cycle thread by the control system; by using the above two parameters, the multiplication operation is performed, so that the execution time Tschedul corresponding to each cycle thread in the control system in the operation cycle T can be obtained, and the value is an absolute value relative to the time value of the system power-on time, that is, is not affected by the execution delay of the previous cycle, so that an accumulated error is not introduced.
The execution time Tschedul is the time information that the periodic thread should be normally executed in the running period; the maximum timeout duration Δ t is a tolerable waiting duration of the system after considering processing performance and other factors comprehensively, and according to the time information, the tolerable maximum timeout time of the system in the current period can be calculated, and the maximum timeout time Tdead can be obtained by calculating the corresponding time of the execution time Tschedul after the timeout duration Δ t.
And 203, managing the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to the cycle threads in the running cycle T.
For each cycle thread, the maximum timeout time Tdead is determined in each operating cycle, that is, any cycle of all cycle threads is scheduled at the determined time, so that monitoring based on absolute time is realized.
In an exemplary embodiment, before the obtaining of the cycle thread running in the current running cycle T in the control system, the method further includes:
creating a cycle monitoring thread, setting the priority of the cycle monitoring thread in the whole control system to be highest, and setting the execution cycle to be minimum
In the exemplary embodiment, the priority of the cycle monitoring thread is the highest and the cycle is the smallest, so that the cycle monitoring thread is guaranteed to be executed in time and effectively in priority to all other cycle threads in the control system, and the purpose of monitoring other cycle threads is achieved.
The periodic monitoring thread monitors based on the determined scheduling time, instead of adopting a query response mode, so that delay is avoided; meanwhile, after the periodic thread fails, the zero clearing operation is not carried out on the running time of the periodic thread, so that the corresponding executed time of each periodic thread is ensured to be absolute time, and the accumulated error cannot be introduced into the subsequent management.
In the process of managing the periodic threads, the running state of the periodic threads can be monitored and managed according to the maximum timeout moment of the current running period of each periodic thread by a method of polling each periodic thread.
In an exemplary embodiment, the managing, according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, a periodic thread running in the running period T includes:
in the operation period T, comparing the current time Tn with the maximum timeout time Tdead of each period thread operated in the operation period T to obtain a comparison result;
selecting a target cycle thread with the current time Tn being greater than the maximum timeout time Tdead from the comparison result;
and performing exception handling on the target period thread.
In the present exemplary embodiment, after the maximum timeout time of each acquired periodic thread, whether the periodic thread is abnormal is determined by determining whether the current time reaches the acquired maximum timeout time, and the target periodic thread with the abnormality is processed, for example, the thread may be stopped, or an alarm prompt may be issued.
The method provided by the embodiment of the application obtains the cycle threads running in the current running cycle T in the control system, determines the maximum timeout time Tdead of each cycle thread running in the running cycle T, and manages the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to each cycle thread in the running cycle T, so that the detection of the running state of the cycle threads is realized by taking the cycle threads as a time unit according to the maximum timeout time, the detection accuracy of the cycle threads is improved, and the purpose of improving the safety of thread management is achieved.
The methods provided herein are further described below:
in an exemplary embodiment, before the obtaining of the cycle thread running in the current running cycle T in the control system, the method further includes:
judging whether the time length of the current output operation period of the clock source of the control system is accurate or not;
and if the time length of the operation cycle output by the clock source at present is accurate, allowing to obtain the cycle thread operated in the current operation cycle T in the control system.
In an exemplary embodiment, by judging whether the current output operation cycle in the control system is accurate, the accuracy of the calculated maximum timeout time Tdead can be ensured, the misjudgment of the monitoring result caused by the clock fault of the control system is reduced, the judgment accuracy is improved, and the safety of thread management is improved.
In an exemplary embodiment, the determining whether the operation period of the clock source output of the control system is accurate includes:
acquiring a first time length of a clock beat currently output by a CPU in the control system;
calculating the difference value between the first time length and a second time length of a pre-acquired reference clock beat;
judging whether the difference value meets a preset difference value judgment strategy or not;
and if the difference value accords with the difference value judgment strategy, determining that the operation cycle of the clock source output of the control system is accurate, otherwise, determining that the operation cycle of the clock source output of the control system is inaccurate.
In the exemplary embodiment, the operation cycle is generated according to the interruption of the time of the CPU self-timer, the clock detection method compares the time of the CPU self-timer with the beat of the reference clock, and determines whether the operation cycle of the current clock source output is accurate by determining whether the difference is within the preset allowable error tolerance.
In an exemplary embodiment, the reference clock beat is output by an independent crystal oscillator module independent from the CPU, and the second duration of the reference clock beat is determined according to the clock beat output by the CPU in a normal operating state.
In the exemplary embodiment, the clock tick generated by the external independent crystal oscillator module is used to detect the time of the CPU timer, so as to effectively determine whether the interrupt source in the system is accurate.
In an exemplary embodiment, after the managing, according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, a periodic thread running in the running period T, the method further includes:
detecting the working state of the periodic monitoring thread according to a preset detection period;
and if the detection signal of the periodic monitoring thread is not received in the detection period, continuing to wait for a preset waiting time length, and if the detection signal is not received, stopping the running of the periodic thread in the control system.
In the exemplary embodiment, the cycle monitoring thread is a thread with the highest priority in the control system, and may manage the cycle thread in the control system, which is also a cycle thread. By detecting the running state of the periodic monitoring thread, whether the periodic thread in the control system is in a monitored state can be effectively judged, and the safety of thread management is improved. When the cycle monitoring thread is in an abnormal working state, the cycle thread in the control system is not in a monitoring state, safety risk exists, the running of the cycle thread in the control system needs to be stopped in time, and the safety of thread management is improved.
In an exemplary embodiment, the detecting the working state of the periodic monitoring thread according to a preset detection period includes: acquiring the working state of the cycle monitoring thread running in the CPU from the CPU of the control system according to the execution cycle of the cycle monitoring thread;
the stopping of the running of the periodic thread in the control system comprises: and sending a control signal, wherein the control signal is used for stopping the running of a CPU in the control system.
In the present exemplary embodiment, the working state of the periodic monitoring thread can be quickly and accurately obtained by acquiring the working state of the periodic monitoring thread from the CPU; when the abnormal working state of the cycle monitoring thread is detected, the running of the cycle monitoring thread and the monitored cycle thread can be effectively stopped by stopping the running of the CPU, the realization mode is quick and accurate, and the safety of thread management is provided.
The method provided by the embodiments of the present application is explained as follows:
in the related art, the thread management is implemented in a train control system by adopting a roll call mode, and through technical research and development, the inventor finds that the safety risk of the method is mainly embodied in the following four aspects, including:
firstly, when the periodic monitoring thread is not the highest priority, the periodic monitoring thread cannot be scheduled to execute monitoring in time;
secondly, the monitoring method is based on query response type monitoring, when wrong clock cycles exist in inter-thread communication, response inevitably generates delay, and possibly causes overlong response time from fault occurrence to fault identification;
thirdly, as the inquiry response mode adopts a handshake mechanism, the condition of accumulated error or accumulated delay caused by multiple delays exists;
fourth, the method does not take into account failures of the operating system external clock.
Based on the technical reasons analyzed by the inventor, the following embodiments are provided to provide technical implementation schemes based on the technical reasons to improve the safety of the train control system, and the following are described as follows:
all cycle threads in the train control system are related to the system safety, so the execution states of all cycle threads need to be monitored in time and necessary measures need to be taken to ensure the safety of the system operation.
Fig. 3 is a schematic diagram of a three-level monitoring system provided in an embodiment provided in the present application.
As shown in fig. 3, the first-stage subsystem detects a clock tick (tick) scheduled by the operating system, where the tick refers to a periodic interrupt, and whether a clock source of the operating system is accurately scheduled can be determined through the detection of the first-stage subsystem; the second-level subsystem monitors all other periodic threads by the periodic monitoring thread with the highest priority based on absolute time; and the third-level subsystem checks the cycle monitoring thread by a soft watchdog module of the coprocessor. The three-stage subsystems have different monitoring concerns, the first-stage subsystem monitors a clock tick generating system thread scheduling interrupt, and the second-stage subsystem and the third-stage subsystem are combined together to monitor periodic thread scheduling, so that the reliability of thread scheduling is improved.
Each stage of subsystem is explained as follows:
first stage subsystem
The clock tick (tick) is a periodic interrupt that schedules the operating system, typically set to 1ms-100ms, which may also be referred to as the pulse of the system's heart. If the clock ticks are inaccurate, the scheduling of the entire operating system is severely impacted.
Fig. 4 is a schematic diagram of an external independent crystal oscillator module generating tick interrupts according to an embodiment of the present application. As shown in fig. 4, the clock interruption is generated by an external independent crystal module, and the clock of the security system is checked in real time.
Fig. 5 is a flowchart of tick interrupt processing function processing of the CPU according to the embodiment of the present application. As shown in fig. 5, the CPU first reads the time of the CPU timer, then subtracts the time of the CPU timer read in the last interrupt function, compares the difference value with the time value tick of the clock tick, and if the difference between the two is greater than the error value, the interrupt processing function reports the clock tick detection fault.
The clock detection method adopts the time of the CPU self timer to detect the clock tick generated by the external independent crystal oscillator module, and can effectively judge whether the interrupt source (such as the external independent crystal oscillator module) in the system is accurate or not.
Second stage subsystem
The periodic thread scheduling in the train control system is realized by an operating system, the absolute time when the thread is scheduled is Tschedul, each thread needs to set a maximum timeout time delta t, and Tschedule + delta t is the maximum timeout time and can be defined as Tdead. The maximum timeout time Tdead of the thread cannot be exceeded during the execution of any periodic thread, otherwise, the normal scheduling execution of the thread is affected, the reaction time of a system is affected, and the safety is affected, so that the maximum timeout time of each periodic thread needs to be monitored.
1) Absolute time: refers to a time value relative to the time of system power-on;
2) the absolute time that the monitored current cycle of the cycle thread should be executed, namely the time that the operating system schedules the thread to start executing, is increased along with the execution times of the cycle, and the Tschedule is a determined value and is not influenced by interruption of other cycle threads and the execution delay of the last cycle of the cycle thread.
3) Delta t is the maximum delay time acceptable for the operation of the periodic thread, also called the maximum timeout time, which can be flexibly configured according to the difference of thread functions, usually has high requirement on the response time of functions in the thread, and the timeout time is set to be smaller; the timeout may be relaxed appropriately if the response time requirements for functions in the thread are low.
4) And Tdead is the maximum timeout moment of the current period of the periodically monitored thread, and each period needs to be calculated according to Tschedul. The calculation method is obtained by adding a maximum timeout time deltat to Tschedul.
The second-level subsystem monitoring is realized by creating a cycle monitoring thread, wherein the execution cycle of the cycle monitoring thread in the system is minimum, and the priority is highest. Because the cycle monitoring thread has the minimum cycle and the highest priority, the thread can be guaranteed to be always executed in time and effectively in preference to all other cycle threads. The periodic threads are monitored based on absolute time, namely any period of all the periodic threads is scheduled at a determined time, and the periodic monitoring threads are also monitored based on the determined scheduling time instead of adopting a query response mode, so that delay is avoided; and meanwhile, the fault is not allowed to be cleared, so that the monitoring of the periodic thread does not introduce accumulated errors. When the period monitoring thread is executed, the running states of all other period threads are checked, whether the current execution time of the period monitored thread exceeds the maximum timeout time Tdead or not is judged, and if the current execution time of the period monitored thread exceeds the maximum timeout time Tdead, measures such as reporting faults, cutting off the output of the thread and the like are taken to ensure the safe operation of the system.
Fig. 6 is a flowchart of a monitoring method of a second-stage system according to an embodiment of the present disclosure. As shown in fig. 6, the steps of the method are as follows:
(1) two arrays are defined, wherein the two arrays are identified by thread id numbers, one array is used for storing the running period (represented by T [ id ]) of the thread in the monitored period, and the other array is used for storing the accumulated number of the execution periods (represented by Count [ id ]) of the thread in the monitored period. When all the monitored cycle threads are executed, the number of the executed cycle is accumulated, and the running cycle and the accumulated number of the executed cycle are filled into the two arrays. Wherein T [ id ] is the period of id number thread; count [ id ] is the accumulated number of current execution cycles of the thread with the thread id number;
(2) reading the current moment Tn of the system in each period by a period monitoring thread, wherein Tn is the nth period;
(3) polling all thread id numbers, and calculating the current execution cycle execution time Tschedul [ id ] of each thread corresponding to the id number (obtained by calculating the cycle T [ id ] execution times Count [ id ]).
(4) Calculating the maximum timeout time Tdead [ id ] of each id number corresponding to the current period of the thread, wherein the Tdead [ id ] is the sum of the Tschedul [ id ] and a maximum timeout time delta T, the delta T can be flexibly configured and is usually set as a period of the corresponding period thread, namely Tdead [ id ] ═ Tschedul [ id ] + T [ id ];
(5) polling each thread id number, comparing the current time Tn with the current maximum timeout time Tdead [ id ] of the thread, if the current time Tn is larger than the Tdead [ id ], indicating that the thread with the current id number cannot be executed in time, and the thread execution is in an abnormal state. The periodic monitoring thread needs the thread to take processing measures including fault reporting, output shutdown and the like.
For example, as shown in fig. 6, the id of the cycle monitoring thread is 0, which is the highest priority and the cycle is the smallest. And setting the maximum timeout time Δ T of each cycle thread as the execution cycle T of the thread, and then the thread maximum timeout time Tdead is Tschedul + T, where T is the execution cycle of the thread.
The monitored threads in the system comprise 3 threads including an IO thread, a communication thread and a diagnosis thread, and the cycle monitoring thread periodically checks whether the 3 threads are all executed effectively in time. The method comprises the steps of obtaining a diagnosis thread, wherein the id of the IO thread is i, the period is T [ i ], the id of the communication thread is j, the period is T [ j ], the id of the diagnosis thread is k, and the period is T [ k ]. The system implementation is shown in fig. 6.
The cycle monitoring thread runs according to a cycle, detects whether the execution of other three cycle threads is normal or not every cycle, when the cycle is running to the nth cycle, the cycle monitoring thread firstly reads the current time Tn, then polls all the 3 threads, at this time, the IO thread executes to the xth cycle, the communication thread executes to the y-1 th cycle, and the diagnosis thread executes to the z-th cycle, as shown in FIG. 7.
The cycle monitoring thread obtains that the current execution cycle of the IO thread is the xth cycle, and calculates that the current maximum timeout time of the IO thread is Tdead [ i ] (x +1) T [ i ], and the current time Tn < Tdead [ i ], so the cycle monitoring thread judges that the IO thread is executed normally.
The method comprises the steps that a cycle monitoring thread obtains the current execution cycle of a communication thread as the (y-1) th cycle, the current maximum timeout time of the communication thread is calculated to be Tdead [ j ] ═ y T [ j ], and the cycle monitoring thread judges that the communication thread is abnormal in execution due to the fact that the current time Tn > Tdead [ j ], reports the fault state of the communication thread and cuts off external communication.
And the cycle monitoring thread acquires that the current execution cycle of the diagnosis thread is the z-th cycle, and calculates the current maximum timeout time Tdead [ k ] (z +1) × T [ k ] of the diagnosis thread and the current time Tn < Tdead [ k ], so that the cycle monitoring thread judges that the diagnosis thread is normally executed.
Third stage subsystem
Fig. 8 is a schematic diagram of interaction between a coprocessor soft watchdog module and a cycle monitoring thread according to an embodiment of the present application. As shown in fig. 8, the cycle monitoring thread is responsible for monitoring whether other monitored cycle threads in the system are normally executed, and for whether the cycle monitoring thread is normally executed, an external coprocessor (such as an FPGA, which is independent from a CPU running the train control system) is required to monitor the cycle monitoring thread, the coprocessor provides a soft watchdog module, the cycle monitoring thread executes a watchdog feeding operation, and the cycle of the soft watchdog module is T. When the soft watchdog module does not feed dogs for more than 2 × T, the watchdog module locks the CPU, so that the system guidance is safe.
According to the method provided by the embodiment of the application, the three-level subsystem is utilized to monitor the cycle thread in the control system, the cycle thread in the current running cycle can be managed by configuring the cycle monitoring thread, the cycle monitoring thread is guaranteed to have the highest priority, and the cycle monitoring thread can be scheduled to execute monitoring in time; the current operation period is used as a time point for detection, so that the condition that the communication between threads monitored based on the query response mode has wrong periods is effectively reduced, and the occurrence of faults is identified in time; the maximum overtime moment is used for judging, so that the condition of accumulated error or accumulated delay existing in response by adopting a handshake mechanism can be avoided, and the accuracy of short judgment is improved; in addition, the accuracy of the running period output by the system clock source is judged, so that the detection accuracy can be effectively improved, and the judgment accuracy is improved. Based on the advantages, the method provided by the embodiment of the application effectively improves the safety of thread management.
An embodiment of the present application provides an apparatus for managing threads in a control system, including a processor and a memory, where the memory stores a computer program, and the processor is configured to call the computer program in the memory to implement the following steps, including:
acquiring a cycle thread running in the current running cycle T in the control system;
determining the maximum timeout time Tdead of each period thread in the operation period T, wherein the maximum timeout time Tdead is a determined time;
and managing the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to the running cycle T of each cycle thread.
In an exemplary embodiment, the processor is configured to invoke the computer program in the memory to implement the method further comprising, before acquiring the cycle thread running in the current running cycle T in the control system:
and creating a cycle monitoring thread, setting the priority of the cycle monitoring thread in the whole control system to be the highest, and setting the execution cycle to be the minimum.
In an exemplary embodiment, the processor is configured to call a computer program in the memory to implement the step of determining a maximum timeout time Tdead for each periodic thread to run within a running period T, and includes:
determining the execution time Tschedul corresponding to each cycle thread in the control system in the operation cycle T according to the executed cycle duration and the executed accumulated times of each cycle thread;
and calculating the maximum timeout time Tdead corresponding to the running period T of each periodic thread according to the execution time Tschedul and the preset maximum timeout duration delta T.
In an exemplary embodiment, the processor is configured to invoke a computer program in the memory to implement the step of determining the maximum timeout time Tdead by calculating a corresponding time of the execution time Tschedul after the timeout duration Δ t elapses.
In an exemplary embodiment, the processor is configured to call a computer program in the memory to implement the step of managing the periodic threads running in the running period T according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, and includes:
in the operation period T, comparing the current time Tn with the maximum timeout time Tdead of each period thread operated in the operation period T to obtain a comparison result;
selecting a target cycle thread with the current time Tn being greater than the maximum timeout time Tdead from the comparison result;
and performing exception handling on the target period thread.
In an exemplary embodiment, before the processor is configured to call the computer program in the memory to implement the steps before acquiring the cycle thread running in the current running cycle T in the control system, the processor is configured to call the computer program in the memory to implement the following steps, including:
judging whether the operation period of the clock source output by the control system is accurate or not;
and if the running period output by the clock source is accurate, allowing to obtain a periodic thread running in the current running period T in the control system.
In an exemplary embodiment, the processor is configured to call a computer program in the memory to implement the step of determining whether the operation cycle of the clock source output of the control system is accurate, and includes:
acquiring a first time length of a clock beat currently output by a CPU in the control system;
calculating the difference value between the first time length and a second time length of a pre-acquired reference clock beat;
judging whether the difference value meets a preset difference value judgment strategy or not;
and if the difference value accords with the difference value judgment strategy, determining that the operation cycle of the clock source output of the control system is accurate, otherwise, determining that the operation cycle of the clock source output of the control system is inaccurate.
In an exemplary embodiment, the processor is configured to call the computer program in the memory to realize that the determined reference clock beat is output by the independent crystal module independent of the CPU, and the second duration of the reference clock beat is determined according to the clock beat output by the CPU in the normal operating state.
In an exemplary embodiment, after the processor is configured to call the computer program in the memory to manage the periodic threads running in the running period T according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, the processor is further configured to call the computer program in the memory to implement the following steps:
detecting the working state of the periodic monitoring thread according to a preset detection period;
and if the detection signal of the periodic monitoring thread is not received in the detection period, continuing to wait for a preset waiting time length, and if the detection signal is not received, stopping the running of the periodic thread in the control system.
In an exemplary embodiment, the processor is configured to call a computer program in the memory to implement the step of detecting the working state of the cycle monitoring thread according to a preset detection cycle, and includes:
acquiring the working state of the cycle monitoring thread running in the CPU from the CPU of the control system according to the execution cycle of the cycle monitoring thread;
the processor is configured to call a computer program in the memory to implement the step of stopping the running of the periodic thread in the control system, and includes:
and sending a control signal, wherein the control signal is used for stopping the running of a CPU in the control system.
According to the device embodiment provided by the application, the cycle threads running in the current running cycle T in the control system are obtained, the maximum timeout time Tdead of each cycle thread running in the running cycle T is determined, and the cycle threads running in the running cycle T are managed according to the maximum timeout time Tdead corresponding to each cycle thread in the running cycle T, so that the detection accuracy of the cycle threads is improved according to the maximum timeout time and the running state of the cycle threads is improved by taking the cycle threads as a time unit, and the purpose of improving the safety of thread management is achieved.
It will be understood by those of ordinary skill in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those of ordinary skill in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.

Claims (9)

1. A method for managing threads in a control system, comprising:
acquiring a cycle thread running in the current running cycle T in the control system;
determining the maximum timeout time Tdead of each period thread in the operation period T, wherein the maximum timeout time Tdead is a determined time;
managing the cycle threads running in the running cycle T according to the maximum timeout time Tdead corresponding to the running cycle T of each cycle thread;
the determining the maximum timeout time Tdead for each periodic thread to run in the running period T includes:
determining the execution time Tschedul corresponding to each cycle thread in the control system in the operation cycle T according to the executed cycle duration and the executed accumulated times of each cycle thread;
and calculating the maximum timeout time Tdead corresponding to the running period T of each periodic thread according to the execution time Tschedul and the preset maximum timeout duration delta T.
2. The method of claim 1, wherein before obtaining a cycle thread running within a current run cycle T in the control system, the method further comprises:
and creating a cycle monitoring thread, setting the priority of the cycle monitoring thread in the whole control system to be the highest, and setting the execution cycle to be the minimum.
3. The method according to claim 1, wherein the managing the periodic threads running in the running period T according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread comprises:
in the operation period T, comparing the current time Tn with the maximum timeout time Tdead of each period thread operated in the operation period T to obtain a comparison result;
selecting a target cycle thread with the current time Tn being greater than the maximum timeout time Tdead from the comparison result;
and performing exception handling on the target period thread.
4. The method of claim 1, wherein before obtaining a cycle thread running within a current run cycle T in the control system, the method further comprises:
judging whether the current output operation period of the clock source of the control system is accurate or not;
and if the current output running period of the clock source is accurate, allowing to obtain the cycle thread running in the current running period T in the control system.
5. The method according to claim 4, wherein said determining whether the operation period of the current output of the clock source of the control system is accurate comprises:
acquiring a first time length of a clock beat currently output by a CPU in the control system;
calculating the difference value between the first time length and a second time length of a pre-acquired reference clock beat;
judging whether the difference value meets a preset difference value judgment strategy or not;
and if the difference value accords with the difference value judgment strategy, determining that the operation cycle of the clock source output of the control system is accurate, otherwise, determining that the operation cycle of the clock source output of the control system is inaccurate.
6. The method of claim 5, wherein the reference clock beat is output by a separate crystal oscillator module independent of the CPU, and the second duration of the reference clock beat is determined according to the clock beat output by the CPU under normal operation.
7. The method according to claim 2, wherein after the management of the periodic threads running in the running period T according to the maximum timeout time Tdead corresponding to the running period T of each periodic thread, the method further comprises:
detecting the working state of the periodic monitoring thread according to a preset detection period;
and if the detection signal of the periodic monitoring thread is not received in the detection period, continuing to wait for a preset waiting time length, and if the detection signal is not received, stopping the running of the periodic thread in the control system.
8. The method of claim 7, wherein:
the method for detecting the working state of the periodic monitoring thread according to the preset detection period comprises the following steps:
acquiring the working state of the periodic monitoring thread from a CPU (central processing unit) of a control system according to the execution period of the periodic monitoring thread;
the stopping of the running of the periodic thread in the control system comprises:
and sending a control signal, wherein the control signal is used for stopping the running of a CPU in the control system.
9. An apparatus for managing threads in a control system, comprising a processor and a memory, wherein the memory stores a computer program and the processor is configured to invoke the computer program in the memory to implement the method of any one of claims 1 to 8.
CN201910228811.XA 2019-03-25 2019-03-25 Method and device for managing threads in control system Active CN110032435B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910228811.XA CN110032435B (en) 2019-03-25 2019-03-25 Method and device for managing threads in control system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910228811.XA CN110032435B (en) 2019-03-25 2019-03-25 Method and device for managing threads in control system

Publications (2)

Publication Number Publication Date
CN110032435A CN110032435A (en) 2019-07-19
CN110032435B true CN110032435B (en) 2021-06-08

Family

ID=67236633

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910228811.XA Active CN110032435B (en) 2019-03-25 2019-03-25 Method and device for managing threads in control system

Country Status (1)

Country Link
CN (1) CN110032435B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6631009B1 (en) * 1999-09-24 2003-10-07 Xerox Corporation Avoiding deadlock situations in a printing system using a locking time-out mechanism
CN103092746A (en) * 2013-02-05 2013-05-08 上海大唐移动通信设备有限公司 Positioning method and system for thread anomaly
CN107247630A (en) * 2017-06-05 2017-10-13 努比亚技术有限公司 Thread detection method, terminal and computer-readable recording medium
CN107589986A (en) * 2017-07-28 2018-01-16 北京北信源软件股份有限公司 A kind of universal process method and device of data processing time-out

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10176012B2 (en) * 2014-12-12 2019-01-08 Nxp Usa, Inc. Method and apparatus for implementing deterministic response frame transmission

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6631009B1 (en) * 1999-09-24 2003-10-07 Xerox Corporation Avoiding deadlock situations in a printing system using a locking time-out mechanism
CN103092746A (en) * 2013-02-05 2013-05-08 上海大唐移动通信设备有限公司 Positioning method and system for thread anomaly
CN107247630A (en) * 2017-06-05 2017-10-13 努比亚技术有限公司 Thread detection method, terminal and computer-readable recording medium
CN107589986A (en) * 2017-07-28 2018-01-16 北京北信源软件股份有限公司 A kind of universal process method and device of data processing time-out

Also Published As

Publication number Publication date
CN110032435A (en) 2019-07-19

Similar Documents

Publication Publication Date Title
US9720761B2 (en) System fault detection and processing method, device, and computer readable storage medium
CN109783262B (en) Fault data processing method, device, server and computer readable storage medium
EP3979079A1 (en) Memory fault handling method and apparatus, device and storage medium
US8458530B2 (en) Continuous system health indicator for managing computer system alerts
US8448025B2 (en) Fault analysis apparatus, fault analysis method, and recording medium
US20170147422A1 (en) External software fault detection system for distributed multi-cpu architecture
CN103268277A (en) Method and system for outputting log information
US20030084376A1 (en) Software crash event analysis method and system
CN111813590B (en) Method and device for diagnosing abnormal reset of main control module and main control module
JP5623557B2 (en) Method, apparatus, and computer program in a multi-threaded computing environment for collecting diagnostic data
CN101221518B (en) Method, device and system for preventing timing device overflow of hardware watchdog
CN110659147B (en) Self-repairing method and system based on module self-checking behavior
CN110032435B (en) Method and device for managing threads in control system
CN113407391A (en) Fault processing method, computer system, substrate management controller and system
CN113297009B (en) Information backup method, equipment, platform and storage medium
JP6504610B2 (en) Processing device, method and program
CN111159051B (en) Deadlock detection method, deadlock detection device, electronic equipment and readable storage medium
KR102213676B1 (en) Terminal apparatus for autosar system with arithmetic operation supervision function and arithmetic operation supervision method of autosar system
CN113535448A (en) Multiple watchdog control method and control system thereof
JP5627414B2 (en) Action log collection system and program
WO2022057373A1 (en) Dual-port disk management method, apparatus and terminal, and storage medium
EP4206839A1 (en) Method for managing ecu on vehicle, and ecu and readable storage medium
JP4985720B2 (en) Log management system, log management method, log collection unit, and program
CN117076186B (en) Memory fault detection method, system, device, medium and server
CN117234787B (en) Method and system for monitoring running state of system-level chip

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant