Working state processing method of timestamp counter, electronic equipment and program product

By isolating and binding the processor core, it ensures that it processes tasks in the target working state and monitors the working state of the timestamp counter, solving the problem of inaccurate count values ​​and achieving the accuracy of count values.

CN120196516AActive Publication Date: 2025-06-24INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510687736.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-27
Publication Date
2025-06-24
Estimated Expiration
2045-05-27

AI Technical Summary

Technical Problem

The working state of the timestamp counter is often affected by hardware interrupts or the operating state of other cores of the processor, resulting in inaccurate count values.

Method used

By dividing the target processor core from multiple processor cores of the processor, isolating it, binding tasks, and blocking interrupts, ensuring that it processes tasks in the target working state, collecting multiple count values ​​of the timestamp counter, monitoring whether their working state matches, and re-dividing the processor cores if they do not match.

Benefits of technology

The working state of the timestamp counter is matched with the target working state, ensuring the accuracy of the count value and solving the problem of inaccurate count value.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120196516A_ABST
    Figure CN120196516A_ABST
Patent Text Reader

Abstract

The invention discloses a working state processing method of a timestamp counter, electronic equipment and a program product, and relates to the technical field of computers. The target processor core is isolated, the target task is bound with the target processor core, and the target processor core is interrupted and shielded, so that the target processor core is not influenced by hardware interruption or the running state of other processor cores in the processor; in the process that the target processor core processes the target task according to the target working state, whether the working state of the timestamp counter is matched with the target working state or not is monitored according to the collected count values of the timestamp counter in the target processor core, so that the working state of the timestamp counter is matched with the target working state; therefore, the problem that the count value acquired by the timestamp-based counter is inaccurate in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method for processing the working state of a timestamp counter, an electronic device, and a program product. Background Art

[0002] Currently, when a processor executes a process of a related task, the execution duration of the processor core for executing the related task is determined based on the count value collected by the timestamp counter, and then the resource occupation situation of the processor core when executing the related task is judged according to the execution duration.

[0003] However, the working state of the timestamp counter is often affected by hardware interrupts or the running states of other processor cores in the processor, which may lead to inaccurate count values collected based on the timestamp counter. Summary of the Invention

[0004] This application provides a method for processing the working state of a timestamp counter, an electronic device, and a program product, so as to at least solve the problem of inaccurate count values collected based on the timestamp counter in the related art.

[0005] This application provides a method for processing the working state of a timestamp counter, including:

[0006] Dividing a preset number of target processor cores from multiple processor cores of a processor; isolating the target processor cores by invoking a preset isolation instruction, so that the target processor cores are removed from the task scheduler of the operating system; binding a target task to the target processor cores by invoking a preset binding instruction; performing interrupt masking processing on the target processor cores by invoking a preset masking instruction; determining a target working state of the target processor cores according to the target task; collecting multiple count values of the timestamp counter in the target processor cores during the process of the target processor cores processing the target task according to the target working state; monitoring whether the working state of the timestamp counter matches the target working state according to the multiple count values; if the working state of the timestamp counter does not match the target working state, then re-execute the step of dividing a preset number of target processor cores from multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

[0007] This application also provides a device for processing the working state of a timestamp counter, including:

[0008] A dividing module, configured to divide a preset number of target processor cores from multiple processor cores of a processor;

[0009] The first processing module is used to isolate the target processor core by calling a preset isolation instruction, so that the target processor core is removed from the task scheduler of the operating system; bind the target task to the target processor core by calling a preset binding instruction; perform interrupt masking processing on the target processor core by calling a preset masking instruction.

[0010] The second processing module is used to determine the target working state of the target processor core according to the target task; collect multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state; monitor whether the working state of the timestamp counter matches the target working state according to the multiple count values; if the working state of the timestamp counter does not match the target working state, then re - execute the step of dividing a preset number of target processor cores from multiple processor cores of the slave processor until the working state of the timestamp counter matches the target working state.

[0011] This application also provides an electronic device, including: a memory for storing a computer program; a processor for implementing the steps of any of the above - mentioned methods for processing the working state of the timestamp counter when executing the computer program.

[0012] This application also provides a computer - readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above - mentioned methods for processing the working state of the timestamp counter are implemented.

[0013] This application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of any of the above - mentioned methods for processing the working state of the timestamp counter are implemented.

[0014] Through the method for processing the working state of the timestamp counter, the electronic device and the program product provided by this application, on the basis of dividing a preset number of target processor cores from multiple processor cores of the slave processor, by isolating the target processor core, binding the target task to the target processor core, and performing interrupt masking processing on the target processor core, it is achieved that the target processor core is not affected by hardware interrupts or the operating states of other processor cores in the processor. Furthermore, during the process of the target processor core processing the target task according to the target working state, according to the multiple count values of the timestamp counter collected in the target processor core, it is monitored whether the working state of the timestamp counter matches the target working state, so as to make the working state of the timestamp counter match the target working state, that is, the problem that the count values collected based on the timestamp counter in the related art are inaccurate is solved. Description of the Drawings

[0015] To more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0016] Figure 1 Schematic flowchart of the method for processing the working state of the timestamp counter provided by the embodiment of the present application Figure 1 ;

[0017] Figure 2 Schematic flowchart of the method for processing the working state of the timestamp counter provided by the embodiment of the present application Figure 2 ;

