CN113176983B - Program flow monitoring method and program flow monitoring system, CPU and chip - Google Patents

Program flow monitoring method and program flow monitoring system, CPU and chip Download PDF

Info

Publication number
CN113176983B
CN113176983B CN202110720483.2A CN202110720483A CN113176983B CN 113176983 B CN113176983 B CN 113176983B CN 202110720483 A CN202110720483 A CN 202110720483A CN 113176983 B CN113176983 B CN 113176983B
Authority
CN
China
Prior art keywords
program flow
program
execution time
execution
monitoring
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
CN202110720483.2A
Other languages
Chinese (zh)
Other versions
CN113176983A (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.)
Marketing Service Center Of State Grid Ningxia Electric Power Co ltd Metering Center Of State Grid Ningxia Electric Power Co ltd
State Grid Corp of China SGCC
State Grid Information and Telecommunication Co Ltd
Beijing Smartchip Microelectronics Technology Co Ltd
Original Assignee
Marketing Service Center Of State Grid Ningxia Electric Power Co ltd Metering Center Of State Grid Ningxia Electric Power Co ltd
State Grid Corp of China SGCC
State Grid Information and Telecommunication Co Ltd
Beijing Smartchip Microelectronics Technology 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 Marketing Service Center Of State Grid Ningxia Electric Power Co ltd Metering Center Of State Grid Ningxia Electric Power Co ltd, State Grid Corp of China SGCC, State Grid Information and Telecommunication Co Ltd, Beijing Smartchip Microelectronics Technology Co Ltd filed Critical Marketing Service Center Of State Grid Ningxia Electric Power Co ltd Metering Center Of State Grid Ningxia Electric Power Co ltd
Priority to CN202110720483.2A priority Critical patent/CN113176983B/en
Publication of CN113176983A publication Critical patent/CN113176983A/en
Application granted granted Critical
Publication of CN113176983B publication Critical patent/CN113176983B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0751Error or fault detection not based on redundancy
    • G06F11/0754Error or fault detection not based on redundancy by exceeding limits
    • G06F11/0757Error or fault detection not based on redundancy by exceeding limits by exceeding a time limit, i.e. time-out, e.g. watchdogs

Abstract

The invention relates to the technical field of CPUs (central processing units), and provides a program flow monitoring method, a program flow monitoring system, a CPU and a chip. The program flow monitoring method comprises the following steps: recording the execution information of the program flow of the program through a monitoring point set in the program, and determining the execution track of the program flow; determining the expected execution time of the program flow according to the recorded execution information of the program flow; counting the actual execution time of the program flow; and determining whether the program flow is executed according to the expected execution time of the program flow according to the comparison result of the actual execution time of the program flow and the expected execution time of the program flow. The invention judges whether the program flow is executed according to expectation or not from the dimension of the combination of time and space, improves the accuracy of program flow monitoring, can simultaneously monitor the execution time and the execution track of the program flow and enhances the reliability of program flow execution.

Description

