Operation duration determination method and device, storage medium and electronic device
By sending trigger instructions to programmable devices to obtain count results, determining the running time of the central processor, solving the problem of inaccurate timing in the existing technology, realizing high-precision timing that does not rely on CPU system and hardware resources, and supporting cross-system timing. .
Patent Information
- Application Number
- CN202310794573.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-29
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, the call to the internal timing module of the CPU system for timing is problematic inaccurate timing, especially in high load and extreme environments, and cross-system timing cannot be achieved.
By sending a trigger command to the programmable device, the counting function is enabled, the counting results are obtained at a specific location of the target program, the running time of the central processor is determined, and high-precision timing that does not depend on the CPU system and hardware resources are achieved.
It solves the problem of inaccurate timing, realizes high-precision timing under high load and extreme environments, and supports cross-system timing, avoiding dependence on CPU and hardware resources.
Smart Images

Figure CN119226105A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of communication technology, and in particular, to a method and device for determining a running time, a storage medium, and an electronic device. Background Art
[0002] The concept of "time" is crucial for the normal operation and management of the Linux system. There are a large number of time-driven functions in the kernel, such as functions that execute periodically and functions that balance the run queue in the scheduler or refresh the screen. For the process scheduling function, it is necessary to decide when to allocate how much time to a certain task or even some tasks. Only by making maximum use of the processor time can we ensure that system resources are maximized.
[0003] In the process of development and troubleshooting, there are many scenarios where you need to obtain time, including absolute time and relative time. The kernel generally uses hardware system timers or real-time clocks to calculate and manage time.
[0004] However, the use of periodic timing (common functions such as gettimeofday() or clock_gettime) has some limitations and cannot be used in some scenarios. The following are the defects of the current timing method:
[0005] In scenario 1, the periodic timing mechanism generates an interrupt for the hardware clock. Based on this, the action of using the timer itself will occupy CPU and memory resources. If the timer is used too frequently, it may also cause the system to be overloaded and affect normal operation.
[0006] Scenario 2: Functions that use the system periodic clock to obtain timing, such as gettimeofday(), essentially obtain time through system calls. When the system is under high load and there are a large number of high-priority interrupt events, the system call for obtaining time will not be able to obtain the processor execution right, resulting in inaccurate timing due to the inability to obtain the system time in a timely manner. In extreme cases, the error will be very large.
[0007] Scenario 3: In some scenarios that require cross-system operation, the timing functions of the Linux system cannot solve the problem. For example, when it is necessary to calculate the time from a certain stage of the boot program to a certain stage of the Linux system, or the time of switching from one system to another, the traditional periodic timing method cannot complete such a task; or during the startup of a kernel, when various hardware devices have not been initialized or system resources have not been configured, the time cannot be obtained or the time accuracy is inaccurate.
[0008] Scenario 4: In the communications industry, devices may work in extreme environments, and changes in external environmental factors can affect the accuracy of Linux device cycle timing. For example, electromagnetic interference may cause errors in instruction execution and interrupt processing delays in the processor. Common temperature interference: When the processor's ambient temperature changes, its internal transistor performance may be affected, causing the time base of the timer to drift, resulting in inaccurate timing.
[0009] Therefore, the method of calling the internal timing module of the current CPU system to perform timing may result in inaccurate timing and other problems. Summary of the invention
[0010] The embodiments of the present invention provide a method and device for determining the running time, a storage medium and an electronic device, so as to at least solve the problem of inaccurate timing in the method of calling the internal timing module of the current CPU system to perform timing in the related art.
[0011] According to one embodiment of the present invention, a method for determining a running time is provided, comprising: starting a target program for running a target instruction; when running to a first code position of the target program, sending a trigger instruction to a programmable device so that the programmable device starts a counting function according to the trigger instruction; when running to a second code position of the target program, obtaining a counting result of the programmable device, and determining the running time of a central processing unit according to the counting result, wherein the running time is used to indicate the time it takes for the central processing unit to run from the first code position to the second code position.
[0012] In an exemplary embodiment, obtaining the counting result of the programmable device includes: sending an end instruction to the programmable device so that the programmable device turns off the counting function according to the end instruction and stores the counting result in a storage register of the programmable device; and reading the counting result output by the storage register.
[0013] In an exemplary embodiment, when running to the first code position of the target program, sending a trigger instruction to the programmable device includes: when running to the starting position of each program block in the target program, sending a trigger instruction to the programmable device; when running to the second code position of the target program, obtaining the counting result of the programmable device, including: when running to the ending position of each program block in the target program, obtaining the counting result of the programmable device, wherein the counting result is used to indicate the running time of running each program block.
[0014] In an exemplary embodiment, when running to a first code position of the target program, sending a trigger instruction to a programmable device includes: when running to a start position of an access function in the target program, sending a trigger instruction to the programmable device, wherein the access function is used to access a target interface; when running to a second code position of the target program, obtaining a counting result of the programmable device, including: when running to an end position of an access function in the target program, obtaining a counting result of the programmable device, wherein the counting result is used to indicate an access duration for accessing an interface corresponding to the access function.
[0015] In an exemplary embodiment, when running to the first code position of the target program, sending a trigger instruction to the programmable device, including: when running to the starting position of the BOOT source code in the target program, sending a trigger instruction to the programmable device; when running to the second code position of the target program, obtaining the counting result of the programmable device, including: when running to the ending position of the kernel source code in the target program, obtaining the counting result of the programmable device, wherein the counting result is used to indicate the startup time of starting the operating system corresponding to the central processing unit.
[0016] In an exemplary embodiment, after determining the running time of the central processing unit according to the counting result, the method further includes: determining the size relationship between the running time and a preset time, wherein the preset time is used to indicate the standard time for running from the first code position to the second code position; when the running time is less than or equal to the preset time, determining that the running efficiency of the central processing unit meets the preset running efficiency; when the running time is greater than the preset time, determining that the running efficiency of the central processing unit does not meet the preset running efficiency.
[0017] In an exemplary embodiment, after determining that the operating efficiency of the central processing unit does not meet the preset operating efficiency, the method includes at least one of the following: determining that there is a fault when the central processing unit runs the target program block of the target program; determining that the speed at which the central processing unit accesses the interface is less than the preset access speed; determining that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is less than the preset startup speed.
[0018] According to another embodiment of the present invention, a device for determining a running time is provided, comprising: a starting module, which starts a target program for running a target instruction; a sending module, which, when running to a first code position of the target program, sends a trigger instruction to a programmable device, so that the programmable device starts a counting function according to the trigger instruction; an acquisition module, which, when running to a second code position of the target program, acquires a counting result of the programmable device, and determines the running time of a central processing unit according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
[0019] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0020] According to another embodiment of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in any one of the above method embodiments when executing the computer program.
[0021] Through the present invention, the target program for running the target instruction is started; when the target program is run to the first code position, a trigger instruction is sent to the programmable device, so that the programmable device starts the counting function according to the trigger instruction; when the target program is run to the second code position, the counting result of the programmable device is obtained, and the running time of the central processing unit is determined according to the counting result. Through the present invention, the method of calling the internal timing module of the current CPU system to time in the related art is solved, and the problem of inaccurate timing is solved, thereby achieving the timing through the timing module that does not rely on the system and hardware resources of the CPU, thereby achieving the technical effect of high-precision timing that does not rely on the system and hardware resources of the CPU. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 is a hardware structure block diagram of a computer terminal according to a method for determining a running time according to an embodiment of the present invention;
[0023] Figure 2 A network architecture of a method for determining a running time according to an embodiment of the present invention;
[0024] Figure 3 is a flow chart of a method for determining a running time according to an embodiment of the present invention;
[0025] Figure 4It is a schematic diagram of a method for determining the running time in the related art;
[0026] Figure 5 is a schematic diagram of a cross-system use method according to an embodiment of the present invention;
[0027] Figure 6 4 is a structural block diagram of a device for determining a running time according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0030] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 1 1 is a hardware structure block diagram of a computer terminal for a method for determining a running time in an embodiment of the present application. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. In an exemplary embodiment, the computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. Figure 1 More or fewer components as shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 A different configuration with more features is shown.
[0031] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for determining the running time in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0032] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0033] The present application embodiment can be run on Figure 2 In the network architecture shown in Figure 2 As shown, the network architecture includes: a CPU program processing module 22, a programmable logic device counting module 24, wherein the programmable logic device counting module includes: a counting unit and a storage register unit. The counting result generated by the counting unit is stored in the storage register unit, and the counting result is read by the storage register unit when needed.
[0034] The CPU program processing module 22 starts a target program for running target instructions; when running to the first code position of the target program, the CPU program processing module 22 sends a trigger instruction to the programmable logic device counting module 24, and the programmable logic device counting module 24 starts the counting function according to the trigger instruction; when running to the second code position of the target program, the CPU program processing module 22 sends an end instruction to the programmable logic device counting module 24, so that the programmable logic device counting module 24 turns off the counting function according to the end instruction and stores the counting result to the storage register; the CPU program processing module 22 reads the counting result output by the storage register; and determines the running time of the central processing unit according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
[0035] In this embodiment, a method for determining the running time is provided, which is used to solve the technical problems and preferred implementation methods existing in the above-mentioned prior art embodiments.
[0036] Figure 3 FIG. 1 is a flow chart of a method for determining a running time according to an embodiment of the present invention. Figure 3 As shown, the process of the method may include the following steps:
[0037] Step S302, starting a target program for running a target instruction;
[0038] Step S304, when the program runs to the first code position of the target program, sending a trigger instruction to the programmable device, so that the programmable device starts a counting function according to the trigger instruction;
[0039] Step S306, when running to the second code position of the target program, obtain the counting result of the programmable device, and determine the running time of the central processing unit according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
[0040] In the embodiment of the present invention, counting is performed by dotting, so the running time of the central processing unit is determined according to the product of the counting result and the time length of each dotting.
[0041] Through the above embodiments, the target program for running the target instruction is started; when the target program is run to the first code position, a trigger instruction is sent to the programmable device, so that the programmable device starts the counting function according to the trigger instruction; when the target program is run to the second code position, the counting result of the programmable device is obtained, and the running time of the central processing unit is determined according to the counting result. Through the present invention, the method of calling the internal timing module of the current CPU system to time in the related art is solved, and the problem of inaccurate timing is solved, thereby achieving the timing through the timing module that does not rely on the system and hardware resources of the CPU, thereby achieving the technical effect of high-precision timing that does not rely on the system and hardware resources of the CPU.
[0042] Optionally, the above step S306 can also be implemented in the following way: obtaining the counting result of the programmable device, including: sending an end instruction to the programmable device so that the programmable device turns off the counting function according to the end instruction, and stores the counting result in the storage register of the programmable device; reading the counting result output by the storage register.
[0043] It can be understood that the above-mentioned programmable device includes: a counting module and a storage register, the counting module is used to count according to the triggering of the CPU module; the storage register is used to store the counting result of the counting module.
[0044] Optionally, in different application scenarios, the first code position and the second code position are different, specifically:
[0045] 1) In scenarios where microsecond accuracy is required and system time adjustment is required, obtain the running time of the program block, and debug and locate the failure of the program block:
[0046] When running to the start position of each program block in the target program, a trigger instruction is sent to the programmable device; when running to the end position of each program block in the target program, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the running time of each program block.
[0047] It can be understood that in the embodiment of the present invention, a trigger instruction is sent to the programmable device at the beginning of each program block, and an end instruction is sent to the programmable device at the end of each program block. Since the programmable device performs a dotting operation after receiving the trigger instruction and stops the dotting operation when receiving the end instruction, the running time of each program block can be determined based on the counting result of the programmable device during the period between receiving the trigger instruction and the end instruction.
[0048] Furthermore, the preset running time of each program block is determined, and whether each program block has a fault is determined based on the size relationship between the preset running time and the running time. Since the preset running time of a program block is the standard running time of the program block, when the running time is greater than the preset running time, it is determined that the program block has a fault; however, when the running time is less than or equal to the preset running time, the program may not run away, but may also fail to execute. Therefore, when the running time is less than or equal to the preset running time, it is necessary to determine whether the program block has a fault again based on other test rules.
[0049] Optionally, in the event of a program block failure, a debugging step is performed: the program block is debugged, and when running to the start position of the debugged program block, a trigger instruction is sent to the programmable device; when running to the end position of the debugged program block, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the running time of the debugged program block, and determine whether the debugged program block fails based on the running time; the above debugging steps are repeated until the running time of the debugged program block is less than or equal to the preset running time.
[0050] Through the above-mentioned embodiment, the running time of the program block can be accurately obtained, and the fault of the program block can be debugged and located according to the running time of the program block. Moreover, the cycle beat of the programmable device can be adjusted to above 1M, and the counting result is not affected by the system time. Therefore, it can be accurate to microseconds, and when the system time is adjusted, the running time of the program block can also be accurately determined.
[0051] 2) When the system is under high load, obtain the running time of the access function to optimize the performance of the access function:
[0052] In development activities, it is often necessary to analyze and optimize the performance of a module under high system load. For example, the access time of nand flash, a common storage device in embedded systems, often needs to be optimized. Therefore, the access time can be obtained in the following ways:
[0053] When running to the start position of the access function in the target program, a trigger instruction is sent to the programmable device, wherein the access function is used to access the target interface; when running to the end position of the access function in the target program, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the access duration of the interface corresponding to the access function.
[0054] It can be understood that in the embodiment of the present invention, a trigger instruction is sent to the programmable device at the start position of the access function, and an end instruction is sent to the programmable device at the end position of the access function. Since the programmable device performs a dotting operation after receiving the trigger instruction and stops the dotting operation when receiving the end instruction, the access duration of the interface corresponding to the access function can be determined based on the counting result of the programmable device during the period between receiving the trigger instruction and the end instruction.
[0055] Furthermore, a preset access time for accessing the interface corresponding to the access function is determined, and whether the speed of the central processing unit accessing the interface is less than the preset access speed is determined based on the size relationship between the access time and the preset access time. Specifically: when the access time is greater than the preset access time, it is determined that the speed of the central processing unit accessing the interface is less than the preset access speed; when the access time is less than or equal to the preset access time, it is determined that the speed of the central processing unit accessing the interface is greater than or equal to the preset access speed.
[0056] When the system is under high load and there are a large number of high-priority interrupt events, the system call for obtaining time will not be able to obtain the processor execution right, resulting in inaccurate timing due to the inability to obtain the system time in time. In extreme cases, the timing error will be very large. However, in the embodiment of the present invention, timing is performed through an external programmable device. Since the external programmable device does not rely on system resources and can perform continuous timing, it is only necessary to read the counting result of the programmable device. Therefore, the method of calling the internal timing module of the current CPU system for timing in the related art can solve the problem of inaccurate timing.
[0057] 3) In the system monitoring scenario, determine the startup time of the operating system corresponding to the central processor:
[0058] In order to monitor the system startup speed and efficiency, and for user experience and collaboration between software and hardware platforms, it is often necessary to measure the system startup time. Embedded systems are large and complex, and sometimes the startup process spans across different systems. For example, the common cross-boot and kernel startup, and timing of the entire startup process, can be achieved in the following ways:
[0059] When running to the start position of the BOOT source code in the target program, a trigger instruction is sent to the programmable device; when running to the end position of the kernel source code in the target program, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the startup time of starting the operating system corresponding to the central processing unit.
[0060] It can be understood that in the embodiment of the present invention, a trigger instruction is sent to the programmable device at the starting position of the BOOT source code, and an end instruction is sent to the programmable device at the end position of the kernel source code. Since the programmable device performs a dot operation after receiving the trigger instruction and stops the dot operation when receiving the end instruction, the startup duration of the operating system corresponding to the central processor can be determined based on the counting result of the programmable device during the period between receiving the trigger instruction and the end instruction.
[0061] Furthermore, the preset startup time for starting the operating system corresponding to the central processing unit is determined, and based on the size relationship between the access time and the preset startup time, it is determined whether the speed at which the central processing unit starts the operating system corresponding to the central processing unit is less than the preset startup speed. Specifically: when the startup time is greater than the preset startup time, it is determined that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is greater than the preset startup speed; when the startup time is less than or equal to the preset startup time, it is determined that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is less than or equal to the preset startup speed.
[0062] The traditional CPU system call timing method cannot achieve cross-system timing, but in the embodiment of the present invention, timing is performed through an external programmable device. Since the external programmable device does not rely on the resources of multiple systems that are started, continuous timing can be performed. It is only necessary to read the counting result of the programmable device. Therefore, the method of calling the internal timing module of the current CPU system for timing in the related technology can solve the problem of inaccurate timing.
[0063] Optionally, in step S306, after determining the running time of the central processing unit according to the counting result, the method further includes: determining the size relationship between the running time and a preset time, wherein the preset time is used to indicate the standard time for running from the first code position to the second code position; when the running time is less than or equal to the preset time, determining that the running efficiency of the central processing unit meets the preset running efficiency; when the running time is greater than the preset time, determining that the running efficiency of the central processing unit does not meet the preset running efficiency.
[0064] Optionally, in step S306, after determining that the operating efficiency of the central processing unit does not meet the preset operating efficiency, the method includes at least one of the following: determining that there is a fault when the central processing unit runs the target program block of the target program; determining that the speed at which the central processing unit accesses the interface is less than the preset access speed; determining that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is less than the preset startup speed.
[0065] In order to better understand the process of the above-mentioned method for determining the running time, the implementation process of the above-mentioned method for determining the running time is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0066] like Figure 4 The figure shows a schematic diagram of the traditional system call method for obtaining system time in Linux. Initiating a system call from user space to executing the corresponding operation in kernel state involves multiple levels and components. The user space calls the encapsulation interface in the C library (usually gettimeofday() or clock_gettime(), etc.), enters the kernel state through the encapsulated function interface to execute the system call. Linux finds the RTC driver according to the corresponding parameters, interacts with the hardware RTC, and obtains the required time data. Finally, the current time is returned to the user space program by the RTC driver.
[0067] However, the method of calling the internal timing module of the current CPU system to time in the prior art generates load on the system, is affected by the high load of the system, cannot realize cross-system timing, is seriously interfered by extreme environment, and thus causes inaccurate timing and other problems. Therefore, in this embodiment, a method of using programmable devices to time across systems is provided, wherein the programmable devices include but are not limited to: CPLD or FPGA and other devices that can count and store, specifically:
[0068] 1. In scenarios where microsecond accuracy is required and system time adjustment is required, high-precision timing methods based on programmable devices are used to debug and locate faults:
[0069] Step 1: Set a clear signal to the counter at the beginning of the program, and set a count output by the storage register of the counter at the end of the program or during the execution of the program;
[0070] It should be noted that the cpld cycle beat is adjusted to above 1M, so it can meet the microsecond requirement; find out the program blocks or processes that may have problems based on the log information. Therefore, in order to locate the fault more intuitively, the operation node information such as start, end and read count results can be output to the window log.
[0071] Step 2: Trigger the target program to run, clear the counter and start counting. Observe the window log, observe the register count results output at the end of the program running and record them.
[0072] Step 3: Convert the count to running time and compare the running time with the standard time of system execution to locate possible problems and where the problems occur. The whole process is not affected by system time adjustment.
[0073] In the embodiment of the present invention, timing is performed through an external programmable device. Since the cpld cycle beat is adjusted to above 1M, the microsecond requirement can be met. Moreover, since it does not rely on system resources, even if the system time is adjusted, it is only necessary to read the counting result of the programmable device to obtain accurate timing results.
[0074] 2. Under high system load, the high-precision timing method based on programmable devices is used to optimize program performance:
[0075] In development activities, it is often necessary to perform performance analysis and optimization on a module when the system is under high load. For example, NAND flash, a common storage device in embedded systems, often needs to have its access time optimized.
[0076] Step 1: Find the flash access (read, write, etc.) interface, and set the clear signal sending operation at the beginning of the access function. Set the register count reading operation at the end of the program execution, and set the count result to be output to the log.
[0077] Step 2: Call the flash read / write interface in the Linux shell or other debugging command line to trigger the counter to clear and start counting. Observe the serial port print log, read the count of the time spent on task execution at the end of the program execution and record it.
[0078] Step 3: Convert the count result into access time. Check the chip manual and compare the actual access time with the theoretical access time. Repeat step 1 as needed until the chip access time is optimized to within the theoretical access time.
[0079] In the embodiment of the present invention, timing is performed through an external programmable device. Since the external programmable device does not rely on system resources and can perform continuous timing, it is only necessary to read the counting result of the programmable device. Therefore, no load is generated on the system, and accurate timing results can be obtained even when the CPU is under high load.
[0080] 3. In the system monitoring scenario, the high-precision timing method implemented based on programmable devices is used to optimize the system startup time:
[0081] In order to monitor the system startup speed and efficiency, and for user experience and collaboration between software and hardware platforms, it is often necessary to measure the system startup time. Embedded systems are large and complex, and sometimes the startup process spans across different systems. Traditional CPU system call timing methods cannot achieve cross-system timing, so cross-system timing can be achieved based on the solution in the embodiment of this application. For example, the common cross-boot and kernel startup, and timing of the entire startup process, such as Figure 5 As shown;
[0082] Step 1: Set the reset signal to the counter at the preset start position in the boot source code. (In theory, counting can start after the cpld is loaded. The loading of the cpld is usually completed in the bootloader stage, so the count trigger signal can be at the front of the boot source code.) Set the count output of the storage register of the read counter at the timing position of the kernel source code, and output the count result to the log.
[0083] Step 2: Upgrade the boot version and kernel version to the device. When the device is powered on, booting automatically triggers the count register to be cleared and starts counting. Boot pulls up the kernel, and booting to the target timing position triggers the count register reading operation. Observe the log and record the counting results.
[0084] Step 3: Convert the obtained counting results into the startup duration to obtain the startup duration of the system. Evaluate the system startup duration based on the obtained timing results. Repeat steps 1 and 2 as needed. In step 2, you can add counting operations at multiple node locations for monitoring and refinement until the system is optimized to the best.
[0085] The embodiment of the present invention no longer uses the traditional CPU system call method to time, but uses a counter to determine an independent timing module. The timing method does not rely on the system and hardware resources of the CPU, and can achieve cross-system timing such as boot and kernel timing; it is less affected by the environment, the timing function is stable, and the result is more accurate.
[0086] In the present embodiment, a device for determining the running time is also provided, and the device is used to implement the above-mentioned embodiments and preferred embodiments, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0087] Figure 6 is a structural block diagram of a device for determining a running time according to an embodiment of the present invention. Figure 6 As shown, the device comprises:
[0088] A start module 62 is used to start a target program for running a target instruction;
[0089] A sending module 64, when running to the first code position of the target program, sends a trigger instruction to the programmable device, so that the programmable device starts a counting function according to the trigger instruction;
[0090] The acquisition module 66 acquires the counting result of the programmable device when running to the second code position of the target program, and determines the running time of the central processing unit according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
[0091] Through the above device, the target program for running the target instruction is started; when the target program is run to the first code position, a trigger instruction is sent to the programmable device, so that the programmable device starts the counting function according to the trigger instruction; when the target program is run to the second code position, the counting result of the programmable device is obtained, and the running time of the central processing unit is determined according to the counting result. Through the present invention, the method of calling the internal timing module of the current CPU system to time in the related art is solved, and the problem of inaccurate timing is solved, thereby achieving the timing through the timing module that does not rely on the system and hardware resources of the CPU, thereby achieving the technical effect of high-precision timing that does not rely on the system and hardware resources of the CPU.
[0092] In an exemplary embodiment, the acquisition module includes: a first sending module, used to send an end instruction to the programmable device, so that the programmable device turns off the counting function according to the end instruction and stores the counting result in the storage register of the programmable device; a reading module, used to read the counting result output by the storage register.
[0093] In an exemplary embodiment, the sending module includes: a second sending module, used to send a trigger instruction to the programmable device when running to the starting position of each program block in the target program; a first acquisition module, used to acquire the counting result of the programmable device when running to the ending position of each program block in the target program, wherein the counting result is used to indicate the running time of each program block.
[0094] In an exemplary embodiment, the sending module includes: a third sending module, which is used to send a trigger instruction to the programmable device when running to the starting position of an access function in the target program, wherein the access function is used to access the target interface; the acquisition module includes: a second acquisition module, which is used to acquire the counting result of the programmable device when running to the ending position of the access function in the target program, wherein the counting result is used to indicate the access duration of the interface corresponding to the access function.
[0095] In an exemplary embodiment, the sending module includes: a fourth sending module, which is used to send a trigger instruction to the programmable device when running to the starting position of the BOOT source code in the target program; the acquisition module includes: a third acquisition module, which is used to obtain the counting result of the programmable device when running to the end position of the kernel source code in the target program, wherein the counting result is used to indicate the startup time of starting the operating system corresponding to the central processing unit.
[0096] In an exemplary embodiment, the acquisition module includes: a first determination module, used to determine the size relationship between the running time and the preset time, and the preset time is used to indicate the standard time for running from the first code position to the second code position; a second determination module, used to determine that the running efficiency of the central processing unit meets the preset running efficiency when the running time is less than or equal to the preset time; and determine that the running efficiency of the central processing unit does not meet the preset running efficiency when the running time is greater than the preset time.
[0097] In an exemplary embodiment, the second determination module is further used to determine that there is a fault when the central processing unit runs the target program block of the target program; determine that the speed at which the central processing unit accesses the interface is less than a preset access speed; and determine that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is less than a preset startup speed.
[0098] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0099] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0100] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0101] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the computer program to execute the steps in any one of the above method embodiments.
[0102] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0103] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0104] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and run by the computing device, and in some cases, the steps shown or described can be run in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0105] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for determining a running time, characterized in that: include: Starting a target program for running a target instruction; When the target program is executed to a first code position, a trigger instruction is sent to the programmable device, so that the programmable device starts a counting function according to the trigger instruction; When running to the second code position of the target program, a counting result of the programmable device is obtained, and the running time of the central processing unit is determined according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
2. The method according to claim 1, characterized in that The obtaining of the counting result of the programmable device comprises: Sending an end instruction to the programmable device, so that the programmable device turns off the counting function according to the end instruction and stores the counting result in a storage register of the programmable device; The counting result output by the storage register is read.
3. The method according to claim 1, characterized in that The step of sending a trigger instruction to a programmable device when the target program is executed to a first code position includes: When the program reaches the start position of each program block in the target program, a trigger instruction is sent to the programmable device; The step of obtaining a counting result of the programmable device when the target program is executed to a second code position includes: When the target program reaches the end position of each program block, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the running time of each program block.
4. The method according to claim 1, characterized in that: The step of sending a trigger instruction to a programmable device when the target program is executed to a first code position includes: When the program runs to the start position of an access function in the target program, sending a trigger instruction to the programmable device, wherein the access function is used to access the target interface; The step of obtaining a counting result of the programmable device when the target program is executed to a second code position includes: When the target program reaches the end position of the access function, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the access duration of the interface corresponding to the access function.
5. The method according to claim 1, characterized in that The step of sending a trigger instruction to a programmable device when the target program is executed to a first code position includes: When the program reaches the start position of the BOOT source code in the target program, a trigger instruction is sent to the programmable device; The step of obtaining a counting result of the programmable device when the target program is executed to a second code position includes: When the kernel source code in the target program is run to the end position, a counting result of the programmable device is obtained, wherein the counting result is used to indicate the startup time length of the operating system corresponding to the central processing unit.
6. The method according to claim 1, characterized in that After determining the running time of the central processing unit according to the counting result, the method further includes: Determine the magnitude relationship between the running time and a preset time, wherein the preset time is used to indicate a standard time for running from the first code position to the second code position; When the running time is less than or equal to the preset time, determining that the running efficiency of the central processing unit meets the preset running efficiency; When the running time is greater than the preset time, it is determined that the running efficiency of the central processing unit does not meet the preset running efficiency.
7. The method according to claim 6, characterized in that After determining that the operating efficiency of the central processing unit does not meet the preset operating efficiency, the method includes at least one of the following: Determining that a fault occurs when the central processing unit runs a target program block of the target program; Determining that the speed at which the central processing unit accesses the interface is less than a preset access speed; It is determined that the speed at which the central processing unit starts the operating system corresponding to the central processing unit is lower than a preset starting speed.
8. A device for determining running time, characterized in that: include: A startup module, used for starting a target program for running a target instruction; A sending module, configured to send a trigger instruction to a programmable device when the target program is executed to a first code position, so that the programmable device starts a counting function according to the trigger instruction; An acquisition module is used to obtain a counting result of the programmable device when running to a second code position of the target program, and determine the running time of the central processing unit according to the counting result, wherein the running time is used to indicate the time length for the central processing unit to run from the first code position to the second code position.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor runs the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Working state processing method of timestamp counter, electronic equipment and program product
CN120196516A
