A method, device, equipment and medium for predicting execution time of PLC control tasks
By performing machine instruction processing and basic block division of PLC control tasks, a control flow chart is built and deep priority traversal is solved, and the problem of difficult task cycle setting in PLC programming is realized, and the accurate execution time prediction of PLC control tasks is achieved.
Patent Information
- Application Number
- CN202411855313.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-17
AI Technical Summary
In PLC programming, users need to repeatedly test to set appropriate task cycles, which leads to difficulty in predicting task execution time and affects the correct and orderly execution and scheduling of tasks.
By processing machine instructions on PLC control tasks, generating machine instruction programs, dividing basic blocks, building control flow charts, traversing the predicted target execution path in depth, and determining the actual execution time in combination with processor clock cycles.
It accurately predicts the execution time of PLC control tasks, solves the problem of unreasonable task cycle settings, and provides programming reference and optimization help for program development.
Smart Images

Figure CN119310922B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device, equipment and medium for predicting the execution time of a PLC control task. Background Art
[0002] With the continuous expansion of PLC functions, mainstream PLC development platforms such as MULTIPROGSUITE and CODESYS are no longer satisfied with basic industrial control functions. They combine the hardware equipment of their products with motion control, image processing, neural network and other technologies to develop many functions and function blocks that are not included in the original standards, which greatly facilitates PLC programming. However, in actual scenarios, user-defined programs also become more complicated. Developers often need to test repeatedly to set the appropriate task cycle, and the task cycle determines whether the task is correctly and orderly executed and scheduled in actual scenarios. Therefore, how to predict the execution time of the entire task has become a technical issue that cannot be underestimated. Summary of the invention
[0003] In view of this, the purpose of this application is to provide a method, device, equipment and medium for predicting the execution time of a PLC control task, which can accurately predict the execution time of a PLC control task, solve the problem of unreasonable task cycle setting, provide a reference convenience for program developers' programming, and provide assistance for subsequent optimization of the program.
[0004] The embodiment of the present application provides a method for predicting the execution time of a PLC control task, the prediction method comprising:
[0005] Performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task;
[0006] Performing basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program;
[0007] Generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks;
[0008] The total cycle of each basic block is used as the weight value of each basic block in the control flow chart, and the control flow chart is traversed in depth first to predict the target execution path corresponding to the PLC control task. Based on the total weight value of the target execution path and the clock cycle of the processor, the actual execution time of the PLC control task is determined.
[0009] In a possible implementation manner, the performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task includes:
[0010] Based on each program in the PLC control task and the function corresponding to each program, generate a machine instruction program set of the PLC control task;
[0011] The linker processes the machine instruction program set to generate the machine instruction program.
[0012] In a possible implementation manner, the performing basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program includes:
[0013] Traversing all instructions in the machine instruction program to detect whether the instruction is the first instruction of a basic block;
[0014] If so, all instructions executed continuously after the first instruction are added to the current basic block until a new basic block is divided when the next instruction that jumps out of the current basic block is detected.
[0015] In a possible implementation manner, generating a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks includes:
[0016] Detecting whether the first instruction of the basic block is executed after the last instruction of another basic block;
[0017] If so, the pointing relationship between the other basic block and the basic block is that the other basic block points to the basic block;
[0018] A directed graph is constructed for the pointing relationship between the plurality of basic blocks to generate a control flow graph corresponding to the machine instruction program.
[0019] In a possible implementation manner, the total cycle of each basic block is used as the weight value of each basic block in the control flow graph, the control flow graph is traversed in depth first to predict the target execution path corresponding to the PLC control task, and the actual execution time of the PLC control task is determined based on the total weight value of the target execution path and the clock cycle of the processor, including:
[0020] Perform a depth-first traversal on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph;
[0021] Determine the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle;
[0022] Determining the shortest execution time corresponding to the shortest execution path based on the total weight value corresponding to the shortest execution path, the number of executions, the remaining maximum total weight value, and the clock cycle;
[0023] Setting equal probability jumps between branches in the control flow chart, predicting a target execution path based on the control flow chart, and calculating a target execution time corresponding to the target execution path;
[0024] Based on the longest execution time and the shortest execution time, verify whether the target execution time is accurate. If so, use the target execution time as the actual execution time of the PLC control task.
[0025] In a possible implementation manner, determining the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle includes:
[0026] Multiplying the total weight value corresponding to the longest execution path by the number of executions to determine a first value;
[0027] Adding the first value to the remaining maximum total weight value to determine a second value;
[0028] The second value is multiplied by the clock cycle to determine the maximum execution time.
[0029] The embodiment of the present application further provides a device for predicting the execution time of a PLC control task, the device comprising:
[0030] An instruction program generating module, used for processing machine instructions for a PLC control task, and generating a machine instruction program corresponding to the PLC control task;
[0031] A partitioning module, configured to perform basic block partitioning processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program;
[0032] A control flow graph generation module, used to generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks;
[0033] A determination module is used to use the total cycle of each basic block as the weight value of each basic block in the control flow chart, perform a depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determine the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor.
[0034] In a possible implementation manner, when the instruction program generation module is used to perform machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task, the instruction program generation module is specifically used to:
[0035] Based on each program in the PLC control task and the function corresponding to each program, generate a machine instruction program set of the PLC control task;
[0036] The linker processes the machine instruction program set to generate the machine instruction program.
[0037] An embodiment of the present application also provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the method for predicting the execution time of a PLC control task are performed as described above.
[0038] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for predicting the execution time of a PLC control task as described above are executed.
[0039] The present application provides a method, device, equipment and medium for predicting the execution time of a PLC control task, the prediction method comprising: performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task; performing basic block division processing on the machine instruction program to determine multiple basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program; generating a control flow chart corresponding to the machine instruction program based on the pointing relationship between multiple basic blocks; taking the total cycle of each basic block as the weight value of each basic block in the control flow chart, performing depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determining the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor. The method realizes that the execution time of the PLC control task can be accurately predicted, solves the problem of unreasonable task cycle setting, and can also provide reference convenience for program developers in programming, and provide help for subsequent optimization programs.
[0040] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 A flowchart of a method for predicting the execution time of a PLC control task provided in an embodiment of the present application;
[0043] Figure 2 A schematic diagram of a control flow chart provided in an embodiment of the present application;
[0044] Figure 3 A schematic diagram of the longest execution path provided by an embodiment of the present application;
[0045] Figure 4 A schematic diagram of the shortest execution path provided by an embodiment of the present application;
[0046] Figure 5 A schematic diagram of the structure of a device for predicting the execution time of a PLC control task provided in an embodiment of the present application;
[0047] Figure 6A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.
[0049] First, the application scenarios to which the present application is applicable are introduced. The present application can be applied in the field of data processing technology.
[0050] According to research, with the continuous expansion of PLC functions, mainstream PLC development platforms such as MULTIPROGSUITE and CODESYS are no longer satisfied with basic industrial control functions. They combine the hardware equipment of their products with motion control, image processing, neural network and other technologies to develop many functions and function blocks that are not included in the original standards, which greatly facilitates PLC programming. However, in actual scenarios, user-defined programs also become more complicated. Developers often need to test repeatedly to set the appropriate task cycle, and the task cycle determines whether the task is correctly and orderly executed and scheduled in actual scenarios. Therefore, how to predict the execution time of the entire task has become a technical issue that cannot be underestimated.
[0051] Based on this, an embodiment of the present application provides a method for predicting the execution time of a PLC control task, which can accurately predict the execution time of a PLC control task, solve the problem of unreasonable task cycle setting, provide a reference convenience for program developers, and provide assistance for subsequent optimization of the program.
[0052] See also Figure 1 , Figure 1 A flowchart of a method for predicting the execution time of a PLC control task provided by an embodiment of the present application. Figure 1 As shown in , the prediction method provided in the embodiment of the present application includes:
[0053] S101: Perform machine instruction processing on a PLC control task to generate a machine instruction program corresponding to the PLC control task.
[0054] In this step, the PLC control task is processed by machine instructions to generate a machine instruction program corresponding to the PLC control task.
[0055] Here, according to the task execution list, each program in the task and the functions and structures referenced by it are compiled into a corresponding machine instruction program set, and a linker is used to link the machine instruction program sets to form a final machine instruction program corresponding to the task execution logic.
[0056] In a possible implementation manner, the performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task includes:
[0057] Based on each program in the PLC control task and the function corresponding to each program, a machine instruction program set of the PLC control task is generated; based on a linker, the machine instruction program set is processed to generate the machine instruction program.
[0058] Here, according to each program in the PLC control task and the function corresponding to each program, a machine instruction program set of the PLC control task is generated; and the machine instruction program set is processed according to the linker to generate a machine instruction program.
[0059] In a specific embodiment, a project is created on SC-ProSys and a task Task1 is created. The task contains two programs MainPrg and Test, where MainPrg references the function AddFun, and Test references the function AddFun and the function block MulFunb. SC-ProSys is used to compile and generate the corresponding machine instruction programs MainPrg.o, Test.o, AddFun.o and MulFunb.o for MainPrg, Test, AddFun and MulFunb. The linker in SC-ProSys is used to link the above four machine instruction programs to generate a machine instruction program Task1.prg corresponding to the execution logic of task Task1.
[0060] S102: Perform basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program.
[0061] In this step, the machine instruction program is divided into basic blocks to determine a plurality of basic blocks in the machine instruction program.
[0062] The basic block is a continuous section of code in the machine instruction program. The starting instruction of the basic block is called the entry instruction, and the ending instruction is called the exit instruction. Each instruction in the basic block will be executed sequentially, and there is no jump instruction. A basic block contains one or more machine instructions.
[0063] In a possible implementation manner, the performing basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program includes:
[0064] (1): Traverse all instructions in the machine instruction program and detect whether the instruction is the first instruction of the basic block.
[0065] Here, all instructions in the machine instruction program are traversed to detect whether the instruction is the first instruction of the basic block.
[0066] (2): If so, all instructions executed continuously after the first instruction are added to the current basic block until the next instruction that jumps out of the current basic block is detected and a new basic block is divided.
[0067] Here, if yes, all the instructions executed continuously after the first instruction are added to the current basic block until a new basic block is divided when the next instruction that jumps out of the current basic block is detected.
[0068] In the specific embodiment, first determine which instructions are the first instructions. The first instruction of the instruction program is the first instruction, the target instruction of any conditional or unconditional jump instruction is the first instruction, and the instruction immediately following a conditional or unconditional jump instruction is the first instruction. Then, the basic block corresponding to each first instruction includes all instructions from itself to the next first instruction (not included) or the end of the instruction sequence. The above steps are used to divide Task1.prg into basic blocks. Since the instruction programs of AddFun and MulFunb are relatively independent, they can be divided into basic blocks separately first. The first instruction of AddFun (MOV R12, SP) is the first instruction, and (SUB SP, R11, #0) as the target instruction after the jump instruction (B loc_140) is also a first instruction. Through these two first instructions, AddFun can be divided into two basic blocks AddFun_B1 and AddFun_B2. The first instruction of MulFunb (MOV R12, SP) is the first instruction. Through this first instruction, MulFunb can be divided into a basic block MulFunb_B1.
[0069] S103: Generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks.
[0070] In this step, a control flow graph corresponding to the machine instruction program is formed with basic blocks as nodes. The control flow graph is a directed graph composed of basic blocks. Each node is a basic block. If the execution path of the program may enter from one basic block B1 to another basic block B2, then B1 has an edge pointing to B2.
[0071] In a possible implementation manner, generating a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks includes:
[0072] a: Detect whether the first instruction of the basic block is executed after the last instruction of another basic block.
[0073] Here, it is checked whether the first instruction of a basic block is executed after the last instruction of another basic block.
[0074] b: If so, the pointing relationship between another basic block and the basic block is that the other basic block points to the basic block.
[0075] Here, if yes, then the pointing relationship between another basic block and the basic block is that the other basic block points to the basic block.
[0076] Among them, it is determined whether there is an edge between every two basic blocks, that is, when and there is a basic block where the first instruction may be executed immediately after the last instruction of another basic block. There are two ways to confirm such an edge. One way is to have a conditional or unconditional jump statement from the end of one basic block to the beginning of another basic block. The other way is to follow the order in the instruction statement sequence, and a basic block is followed by another basic block, and there is no unconditional jump statement at the end of this basic block.
[0077] c: constructing a directed graph of the pointing relationships between the multiple basic blocks to generate a control flow graph corresponding to the machine instruction program.
[0078] Here, a directed graph is constructed for the pointing relationship between multiple basic blocks to generate a control flow graph corresponding to the machine instruction program.
[0079] For further information, see Figure 2 , Figure 2 A schematic diagram of a control flow chart provided in an embodiment of the present application. Figure 2As shown, for the above task Task1.prg, check whether there is a conditional or unconditional jump statement from the end of one basic block to the beginning of another basic block, so as to obtain AddFun_B1->AddFun_B2,MainPrg_B1->MainPrg_B3,MainPrg_B4->MainPrg_B7,Test_B1->Test_B3,Test_B2->Test_B4,Test_B5->Test_B7,Test_B6->Test_B8Test_B8->Test_B10,Test_B9->Test_B11,Test_B11- >Test_B24,Test_B4->Test_B20,Test_B23->Test_B13,Test_B13->Test_B15,Test_B14->Test_B16,Test_B16->Test_B18,Test_B17->Test_B19,Test_B19->Test_B24,Test_B24->Test_B25, check whether there is a basic block followed by another basic block, and there is no unconditional jump statement at the end of this basic block. The detected edges are MainPrg_B1->MainPrg_B2, MainPr g_B3->MainPrg_B4,MainPrg_B4->MainPrg_B5,MainPrg_B5->AddFun_B1AddFun_B2->MainPrg_B6,MainPrg_B6->MainPrg_B7,Test_B1->Test_ B2,Test_B3->Test_B4,Test_B4->Test_B5,Test_B5->Test_B6,Test_B8->Test_B9,Test_B10->Test_B11,Test_B11->Test_B12,Test_B12->T est_B13,Test_B13->Test_B14,Test_B15->Test_B16,Test_B16->Test_B17,Test_B18->Test_B19,Test_B19->Test_B22,Test_B20->AddFun_B1AddFun_B2->Test_B21,Test_B21->Test_B25,Test_B22->MulFunb_B1,MulFunb_B1->Test_B23,MainPrg_B7->Test_B1, combine the above edges to generate a control flow graph.
[0080] S104: Taking the total cycle of each basic block as the weight value of each basic block in the control flow chart, performing a depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determining the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor.
[0081] In this step, the total cycle of each basic block is used as the weight value of each basic block in the control flow graph, and the control flow graph is traversed depth-first to predict the target execution path corresponding to the PLC control task. According to the total weight value of the target execution path and the clock cycle of the processor, the actual execution time of the PLC control task is determined.
[0082] The processor manual is queried to obtain the average clock cycle number (CPI, Cycle Per Instruction), and the total number of instructions N required to execute each basic block is obtained. The total number of clock cycles is N*CPI, and the total cycle is used as the weight value of the basic block.
[0083] In a possible implementation manner, the total cycle of each basic block is used as the weight value of each basic block in the control flow graph, the control flow graph is traversed in depth first to predict the target execution path corresponding to the PLC control task, and the actual execution time of the PLC control task is determined based on the total weight value of the target execution path and the clock cycle of the processor, including:
[0084] (1): Perform a depth-first traversal on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph.
[0085] Here, a depth-first traversal is performed on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph.
[0086] (2): Based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value and the clock cycle, determine the longest execution time corresponding to the longest execution path.
[0087] Here, the longest execution time corresponding to the longest execution path is determined according to the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle.
[0088] The remaining maximum total weight value is the sum of the number of cycles corresponding to the remaining basic blocks except the longest execution path.
[0089] In a possible implementation manner, determining the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle includes:
[0090] The total weight value corresponding to the longest execution path is multiplied by the number of executions to determine a first value; the first value is added to the remaining maximum total weight value to determine a second value; the second value is multiplied by the clock cycle to determine the longest execution time.
[0091] Here, the maximum execution time is determined by the following formula:
[0092]
[0093] Among them, T is the longest execution time and L is the longest execution path.
[0094] (3): Based on the total weight value corresponding to the shortest execution path, the number of executions, the remaining maximum total weight value and the clock cycle, determine the shortest execution time corresponding to the shortest execution path.
[0095] Here, the shortest execution time corresponding to the shortest execution path is determined according to the total weight value, the number of executions, the remaining maximum total weight value, and the clock cycle corresponding to the shortest execution path.
[0096] Among them, the shortest execution time is consistent with the calculation process of the above-mentioned longest time, which will not be repeated in this part.
[0097] (4): Set equal probability jumps between branches in the control flow chart, predict the target execution path based on the control flow chart, and calculate the target execution time corresponding to the target execution path; verify whether the target execution time is accurate based on the longest execution time and the shortest execution time. If so, use the target execution time as the actual execution time of the PLC control task.
[0098] Here, set the jumps between the branches in the control flow chart with equal probability, predict the target execution path according to the control flow chart, and calculate the target execution time corresponding to the target execution path. Verify whether the target execution time is accurate according to the longest execution time and the shortest execution time. If so, use the target execution time as the actual execution time of the PLC control task. If not, continue to screen the actual path to determine the actual execution time.
[0099] In the specific embodiment, please refer to 3. Figure 4 , Figure 3 A schematic diagram of the longest execution path provided by an embodiment of the present application; Figure 4This is a schematic diagram of the shortest execution path provided by the embodiment of the present application. The CPU model used by the PLC is Phytium FT-2000 / 4, the frequency is 1000MHZ, and its clock cycle is 1ns. The Phytium FT-2000 / 4 manual is consulted to obtain the CPI corresponding to its instructions as 0.5, and then Figure 2 The total number of clock cycles required for the instructions of the 35 basic blocks in the example are calculated, and the number of clock cycles is used as the weight value. The preset number of executions is 15000000. The longest path is obtained by using the depth traversal. Figure 3 As shown, using depth traversal to obtain a shortest path is shown in Figure 4. Figure 3 as well as Figure 4 The numerical value on each basic block represents the weight value of the basic block, and determines the longest execution time corresponding to the longest execution path, and the shortest execution time corresponding to the shortest execution path. Set equal probability jumps between each branch in the control flow graph, predict the target execution path based on the control flow graph, and calculate the target execution time corresponding to the target execution path.
[0100] In this application, the execution time of the entire task is predicted by cycle weighted flow, the average clock cycle number (CPI, Cycle Per Instruction) is obtained by querying the manual of the processor, and the total number of instructions N required to execute each basic block is obtained. The total number of clock cycles is N*CPI, and the total number of cycles is used as the weight of the generated control flow graph. Using depth-first traversal, the longest path and the minimum path in the control flow graph are obtained, and the sum of the weights of the minimum path and the CPU clock cycle determine the minimum execution time. When the entire task is executed, the branches in the control flow graph are jumped with equal probability, and the actual execution time of the task is determined by the sum of the weights on the actual execution path and the CPU clock cycle.
[0101] The embodiment of the present application provides a method for predicting the execution time of a PLC control task, the prediction method comprising: performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task; performing basic block division processing on the machine instruction program to determine multiple basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program; generating a control flow chart corresponding to the machine instruction program based on the pointing relationship between multiple basic blocks; taking the total cycle of each basic block as the weight value of each basic block in the control flow chart, performing depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determining the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor. The method realizes that the execution time of the PLC control task can be accurately predicted, solves the problem of unreasonable task cycle setting, and can also provide reference convenience for program developers in programming, and provide help for subsequent optimization programs.
[0102] See also Figure 5 , Figure 5 A schematic diagram of a structure of a device for predicting the execution time of a PLC control task provided in an embodiment of the present application. Figure 5 As shown in , the prediction device 500 includes:
[0103] The instruction program generating module 510 is used to perform machine instruction processing on the PLC control task and generate a machine instruction program corresponding to the PLC control task;
[0104] A partitioning module 520 is used to perform basic block partitioning processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program;
[0105] A control flow graph generation module 530, configured to generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks;
[0106] The determination module 540 is used to use the total cycle of each basic block as the weight value of each basic block in the control flow chart, perform a depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determine the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor.
[0107] Furthermore, when the instruction program generation module is used to perform machine instruction processing on the PLC control task and generate a machine instruction program corresponding to the PLC control task, the instruction program generation module is specifically used to:
[0108] Based on each program in the PLC control task and the function corresponding to each program, generate a machine instruction program set of the PLC control task;
[0109] The linker processes the machine instruction program set to generate the machine instruction program.
[0110] Furthermore, when the division module is used to perform basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program, the division module is specifically used to:
[0111] Traversing all instructions in the machine instruction program to detect whether the instruction is the first instruction of a basic block;
[0112] If so, all instructions executed continuously after the first instruction are added to the current basic block until a new basic block is divided when the next instruction that jumps out of the current basic block is detected.
[0113] Furthermore, when the control flow graph generation module is used to generate the control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks, the control flow graph generation module is specifically used to:
[0114] Detecting whether the first instruction of the basic block is executed after the last instruction of another basic block;
[0115] If so, the pointing relationship between the other basic block and the basic block is that the other basic block points to the basic block;
[0116] A directed graph is constructed for the pointing relationship between the plurality of basic blocks to generate a control flow graph corresponding to the machine instruction program.
[0117] Further, when the determination module is used to use the total cycle of each basic block as the weight value of each basic block in the control flow chart, perform a depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determine the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor, the determination module is specifically used to:
[0118] Perform a depth-first traversal on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph;
[0119] Determine the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle;
[0120] Determining the shortest execution time corresponding to the shortest execution path based on the total weight value corresponding to the shortest execution path, the number of executions, the remaining maximum total weight value, and the clock cycle;
[0121] Setting equal probability jumps between branches in the control flow chart, predicting a target execution path based on the control flow chart, and calculating a target execution time corresponding to the target execution path;
[0122] Based on the longest execution time and the shortest execution time, verify whether the target execution time is accurate. If so, use the target execution time as the actual execution time of the PLC control task.
[0123] Further, when the determination module is used to determine the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle, the determination module is specifically used to:
[0124] Multiplying the total weight value corresponding to the longest execution path by the number of executions to determine a first value;
[0125] Adding the first value to the remaining maximum total weight value to determine a second value;
[0126] The second value is multiplied by the clock cycle to determine the maximum execution time.
[0127] The present application provides a prediction device for the execution time of a PLC control task, the prediction device comprising: an instruction program generation module, for performing machine instruction processing on the PLC control task, and generating a machine instruction program corresponding to the PLC control task; a division module, for performing basic block division processing on the machine instruction program, and determining multiple basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program; a control flow chart generation module, for generating a control flow chart corresponding to the machine instruction program based on the pointing relationship between multiple basic blocks; a determination module, for taking the total cycle of each basic block as the weight value of each basic block in the control flow chart, performing depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determining the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor. The execution time of the PLC control task can be accurately predicted, the problem of unreasonable task cycle setting can be solved, and reference convenience can be provided for programming of program developers, and help can be provided for subsequent optimization programs.
[0128] See also Figure 6 , Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 As shown in , the electronic device 600 includes a processor 610 , a memory 620 and a bus 630 .
[0129] The memory 620 stores machine-readable instructions executable by the processor 610. When the electronic device 600 is running, the processor 610 communicates with the memory 620 via the bus 630. When the machine-readable instructions are executed by the processor 610, the above-mentioned Figure 1 The steps of the method for predicting the execution time of a PLC control task in the method embodiment shown, and the specific implementation manner can be found in the method embodiment, which will not be repeated here.
[0130] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 The steps of the method for predicting the execution time of a PLC control task in the method embodiment shown, and the specific implementation manner can be found in the method embodiment, which will not be repeated here.
[0131] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0132] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0133] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0134] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0135] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0136] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for predicting the execution time of a PLC control task, characterized in that: The prediction method comprises: Performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task; Performing basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program; Generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks; The total cycle of each basic block is used as the weight value of each basic block in the control flow chart, the control flow chart is traversed in depth first to predict the target execution path corresponding to the PLC control task, and the actual execution time of the PLC control task is determined based on the total weight value of the target execution path and the clock cycle of the processor; The method of using the total cycle of each basic block as the weight value of each basic block in the control flow chart, performing depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determining the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor includes: Perform a depth-first traversal on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph; Determine the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle; Determining the shortest execution time corresponding to the shortest execution path based on the total weight value corresponding to the shortest execution path, the number of executions, the remaining maximum total weight value, and the clock cycle; Setting equal probability jumps between branches in the control flow chart, predicting a target execution path based on the control flow chart, and calculating a target execution time corresponding to the target execution path; Based on the longest execution time and the shortest execution time, verify whether the target execution time is accurate. If so, use the target execution time as the actual execution time of the PLC control task.
2. The prediction method according to claim 1, characterized in that: The performing machine instruction processing on the PLC control task to generate a machine instruction program corresponding to the PLC control task includes: Based on each program in the PLC control task and the function corresponding to each program, generate a machine instruction program set of the PLC control task; The linker processes the machine instruction program set to generate the machine instruction program.
3. The prediction method according to claim 1, characterized in that: The performing basic block division processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program includes: Traversing all instructions in the machine instruction program to detect whether the instruction is the first instruction of a basic block; If so, all instructions executed continuously after the first instruction are added to the current basic block until a new basic block is divided when the next instruction that jumps out of the current basic block is detected.
4. The prediction method according to claim 1, characterized in that: The step of generating a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks includes: Detecting whether the first instruction of the basic block is executed after the last instruction of another basic block; If so, the pointing relationship between the other basic block and the basic block is that the other basic block points to the basic block; A directed graph is constructed for the pointing relationship between the plurality of basic blocks to generate a control flow graph corresponding to the machine instruction program.
5. The prediction method according to claim 1, characterized in that: The determining, based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle, of the longest execution time corresponding to the longest execution path includes: Multiplying the total weight value corresponding to the longest execution path by the number of executions to determine a first value; Adding the first value to the remaining maximum total weight value to determine a second value; The second value is multiplied by the clock cycle to determine the maximum execution time.
6. A device for predicting the execution time of a PLC control task, characterized in that: The prediction device comprises: An instruction program generating module, used for processing machine instructions for a PLC control task, and generating a machine instruction program corresponding to the PLC control task; A partitioning module, configured to perform basic block partitioning processing on the machine instruction program to determine a plurality of basic blocks in the machine instruction program; wherein the basic block is a continuous section of code in the machine instruction program; A control flow graph generation module, used to generate a control flow graph corresponding to the machine instruction program based on the pointing relationship between the multiple basic blocks; A determination module, configured to use the total cycle of each basic block as the weight value of each basic block in the control flow graph, perform a depth-first traversal on the control flow graph to predict the target execution path corresponding to the PLC control task, and determine the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor; The determination module is used to use the total cycle of each basic block as the weight value of each basic block in the control flow chart, perform a depth-first traversal on the control flow chart to predict the target execution path corresponding to the PLC control task, and determine the actual execution time of the PLC control task based on the total weight value of the target execution path and the clock cycle of the processor, including: Perform a depth-first traversal on the control flow graph to determine the longest execution path and the shortest execution path in the control flow graph; Determine the longest execution time corresponding to the longest execution path based on the total weight value corresponding to the longest execution path, the preset number of executions, the remaining maximum total weight value, and the clock cycle; Determining the shortest execution time corresponding to the shortest execution path based on the total weight value corresponding to the shortest execution path, the number of executions, the remaining maximum total weight value, and the clock cycle; Setting equal probability jumps between branches in the control flow chart, predicting a target execution path based on the control flow chart, and calculating a target execution time corresponding to the target execution path; Based on the longest execution time and the shortest execution time, verify whether the target execution time is accurate. If so, use the target execution time as the actual execution time of the PLC control task.
7. The prediction device according to claim 6, characterized in that When the instruction program generation module is used to perform machine instruction processing on the PLC control task and generate a machine instruction program corresponding to the PLC control task, the instruction program generation module is specifically used to: Based on each program in the PLC control task and the function corresponding to each program, generate a machine instruction program set of the PLC control task; The linker processes the machine instruction program set to generate the machine instruction program.
8. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and the machine-readable instructions are executed by the processor to execute the steps of the method for predicting the execution time of a PLC control task as described in any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for predicting the execution time of a PLC control task as claimed in any one of claims 1 to 5 are executed.
Citation Information
Patent Citations
Distribution function-based WCET (Worst Case Execution Time) quick estimation method
CN104572103A