[0018] Figure 3 Schematic structural diagram of the device for processing the working state of the timestamp counter provided by the embodiment of the present application;

[0019] Figure 4 Schematic structural diagram of the electronic device provided by the present application. Detailed implementation manners

[0020] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, rather than all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.

[0021] It should be noted that in the description of the present application, the terms "including", "comprising" or any other variation thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0022] Currently, when the processor executes a related task process, the execution duration of the processor core for executing the related task is determined based on the count value collected by the timestamp counter, and then the resource occupation situation of the processor core when executing the related task is judged according to the execution duration.

[0023] However, the working state of the timestamp counter is often affected by hardware interrupts or the running states of other processor cores in the processor, which may lead to inaccurate count values collected by the timestamp counter.

[0024] To solve the above technical problems, the embodiments of the present application propose the following technical concepts:

[0025] Based on partitioning a preset number of target processor cores from multiple processor cores of a processor, by performing isolation processing on the target processor cores, binding the target tasks to the target processor cores, and performing interrupt masking processing on the target processor cores, it is achieved that the target processor cores are not affected by hardware interrupts or the operating states of other processor cores in the processor. Furthermore, during the process of the target processor cores processing the target tasks according to the target working state, based on multiple count values of the timestamp counter collected in the target processor cores, it is monitored whether the working state of the timestamp counter matches the target working state, so as to make the working state of the timestamp counter match the target working state, and thus ensure the accuracy of the count values collected based on the timestamp counter, that is, solve the problem that the count values collected based on the timestamp counter in the related art are inaccurate.

[0026] To enable those skilled in the art of this technology to better understand the solution of the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0027] Figure 1 Flow schematic of the method for processing the working state of the timestamp counter provided by the embodiments of the present application Figure 1 , as Figure 1 shown, the embodiments of the present application provide a method for processing the working state of a timestamp counter, and the execution subject can be any form of electronic device. The method is described in detail as follows:

[0028] Step S101: Partition a preset number of target processor cores from multiple processor cores of a processor.

[0029] Exemplarily, the preset number can be determined based on the tasks running when the electronic device is operating, or can be a value input manually; and then based on the preset number, the corresponding number of target processor cores are partitioned from multiple processor cores of the processor.

[0030] Specifically, the specific implementation steps of step S101 include:

[0031] Step S1011: Determine the task complexity of the target task.

[0032] Step S1012: If the task complexity of the target task is greater than or equal to the preset complexity limit value, then partition the target processor cores from multiple processor cores of the processor according to the first preset number.

[0033] Step S1013: If the task complexity of the target task is less than the preset complexity limit value, divide the target processor cores from multiple processor cores of the processor according to a second preset quantity, where the first preset quantity is greater than the second preset quantity.

[0034] Exemplarily, determine the task complexity of the target task according to the target task to be run in the target processor cores; then, by judging the magnitude relationship between the task complexity and the preset complexity limit value, determine the corresponding preset quantity, and based on the corresponding preset quantity, divide the target processor cores from multiple processor cores of the processor. Specifically, if the task complexity of the target task is greater than or equal to the preset complexity limit value, divide the target processor cores from multiple processor cores of the processor according to the first preset quantity; if the task complexity of the target task is less than the preset complexity limit value, divide the target processor cores from multiple processor cores of the processor according to the second preset quantity; where the first preset quantity is greater than the second preset quantity.

[0035] In a possible implementation manner, the target task includes multiple target subtasks. The specific implementation steps of step S1011 include:

[0036] Step S10111: Obtain the number of tasks of the target subtask.

[0037] Step S10112: Determine the task complexity of the target task according to the number of tasks of the target subtask.

[0038] In this embodiment, the number of tasks of the target subtask may be the cumulative total number in the preset execution cycle of the processor, or after dividing the preset execution cycle of the processor into at least two execution sub-cycles, obtain the cycle task numbers of the target subtasks corresponding to each execution sub-cycle, and then determine the maximum cycle task number among the cycle task numbers as the number of tasks of the target subtask. Furthermore, according to the number of tasks of the target subtask, the task complexity of the target task can be determined.

[0039] In another possible implementation manner, the target task includes multiple target subtasks. The specific implementation steps of step S1011 include:

[0040] Step S1011a: Obtain the execution time of each target subtask.

[0041] Step S1011b: Obtain the execution time of each ordinary subtask other than the target subtask.

[0042] Step S1011c: Divide the preset execution cycle of the processor into multiple execution cycles according to the execution time of each target subtask and the execution time of each ordinary subtask.

[0043] Exemplarily, the execution times of each target subtask include gtime_1_1, gtime_1_2, gtime_1_3, gtime_2_1, gtime_3_1, gtime_3_2, gtime_4_1, and the execution times of each ordinary subtask include ptime_1_1, ptime_1_2, ptime_2_1, ptime_2_2, ptime_3_1; furthermore, according to the execution times of each of the above target subtasks and the execution times of each ordinary subtask, the preset execution cycle of the processor is divided into four execution cycles.

[0044] Step S1011d: For each execution cycle, determine the target task quantity of the corresponding target subtask and the ordinary task quantity of the ordinary subtask within one execution cycle.

