Time processing methods, electronic devices, storage media and program products
By using the time namespace in kernel mode to record and adjust the time difference information of high-precision hardware clocks, the problem of process recovery errors during container migration is solved, ensuring normal process execution.
Patent Information
- Application Number
- CN202511149316.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-18
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2045-08-18
AI Technical Summary
During container migration, inconsistencies in high-precision hardware clocks before and after migration can cause errors after process recovery, such as infinite running or failure to exit.
The process is restored in kernel mode based on the saved process state information and placed in the time namespace to record the time difference information. When the process switches from kernel mode to user mode, the time recorded by the high-precision hardware clock is adjusted based on the time difference information.
It eliminates the time difference recorded by the high-precision hardware clock after process recovery, ensuring normal process execution.
Smart Images

Figure CN120743037B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of timestamp counters, and more particularly to a time processing method, electronic device, storage medium, and program product. Background Technology
[0002] A high-precision hardware clock is a critical component in a computer system used to provide accurate time measurements and delivers highly accurate timestamps. In tasks such as performance testing, timing analysis, and benchmarking, it is often necessary to calculate the difference between two readings of the high-precision hardware clock to determine the duration.
[0003] Taking a high-precision hardware clock, specifically a timestamp counter (TSC), as an example, in container migration scenarios, the container's process state is first saved, and then the process is restored on the new processing node. Because the TSCs of the processing nodes before and after migration differ, errors can occur after process restoration. For example, the TSC before migration might be less than the TSC after migration, resulting in a negative difference between the two TSC readings. This could lead to errors such as the process running indefinitely or never exiting. Therefore, in related technologies, a method is urgently needed to ensure the normal execution of the restored process in scenarios where the high-precision hardware clocks are inconsistent before and after migration. Summary of the Invention
[0004] This application provides a time processing method, electronic device, storage medium, and program product to ensure the normal execution of the restored process in scenarios where there is an inconsistency between the high-precision hardware clock before and after migration.
[0005] Firstly, this application provides a time processing method, including:
[0006] When restoring the first process based on the saved state information of the first process in kernel mode, the restored first process is placed in the first time namespace so as to record the first time difference information through the first time namespace. The first time difference information is used to indicate the difference between the time recorded by the first high-precision hardware clock corresponding to the first process when it is saved and the time recorded by the second high-precision hardware clock corresponding to the first process when it is restored.
[0007] When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0008] In one possible implementation, after adjusting the processor's hardware time based on the first time difference information when the first process switches from kernel mode to user mode, the method further includes:
[0009] When the first process switches from user mode to kernel mode again, the time recorded by the second high-precision hardware clock is restored based on the first time difference information.
[0010] In one possible implementation, after recovering the time recorded by the second high-precision hardware clock, the method further includes:
[0011] When the restored second process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the second time difference information recorded in the second time namespace corresponding to the second process. The second time difference information is used to indicate the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored.
[0012] In one possible implementation, after recovering the time recorded by the second high-precision hardware clock, the method further includes:
[0013] When the first process switches from kernel mode to user mode again, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0014] In one possible implementation, adjusting the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode includes:
[0015] Without disabling the use of the target instruction by the first process, when the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information; the target instruction is an instruction for reading the time recorded by the second high-precision hardware clock.
[0016] In one possible implementation, the method further includes:
[0017] When restoring the first process in kernel mode based on the saved state information of the first process, set whether to disable the first process from using the target instruction.
[0018] In one possible implementation, whether the setting disables the first process from using the target instruction includes:
[0019] When the first process is disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a first value;
[0020] Without disabling the first process from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to the second value;
[0021] The method further includes:
[0022] Based on the value of the high-precision hardware clock flag bit in the control register corresponding to the first process, it is determined whether the first process is disabled from using the target instruction.
[0023] In one possible implementation, the method further includes:
[0024] Based on the frequency with which the first process has historically used the target instruction, determine whether to disable the first process from using the target instruction.
[0025] In one possible implementation, the method further includes:
[0026] When the first process is disabled from using the target instruction, the time recorded by the second high-precision hardware clock is maintained when the first process switches from kernel mode to user mode.
[0027] If the first process switches from user mode to kernel mode due to an exception triggered by using the target instruction, the use of the target instruction by the first process is not disabled, and the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information when the first process switches from kernel mode to user mode.
[0028] In one possible implementation, the method further includes:
[0029] Without disabling the first process from using the target instruction for a preset duration, disable the first process from using the target instruction again.
[0030] Secondly, this application provides a time processing method, the method comprising:
[0031] In response to the user's migration command, the container is migrated to the new processing node by saving the state information of the first process through the container runtime interface.
[0032] The first process is restored in kernel mode based on the saved state information of the first process. During the restoration process, the method described in any one of the first aspects is executed.
[0033] Thirdly, this application provides a time processing apparatus, comprising: a recording module and an adjustment module, wherein...
[0034] The recording module is used to place the restored first process in a first time namespace when restoring the first process based on the state information of the first process saved in kernel mode, so as to record the first time difference information through the first time namespace. The first time difference information is used to indicate the difference between the time recorded by the first high-precision hardware clock corresponding to the first process when it is saved and the time recorded by the second high-precision hardware clock corresponding to the first process when it is restored.
[0035] The adjustment module is used to adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode.
[0036] In one possible implementation, after restoring the time recorded by the second high-precision hardware clock, the adjustment module is further configured to:
[0037] When the restored second process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the second time difference information recorded in the second time namespace corresponding to the second process. The second time difference information is used to indicate the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored.
[0038] In one possible implementation, after restoring the time recorded by the second high-precision hardware clock, the adjustment module is further configured to:
[0039] When the first process switches from kernel mode to user mode again, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0040] In one possible implementation, the adjustment module is specifically used for:
[0041] Without disabling the use of the target instruction by the first process, when the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information; the target instruction is an instruction for reading the time recorded by the second high-precision hardware clock.
[0042] In one possible implementation, the time processing device further includes: a recovery module, wherein,
[0043] When the first process switches from kernel mode to user mode, after adjusting the processor's hardware time based on the first time difference information, the recovery module is specifically used for:
[0044] When the first process switches from user mode to kernel mode again, the time recorded by the second high-precision hardware clock is restored based on the first time difference information.
[0045] In one possible implementation, the time processing device further includes: a setting module and a determining module, wherein,
[0046] The setting module is specifically used for:
[0047] When restoring the first process in kernel mode based on the saved state information of the first process, set whether to disable the first process from using the target instruction.
[0048] In one possible implementation, the setting module is specifically used for:
[0049] When the first process is disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a first value;
[0050] Without disabling the first process from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to the second value;
[0051] Accordingly, the determining module is specifically used for:
[0052] Based on the value of the high-precision hardware clock flag bit in the control register corresponding to the first process, it is determined whether the first process is disabled from using the target instruction.
[0053] In one possible implementation, the determining module is further configured to:
[0054] Based on the frequency with which the first process has historically used the target instruction, determine whether to disable the first process from using the target instruction.
[0055] In one possible implementation, the setting module is further configured to:
[0056] When the first process is disabled from using the target instruction, the time recorded by the second high-precision hardware clock is maintained when the first process switches from kernel mode to user mode.
[0057] If the first process switches from user mode to kernel mode due to an exception triggered by using the target instruction, the use of the target instruction by the first process is not disabled, and the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information when the first process switches from kernel mode to user mode.
[0058] In one possible implementation, the setting module is further configured to:
[0059] Without disabling the first process from using the target instruction for a preset duration, disable the first process from using the target instruction again.
[0060] Fourthly, this application provides a time processing apparatus, comprising: a migration module and a processing module, wherein,
[0061] The migration module is used to respond to the user's migration command, save the state information of the first process through the container runtime interface, and migrate the container to the new processing node;
[0062] The processing module is used to restore the first process in kernel mode based on the saved state information of the first process, and during the restoration process, execute the method shown in the above-described time processing method embodiment.
[0063] Fifthly, this application provides an electronic device, comprising:
[0064] At least one processor; and a memory communicatively connected to said at least one processor;
[0065] The memory stores instructions executable by the at least one processor to cause the electronic device to perform the method as described in any one of the first aspects.
[0066] In a sixth aspect, this application provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the method as described in any one of the first aspects.
[0067] In a seventh aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method as described in any one of the first aspects.
[0068] This application provides a time processing method, electronic device, storage medium, and program product. When restoring the first process based on the saved state information of the first process in kernel mode, the restored first process is placed in a first time namespace to record first time difference information. When the first process switches from kernel mode to user mode, the time recorded by a second high-precision hardware clock is adjusted based on the first time difference information. Based on this method, after the first process switches to user mode, the time obtained by reading the second high-precision hardware clock through an instruction is the time adjusted based on the time difference information. This eliminates the difference between the time recorded by the first high-precision hardware clock when the first process is saved and the time recorded by the second high-precision hardware clock when it is restored, ensuring that the logic executed by the restored first process relying on the second high-precision hardware clock is not affected and that the process can execute normally. Attached Figure Description
[0069] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0070] Figure 1 A schematic diagram illustrating an application scenario provided for an exemplary embodiment of this application;
[0071] Figure 2 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 1 ;
[0072] Figure 3 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 2 ;
[0073] Figure 4 A schematic diagram illustrating the state switching of a multi-process embodiment provided in this application;
[0074] Figure 5 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 3 ;
[0075] Figure 6 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 4 ;
[0076] Figure 7 A schematic diagram of the structure of a first time processing apparatus provided for an exemplary embodiment of this application;
[0077] Figure 8A schematic diagram of the structure of a second time processing apparatus provided as an exemplary embodiment of this application;
[0078] Figure 9 A schematic diagram of the structure of a third time processing apparatus provided as an exemplary embodiment of this application;
[0079] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0080] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0081] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0082] Below, in order to facilitate understanding of the technical solution of this application, the concepts involved in this application will be explained first.
[0083] 1. Time Namespace: A mechanism provided by the Linux kernel that allows different process groups or containers to have independent time views. Time Namespace allows processes within each namespace to see different system times without affecting the global system time or times in other namespaces.
[0084] 2. Time Stamp Counter (TSC): This is a hardware register built into the x86 processor. It provides nanosecond-level timing accuracy in units of processor clock cycles. It increments at the CPU's base clock frequency from the moment the system powers on to provide a high-precision timestamp.
[0085] 3. Read Time Stamp Counter (RDTSC) instruction: An x86 architecture instruction used to read the current value of the TSC and store it in a register.
[0086] 4. Read Time Stamp Counter and Processor Identity (RDTSCP) instruction: An x86 architecture instruction used to read the current value of TSC and store it in a register.
[0087] 5. High-precision hardware clocks are key components in computer systems used to provide accurate time measurements and provide high-precision timestamps. Examples include the TSC in the x86 architecture, the System Counter (SC) in the Advanced Reduced Instruction Set Machine (ARM) architecture, and the Time Base (TB) in the Performance Optimization With Enhanced Reduced Instruction Set Computer-Performance Computing (PowerPC) architecture.
[0088] Below, we will take TSC, a high-precision hardware clock, as an example, combined with... Figure 1 The application scenarios of the exemplary embodiments of this application will be described in detail.
[0089] In container migration scenarios, the container's process state is saved first, and then the process is restored on the new processing node. Because the TSC (Transaction Control Center) of the processing nodes before and after the migration is different, errors may occur after the process is restored. Figure 1 This is a schematic diagram illustrating an application scenario provided for an exemplary embodiment of this application. Please refer to... Figure 1 Before migration, the process reads the hardware time based on TSC101, which increments based on the reference clock frequency of CPU102. After migration, the process reads the hardware time based on TSC103, which increments based on the reference clock frequency of CPU104.
[0090] Taking the decimal value converted from the TSC value as an example, for instance, if a process is in a timed execution state, and the TSC101 value obtained when the process starts executing on CPU102 is 990,000,000,000, when the difference between TSC and 990,000,000,000 is read as 32,000,000,000, the timeout period is met, and the process should terminate execution.
[0091] If the value of TSC101 read by CPU101 before the migration is 1000,000,000,000, and the value of TSC103 read by CPU104 after the migration recovery is 100,000,000,000, then the difference between the currently obtained value of TSC103 and the value of TSC101 obtained at the start of the timer is negative, causing the process to have a timer error and fail to terminate normally.
[0092] Therefore, in related technologies, there is an urgent need for a method to ensure the normal execution of the process after recovery in scenarios where the high-precision hardware clock is inconsistent before and after migration.
[0093] Analysis revealed that Time Namespace can be used to isolate the monotonic time and startup time of a process. Obtaining the monotonic time and startup time involves calling a system method to retrieve the system time from the kernel. In this method, the kernel can adjust the system time using the stored time offset. Therefore, the monotonic time and startup time obtained by the process are the times adjusted by the kernel.
[0094] The above method of adjusting based on Time Namespace is because obtaining monotonic time and startup time involves calling system methods to obtain the system time from the kernel. Therefore, the system time can be adjusted through the kernel.
[0095] Processes operate in two modes: user mode and kernel mode. Processes in user mode can only access limited resources. When a process makes a system call, it switches from user mode to kernel mode for processing. Once the kernel has finished processing, it returns to user mode to continue execution.
[0096] The process reads the high-precision hardware clock through a high-precision hardware clock read instruction. Taking TSC as an example, the process can read TSC through the RDTSC / RDTSCP instruction. In this method, the process is executing in user mode, therefore, the aforementioned method of adjusting time using Time Namespace cannot be directly applied to adjust the TSC. However, since the process recovery is completed in kernel mode, after kernel mode processing, the process will switch from kernel mode to user mode to continue running. Therefore, this embodiment of the application utilizes the switching between user mode and kernel mode of the process to adjust the second high-precision hardware clock based on Time Namespace.
[0097] To address the aforementioned issues, this application provides a time processing method. During process recovery, the process is placed in a time namespace. This namespace records the time difference between the time recorded by the high-precision hardware clock before recovery and the time recorded by the high-precision hardware clock during recovery. When the process switches from kernel mode to user mode, the time recorded by the high-precision hardware clock is adjusted based on this time difference information. In this method, after the process switches to user mode, the time obtained by reading the high-precision hardware clock via instructions is the adjusted time based on the time difference information. This eliminates the difference between the time recorded by the high-precision hardware clock when the process was saved and the time recorded during recovery, ensuring that the logic of the recovered process that relies on the high-precision hardware clock is unaffected and that the process can execute normally.
[0098] It should be understood that the time processing method in this application embodiment can be used in any recovery process scenario. For example, when the cloud desktop cluster is overloaded and some containerized applications are migrated to a less overloaded cloud desktop cluster, the execution entity in the recovery process in the less overloaded cloud desktop cluster can be any virtual computing service node. For example, in the migration of the file system of a local terminal, the execution entity can be a time processing device such as a processor, electronic device, or embedded chip.
[0099] The time processing method described in this specification can also be applied to plugins or scripts for process recovery. For example, a plugin containing a program that implements the time processing method of this application can adjust the time recorded by a high-precision hardware clock. The time processing method described in this specification can also be an operating system kernel. The time processing method of this application is implemented through the operating system kernel based on coding. The following description uses the kernel as the execution subject as an example.
[0100] The technical solutions shown in this application will now be described in detail through specific embodiments. It should be noted that the following embodiments may exist independently or in combination with each other; for identical or similar content, the description will not be repeated in different embodiments.
[0101] Figure 2 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 1 Please see. Figure 2 The methods may include:
[0102] S201. When restoring the first process based on the saved state information of the first process in kernel mode, the restored first process is placed in the first time namespace so as to record the first time difference information through the first time namespace.
[0103] The state information of the first process refers to the information about the first process running before the migration. For example, the state information of the first process includes its identifier, memory state, execution context, etc.
[0104] The first high-precision hardware clock is the high-precision hardware clock in the runtime environment before the first process migrates, that is, the high-precision hardware clock that can be obtained before the first process is restored.
[0105] The second high-precision hardware clock is the high-precision hardware clock in the runtime environment after the first process is migrated, that is, the high-precision hardware clock that can be obtained when the first process resumes.
[0106] The first time difference information is used to indicate the difference between the time recorded by the first high-precision hardware clock when the first process is saved and the time recorded by the second high-precision hardware clock when it is restored.
[0107] The first time namespace is an independent time view that places the first process in the first time namespace and records the first time difference information in the first time namespace. The first time namespace becomes an independent time view of the first process.
[0108] For example, a snapshot file is generated based on a snapshot in the runtime environment before migration. The snapshot file includes the state information of the first process. The snapshot file is packaged, compressed, and transmitted to the new runtime environment for restoration. The kernel reconstructs the first process based on its state information, binds the reconstructed first process to a first time namespace, and determines the first time difference information by subtracting the time t1 recorded by the first high-precision hardware clock corresponding to the first process when it was saved from the time t2 recorded by the second high-precision hardware clock corresponding to the time of restoration. This difference is recorded in the first time namespace.
[0109] S202. When the first process switches from kernel mode to user mode, adjust the time recorded by the second high-precision hardware clock based on the first time difference information.
[0110] For example, after the first process is rebuilt from kernel mode, it will switch from kernel mode to user mode. During this switch, the kernel can adjust the time recorded by the second high-precision hardware clock based on the first time difference information. For instance, the kernel retrieves the first time difference information from the first time namespace, reads the current time recorded by the second high-precision hardware clock, and adjusts the time recorded by the second high-precision hardware clock by adding the first time difference information to the original time. For example, if the first time difference information is t1-t2 and the time recorded by the second high-precision hardware clock is t3, then t3 + (t1-t2) equals the adjusted time recorded by the second high-precision hardware clock.
[0111] The time processing method in this application embodiment restores the first process based on the saved state information of the first process in kernel mode. The restored first process is placed in a first time namespace to record first time difference information. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information. Based on this method, after the first process switches to user mode, the time obtained by reading the second high-precision hardware clock through an instruction is the time adjusted based on the time difference information. This eliminates the difference between the time recorded by the first high-precision hardware clock when the first process is saved and the time recorded by the second high-precision hardware clock when it is restored. This ensures that the logic executed by the restored first process relying on the second high-precision hardware clock is not affected, and that the process can execute normally.
[0112] In the above embodiments, after the first process is restored, when the first process switches from kernel mode to user mode, the kernel can adjust the processor's hardware time based on the first time difference information. Optionally, after that, the kernel can also adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode again.
[0113] For example, when the first process makes a system call or encounters an interrupt or exception during execution, the first process will switch from user mode to kernel mode for processing. Therefore, the kernel can use the switching between user mode and kernel mode of the process to adjust the second high-precision hardware clock.
[0114] For example, when the first process actively makes a system call, the first process switches from kernel mode to user mode. The kernel obtains the first time difference information from the first time namespace, reads the time recorded by the current second high-precision hardware clock, and adjusts the time recorded by the second high-precision hardware clock by adding the first time difference information to the time recorded by the second high-precision hardware clock. For example, if the first time difference information is t1-t2, and the time recorded by the second high-precision hardware clock is t3, then t3+(t1-t2) gives the adjusted time recorded by the second high-precision hardware clock.
[0115] For example, in the event of a CPU interruption or exception, the first process is passively switched from kernel mode to user mode. The kernel obtains the first time difference information from the first time namespace, reads the time recorded by the current second high-precision hardware clock, and uses the first time difference information to adjust the time recorded by the second high-precision hardware clock.
[0116] Optionally, the kernel can recover the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches back from user mode to kernel mode.
[0117] The following is combined with Figure 3 This application describes how the time recorded by the second high-precision hardware clock is adjusted when the first process switches from kernel mode to user mode and from user mode to kernel mode.
[0118] Figure 3 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 2 .like Figure 3 As shown, the following steps may be included:
[0119] S301. When the first process switches from kernel mode to user mode, adjust the time recorded by the second high-precision hardware clock based on the first time difference information.
[0120] For example, the kernel can add a kernel probe at the instruction where the first process enters user mode. When the first process enters user mode, it can trigger adjustment processing based on the added kernel probe, obtain first time difference information from the first namespace, and use the first time difference information to adjust the time recorded by the second high-precision hardware clock.
[0121] S302, When the first process switches from user mode to kernel mode again, restore the time recorded by the second high-precision hardware clock based on the first time difference information.
[0122] For example, the kernel can monitor the state transition of the first process by capturing the system calls of the first process. When the kernel captures the first process making a system call, it obtains the first time difference information from the first namespace and uses the first time difference information to recover the time recorded by the second high-precision hardware clock.
[0123] For example, the kernel can add a kernel probe at the instruction where the first process enters kernel mode to monitor the state transition of the first process. When the first process enters kernel mode, it can trigger recovery processing based on the added kernel probe to restore the time recorded by the second high-precision hardware clock.
[0124] The above example illustrates how, during the switching of the first process's running mode, the time recorded by the second high-precision hardware clock is adjusted to ensure that the time obtained by the first process through the instruction to read the second high-precision hardware clock is the time adjusted based on the time difference information. This eliminates the difference between the time recorded by the second high-precision hardware clock before the first process resumes and the time recorded by the second high-precision hardware clock during the resume, ensuring that the first process can execute normally.
[0125] The following describes how the time processing method of this application embodiment adjusts the time recorded by the second high-precision hardware clock in the case of multi-process concurrency.
[0126] Figure 4This is a schematic diagram illustrating a multi-process state transition as provided in an exemplary embodiment of this application. Please refer to... Figure 4 When the first process makes a system call or experiences an interrupt or exception, it switches from user mode to kernel mode. After processing in kernel mode, the first process returns to user mode. Similarly, after the first process switches from user mode to kernel mode, the second process may also experience a system call, interrupt, or exception. In this case, the second process switches from user mode to kernel mode, and after processing in kernel mode, it returns to user mode.
[0127] The above embodiments can eliminate the difference between the time recorded by the second high-precision hardware clock when the first process is saved and the time recorded by the second high-precision hardware clock when it is restored, so that the restored first process can execute normally. The following explains how to adjust the time recorded by the second high-precision hardware clock for processes other than the first process in a multi-process architecture.
[0128] Optionally, after restoring the time recorded by the second high-precision hardware clock, the kernel can also adjust the time recorded by the second high-precision hardware clock based on the second time difference information recorded in the second time namespace corresponding to the second process when the restored second process switches from kernel mode to user mode.
[0129] The second time difference information is used to indicate the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored.
[0130] The third high-precision hardware clock is the high-precision hardware clock in the runtime environment before the second process migration, that is, the high-precision hardware clock that can be obtained before the second process is restored.
[0131] The running environment after the second process is migrated is the same as the running environment after the first process is migrated. Therefore, the high-precision hardware clock corresponding to the second process when it is restored is the second high-precision hardware clock.
[0132] It should be noted that the time processing steps for the second process can refer to the time processing steps for the first process described above.
[0133] Optionally, the kernel can also restore the time recorded by the second high-precision hardware clock based on the second time difference information recorded in the second time namespace corresponding to the second process when the restored second process switches from user mode to kernel mode.
[0134] Optionally, after restoring the time recorded by the second high-precision hardware clock, the method can also adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode again.
[0135] Below, in conjunction with Figure 5 In the case of multiple processes, the steps for time processing based on the states of the first and second processes are explained. Figure 5 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 3 Please refer to Figure 5 The time processing method may include the following steps:
[0136] S501: When the first process switches from kernel mode to user mode, adjust the time recorded by the second high-precision hardware clock based on the first time difference information.
[0137] During the process of restoring the first process, the first process is created by the kernel. After creation, the first process switches from kernel mode to user mode for execution. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0138] After adjusting the time recorded by the second high-precision hardware clock based on the first time difference information, the first process enters user mode. The first process can read the hardware time through instructions. The hardware time read is the time adjusted based on the first time difference information.
[0139] This method eliminates the difference between the time recorded by the first high-precision hardware clock when the first process is saved and the time recorded by the second high-precision hardware clock when it is restored, ensuring that the first process can be executed normally.
[0140] S502: When the first process switches from user mode to kernel mode again, the time recorded by the second high-precision hardware clock is restored based on the first time difference information.
[0141] If the first process makes a system call, encounters an exception, or experiences an interrupt in user mode, it can switch back to kernel mode. The kernel can then recover the time recorded by the second high-precision hardware clock based on the first time difference information.
[0142] In this method, the time recorded by the second high-precision hardware clock is recovered based on the first time difference information to avoid affecting other second processes from reading the hardware time adjusted based on the first time difference information.
[0143] S503: When the second process switches from kernel mode to user mode, adjust the time recorded by the second high-precision hardware clock based on the second time difference information recorded in the second time namespace corresponding to the second process.
[0144] When the first process switches from user mode to kernel mode, the second process may be executed first. For example, the second process preempts the CPU for processing and executes in kernel mode. After kernel mode execution, the second process switches from kernel mode to user mode. The kernel retrieves the second time difference information from the second time namespace, reads the time recorded by the current second high-precision hardware clock, and adjusts the recorded time by adding the second time difference information to the original recorded time. For example, if the second time difference information is t4 and the recorded time by the second high-precision hardware clock is t5, then t5 plus t4 equals the adjusted recorded time by the second high-precision hardware clock.
[0145] For example, the second process switching from kernel mode to user mode can be triggered by various situations. For instance, the second process may be in the process of recovery, i.e., the second process is recreated in the kernel, and then switches from kernel mode to user mode. For instance, the second process may switch from user mode to kernel mode when it makes a system call, encounters an exception, or is interrupted, and then switch back from kernel mode to user mode after the kernel processing is completed.
[0146] After adjusting the time recorded by the second high-precision hardware clock based on the second time difference information, the second process enters user mode. The second process can read the hardware time through instructions. The hardware time read is the time adjusted based on the second time difference information.
[0147] This method eliminates the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored, ensuring that the second process can be executed normally.
[0148] S504. When the second process switches from user mode to kernel mode, the time recorded by the second high-precision hardware clock is restored based on the second time difference information.
[0149] For example, the kernel can monitor the state transition of the second process by capturing the system calls of the second process. When the kernel captures the second process making a system call, it can obtain the second time difference information from the second namespace and use the second time difference information to recover the time recorded by the second high-precision hardware clock.
[0150] For example, the kernel can add a kernel probe at the instruction where the second process enters kernel mode to monitor the state transition of the second process. When the second process enters kernel mode, it can trigger recovery processing based on the added kernel probe to restore the time recorded by the second high-precision hardware clock.
[0151] S505: When the first process switches from kernel mode to user mode again, adjust the time recorded by the second high-precision hardware clock based on the first time difference information.
[0152] It should be noted that, in Figure 5 The various processing steps (S501-S505) shown in the embodiments can be implemented with reference to the specific implementation of the same or similar steps in the above embodiments. Figure 5 The processing steps shown in the embodiments do not constitute a specific limitation on the time processing procedure. In other embodiments of this application, the processing procedure may include more than Figure 5 The embodiments may include more or fewer steps. For example, the process may include... Figure 5 Some steps in the embodiments, or, Figure 5 Some steps in the embodiments can be replaced by steps with the same function, or Figure 5 Some steps in the embodiments can be broken down into multiple steps, etc.
[0153] In the above steps, during the time period from the end of S501 to the start of S502, and during the time period after the end of S505, the first process in user mode can read the hardware time through instructions. The hardware time read is the time adjusted based on the first time difference information. During the time period from the end of S503 to the start of S504, the second process in user mode can read the hardware time through instructions. The hardware time read is the time adjusted based on the second time difference information.
[0154] The time processing method in this application embodiment adjusts or restores the time recorded by the second high-precision hardware clock based on the first time difference information recorded in the first time namespace when the first process switches between kernel mode and user mode. Similarly, when the second process switches between kernel mode and user mode, it adjusts or restores the time recorded by the second high-precision hardware clock based on the second time difference information recorded in the second time namespace. This ensures that in a multi-process environment, each process can read the hardware time with the differences eliminated, thus ensuring normal execution in a multi-process environment.
[0155] For example, the kernel can adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode, without disabling the first process from using the target instruction.
[0156] The target instruction is used to read the time recorded by a second high-precision hardware clock. For example, an instruction generated based on RDTSC or RDTSCP.
[0157] For example, when the first process is disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a first value; when the first process is not disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a second value.
[0158] The kernel can determine whether the first process is disabled from using the target instruction based on the value of the high-precision hardware clock flag bit in the control register corresponding to the first process.
[0159] The following explanation uses the example of reading the TSC using the RDTSC / RDTSCP instructions under the x86 architecture.
[0160] For example, in the x86 architecture, the CR4 register is a control register. When the high-precision hardware clock flag bit in the control register is set to the second value of 0, the user mode can use the RDTSC / RDTSCP instructions normally. When the high-precision hardware clock flag bit in the control register is set to the first value of 1, the user mode is prohibited from using the RDTSC / RDTSCP instructions. If a process tries to read the data using the RDTSC / RDTSCP instructions, an exception will be triggered. The high-precision hardware clock flag bit in the CR4 register is the bit that sets whether TSC is disabled. The kernel can obtain the value of the high-precision hardware clock flag bit in the CR4 register. When the value of the high-precision hardware clock flag bit in the CR4 register is 0, when the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0161] In this mode, if the system prohibits the use of RDTSC / RDTSCP instructions in user space, the kernel can avoid time processing.
[0162] In the above embodiments, without disabling the first process from using the target instruction, regardless of whether the first process needs to read the second high-precision hardware clock, the kernel will adjust the time recorded by the second high-precision hardware clock based on the first time difference information each time the first process switches from kernel mode to user mode. Optionally, the kernel can determine whether to adjust the time recorded by the second high-precision hardware clock based on whether the first process performs the operation of reading the second high-precision hardware clock.
[0163] According to the above embodiment, when the control register is set to its first value, the RDTSC / RDTSCP instructions are prohibited in user mode. If the first process uses the RDTSC / RDTSCP instructions to read the clock, an exception will be triggered, causing the process to enter the kernel, i.e., a switch from user mode to kernel mode occurs. Therefore, based on this switch state, it can be determined whether the first process performs the operation of reading the second high-precision hardware clock.
[0164] It should be understood that the following embodiments are time processing performed under the premise that the system does not disable the first process from using the target instruction in principle. The settings of the control register described below are for determining whether the first process performs the operation of reading the second high-precision hardware clock. That is, the kernel's settings of the control register are only for determining whether the first process performs the operation of reading the second high-precision hardware clock, and do not mean that the kernel prohibits or does not prohibit the first process from using the target instruction by setting the control register.
[0165] Optionally, when the kernel restores the first process based on the saved state information of the first process in kernel mode, it can set whether to disable the first process from using the target instruction.
[0166] For example, when restoring the first process in kernel mode based on the saved state information of the first process, the kernel disables the first process from using the target instructions. For instance, setting the control register to a first value indicates that the first process is disabled from using the target instructions.
[0167] For example, when the first process is disabled from using the target instruction, the time recorded by the second high-precision hardware clock is maintained when the first process switches from kernel mode to user mode; when the first process switches from user mode to kernel mode due to an exception triggered by using the target instruction, the first process is not disabled from using the target instruction, and the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information when the first process switches from kernel mode to user mode.
[0168] Below, taking the CR4 register as the control register as an example, combined with... Figure 6 Explain how time processing is performed based on the settings of the control register. Figure 6 A flowchart illustrating a time processing method provided for an exemplary embodiment of this application. Figure 4 Please see. Figure 6 This may include the following steps:
[0169] S601. During the process of restoring the first process, the kernel sets the value of the high-precision hardware clock flag bit in the CR4 register to 1.
[0170] For example, the kernel sets the value of the high-precision hardware clock flag bit in the CR4 register to 1, indicating that the first process is prohibited from reading the hardware time in user mode using the RDTSC / RDTSCP instructions.
[0171] S602, The first process uses the RDTSC / RDTSCP instruction to read the hardware time.
[0172] If the value of the high-precision hardware clock flag bit in the CR4 register is set to 1, and the first process uses the RDTSC / RDTSCP instruction to read it, the first process will trigger an exception and switch from user mode to kernel mode.
[0173] S603, Kernel caught an exception, and the first process switched from user mode to kernel mode.
[0174] S604, the kernel sets the value of the high-precision hardware clock flag bit in the CR4 register to 0.
[0175] The kernel sets the value of the high-precision hardware clock flag bit in the CR4 register to 1, indicating that the first process is not prohibited from using the RDTSC / RDTSCP instructions in user mode. After this, the first process can use the RDTSC / RDTSCP instructions to read the hardware time without triggering an exception and can obtain the hardware time.
[0176] S605: When the first process switches from kernel mode to user mode, adjust the time recorded by the second high-precision hardware clock based on the first time difference information.
[0177] S606, the first process uses the RDTSC / RDTSCP instruction again to read the hardware time.
[0178] Based on the S602 first process using the RDTSC / RDTSCP instruction to read the hardware time, an exception is triggered. After the exception is handled in kernel mode and the kernel returns to user mode, the RDTSC / RDTSCP instruction will be used again in user mode to try to read the hardware time, based on the exception handling logic.
[0179] Since the kernel has set the value of the high-precision hardware clock flag bit in the CR4 register to 0, the first process can read the hardware time again using the RDTSC / RDTSCP instruction. The obtained hardware time is the time adjusted based on the first time difference information.
[0180] It should be noted that, in Figure 6 The various processing steps (S601-S606) shown in the embodiments can be implemented with reference to the specific implementation of the same or similar steps in the above embodiments. Figure 6 The processing steps shown in the embodiments do not constitute a specific limitation on the time processing procedure. In other embodiments of this application, the processing procedure may include more than Figure 6 The embodiments may include more or fewer steps. For example, the process may include... Figure 6 Some steps in the embodiments, or, Figure 6 Some steps in the embodiments can be replaced by steps with the same function, or Figure 6 Some steps in the embodiments can be broken down into multiple steps, etc.
[0181] Reference Figure 6As shown in the steps, when the value of the high-precision hardware clock flag bit in the CR4 register is set to 1 in S601, the kernel does not adjust or restore the time recorded by the second high-precision hardware clock between the first process switching between memory mode and user mode. This continues until S602 when the first process uses the RDTSC / RDTSCP instruction to read the hardware time, i.e., it is determined that the first process has performed an operation to read the second high-precision hardware clock. Based on S603 to S605, the time recorded by the second high-precision hardware clock is adjusted. In the time period after S605, the first process can obtain the adjusted hardware time by using the RDTSC / RDTSCP instruction to read the hardware time again.
[0182] It should be understood that during the time period after S605, the kernel adjusts and restores the time recorded by the second high-precision hardware clock according to the above-described time processing method. That is, the kernel can adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode, and restore the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from user mode to kernel mode again.
[0183] Through the above embodiments, the kernel does not adjust the time recorded by the second high-precision hardware clock before the first process reads the hardware time using the RDTSC / RDTSCP instruction. The adjustment is only made after the first process reads the hardware time using the RDTSC / RDTSCP instruction, thus saving system overhead and improving system performance.
[0184] Optionally, the kernel can disable the first process from using the target instruction again without disabling it for a preset duration.
[0185] For example, please refer to Figure 6 The processing steps shown indicate that the kernel can start timing by setting the value of the high-precision hardware clock flag in the CR4 register to 0, and then setting it back to 1 once the preset duration has elapsed. In this mode, the kernel does not adjust the time recorded by the second high-precision hardware clock until the first process uses the RDTSC / RDTSCP instruction to read the hardware time again, triggering an exception.
[0186] Optionally, the kernel can determine whether to disable the first process from using the target instruction based on the frequency with which the first process has historically used the target instruction.
[0187] For example, taking the control of whether to disable the first process from using the target instruction by the value of the high-precision hardware clock flag bit in the CR4 register as an example, the kernel can obtain the frequency of historical use of the target instruction from the log. If the frequency of historical use of the target instruction indicates that the usage frequency is high in any time period, then in this time period, the kernel sets the value of the high-precision hardware clock flag bit in the CR4 register to 0, so that the time recorded by the second high-precision hardware clock can be adjusted in this time period.
[0188] The time processing method in this application embodiment restores the first process based on the saved state information of the first process in kernel mode, places the restored first process in a first time namespace, and records the first time difference information through the first time namespace. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information. Based on the technical solution of this application, after the process switches to user mode, the time obtained by reading the second high-precision hardware clock through the instruction is the time adjusted based on the time difference information, eliminating the difference between the time recorded by the second high-precision hardware clock at the time of saving and the time recorded by the second high-precision hardware clock at the time of restoration, so that the logic executed by the restored process relying on the second high-precision hardware clock is not affected, and the process can be executed normally.
[0189] Accordingly, this application provides a time processing method in which the kernel can respond to the user's migration command, save the state information of the first process through the container runtime interface, migrate the container to the new processing node, restore the first process in kernel mode based on the saved state information of the first process, and execute the method as described in the above embodiment during the restoration process.
[0190] For example, in response to a user's migration command, the kernel can save the state information of the first process through the container runtime interface. This state information may include process identifiers and memory images, etc. The kernel then packages and compresses the state information and transmits it to the new processing node via a secure channel. On the new node, the state information is decompressed and the first process is rebuilt and restored. During the restoration process, the restored first process is placed in a first time namespace to record first time difference information. This first time difference information indicates the difference between the time recorded by the second high-precision hardware clock when the first process was saved and the time recorded by the second high-precision hardware clock when it was restored. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0191] In this approach, the kernel can execute the technical solution shown in the above method embodiments. Its implementation principle and beneficial effects are similar, and will not be repeated here.
[0192] Accordingly, this application provides a time processing system, which includes an operating system kernel. The operating system kernel is used to restore a first process based on the state information of a first process in the container saved before migration, when migrating a container to the system. During the restoration process, the restored first process is placed in a first time namespace to record first time difference information. The first time difference information indicates the difference between the time recorded by a second high-precision hardware clock when the first process was saved and the time recorded by the second high-precision hardware clock when it was restored. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0193] In this approach, the operating system kernel can execute the technical solution shown in the above method embodiments. Its implementation principle and beneficial effects are similar and will not be repeated here.
[0194] Figure 7 A schematic diagram of the structure of a first time processing apparatus provided for an exemplary embodiment of this application. Please refer to... Figure 7 The time processing device 700 may include: a recording module 701 and an adjustment module 702, wherein,
[0195] The recording module 701 is used to place the restored first process in a first time namespace when restoring the first process based on the state information of the first process saved in kernel mode, so as to record the first time difference information through the first time namespace. The first time difference information is used to indicate the difference between the time recorded by the first high-precision hardware clock corresponding to the first process when it is saved and the time recorded by the second high-precision hardware clock corresponding to the first process when it is restored.
[0196] The adjustment module 702 is used to adjust the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode.
[0197] In one possible implementation, after restoring the time recorded by the second high-precision hardware clock, the adjustment module 702 is further configured to:
[0198] When the restored second process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the second time difference information recorded in the second time namespace corresponding to the second process. The second time difference information is used to indicate the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored.
[0199] In one possible implementation, after restoring the time recorded by the second high-precision hardware clock, the adjustment module 702 is further configured to:
[0200] When the first process switches from kernel mode to user mode again, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
[0201] In one possible implementation, the adjustment module 702 is specifically used for:
[0202] Without disabling the use of the target instruction by the first process, when the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information; the target instruction is an instruction for reading the time recorded by the second high-precision hardware clock.
[0203] The first time processing device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0204] Figure 8 A schematic diagram of the structure of a second time processing apparatus provided for an exemplary embodiment of this application. Please refer to... Figure 8 ,exist Figure 7 Based on the illustrated embodiment, the time processing device 700 may further include: a recovery module 801, a setting module 802, and a determining module 803, wherein,
[0205] In one possible implementation, after adjusting the processor's hardware time based on the first time difference information when the first process switches from kernel mode to user mode, the recovery module 801 is specifically used for:
[0206] When the first process switches from user mode to kernel mode again, the time recorded by the second high-precision hardware clock is restored based on the first time difference information.
[0207] In one possible implementation, the setting module 802 is specifically used for:
[0208] When restoring the first process in kernel mode based on the saved state information of the first process, set whether to disable the first process from using the target instruction.
[0209] In one possible implementation, the setting module 802 is specifically used for:
[0210] When the first process is disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a first value;
[0211] Without disabling the first process from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to the second value;
[0212] Accordingly, the determining module 803 is specifically used for:
[0213] Based on the value of the high-precision hardware clock flag bit in the control register corresponding to the first process, it is determined whether the first process is disabled from using the target instruction.
[0214] In one possible implementation, the determining module 803 is further configured to:
[0215] Based on the frequency with which the first process has historically used the target instruction, determine whether to disable the first process from using the target instruction.
[0216] In one possible implementation, the setting module 802 is further configured to:
[0217] When the first process is disabled from using the target instruction, the time recorded by the second high-precision hardware clock is maintained when the first process switches from kernel mode to user mode.
[0218] If the first process switches from user mode to kernel mode due to an exception triggered by using the target instruction, the use of the target instruction by the first process is not disabled, and the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information when the first process switches from kernel mode to user mode.
[0219] In one possible implementation, the setting module 802 is further configured to:
[0220] Without disabling the first process from using the target instruction for a preset duration, disable the first process from using the target instruction again.
[0221] The second time processing device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0222] Figure 9 A schematic diagram of the structure of a third time processing apparatus provided for an exemplary embodiment of this application. Please refer to... Figure 9 The time processing device 900 may include a migration module 901 and a processing module 902, wherein,
[0223] The migration module 901 is used to respond to the user's migration command, save the state information of the first process through the container runtime interface, and migrate the container to the new processing node.
[0224] The processing module 902 is used to restore the first process in kernel mode based on the saved state information of the first process, and during the restoration process, execute the method shown in the above-described time processing method embodiment.
[0225] The third time processing device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0226] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Please refer to... Figure 10 The electronic device 1000 may include a processor 1001 and a memory 1002. Exemplarily, the processor 1001 and the memory 1002 are interconnected via a bus 1003.
[0227] The memory 1002 stores computer-executed instructions;
[0228] The processor 1001 executes the computer execution instructions stored in the memory 1002, causing the processor 1001 to perform the method as shown in the above method embodiment.
[0229] Accordingly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method described in the above-described method embodiments.
[0230] Accordingly, embodiments of this application may also provide a computer program product, including a computer program, which, when executed by a processor, can implement the methods shown in the above-described method embodiments.
[0231] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0232] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0233] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0234] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0235] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0236] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0237] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0238] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0239] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A time processing method, characterized in that, The method includes: When restoring the first process in kernel mode based on the saved state information of the first process, the restored first process is placed in a first time namespace to record first time difference information. The first time difference information is used to indicate the difference between the time recorded by the first high-precision hardware clock corresponding to the first process when it was saved and the time recorded by the second high-precision hardware clock corresponding to the first process when it was restored. The first high-precision hardware clock is the high-precision hardware clock in the runtime environment before the first process was migrated; the second high-precision hardware clock is the high-precision hardware clock in the runtime environment after the first process was migrated. When the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
2. The method according to claim 1, characterized in that, After adjusting the processor's hardware time based on the first time difference information when the first process switches from kernel mode to user mode, the method further includes: When the first process switches from user mode to kernel mode again, the time recorded by the second high-precision hardware clock is restored based on the first time difference information.
3. The method according to claim 2, characterized in that, After restoring the time recorded by the second high-precision hardware clock, the method further includes: When the restored second process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the second time difference information recorded in the second time namespace corresponding to the second process. The second time difference information is used to indicate the difference between the time recorded by the third high-precision hardware clock when the second process is saved and the time recorded by the second high-precision hardware clock when it is restored.
4. The method according to claim 2, characterized in that, After restoring the time recorded by the second high-precision hardware clock, the method further includes: When the first process switches from kernel mode to user mode again, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information.
5. The method according to any one of claims 1-4, characterized in that, The step of adjusting the time recorded by the second high-precision hardware clock based on the first time difference information when the first process switches from kernel mode to user mode includes: Without disabling the use of the target instruction by the first process, when the first process switches from kernel mode to user mode, the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information; the target instruction is an instruction for reading the time recorded by the second high-precision hardware clock.
6. The method according to claim 5, characterized in that, The method further includes: When restoring the first process in kernel mode based on the saved state information of the first process, set whether to disable the first process from using the target instruction.
7. The method according to claim 6, characterized in that, Whether the setting disables the first process from using the target instruction includes: When the first process is disabled from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to a first value; Without disabling the first process from using the target instruction, the high-precision hardware clock flag bit of the control register corresponding to the first process is set to the second value; The method further includes: Based on the value of the high-precision hardware clock flag bit in the control register corresponding to the first process, it is determined whether the first process is disabled from using the target instruction.
8. The method according to claim 6, characterized in that, The method further includes: Based on the frequency with which the first process has historically used the target instruction, determine whether to disable the first process from using the target instruction.
9. The method according to claim 5, characterized in that, The method further includes: When the first process is disabled from using the target instruction, the time recorded by the second high-precision hardware clock is maintained when the first process switches from kernel mode to user mode. If the first process switches from user mode to kernel mode due to an exception triggered by using the target instruction, the use of the target instruction by the first process is not disabled, and the time recorded by the second high-precision hardware clock is adjusted based on the first time difference information when the first process switches from kernel mode to user mode.
10. The method according to claim 9, characterized in that, The method further includes: Without disabling the first process from using the target instruction for a preset duration, disable the first process from using the target instruction again.
11. A time processing method, characterized in that, The method includes: In response to the user's migration command, the container is migrated to the new processing node by saving the state information of the first process through the container runtime interface. The first process is restored in kernel mode based on the saved state information of the first process. During the restoration process, the method described in any one of claims 1-10 is executed.
12. A time processing system, characterized in that, The system includes: an operating system kernel; The operating system kernel is configured to restore the first process based on the state information of the first process in the container saved before the migration when the container is migrated to the system, and to execute the method described in any one of claims 1-10 during the restoration process.
13. An electronic device, characterized in that, include: At least one processor; as well as A memory that is communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, cause the electronic device to perform the method according to any one of claims 1-10.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, implement the method as described in any one of claims 1-10.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-10.
Citation Information
Patent Citations
Time synchronization method and device of system on chip, equipment and storage medium
CN118964282A
Techniques for generating unique identifiers for tracking process activity
US20240202134A1