Program flow monitoring method and program flow monitoring system, CPU and chip
Technical Field
The present invention relates to the field of CPU technology, and in particular, to a program flow monitoring method, a program flow monitoring system, a CPU, a chip, and a storage medium.
Background
A CPU (Central Processing Unit) is widely used in the field of electric power as a core device on an industrial control chip. Due to the particularity of the power system environment, the CPU is easily affected by factors such as electromagnetic interference and line crosstalk to generate hardware faults. For example, the program counter in the CPU is abnormally rewritten to cause a fault such as a disordered program flow execution sequence, and the fault is influenced by an external environment and has randomness, and cannot be solved by a conventional software testing method. Generally, a compiler compiles a software program into a series of binary instruction stream sequences, and a CPU performs instruction fetching, decoding, and execution operations on the instruction stream sequences in sequence according to the order of the instruction stream to complete execution of instructions. The CPU can only guarantee that the operation of the program meets the expected logic by executing the instructions in sequence according to the instruction stream order. If the CPU is affected by interference factors, the execution sequence of the program flow is damaged (for example, partial instructions are not executed, a branch jump error and the like), a program logic error is generated, the execution result of the program does not meet the expectation, and even the whole system is abnormal. Therefore, it is necessary to monitor the program flow so as to find out the execution exception of the program flow in time and ensure the safe and reliable operation of the whole system program.
The current method for monitoring program flow is to use a watchdog module in the CPU or in the external system to monitor the running condition of the software, the watchdog circuit has a timing function, if the program does not initialize the count value within a specified time, the program is considered to be abnormal, and at this time, the watchdog circuit will output an interrupt or reset signal. However, the watchdog-based program flow monitoring method can only detect whether the program is executed within a period of time, and cannot achieve the purpose of monitoring whether the program flow is effectively executed according to the design logic, for example, the monitoring cannot be performed when a counter is abnormal and a part of instructions are skipped during the execution of the program flow. The watchdog-based program flow monitoring method can only confirm whether a program enters an exception or not, but cannot confirm whether the program flow is executed as expected or not.
Disclosure of Invention
An object of an embodiment of the present invention is to provide a program flow monitoring method and a program flow monitoring system, so as to solve at least the above problem that it is not possible to confirm whether a program flow is executed as expected.
In order to achieve the above object, an aspect of the present invention provides a program flow monitoring method, including:
recording the execution information of the program flow of the program through a monitoring point set in the program, and determining the execution track of the program flow;
determining the expected execution time of the program flow according to the recorded execution information of the program flow;
counting the actual execution time of the program flow;
and determining whether the program flow is executed according to the expected execution time of the program flow according to the comparison result of the actual execution time of the program flow and the expected execution time of the program flow.
Further, the recording of the execution information of the program flow of the program by the monitoring point set in the program includes: and setting the monitoring point in each sub program flow of the program flow, and recording the execution information of each sub program flow through the monitoring point.
Further, the determining the expected execution time of the program flow according to the recorded execution information of the program flow comprises; determining the execution times of each sub program flow segment according to the execution information of each sub program flow segment of the program flow; and determining the expected execution time of the program flow according to the expected execution time of executing each segment of the subprogram flow once and the execution times of each segment of the subprogram flow.
Further, where the program stream of the program is divided into multiple segments of sub-program streams, the types of the multiple segments of sub-program streams include one or more of: the program flow is executed in sequence, the program flow with fixed cycle times, the program flow with unfixed cycle times and the program flow with branch jump.
Further, the marking different monitoring points with different identifiers includes: initializing the monitoring points set in each sub program flow, and setting the identifiers of the monitoring points.
Further, the expected execution time T of the program streameThe calculation formula of (2) is as follows:
Figure 942471DEST_PATH_IMAGE001
wherein, TiIs the expected execution time, Count, of the sub-program flow of the program flowiIs the number of executions of the sub-program stream, n is the number of sub-program streams of said program stream, TiAnd CountiThe index i of (a) indicates the sequence number of the subroutine stream.
Further, the recording, by the monitoring point, the execution information of each sub-program stream includes: and marking different monitoring points by adopting different identifiers, and recording whether the monitoring points corresponding to the identifiers are executed and the execution times.
Further, the determining whether the program stream is executed as expected according to the comparison result between the actual execution time of the program stream and the expected execution time of the program stream includes: comparing the actual execution time of the program flow with the expected execution time of the program flow to obtain a difference value between the actual execution time of the program flow and the expected execution time of the program flow; and judging whether the difference value between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value, if so, determining that the program flow is executed according to expectation.
Further, the determining whether the difference between the actual execution time of the program stream and the expected execution time of the program stream is within the reference range value includes: substituting the actual execution time and the expected execution time into a formula | Tr-TeJudging whether the formula is established or not if the formula is established, and if the formula is established, determining that the program flow is executed according to expectation; wherein, TrRepresenting said actual execution time, TeRepresenting the expected execution time and alpha representing the reference range value.
Further, the counting the actual execution time of the program stream includes: and calculating the actual execution time of the program flow according to the starting execution timing value and the ending execution timing value of the program flow recorded by the timer.
Another aspect of the present invention provides a program flow monitoring system, including:
the system comprises a monitoring point management module, a monitoring point management module and a monitoring point management module, wherein the monitoring point management module is used for recording execution information of a program flow of a program through a monitoring point set in the program, determining an execution track of the program flow and determining expected execution time of the program flow according to the execution information of the program flow;
the timing module is used for counting the actual execution time of the program flow;
and the decision module is used for determining whether the program flow is executed according to the expectation according to the comparison result of the actual execution time of the program flow and the expectation execution time of the program flow.
Further, the recording of the execution information of the program flow of the program by the monitoring point set in the program includes: the monitoring point management module sets the monitoring points in each sub program flow of the program flow, and records the execution information of each sub program flow through the monitoring points.
Further, the recording, by the monitoring point, the execution information of each sub-program stream includes: the monitoring point management module adopts different identifiers to mark different monitoring points and records whether the monitoring points corresponding to the identifiers are executed and the execution times.
Further, the monitoring point management module marks different monitoring points by using different identifiers, including: the monitoring point management module initializes the monitoring points set in each sub program flow and sets the identifiers of the monitoring points.
Further, the determining the expected execution time of the program stream according to the recorded execution information of the program stream includes: the monitoring point management module determines the execution times of each sub program flow according to the execution information of each sub program flow, and determines the expected execution time of each program flow according to the expected execution time of each sub program flow executed once and the execution times of each sub program flow.
Further, the determining whether the program stream is executed as expected according to the comparison result between the actual execution time of the program stream and the expected execution time of the program stream includes: the decision module compares the actual execution time of the program flow with the expected execution time of the program flow to obtain the difference value of the actual execution time of the program flow and the expected execution time of the program flow; judging whether the difference value between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value, if so, determining that the program flow is executed according to expectation; if not, determining that the program flow is abnormal in execution.
Further, the determining whether the difference between the actual execution time of the program stream and the expected execution time of the program stream is within the reference range value includes: the decision module compares the actual execution time and the expectationExecution time substitution formula | Tr-TeJudging whether the formula is established or not if the formula is established, and if the formula is established, determining that the program flow is executed according to expectation; wherein, TrRepresenting said actual execution time, TeRepresenting the expected execution time and alpha representing the reference range value.
Further, the counting the actual execution time of the program stream includes: and the timing module records the starting execution time and the ending execution time of the program flow and calculates the actual execution time of the program flow according to the starting execution time and the ending execution time.
The invention also provides a CPU, which comprises the program flow monitoring system.
The invention also provides a chip which comprises the program flow monitoring system.
The present invention also provides a storage medium having stored thereon computer program instructions which, when executed, implement the program flow monitoring method described above.
The program flow monitoring method and the program flow monitoring system provided by the invention adopt a monitoring mode of combining time and space, and compare the actual execution time with the expected execution time by calculating the actual execution time of each subprogram flow in time to confirm whether the actual execution time is in accordance with the expected execution time; spatially, the monitoring point set in the program flow records the execution information of the program flow, determines the execution track of the program flow, and provides the parameter information of the execution times for calculating the expected execution time of the program flow. The invention judges whether the program flow is executed according to expectation or not from the dimension of the combination of time and space, thereby improving the accuracy of program flow monitoring; moreover, the invention can simultaneously realize the dual monitoring of the execution time and the execution track of the program flow and enhance the reliability of the execution of the program flow.
Additional features and advantages of embodiments of the invention will be set forth in the detailed description which follows.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the embodiments of the invention without limiting the embodiments of the invention. In the drawings:
FIG. 1 is a flow chart of a method for monitoring program flow according to an embodiment of the invention;
FIG. 2 is a flow diagram of a multi-segment subroutine flow of a program flow provided by one embodiment of the present invention;
fig. 3 is a block diagram of a program flow monitoring system according to an embodiment of the invention.
Detailed Description
The following detailed description of embodiments of the invention refers to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present invention, are given by way of illustration and explanation only, not limitation.
Based on the calling relation of the program, the program is divided into a main program and a subprogram, and the main program calls the subprogram to realize functions; the subprogram is composed of multiple subprogram flows (sequential execution program flow, loop number fixed program flow, loop number unfixed program flow, branch jump program flow, etc.) and provides basic functional logic. The program described below may be a main program or a sub program.
The embodiment of the invention provides a program flow monitoring method, which comprises the following steps: recording the execution information of the program flow of the program through a monitoring point set in the program, and determining the execution track of the program flow; determining the expected execution time of the program flow according to the recorded execution information of the program flow; counting the actual execution time of the program flow; and determining whether the program flow is executed according to the expected execution time of the program flow according to the comparison result of the actual execution time of the program flow and the expected execution time of the program flow. Specifically, the monitoring point is set in each sub program flow of the program flow before the program flow is executed. In the program flow executing process, recording the executing information of each sub program flow segment through the monitoring point, thereby determining the executing track of the program flow; and determining the execution times of each sub program stream according to the execution information of each sub program stream of the program stream, and determining the expected execution time of the program stream according to the expected execution time of each sub program stream executed once and the execution times of each sub program stream. After the execution of the program stream is finished, counting the actual execution time of the program stream, and comparing the actual execution time of the program stream with the expected execution time of the program stream to obtain a difference value between the actual execution time of the program stream and the expected execution time of the program stream; and judging whether the difference value between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value, if so, determining that the program flow is executed according to the expectation, and if not, determining that the program flow is abnormal in execution. The method for recording the execution information of each sub program flow by the monitoring point comprises the following steps: and marking different monitoring points by adopting different identifiers, and recording whether the monitoring points corresponding to the identifiers are executed and the execution times.
And setting the monitoring point in each divided sub program flow when the program flow of the program is divided into a plurality of sub program flows. FIG. 2 is a flow diagram of a multi-segment sub-program flow of a program flow provided by one embodiment of the present invention. As shown in fig. 2, the multi-segment subroutine stream of the program stream of the present embodiment includes: the program flow is executed in sequence, the program flow with fixed loop times, the program flow with unfixed loop times and the program flow with branch jump. In this embodiment, the program flow of a program or a subprogram is divided into 5 subprogram flows, including a sequentially executed program flow, a fixed loop program flow, a variable loop program flow, a conditional branch jump program flow (condition 1), and a conditional branch jump program flow (condition 2), which are sequentially labeled as P1-P5, where P1 is the first subprogram flow that is sequentially executed; p2 is a loop body with fixed loop times, and the loop times are j; p3 is a loop body with unfixed loop times, and the loop times are recorded as k; p4 is a subroutine stream executed when condition 1 is satisfied; p5 is a subroutine stream executed when condition 2 is satisfied. Each subprogram flow is provided with a monitoring point with a corresponding number, identifiers of the monitoring points corresponding to the subprogram flows P1-P5 are M1-M5 in sequence, and codes of the monitoring points are dispersed into the corresponding subprogram flows. The number of times of execution of the subroutine flows P1-P5 is recorded as Count 1-Count 5. The expected execution times of the subroutine flows P1 to P5 are denoted as T1 to T5. The execution sequence of the subroutine flows P1 and P2 is fixed, the expected execution time is a fixed value, which is denoted as T1 and T2, and the execution times Count1 and Count2 are assigned to 1. The execution sequence of the subroutine flow P3 affected by the parameter k is not fixed, the number of times of execution Count3 is k, the expected time for executing one loop is denoted as T3, and the expected execution time T3 is equal to Count3 × T3. The subroutine flows P4 and P5 are assigned with the number of times of execution Count4 and Count5 as 1 if the execution conditions are satisfied, and otherwise, the number of times of execution Count4 and Count5 are assigned with 0. Then, the expected execution time Te of the program flow of the sub-program is represented as T1 × Count1+ T2 × Count2+ T3 × Count3+ T4 × Count4+ T5 × Count5, and the execution times of the corresponding sub-program flow is substituted into the above formula, and depending on whether P4 and P5 satisfy the execution condition, the value of Te may have the following four cases:
Figure 397041DEST_PATH_IMAGE002
assuming that there are n sub program streams in the program stream of a program, the expected execution time T of the programeExpressed as:
Figure 16241DEST_PATH_IMAGE001
wherein, for a fixed number of loop times of the sub-program stream, TiTo perform the expected time of the entire cycle, CountiIs 1; for a subroutine flow with unfixed number of cycles, TiTo perform the desired time of a single cycle, CountiFor the actual number of cycles, TiAnd CountiSubscript i of (a) denotes the sequence number of the subroutine stream; for subroutine flows in conditional branches, TiFor the expected time that the subroutine stream is executed, Count if the condition is not metiIs 0, otherwise is 1. Actual execution times Count of subprogram flow with unfixed execution timesiRecording by the monitoring point, counting the execution times Count of each sub-program flowiIn the process of (2), also realize the pairThe execution trajectory of the program stream is recorded.
Expected execution time T of each sub-program flowiThe calculation may be performed during the program development phase, for example, by counting the number of clock cycles required to execute the sub program stream by debugging techniques, calculating the expected execution time from the number of clock cycles and the CPU clock frequency, or calculating the expected execution time by adding a clock timing program at the start and stop positions of the program stream.
In the actual execution time statistics of the program flow, in consideration of the execution efficiency of the program, a timer is used to time the whole program or subprogram when the actual execution time is calculated, the time starting and stopping program is respectively positioned at the front and rear positions of calling the program or subprogram, and the actual execution time T isrExpressed as: t isr=Tend –TbeginWherein T isbeginFor starting the count-time value of a timer, TendThe value of the timer is counted for the expiration of the timer. The expected execution time and the actual execution time may not be exactly the same due to the influence of the factors of starting, stopping, calling the subroutine, etc., and the reference range value parameter α may be introduced as long as | T is satisfiedr-TeThe actual execution of the program flow is deemed to meet expectations | ≦ α. The selection of the reference range parameter α can be flexibly set according to the specific implementation of the subprogram, and the accuracy and feasibility of program flow monitoring need to be considered.
Fig. 1 is a flowchart of a program flow monitoring method according to an embodiment of the present invention. As shown in fig. 1, in a preferred embodiment, the procedure of monitoring program flow for a subroutine is as follows:
s1, initializing the monitoring points of each sub-program flow in the sub-program, including setting identifiers of the monitoring points (i.e. marking different monitoring points with different identifiers), and referring to the range value parameter α.
S2, starting the timer, recording the start timing value T of the timerbegin
S3, calling the subprogram, and recording whether each monitoring point is executed and the execution times Count through the monitoring point of each subprogram flow in the subprogrami
S4, when the subprogram returns, the timer is terminated, and the time value T of the timer is recordedend
S5, counting time value T according to the start of timerbeginAnd the end count value T of the timerendCalculating the actual execution time T of the subprogramrThrough the execution times CountiCalculating the expected execution time T of the subprograme
S6, executing time T actuallyrAnd expected execution time TeAnd comparing to determine whether the program flow of the subprogram is executed according to the expectation. Specifically, the actual execution time T isrAnd expected execution time TeSubstituting formula | Tr-TeIf the formula is established, the execution of the program flow meets the expectation; if not, the execution of the program flow is indicated to be abnormal.
The program flow monitoring method provided by the embodiment of the invention adopts a monitoring mode of combining time and space, compares the actual execution time with the expected execution time by calculating the actual execution time of each subprogram flow in time, and confirms whether the actual execution time is consistent with the expected execution time or not; spatially, the monitoring point set in the program flow records the execution information of the program flow, determines the execution track of the program flow, and provides the parameter information of the execution times for calculating the expected execution time of the program flow. The invention judges whether the program flow is executed according to expectation or not from the dimension of the combination of time and space, thereby improving the accuracy of program flow monitoring; moreover, the invention can simultaneously realize the dual monitoring of the execution time and the execution track of the program flow, can effectively detect the problem that the execution behavior of the program is inconsistent with the expectation caused by the failure of the program counter, and enhances the execution reliability of the program flow so as to ensure the safe and reliable operation of the whole system program.
In addition, due to the difference of the parameter values of the subroutines, the program flow such as loop and branch jump has different execution times during execution. The invention divides the program flow into a plurality of sections of subprogram flows of different types, carries out refinement according to the execution condition and improves the monitoring precision of the program flow.
Fig. 3 is a block diagram of a program flow monitoring system according to an embodiment of the invention. As shown in fig. 3, the program flow monitoring system of the present embodiment includes a monitoring point management module, a timing module, and a decision module. The monitoring point management module is used for recording the execution information of the program flow of the program through the monitoring points set in the program, determining the execution track of the program flow and determining the expected execution time of the program flow according to the execution information of the program flow. Specifically, the monitoring point management module is configured to set the monitoring point in each sub program stream of the program stream, and record execution information of each sub program stream through the monitoring point. The monitoring point management module adopts different identifiers to mark different monitoring points, records whether the monitoring points corresponding to the identifiers are executed or not and the execution times, and comprises the steps of initializing the monitoring points set in each sub program flow, and setting the identifiers and the reference range values of the monitoring points. Further, the checkpoint management module is configured to determine, according to the execution information of each segment of the sub-program stream of the program stream, the number of times of executing each segment of the sub-program stream, and determine, according to the expected execution time for executing each segment of the sub-program stream once and the number of times of executing each segment of the sub-program stream, the expected execution time of the program stream. In an alternative embodiment, the monitoring point is a code segment in the function that implements a location marking function, and the callo function determines whether the monitored program stream is actually executed according to the marking information. The execution information of the program stream is recorded by a structure of the monitoring point, the structure comprising an identifier and execution status information. The identifiers are used for marking different monitoring points so as to facilitate the retrieval of monitoring point information and not participate in the calculation of monitoring decisions; the execution state information is used for recording whether the monitoring point is executed and the execution times. The execution times refer to the actual execution times of the monitoring points with unfixed execution times. For the monitoring point with fixed execution times, if the monitoring point is executed, the execution times are fixed to 1, otherwise, the execution times are 0. For the case where the monitor point location is in a conditional branch or loop body, the number of executions affected by external parameters is not fixed, and therefore the program flowThe expected execution time T can not be calculated in advance, and the expected execution time T is calculated according to the pre-calculated single execution time multiplied by the actual execution timese
In a preferred embodiment, the multi-segment subroutine stream includes: the program flow is executed in sequence, the program flow with fixed loop times, the program flow with unfixed loop times and the program flow with branch jump. For example, the program flow of a program or a subprogram is divided into 5 subprogram flows, labeled as P1-P5, wherein P1 is the first subprogram flow executed sequentially; p2 is a loop body with fixed loop times, and the loop times are j; p3 is a loop body with unfixed loop times, and the loop times are recorded as k; p4 is a subroutine stream executed when condition 1 is satisfied; p5 is a subroutine stream executed when condition 2 is satisfied. Each subprogram flow is provided with a monitoring point with a corresponding number, identifiers are M1-M5 in sequence, and codes of the monitoring points are dispersed into the corresponding subprogram flows. The number of times of execution of the subroutine flows P1-P5 is recorded as Count 1-Count 5. The expected execution times of the subroutine flows P1 to P5 are denoted as T1 to T5. The execution sequence of the subroutine flows P1 and P2 is fixed, the expected execution time is a fixed value, which is denoted as T1 and T2, and the execution times Count1 and Count2 are assigned to 1. The execution sequence of the subroutine flow P3 affected by the parameter k is not fixed, the number of times of execution Count3 is k, the expected time for executing one loop is denoted as T3, and the expected execution time T3 is equal to Count3 × T3. The subroutine flows P4 and P5 are assigned with the number of times of execution Count4 and Count5 as 1 if the execution conditions are satisfied, and otherwise, the number of times of execution Count4 and Count5 are assigned with 0. The expected execution time Te of the program flow of the subroutine is represented as T1 × Count1+ T2 × Count2+ T3 × Count3+ T4 × Count4+ T5 × Count 5.
The timing module is used for counting the actual execution time of the program flow. Specifically, the starting execution time and the ending execution time of the program stream are recorded, and the actual execution time of the program stream is calculated according to the starting execution time and the ending execution time. For example, when calculating the actual execution time, a timer is used to time the whole program or subprogram, the start and stop timing programs are respectively located before and after the program or subprogram is called, and the actual execution time TrExpressed as:Tr=Tend –Tbeginwherein T isbeginFor starting the count-time value of a timer, TendThe value of the timer is counted for the expiration of the timer.
The decision module is used for determining whether the program flow is executed according to the expectation according to the comparison result of the actual execution time of the program flow and the expectation execution time of the program flow. For example, the value T is counted according to the start of the timerbeginAnd the end count value T of the timerendCalculating the actual execution time T of the subprogramrThrough the execution times CountiCalculating the expected execution time T of the subprogrameWill actually execute time TrAnd expected execution time TeAnd (6) carrying out comparison. The expected execution time and the actual execution time may not be exactly the same due to the influence of the factors such as the start, stop and subroutine call of the timer, and the reference range value parameter α may be introduced as long as the formula | T is satisfiedr-TeThe actual execution of the program flow is deemed to meet expectations | ≦ α.
The program flow monitoring system provided by the embodiment of the invention adopts a monitoring mode of combining time and space, calculates the actual execution time of each subprogram flow through the timing module in time, compares the actual execution time with the expected execution time through the decision module, and confirms whether the actual execution time is consistent with the expected execution time or not; in space, a monitoring point is set in the program flow, the execution information of the program flow is recorded through a monitoring point management module, the execution track of the program flow is determined, and parameter information of the execution times is provided for determining the expected execution time of the program flow. The invention judges whether the program flow is executed according to expectation or not from the dimension of the combination of time and space, thereby improving the accuracy of program flow monitoring; the invention can simultaneously realize double monitoring of the execution time and the execution track of the program flow and enhance the reliability of the execution of the program flow.
The embodiment of the invention also provides a CPU, which comprises the program flow monitoring system, or adopts the program flow monitoring method. The CPU of the invention carries out double monitoring on the execution time and the execution track of the program flow at the same time, can effectively detect the problem that the execution behavior of the program is inconsistent with the expectation caused by the failure of the program counter, enhances the execution reliability of the program flow, and ensures the safe and reliable operation of the CPU system program. The program flow monitoring system can be used together with a watchdog circuit of a CPU external system, if the CPU is abnormally suspended during the program flow, a program timer of the CPU can not count, and at the moment, the external system watchdog circuit monitors the CPU system program to detect the problem of CPU suspension caused by abnormal program flow.
An embodiment of the present invention further provides a chip, including: and the processor is used for calling and running a computer program from the memory so that the equipment provided with the chip executes the program flow monitoring method, or the chip comprises the program flow monitoring system.
Embodiments of the present invention also provide a storage medium having computer program instructions stored thereon, which when executed implement the program flow monitoring method described above.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, systems and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting the same, and although the present invention is described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that: modifications and equivalents may be made to the embodiments of the invention without departing from the spirit and scope of the invention, which is to be covered by the claims.