[0045] Exemplarily, based on the execution times of each target subtask and the execution times of each ordinary subtask shown in step S1011c, for each execution cycle, the target task quantity of the corresponding target subtask and the ordinary task quantity of the ordinary subtask determined within one execution cycle are shown in Table 1.

[0046] Table 1

[0047]

[0048] Specifically, in the first execution cycle, the target task quantity of the target subtask is 3, and the ordinary task quantity of the ordinary subtask is 1. Among them, the execution times corresponding to each target subtask are gtime_1_1, gtime_1_2, gtime_1_3, and the execution time corresponding to each ordinary subtask is ptime_1_1; in the second execution cycle, the target task quantity of the target subtask is 1, and the ordinary task quantity of the ordinary subtask is 3. Among them, the execution time corresponding to each target subtask is gtime_2_1, and the execution times corresponding to each ordinary subtask are ptime_1_2, ptime_2_1, ptime_2_2; in the third execution cycle, the target task quantity of the target subtask is 2, and the ordinary task quantity of the ordinary subtask is 1. Among them, the execution times corresponding to each target subtask are gtime_3_1, gtime_3_2, and the execution time corresponding to each ordinary subtask is ptime_3_1; in the fourth execution cycle, the target task quantity of the target subtask is 1, and the ordinary task quantity of the ordinary subtask is 0. Among them, the execution time corresponding to each target subtask is gtime_4_1.

[0049] Step S1011e: Determine the task complexity of the target task according to the target task quantity and the ordinary task quantity.

[0050] Exemplarily, for each execution cycle segment, within one execution cycle segment, according to the number of target tasks and the number of ordinary tasks, determine the task complexity of the target tasks corresponding to the execution cycle segment. Specifically, for example, according to the number of target tasks and the number of ordinary tasks in each execution cycle segment of Table 1, obtain the task complexity data_1 of the target tasks in the first execution cycle segment, the task complexity data_2 of the target tasks in the second execution cycle segment, the task complexity data_3 of the target tasks in the third execution cycle segment, and the task complexity data_4 of the target tasks in the fourth execution cycle segment.

[0051] Correspondingly, based on the comparison of the task complexity of the target tasks corresponding to each execution cycle segment with the size relationship of the preset complexity limit value respectively, determine the preset quantity corresponding to each execution cycle segment. Furthermore, according to the preset quantity in each execution cycle segment, divide the target processor cores from multiple processor cores of the processor.

[0052] In the steps of this embodiment, by dividing the preset execution cycle of the processor into multiple execution cycle segments, obtain the task complexity of the target tasks in each execution cycle segment, and further obtain the preset quantity corresponding to each execution cycle segment; realizing the dynamic adjustment of the processor resources, that is, avoiding the situation where the number of target processor cores is insufficient but there are idle processor cores in the processor when processing the target subtasks (or, target tasks), or the situation where the number of non-target processor cores in the processor is insufficient but the target processor cores are in an idle state when processing ordinary subtasks.

[0053] In another possible implementation manner, the specific implementation steps of step S1011 include: input the target task into a pre-trained large language model, and the large language model selects the corresponding pre-trained parsing logic according to at least one preset logical prompt word, parses the task complexity of the target task, and then outputs the task complexity of the target task.

[0054] Step S102: Perform isolation processing on the target processor cores by calling a preset isolation instruction, so that the target processor cores are removed from the task scheduler of the operating system.

[0055] Exemplarily, the preset isolation instruction includes the isolcpus parameter provided by the Linux operating system. By performing isolation processing on the target processor cores, the target processor cores are removed from the task scheduler of the operating system, thereby realizing that the target processor cores are not automatically assigned tasks by the task scheduler.

[0056] Step S103: Bind the target task to the target processor cores by calling a preset binding instruction.

[0057] Exemplarily, the preset binding instruction includes the taskset command provided by the Linux operating system. By invoking the preset binding instruction, the target task can be bound to the target processor core.

[0058] Step S104: Perform interrupt masking processing on the target processor core by invoking a preset masking instruction.

[0059] Exemplarily, the masking instruction includes an instruction generated based on the SMP IRQ Affinity technology provided by the Linux operating system. By performing interrupt masking processing on the target processor core, the target processor core does not execute hardware interrupt tasks, achieving freedom from hardware interrupt interference.

[0060] It can be understood that the present application embodiment does not limit the execution order of steps S102, S103, and step S104. That is, steps S102 and S103 can be executed first, and then step S104 can be executed, or step S104 can be executed first, and then steps S102 and S103 can be executed.

[0061] Step S105: Determine the target working state of the target processor core according to the target task.

[0062] Exemplarily, the working states of the target processor core include a normal performance state, an energy-saving state, a high-frequency state, and a special instruction optimization state; furthermore, according to the task information of the target task, the target working state of the target processor core can be determined.

[0063] Furthermore, after step S105, the method provided by the present application embodiment further includes:

[0064] Step S10A: Obtain the current working state of the target processor core.

[0065] Step S10B: Determine whether the current working state of the target processor core is the target working state.

[0066] Step S10C: If the current working state of the target processor core is the target working state, then execute step S106.

[0067] Step S10D: If the current working state of the target processor core is not the target working state, then after changing the current working state of the target processor core to the target working state, execute step S106.

[0068] Step S10E: If the current working state of the target processor core cannot be changed to the target working state, then re-execute step S101 until the current working state of the target processor core is the target working state, and then execute step S106.

[0069] In the steps of the embodiment of the present application, before executing step S106, by determining whether the current working state of the target processor core is the target working state, it is ensured that when step S106 is executed, the target processor core is in the target working state, thereby ensuring the accuracy of the count values collected based on the timestamp counter.

[0070] The steps of the embodiment of the present application achieve that when the target processor core is not executing the target task, the target processor core is in an energy-saving state, and when the target processor core is executing the target task, the target processor core changes to the target working state. Thereby, not only is the accuracy of the count values collected based on the timestamp counter ensured when the target processor core is executing the target task, but also the energy consumption is reduced when the target processor core is not executing the target task.

[0071] Step S106: During the process of the target processor core processing the target task according to the target working state, collect multiple count values of the timestamp counter in the target processor core.

[0072] Exemplarily, the target task includes a collection instruction for collecting the count value of the timestamp counter in the target processor core; furthermore, during the process of the target processor core processing the target task according to the target working state, multiple count values of the timestamp counter in the target processor core can be collected.

[0073] In a possible implementation manner, before step S106, the method provided by the embodiment of the present application further includes:

[0074] Step S106A: Obtain the start time of task execution of the target task.

[0075] Step S106B: Determine the corresponding first test task according to the target task.

[0076] Exemplarily, based on the target working state of the target processor core determined by the target task, determine the corresponding first test task, that is, when the target processor core processes the first test task, the working state of the target processor core is the target working state.

[0077] Step S106C: Before the start time of task execution of the target task, control the target processor core to process the first test task according to the target working state, and collect multiple first test count values of the timestamp counter in the target processor core.

[0078] Step S106D: According to the multiple first test count values, monitor whether the working state of the timestamp counter matches the target working state.

[0079] Step S106E: If the working state of the timestamp counter matches the target working state, then execute step S106.

[0080] Step S106F: If the working state of the timestamp counter does not match the target working state, re-execute Step S101 until the working state of the timestamp counter matches the target working state, and then execute Step S106.

[0081] Exemplarily, based on multiple first test count values, multiple test durations when the target processor core processes the first test task according to the target working state are obtained. Then, according to the degree of dispersion between the multiple test durations and the test duration threshold, it is determined whether the working state of the timestamp counter matches the target working state. Further, if it matches, execute Step S106 and subsequent steps; if it does not match, re-execute Step S101 until the working state of the timestamp counter matches the target working state, and then execute Step S106 and subsequent steps.

[0082] In the steps of this embodiment, by obtaining the start moment of task execution of the target task, and then before the start moment of task execution, by controlling the target processor core to process the first test task according to the target working state, it is realized to determine whether the working state of the timestamp counter matches the target working state; through responsive test judgment, it is realized to check the working state of the timestamp counter before the target processor core processes the target task according to the target working state, ensuring the accuracy of the count values collected by the timestamp counter when the target processor core executes the target task, and also realizing that when the target processor core does not execute the target task, the working state of the timestamp counter can be any state. For example, when the target processor core is in the energy-saving state, the working state of the timestamp counter also corresponds to the energy-saving state synchronously, reducing energy consumption.

[0083] Step S107: According to multiple count values, monitor whether the working state of the timestamp counter matches the target working state.

[0084] Specifically, the specific implementation steps of Step S107 include:

[0085] Step S1071: According to multiple count values, obtain multiple execution durations of the target task.

[0086] Exemplarily, according to multiple count values, multiple execution durations in the process of the target processor core processing the target task according to the target working state are obtained.

[0087] Step S1072: Determine a preset duration threshold according to the target task.

[0088] Exemplarily, different tasks have different corresponding execution durations. Then, according to the task information of the target task, a matching preset duration threshold is determined.

[0089] Step S1073: Monitor whether the working state of the timestamp counter matches the target working state according to multiple execution durations and a preset duration threshold.

[0090] Exemplarily, according to the dispersion degree of multiple execution durations and the preset duration threshold, it is possible to monitor whether the working state of the timestamp counter matches the target working state. Specifically, if the dispersion degree of multiple execution durations and the preset duration threshold is large, the working state of the timestamp counter does not match the target working state; if the dispersion degree of multiple execution durations and the preset duration threshold is small, the working state of the timestamp counter matches the target working state.

[0091] Further, the specific implementation steps of step S1073 include:

[0092] Step S10731: Generate a duration variance according to multiple execution durations and a preset duration threshold.

[0093] Specifically, the calculation formula for generating the duration variance according to multiple execution durations and a preset duration threshold is as shown in Equation (1).

[0094] (1)

[0095] Where, is the duration variance, is the number of execution durations, is the th execution duration, is the preset duration threshold.

[0096] Step S10732: Monitor whether the working state of the timestamp counter matches the target working state according to the magnitude relationship between the duration variance and the preset variance threshold.

[0097] Exemplarily, if the duration variance is greater than the preset variance threshold, the working state of the timestamp counter does not match the target working state; if the duration variance is less than or equal to the preset variance threshold, the working state of the timestamp counter matches the target working state. It can be understood that the smaller the duration variance, the smaller the dispersion degree of multiple execution durations and the preset duration threshold, and the larger the duration variance, the larger the dispersion degree of multiple execution durations and the preset duration threshold.