Claims (17)

1. A method of program flow monitoring, the method comprising:
recording the execution information of the program flow of the program through a monitoring point set in the program, and determining the execution track of the program flow;
determining the expected execution time of the program flow according to the recorded execution information of the program flow;
counting the actual execution time of the program flow;
determining whether the program flow is executed according to expectation according to a comparison result of the actual execution time of the program flow and the expected execution time of the program flow;
wherein the recording of the execution information of the program flow of the program by the monitor point set in the program includes:
setting the monitoring point in each sub program flow of the program flow, and recording the execution information of each sub program flow through the monitoring point;
the recording, by the monitoring point, execution information of each sub-program stream includes:
and marking different monitoring points by adopting different identifiers, and recording whether the monitoring points corresponding to the identifiers are executed and the execution times.
2. The method of claim 1, wherein determining the expected execution time of the program stream according to the recorded execution information of the program stream comprises:
determining the execution times of each sub program flow segment according to the execution information of each sub program flow segment of the program flow;
and determining the expected execution time of the program flow according to the expected execution time of executing each segment of the subprogram flow once and the execution times of each segment of the subprogram flow.
3. The program flow monitoring method according to claim 1, wherein in a case where the program flow of the program is divided into a plurality of pieces of subroutine flows, the types of the plurality of pieces of subroutine flows include one or more of:
the program flow is executed in sequence, the program flow with fixed cycle times, the program flow with unfixed cycle times and the program flow with branch jump.
4. The program flow monitoring method according to claim 3, wherein the expected execution time T of the program floweThe calculation formula of (2) is as follows:
Figure 867382DEST_PATH_IMAGE001
wherein, TiIs the expected execution time, Count, of the sub-program flow of the program flowiIs the number of executions of the sub-program stream, n is the number of sub-program streams of said program stream, TiAnd CountiThe index i of (a) indicates the sequence number of the subroutine stream.
5. The program flow monitoring method of claim 1, wherein marking different monitoring points with different identifiers comprises:
initializing the monitoring points set in each sub program flow, and setting the identifiers of the monitoring points.
6. The method for monitoring program flow according to claim 1, wherein said determining whether the program flow is executed as expected according to the comparison result of the actual execution time of the program flow and the expected execution time of the program flow comprises:
comparing the actual execution time of the program flow with the expected execution time of the program flow to obtain a difference value between the actual execution time of the program flow and the expected execution time of the program flow;
and judging whether the difference value between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value, if so, determining that the program flow is executed according to expectation.
7. The method of claim 6, wherein the determining whether the difference between the actual execution time of the program stream and the expected execution time of the program stream is within a reference range value comprises:
substituting the actual execution time and the expected execution time into a formula | Tr-TeJudging whether the formula is established or not if the formula is established, and if the formula is established, determining that the program flow is executed according to expectation;
wherein, TrRepresenting said actual execution time, TeRepresenting the expected execution time and alpha representing the reference range value.
8. The method of claim 1, wherein said counting actual execution times of said program streams comprises:
and calculating the actual execution time of the program flow according to the starting execution timing value and the ending execution timing value of the program flow recorded by the timer.
9. A program flow monitoring system, the system comprising:
the system comprises a monitoring point management module, a monitoring point management module and a monitoring point management module, wherein the monitoring point management module is used for recording execution information of a program flow of a program through a monitoring point set in the program, determining an execution track of the program flow and determining expected execution time of the program flow according to the execution information of the program flow;
the timing module is used for counting the actual execution time of the program flow;
the decision-making module is used for determining whether the program flow is executed according to expectation according to a comparison result of the actual execution time of the program flow and the expected execution time of the program flow;
wherein the recording of the execution information of the program flow of the program by the monitor point set in the program includes:
the monitoring point management module sets the monitoring points in each sub program flow of the program flow, and records the execution information of each sub program flow through the monitoring points;
the recording, by the monitoring point, execution information of each sub-program stream includes:
the monitoring point management module adopts different identifiers to mark different monitoring points and records whether the monitoring points corresponding to the identifiers are executed and the execution times.
10. The program flow monitoring system of claim 9, wherein the monitoring point management module marks different monitoring points with different identifiers, comprising:
the monitoring point management module initializes the monitoring points set in each sub program flow and sets the identifiers of the monitoring points.
11. The program flow monitoring system of claim 9, wherein the determining the expected execution time of the program flow from the recorded execution information of the program flow comprises:
the monitoring point management module determines the execution times of each sub program flow according to the execution information of each sub program flow, and determines the expected execution time of each program flow according to the expected execution time of each sub program flow executed once and the execution times of each sub program flow.
12. The program flow monitoring system of claim 9, wherein determining whether the program flow is executing as expected based on the comparison of the actual execution time of the program flow to the expected execution time of the program flow comprises:
the decision module compares the actual execution time of the program flow with the expected execution time of the program flow to obtain the difference value of the actual execution time of the program flow and the expected execution time of the program flow;
judging whether the difference value between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value, if so, determining that the program flow is executed according to expectation; if not, determining that the program flow is abnormal in execution.
13. The program flow monitoring system of claim 12, wherein the determining whether the difference between the actual execution time of the program flow and the expected execution time of the program flow is within a reference range value comprises:
the decision module executes the actual executionSubstituting time and the expected execution time into the formula | Tr-TeJudging whether the formula is established or not if the formula is established, and if the formula is established, determining that the program flow is executed according to expectation;
wherein, TrRepresenting said actual execution time, TeRepresenting the expected execution time and alpha representing the reference range value.
14. The program flow monitoring system of claim 9, wherein the accounting for the actual execution time of the program flow comprises:
and the timing module records the starting execution time and the ending execution time of the program flow and calculates the actual execution time of the program flow according to the starting execution time and the ending execution time.
15. A CPU comprising the program flow monitoring system of any one of claims 9-14.
16. A chip comprising a program flow monitoring system according to any one of claims 9 to 14.
17. A storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed, implement the program flow monitoring method of any one of claims 1-8.
CN202110720483.2A 2021-06-28 2021-06-28 Program flow monitoring method and program flow monitoring system, CPU and chip Active CN113176983B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110720483.2A CN113176983B (en) 2021-06-28 2021-06-28 Program flow monitoring method and program flow monitoring system, CPU and chip

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110720483.2A CN113176983B (en) 2021-06-28 2021-06-28 Program flow monitoring method and program flow monitoring system, CPU and chip