[0098] Step S108: If the working state of the timestamp counter matches the target working state, cause the target processor core to continue processing the target task according to the target working state.

[0099] Exemplarily, when the working state of the timestamp counter matches the target working state, the target processor core can continue to process the target task according to the target working state.

[0100] Further, during the subsequent processing, based on a preset duration, steps S106 and subsequent steps are executed to determine whether the working state of the timestamp counter matches the target working state at regular intervals.

[0101] Step S109: If the working state of the timestamp counter does not match the target working state, step S101 is re-executed until the working state of the timestamp counter matches the target working state.

[0102] Exemplarily, if the working state of the timestamp counter does not match the target working state, it indicates that the current target processor core cannot meet the requirements for executing the target task. Therefore, step S101 is re-executed until the working state of the timestamp counter matches the target working state.

[0103] In this embodiment, based on partitioning a preset number of target processor cores from multiple processor cores of the slave processor, by isolating the target processor cores, binding the target task to the target processor cores, and performing interrupt masking processing on the target processor cores, the target processor cores are made immune to hardware interrupts or the operating states of other processor cores in the processor. Further, during the process of the target processor cores processing the target task according to the target working state, based on multiple count values of the timestamp counter collected from the target processor cores, it is determined whether the working state of the timestamp counter matches the target working state, so that the working state of the timestamp counter matches the target working state, thereby ensuring the accuracy of the count values collected based on the timestamp counter, that is, solving the problem of inaccurate count values collected based on the timestamp counter in the related art.

[0104] Further, the method provided in the embodiment of the present application further includes:

[0105] Step S110: After the target processor core finishes processing the target task, the count value at the start time and the count value at the completion time are obtained.

[0106] Step S111: Based on the count value at the start time and the count value at the completion time, the processing duration for completing the processing of the target task is output.

[0107] Exemplarily, after the target processor core finishes processing the target task, the count value at the start time and the count value at the completion time when the target processor core processes the target task are obtained.

[0108] Furthermore, based on the count value at the start time, the count value at the completion time, and the clock cycle corresponding to the target processor core, the processing duration for the target processor core to complete the processing of the target task can be obtained and output.

[0109] Figure 2Flow schematic of the working state processing method of the timestamp counter provided by the embodiment of the present application Figure 2 In the embodiment of the present application, based on the Figure 1 embodiment provided, a detailed description is given. As Figure 2 shown, the method includes:

[0110] Step S201: Divide a preset number of target processor cores from multiple processor cores of the processor.

[0111] Step S202: Perform isolation processing on the target processor cores by calling a preset isolation instruction, so that the target processor cores are removed from the task scheduler of the operating system.

[0112] Step S203: Bind the target task to the target processor cores by calling a preset binding instruction.

[0113] Step S204: Perform interrupt masking processing on the target processor cores by calling a preset masking instruction, so that the target processor cores do not execute hardware interrupt tasks.

[0114] Step S205: Determine the target working state of the target processor cores according to the target task.

[0115] Step S206: Determine the idle times of the target processor cores.

[0116] Specifically, the specific implementation steps of step S206 include:

[0117] Step S2061: Obtain the execution time of the target task and the preset execution cycle of the target processor cores.

[0118] Step S2062: Screen and determine the idle times of the target processor cores from the preset execution cycle of the target processor cores according to the execution time of the target task.

[0119] Exemplarily, the execution time of the target task includes time_2 and time_3, and the preset execution cycle of the target processor cores includes time_1, time_2, time_3, time_4, and time_5; furthermore, according to the execution time time_2 and time_3 of the target task, the idle times of the target processor cores screened and determined from the preset execution cycle of the target processor cores include time_1, time_4, and time_5.

[0120] Step S207: Select one or more idle times from the idle times and determine them as the test time.

[0121] Exemplarily, each idle time of the target processor core includes time_1, time_4, and time_5, and then time_1 and time_4 are determined as the test times.

[0122] Step S208: At each test time, determine the corresponding second test task according to the target task.

[0123] Exemplarily, at the test time time_1, based on the target working state of the target processor core determined by the target task, determine the corresponding second test task, that is, when the target processor core processes the second test task, the working state of the target processor core is the target working state.

[0124] Step S209: Control the target processor core to process the second test task according to the target working state, and collect multiple second test values of the timestamp counter in the target processor core.

[0125] Step S210: According to the multiple second test values, monitor whether the working state of the timestamp counter matches the target working state.

[0126] Step S211: If the working state of the timestamp counter matches the target working state, keep the working state of the timestamp counter unchanged.

[0127] Step S212: If the working state of the timestamp counter does not match the target working state, restart step S201 until the working state of the timestamp counter matches the target working state.

[0128] Exemplarily, according to the multiple second test values, obtain multiple test durations when the target processor core processes the second test task according to the target working state, and then judge whether the working state of the timestamp counter matches the target working state according to the dispersion degree between the multiple test durations and the test duration threshold. Further, if they match, keep the working state of the timestamp counter unchanged; if they do not match, restart step S201 until the working state of the timestamp counter matches the target working state, and then keep the working state of the timestamp counter unchanged.

[0129] In the steps of this embodiment, based on determining the idle times of the target processor core, the test time of the target processor core is determined. Then, at the test time, it is monitored whether the working state of the timestamp counter matches the target working state, realizing the timed monitoring of the working state of the timestamp counter and keeping the working state of the timestamp counter unchanged as the target working state. Furthermore, when the target processor core processes the target task according to the target working state, optionally, it is not necessary to calibrate the working state of the timestamp counter before the target processor core starts to process the target task according to the target working state, improving the processing efficiency of the target processor core when processing the target task according to the target working state.

[0130] It can be understood that when the target processor core processes the target task according to the target working state, optionally, the working state of the timestamp counter can also be calibrated before the target processor core starts to process the target task according to the target working state to ensure the accuracy of the count value collected by the timestamp counter.

[0131] It can be understood that the test time when the target processor core processes the second test task according to the target working state can be before the target processor core starts to process the target task according to the target working state, for example, processed at the test time time_1; or after the target processor core finishes processing the target task according to the target working state, for example, processed at the test time time_4.

[0132] Step S213: During the process of the target processor core processing the target task according to the target working state, collect multiple count values of the timestamp counter in the target processor core.

[0133] Step S214: According to the multiple count values, monitor whether the working state of the timestamp counter matches the target working state.

[0134] Step S215: If the working state of the timestamp counter matches the target working state, then make the target processor core continue to process the target task according to the target working state.

[0135] Step S216: If the working state of the timestamp counter does not match the target working state, then re-execute step S201 until the working state of the timestamp counter matches the target working state.

[0136] In this embodiment, the implementation manners of steps S201 - S205 are the same as those of steps S101 - S105 in the embodiment Figure 1 shown in the present application, and the implementation manners of steps S213 - S216 are the same as those of steps S106 - S109 in the embodiment Figure 1 shown in the present application, which will not be elaborated one by one here.

[0137] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method.

[0138] Figure 3 It is a schematic structural diagram of a working state processing device for a timestamp counter provided by an embodiment of the present application. As Figure 3 shown, an embodiment of the present application further provides a working state processing device 3 for a timestamp counter, including:

[0139] A partitioning module 31, configured to partition a preset number of target processor cores from multiple processor cores of a processor;

[0140] A first processing module 32, configured to perform isolation processing on the target processor cores by invoking a preset isolation instruction, so that the target processor cores are removed from the task scheduler of the operating system; bind the target task to the target processor cores by invoking a preset binding instruction; perform interrupt masking processing on the target processor cores by invoking a preset masking instruction;

[0141] A second processing module 33, configured to determine a target working state of the target processor cores according to the target task; during the process of the target processor cores processing the target task according to the target working state, collect multiple count values of the timestamp counter in the target processor cores; monitor whether the working state of the timestamp counter matches the target working state according to the multiple count values; if the working state of the timestamp counter does not match the target working state, then re-execute the step of partitioning a preset number of target processor cores from multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

[0142] In a possible implementation manner, when the second processing module 33 monitors whether the working state of the timestamp counter matches the target working state according to the multiple count values, it is specifically configured to: obtain multiple execution durations of the target task according to the multiple count values; determine a preset duration threshold according to the target task; monitor whether the working state of the timestamp counter matches the target working state according to the multiple execution durations and the preset duration threshold.

[0143] In a possible implementation manner, when the second processing module 33 monitors whether the working state of the timestamp counter matches the target working state according to the multiple execution durations and the preset duration threshold, it is specifically configured to: generate a duration variance according to the multiple execution durations and the preset duration threshold; monitor whether the working state of the timestamp counter matches the target working state according to the magnitude relationship between the duration variance and the preset variance threshold.

[0144] In a possible implementation, according to multiple execution durations and a preset duration threshold, a calculation formula for duration variance is generated as follows:

[0145]

[0146] wherein, is the duration variance, is the number of execution durations, is the th execution duration, is the preset duration threshold.

[0147] In a possible implementation, when the partitioning module 31 partitions a preset number of target processor cores from multiple processor cores of the processor, it specifically is used for: determining the task complexity of the target task; if the task complexity of the target task is greater than or equal to a preset complexity limit value, partitioning the target processor cores from the multiple processor cores of the processor according to a first preset number; if the task complexity of the target task is less than the preset complexity limit value, partitioning the target processor cores from the multiple processor cores of the processor according to a second preset number; wherein the first preset number is greater than the second preset number.

[0148] In a possible implementation, the target task includes multiple target subtasks; correspondingly, when the partitioning module 31 determines the task complexity of the target task, it specifically is used for: obtaining the execution time of each target subtask; obtaining the execution time of each ordinary subtask other than the target subtasks; dividing the preset execution cycle of the processor into multiple segments of execution cycles according to the execution time of each target subtask and the execution time of each ordinary subtask; for each segment of execution cycle, determining the number of target tasks of the corresponding target subtasks and the number of ordinary tasks of the ordinary subtasks within one segment of execution cycle; and determining the task complexity of the target task according to the number of target tasks and the number of ordinary tasks.

[0149] In a possible implementation, the target task includes multiple target subtasks; correspondingly, when the partitioning module 31 determines the task complexity of the target task, it specifically is used for: obtaining the number of target tasks; and determining the task complexity of the target task according to the number of target tasks.