Publications (2)

Publication Number Publication Date
CN113176983A CN113176983A (en) 2021-07-27
CN113176983B true CN113176983B (en) 2021-09-28

Family

ID=76928029

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110720483.2A Active CN113176983B (en) 2021-06-28 2021-06-28 Program flow monitoring method and program flow monitoring system, CPU and chip

Country Status (1)

Country Link
CN (1) CN113176983B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1527966A (en) * 2001-03-12 2004-09-08 ض� Method and apparatus to monitor use of a program
CN103135518A (en) * 2011-12-02 2013-06-05 费希尔控制国际公司 Program flow control monitoring routines, related methods and systems

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3121749B1 (en) * 2015-07-22 2019-06-26 Nxp B.V. Method and apparatus for ensuring control flow integrity
CN106776236B (en) * 2017-02-07 2020-05-08 北京龙鼎源科技股份有限公司 Method and apparatus for monitoring execution of a program
CN106844084B (en) * 2017-03-16 2020-03-17 北京新能源汽车股份有限公司 Program control method and device and automobile
CN107741897A (en) * 2017-09-11 2018-02-27 广州市百果园信息技术有限公司 Application program smoothness degree detection method, device and intelligent terminal

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1527966A (en) * 2001-03-12 2004-09-08 ض� Method and apparatus to monitor use of a program
CN103135518A (en) * 2011-12-02 2013-06-05 费希尔控制国际公司 Program flow control monitoring routines, related methods and systems