[0150] In a possible implementation, after determining the target working state of the target processor core according to the target task, the working state processing device 3 of the timestamp counter is further configured to: obtain the current working state of the target processor core; determine whether the current working state of the target processor core is the target working state; if the current working state of the target processor core is the target working state, execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state; if the current working state of the target processor core is not the target working state, after changing the current working state of the target processor core to the target working state, execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state; if the current working state of the target processor core cannot be changed to the target working state, re-execute the step of partitioning a preset number of target processor cores from the multiple processor cores of the processor until the current working state of the target processor core is the target working state, and then execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state.

[0151] In a possible implementation, before collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state, the working state processing device 3 of the timestamp counter is further configured to: obtain the start time of task execution of the target task; determine a corresponding first test task according to the target task; before the start time of task execution of the target task, control the target processor core to process the first test task according to the target working state, and collect multiple first test count values of the timestamp counter in the target processor core; monitor whether the working state of the timestamp counter matches the target working state according to the multiple first test count values; if the working state of the timestamp counter does not match the target working state, re-execute the step of partitioning a preset number of target processor cores from the multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

[0152] In a possible implementation, after determining the target working state of the target processor core according to the target task, the working state processing device 3 of the timestamp counter is further configured to: determine the idle times of the target processor core; select one or more idle times from the idle times and determine them as test times; at each test time, determine a corresponding second test task according to the target task; control the target processor core to process the second test task according to the target working state, and collect multiple second test count values of the timestamp counter in the target processor core; monitor whether the working state of the timestamp counter matches the target working state according to the multiple second test count values; if the working state of the timestamp counter does not match the target working state, re - execute the step of partitioning a preset number of target processor cores from multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

[0153] In a possible implementation, when the working state processing device 3 of the timestamp counter determines the idle times of the target processor core, it is specifically configured to: obtain the execution time of the target task and the preset execution cycle of the target processor core; filter and determine the idle times of the target processor core from the preset execution cycle of the target processor core according to the execution time of the target task.

[0154] In a possible implementation, the working state processing device 3 of the timestamp counter is further configured to: after the target processor core finishes processing the target task, obtain the count value at the start time and the count value at the end time; output the processing duration of finishing processing the target task according to the count value at the start time and the count value at the end time.

[0155] For the description of the features in the embodiments corresponding to the working state processing device 3 of the timestamp counter, reference can be made to the relevant descriptions in the embodiments corresponding to the working state processing method of the timestamp counter, which will not be elaborated here one by one.

[0156] Figure 4 This is a schematic structural diagram of the electronic device provided by this application. As Figure 4 shown, the electronic device 50 provided in this embodiment includes: at least one processor 501 and a memory 502. Optionally, the electronic device 50 further includes a communication component 503. Among them, the processor 501, the memory 502, and the communication component 503 are connected through a bus.

[0157] In a specific implementation process, at least one processor 501 executes the computer - executable instructions stored in the memory 502, so that at least one processor 501 executes the above - mentioned embodiments of the working state processing method of the timestamp counter.

[0158] For the specific implementation process of the processor 501, reference may be made to the foregoing method embodiments. Their implementation principles and technical effects are similar, and will not be elaborated herein.

[0159] In the foregoing embodiments, it should be understood that the processor may be a central processing unit (Central Processing Unit, abbreviated as CPU), or may also be other general-purpose processors, digital signal processors (Digital Signal Processor, abbreviated as DSP), application specific integrated circuits (Application Specific Integrated Circuit, abbreviated as ASIC), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the application can be directly implemented by the execution of the hardware processor, or can be implemented by the combination of the hardware and software modules in the processor.

[0160] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.

[0161] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, the buses in the drawings of this application are not limited to only one bus or one type of bus.

[0162] The embodiments of the present application also provide a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any of the foregoing method embodiments for processing the working state of the timestamp counter when running.

[0163] In an exemplary embodiment, the foregoing computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (Read-Only Memory, abbreviated as ROM), random access memories (Random Access Memory, abbreviated as RAM), mobile hard disks, magnetic disks, or optical discs and other media that can store computer programs.

[0164] An embodiment of the present application also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above embodiments of the method for processing the working state of the timestamp counter.

[0165] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above embodiments of the method for processing the working state of the timestamp counter.

[0166] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0167] The above has introduced in detail a method for processing the working state of a timestamp counter, an electronic device, and a program product provided by the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A method for processing the working state of a timestamp counter, characterized in that, Including: Dividing a preset number of target processor cores from multiple processor cores of a processor; Performing isolation processing on the target processor cores by invoking a preset isolation instruction, so that the target processor cores are removed from the task scheduler of the operating system; Binding a target task to the target processor cores by invoking a preset binding instruction; Performing interrupt masking processing on the target processor cores by invoking a preset masking instruction; Determining a target working state of the target processor cores according to the target task; During the process of the target processor cores processing the target task according to the target working state, collecting multiple count values of a timestamp counter in the target processor cores; Monitoring whether the working state of the timestamp counter matches the target working state according to the multiple count values; If the working state of the timestamp counter does not match the target working state, re-execute the step of dividing a preset number of target processor cores from multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

2. The method for processing the working state of the timestamp counter according to claim 1, characterized in that The monitoring whether the working state of the timestamp counter matches the target working state according to the multiple count values includes: Obtaining multiple execution durations of the target task according to the multiple count values; Determining a preset duration threshold according to the target task; Monitoring whether the working state of the timestamp counter matches the target working state according to the multiple execution durations and the preset duration threshold.