Also Published As

Publication number Publication date
CN113176983A (en) 2021-07-27

Similar Documents

Publication Publication Date Title
US8726225B2 (en) Testing of a software system using instrumentation at a logging module
US8140901B2 (en) Validation of processors using a self-generating test case framework
US9569339B1 (en) Debugging in an actor-based system
US9329977B2 (en) Framework for a software error inject tool
EP3835944B1 (en) Apparatus and method for source code optimisation
JPH06139107A (en) Brake address detecting circuit
CN109144873B (en) Linux kernel processing method and device
US8914622B2 (en) Processor testing
CN104220989A (en) Methods and systems to identify and reproduce concurrency violations in multi-threaded programs
TW201734768A (en) Branch instruction
CN110892384B (en) Playback time-travel tracking for undefined behavior dependencies of a processor
CN104899125A (en) Operation information acquisition method and operation information acquisition device for single-board system
CN113176983B (en) Program flow monitoring method and program flow monitoring system, CPU and chip
CN111819551A (en) Tracing branch instructions
EP4089538A1 (en) System and method for improved control flow monitoring of processors
US10558556B2 (en) Introspective fault and workload injection for service assurance
CN116090374A (en) Instruction test sequence generation method based on instruction code table
JP2023504188A (en) Extended performance monitor counter triggered by debug state machine
Almukhaizim et al. On concurrent error detection with bounded latency in FSMs
KR100311366B1 (en) Controller having watch dog timer function
JP3575980B2 (en) Timer circuit
JP2013109652A (en) Compiler, control method of program module generated by compiler, and control device which achieves control method
CN106021041B (en) Multi-cycle non-pipeline CPU debugging method based on finite state machine
CN116881919B (en) Vulnerability discovery method and device, electronic equipment and storage medium
Michel et al. Taking advantage of ASICs to improve dependability with very low overheads/spl lsqb/PLC/spl rsqb

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