3. The method for processing the working state of the timestamp counter according to claim 2, wherein The monitoring whether the working state of the timestamp counter matches the target working state according to the multiple execution durations and the preset duration threshold includes: Generating a duration variance according to the multiple execution durations and the preset duration threshold; Monitoring whether the working state of the timestamp counter matches the target working state according to the magnitude relationship between the duration variance and a preset variance threshold.

4. The method for processing the working state of the timestamp counter according to claim 3, wherein The calculation formula for generating the duration variance according to the multiple execution durations and the preset duration threshold is: , Wherein, is the duration variance, is the number of execution durations, is the th execution duration, is the preset duration threshold.

5. The method for processing the working state of the timestamp counter according to claim 1, characterized in that The dividing a preset number of target processor cores from multiple processor cores of the processor includes: Determining the task complexity of the target task; If the task complexity of the target task is greater than or equal to a preset complexity limit value, dividing target processor cores from multiple processor cores of the processor according to a first preset number; If the task complexity of the target task is less than the preset complexity limit value, dividing target processor cores from multiple processor cores of the processor according to a second preset number; Wherein the first preset number is greater than the second preset number.

6. The method for processing the working state of the timestamp counter according to claim 5, wherein, The target task includes multiple target subtasks; Correspondingly, the determining the task complexity of the target task includes: Obtaining the execution time of each target subtask; Obtaining the execution time of each ordinary subtask other than the target subtasks; Dividing a preset execution cycle of the processor into multiple execution cycles according to the execution time of each target subtask and the execution time of each ordinary subtask; For each execution cycle segment, determine the target task quantity of the corresponding target subtask and the ordinary task quantity of the ordinary subtask within one execution cycle segment; Determine the task complexity of the target task according to the target task quantity and the ordinary task quantity.

7. The method for processing the working state of the timestamp counter according to claim 5, characterized in that, The target task includes multiple target subtasks; Correspondingly, the determining the task complexity of the target task includes: Obtain the task quantity of the target subtask; Determine the task complexity of the target task according to the task quantity of the target subtask.

8. The method for processing the working state of the timestamp counter according to any one of claims 1-7, characterized in that After determining the target working state of the target processor core according to the target task, it further includes: Obtain the current working state of the target processor core; Judge whether the current working state of the target processor core is the target working state; If the current working state of the target processor core is the target working state, execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state; If the current working state of the target processor core is not the target working state, after changing the current working state of the target processor core to the target working state, execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state; If the current working state of the target processor core cannot be changed to the target working state, re-execute the step of partitioning a preset number of target processor cores from multiple processor cores of the processor until the current working state of the target processor core is the target working state, and then execute the step of collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state.

9. The method for processing the working state of the timestamp counter according to claim 1, wherein, Before collecting multiple count values of the timestamp counter in the target processor core during the process of the target processor core processing the target task according to the target working state, it further includes: Obtain the task execution start time of the target task; Determine the corresponding first test task according to the target task; Before the task execution start time of the target task, control the target processor core to process the first test task according to the target working state, and collect multiple first test count values of the timestamp counter in the target processor core; Monitor whether the working state of the timestamp counter matches the target working state according to the multiple first test count values; If the working state of the timestamp counter does not match the target working state, re-execute the step of partitioning a preset number of target processor cores from multiple processor cores of the processor until the working state of the timestamp counter matches the target working state.

10. The method for processing the working state of the timestamp counter according to claim 1, wherein After determining the target working state of the target processor core according to the target task, it further includes: Determine the idle times of the target processor core; Select one or more idle times from the respective idle times and determine them as test times; At each test time, determine a corresponding second test task according to the target task; Control the target processor core to process the second test task according to the target working state, and collect a plurality of second test count values of the timestamp counter in the target processor core; According to the plurality of second test count values, monitor whether the working state of the timestamp counter matches the target working state; If the working state of the timestamp counter does not match the target working state, re-execute the step of dividing a preset number of target processor cores from the plurality of processor cores of the processor until the working state of the timestamp counter matches the target working state.

11. The method for processing the working state of the timestamp counter according to claim 10, wherein, The determining of the respective idle times of the target processor core includes: Obtain the execution time of the target task and the preset execution cycle of the target processor core; According to the execution time of the target task, screen and determine the respective idle times of the target processor core from the preset execution cycle of the target processor core.

12. The method for processing the working state of the timestamp counter according to claim 1, wherein It further includes: After the target processor core finishes processing the target task, obtain the count value at the start time and the count value at the end time; According to the count value at the start time and the count value at the end time, output the processing duration for finishing processing the target task.

13. An electronic device, characterized in that, It includes: A memory for storing a computer program; A processor for implementing the steps of the method for processing the working state of the timestamp counter according to any one of claims 1 to 12 when executing the computer program.

14. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program, when executed by a processor, implements the steps of the method for processing the working state of the timestamp counter according to any one of claims 1 to 12.

15. A computer program product, comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the steps of the method for processing the working state of the timestamp counter according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Timestamp acquisition method, system and chip

    CN118170523A

  • Universal timestamp counter, universal timestamp counting method and electronic equipment

    CN119065895A

  • Operation duration determination method and device, storage medium and electronic device

    CN119226105A