Virtual Machine Load Detection Method, Device, Electronic Device and Storage Medium
By obtaining the duration and proportion of the VM's exclusive thread in guest mode, the problem that the exclusive thread virtual machine cannot detect the load is solved, and high-accurate virtual machine load detection is achieved.
Patent Information
- Application Number
- CN202310645315.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-01
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2043-06-01
AI Technical Summary
In the prior art, virtual machines targeting exclusive threads cannot realize out-of-band detection of virtual machine load, resulting in the inability to accurately manage and monitor the operating status of virtual machines.
By obtaining the occupied duration of the target virtual machine's exclusive thread in guest mode, combining the proportion of the occupied duration in the detection cycle, the running load of the virtual machine is calculated, the resource overhead of the virtualization layer is eliminated, and the detection accuracy is improved.
It realizes load detection of exclusive threaded virtual machines, improves detection accuracy and real-timeness, and can truly reflect the operating status of the virtual machine.
Smart Images

Figure CN116627592B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of virtual machine technology, and in particular to a virtual machine load detection method, device, electronic device, and storage medium. Background Art
[0002] A virtual machine (VM) is a complete computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. Cloud service providers create VM instances through physical machine clusters to provide users with VMs with different computing capabilities.
[0003] The running load of a virtual machine is one of the important indicators for managing and monitoring the virtual machine. In the existing technology, out-of-band detection of the virtual machine load is usually achieved by detecting the halt instruction that indicates that the virtual machine has entered the idle state, thereby calculating the running load of the virtual machine.
[0004] However, for a virtual machine with an exclusive thread, since a halt instruction cannot be obtained, it leads to the problem that the running load of the virtual machine cannot be detected out of band. Summary of the Invention
[0005] Embodiments of the present disclosure provide a virtual machine load detection method, device, electronic device, and storage medium to overcome the problem that out-of-band detection of virtual machine load cannot be implemented for virtual machines with dedicated threads.
[0006] In a first aspect, an embodiment of the present disclosure provides a method for detecting a virtual machine load, comprising:
[0007] Obtain a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine; obtain a first occupancy time of the virtual processor thread in guest mode within a first detection cycle, wherein the virtual processor thread in guest mode is used to execute a task request of the target virtual machine, and the first occupancy time represents a length of time that the virtual processor thread is in a state of executing the task request of the target virtual machine; and obtain an operating load of the target virtual machine based on the first occupancy time and a proportion within the first detection cycle.
[0008] In a second aspect, an embodiment of the present disclosure provides a virtual machine load detection device, comprising:
[0009] An acquisition module is used to acquire a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine;
[0010] a processing module, configured to obtain a first occupancy duration of the virtual processor thread in the guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used to execute the task request of the target virtual machine, and the first occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the target virtual machine;
[0011] A detection module is used to obtain the operating load of the target virtual machine according to the first occupancy time and the proportion in the first detection period.
[0012] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:
[0013] a processor, and a memory communicatively connected to the processor;
[0014] The memory stores computer-executable instructions;
[0015] The processor executes the computer-executable instructions stored in the memory to implement the virtual machine load detection method as described in the first aspect and various possible designs of the first aspect.
[0016] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the virtual machine load detection method described in the first aspect and various possible designs of the first aspect is implemented.
[0017] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the virtual machine load detection method described in the first aspect and various possible designs of the first aspect.
[0018] The virtual machine load detection method, apparatus, electronic device, and storage medium provided in this embodiment obtain a virtual processor thread corresponding to a target virtual machine, the virtual processor thread being a dedicated thread of the target virtual machine; obtain a first occupancy time of the virtual processor thread in guest mode during a first detection period, wherein the virtual processor thread in guest mode is used to execute a task request of the target virtual machine, and the first occupancy time represents the length of time the virtual processor thread is in a state of executing the task request of the target virtual machine; and obtain the target virtual machine's operating load based on the first occupancy time and its proportion within the first detection period. By obtaining the first occupancy time of the target virtual machine's virtual processor thread in guest mode and determining the target virtual machine's operating load based on the proportion of the first occupancy time within the first detection period, the target virtual machine's operating load is determined based on the proportion of the virtual processor thread's occupied time in guest mode. This solves the problem of being unable to perform out-of-band virtual machine load detection for dedicated threads of the virtual machine; and, because the calculation is based on the first occupancy time corresponding to the guest mode, the time consumption caused by resource overhead of the virtualization layer is eliminated, thereby improving the accuracy of load detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0020] Figure 1 A diagram of an application scenario of the virtual machine load detection method provided in an embodiment of the present disclosure;
[0021] Figure 2 Schematic diagram of the virtual machine load detection method provided in the embodiment of the present disclosure Figure 1 ;
[0022] Figure 3 A schematic diagram of an execution process of a virtual processor thread provided by an embodiment of the present disclosure;
[0023] Figure 4 for Figure 2 A flowchart of a specific implementation method of step S102 in the embodiment shown;
[0024] Figure 5 A schematic diagram of an occupancy sub-duration provided in an embodiment of the present disclosure;
[0025] Figure 6Schematic diagram of the process of the virtual machine load detection method provided in the embodiment of the present disclosure Figure 2 ;
[0026] Figure 7 A schematic diagram of a process for obtaining a first state value and a second state value provided in an embodiment of the present disclosure;
[0027] Figure 8 for Figure 6 A flowchart of a specific implementation method of step S204 in the embodiment shown;
[0028] Figure 9 for Figure 6 A flowchart of a specific implementation method of step S206 in the embodiment shown;
[0029] Figure 10 A structural block diagram of a virtual machine load detection device provided in an embodiment of the present disclosure;
[0030] Figure 11 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure;
[0031] Figure 12 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0032] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure more clear, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present disclosure without making any creative efforts shall fall within the scope of protection of the present disclosure.
[0033] 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, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0034] The following explains the application scenarios of the embodiments of the present disclosure:
[0035] Figure 1 This is an application scenario diagram of the virtual machine load detection method provided by the embodiment of the present disclosure. The virtual machine load detection method provided by the embodiment of the present disclosure can be applied to application scenarios such as virtual machine load management and virtual machine status query. Specifically, Figure 1 As shown, the method provided by the embodiment of the present disclosure can be applied to a physical machine cluster corresponding to a virtual machine, hereinafter referred to as a physical machine server, wherein the physical machine server is configured with a data processor (Data Processing Unit, DPU) based on the X86 architecture, and the data processor has network capabilities and general computing capabilities, and can assist the central processing unit (Central Processing Unit, CPU) in network load, as well as data detection and processing. Therefore, in other possible implementations, the method provided by the embodiment of the present disclosure can also be directly applied to the data processor. Taking a physical machine server configured with a data processor as an example, the physical machine server further configures multiple virtual machines through virtual machine management software, wherein each virtual machine is an instance created by the physical machine server through the central processing unit, corresponding to one or more threads in the physical machine server, and each thread serves as a virtual processor (VCPU) of the virtual machine, wherein the exclusive virtual machine has an exclusive thread provided by the physical machine server, that is, the thread is not shared with other virtual machines. On the user side, on the one hand, the user can log in to the authorized virtual machine through the terminal device and configure and manage the virtual machine, so that the virtual machine can realize the corresponding functions, such as providing website services, application services, etc. On the other hand, users can obtain the operating load of authorized virtual machines by sending a query request to the physical machine server, that is, out-of-band detection of the virtual machine operating load. The physical machine server (or the data processor within the physical machine server) obtains the operating load of the configured virtual machine through the virtual machine load detection method provided by the embodiment of the present disclosure, and provides a corresponding query interface, which the user can access through a terminal device. The query interface provided by the physical machine server implements out-of-band detection of the virtual machine operating load.
[0036] In the prior art, for out-of-band detection of virtual machine load, for virtual machines that share threads, the halt instruction is usually detected in the virtualization layer of the physical server (to achieve sharing of thread resources). The halt instruction is used to put the virtual processor of the virtual machine into an idle state, and then the idle ratio of the virtual processor is calculated to achieve the calculation of the virtual machine's running load. However, for virtual machines that exclusively share threads, since there is no need to share thread resources, the virtualization layer no longer intercepts the halt instruction of the virtual machine, which results in the problem of being unable to achieve out-of-band detection of the virtual machine's running load. The embodiments of the present disclosure provide a virtual machine load detection method to solve the above problems.
[0037] refer to Figure 2 , Figure 2 Schematic diagram of the virtual machine load detection method provided in the embodiment of the present disclosure Figure 1The method of this embodiment can be applied to a physical server. The virtual machine load detection method includes:
[0038] Step S101: obtaining a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine.
[0039] For example, refer to Figure 1 As shown in the schematic diagram of the application scenario, the execution subject of the virtual machine load detection method provided by the embodiment of the present disclosure can be a physical machine server. The physical machine server creates one or more virtual machine instances based on the configuration information, including the target virtual machine as the detection object in this embodiment. Among them, the virtual machine instance includes one or more virtual processors, and the virtual processor is a virtual processor thread provided by the physical machine server, that is, the target virtual machine corresponds to one or more virtual processor threads. Among them, the solution provided by this embodiment is applicable to exclusive virtual machines, that is, the virtual processor thread corresponding to the target virtual machine is an exclusive thread allocated by the physical machine server to the target virtual machine, and even in an idle state, the thread resource will not be shared with other virtual machines.
[0040] Specifically, when the physical machine server needs to detect the running load of the target virtual machine, it can obtain one or more virtual processor threads corresponding to the target virtual machine based on the identification identifier of the target virtual machine. The identification identifier of the target virtual machine and the thread identifier of the virtual processor thread have a preset mapping relationship. The mapping relationship is generated when the target virtual machine is created and will not be repeated here.
[0041] Step S102: Obtain a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle, wherein the virtual processor thread in the guest mode is used to execute the task request of the target virtual machine, and the first occupancy time represents the length of time the virtual processor thread is in a state of executing the task request of the target virtual machine.
[0042] Exemplarily, after locating the virtual processor thread corresponding to the target virtual machine, the virtual processor thread is cyclically detected based on a fixed detection period, thereby achieving continuous real-time detection of the target virtual machine's operating load. More specifically, the detection period is, for example, 1 second, 10 seconds, etc., that is, the virtual processor thread is detected at a detection period of 1 second or 10 seconds. The same detection steps are performed in each detection period, and the first detection period is a detection period for detecting the virtual processor thread.
[0043] Furthermore, based on the implementation principle of the virtual machine, the virtual processor thread will alternately be in the guest mode (GUEST) and host mode (HOST) states. The above two modes are mainly used to isolate operation permissions and ensure the operational security of the physical machine server. Therefore, the virtual processor thread has different operation permissions in different modes and uses the corresponding operation permissions to complete the corresponding functions. When the virtual processor thread enters the guest mode, the virtual processor thread executes the task request of the target virtual machine, more specifically, the code and instructions of the virtual machine system of the target virtual machine. When the virtual processor thread enters the host mode, the virtual processor thread executes the task request of the physical machine, that is, the code and instructions of the physical machine system. By switching between the above host mode and guest mode, permission isolation is achieved to ensure the operational security of the physical machine. The specific implementation methods of the above host mode and guest mode are existing technologies and will not be repeated here.
[0044] Furthermore, when the virtual processor thread enters the access mode, it will be in one of two possible states, namely idle or running. When the virtual processor thread is in the state of executing the task request of the target virtual machine, the virtual processor thread is in the running state; conversely, when the virtual processor thread is in the state of not executing the task request of the target virtual machine, the virtual processor thread is in the idle state. According to the specific task request of the target virtual machine, the virtual processor thread will continue to stay and switch between the two states until the mode switching condition is triggered. For example, when the task request of the target virtual machine needs to call the internal function of the physical machine to implement, the virtual processor thread will leave the guest mode and enter the host mode with better permissions, and execute the task request of the corresponding physical machine to implement the corresponding function. In this process, the total time that the virtual processor thread is in the running state in the guest mode is the first occupancy time. In the steps of this embodiment, by counting the first occupancy time in the guest mode and then using the first occupancy time to obtain the running load of the target virtual machine, the time consumption caused by executing the instructions of the virtualization layer in the host mode is eliminated. Therefore, the running load of the target virtual machine finally obtained can truly reflect the actual load on the target virtual machine side, thereby improving the accuracy of load detection.
[0045] Figure 3 A schematic diagram of the execution process of a virtual processor thread provided by an embodiment of the present disclosure is shown in FIG. Figure 3As shown, after a virtual processor thread enters guest mode from host mode, it continuously stays and switches between the idle state and the running state, and the virtual processor thread records the cumulative stay time in each state. Afterwards, the virtual processor thread leaves guest mode, enters host mode to execute the task request of the physical machine, and then re-enters guest mode, repeating the above process. During this cyclic process, the cumulative stay time recorded by the virtual processor thread in each state is continuously accumulated until the end of the first detection cycle. Based on the cumulative time recorded by the virtual processor thread in the running state, the first occupancy time is obtained, i.e., the length of time the virtual processor thread is in the state of executing the task request of the target virtual machine.
[0046] In one possible implementation, Figure 4 As shown, the specific implementation of step S102 includes:
[0047] Step S1021: in the first detection cycle, obtaining at least two occupancy sub-durations, where the occupancy sub-durations represent the duration of time that the virtual processor thread is in a state of executing a task request of the target virtual machine during a single time in the guest mode.
[0048] Step S1022: Obtaining an occupation duration according to a weighted sum of at least two occupation sub-durations, wherein a weighting coefficient corresponding to the occupation sub-duration is related to the time of entering the visitor mode corresponding to the occupation sub-duration.
[0049] For example, refer to Figure 3 The schematic diagram of the execution process of the virtual processor thread shown in the figure shows that during the first detection cycle, each time the virtual processor thread enters the guest mode, the accumulated time the virtual processor thread stays in the running state is calculated, i.e., the occupancy sub-time. After multiple cycles of entering and leaving the guest mode, multiple occupancy sub-times are obtained, and the total occupancy time is obtained by summing them. Among them, the weighting coefficient corresponding to the occupancy sub-time is related to the time of entering the guest mode corresponding to the occupancy sub-time, that is, the closer the time of entering the guest mode corresponding to the occupancy sub-time is to the current time, the larger the weighting coefficient; in other words, the farther the time of entering the guest mode corresponding to the occupancy sub-time is from the current time, the smaller the weighting coefficient. Figure 5 A schematic diagram of an occupancy sub-duration provided in an embodiment of the present disclosure, such as Figure 5As shown, during the first detection cycle, as the virtual processor thread enters guest mode multiple times, multiple occupancy sub-durations are obtained. As shown in the reference figure, the virtual processor thread enters guest mode for the first time at time p1, leaves guest mode at time p2, and enters host mode. During this entry into guest mode, the cumulative time in run mode is A seconds, i.e., sub-occupancy duration A is obtained (shown as A in the figure); similarly, the virtual processor thread enters guest mode for the first time at time p3 and leaves guest mode at time p4, corresponding to sub-occupancy duration B (shown as B in the figure); the virtual processor thread enters guest mode for the first time at time p5 and leaves guest mode at time p6, corresponding to sub-occupancy duration C (shown as C in the figure). The first detection cycle then ends at time p7. Based on the distance between the starting point (p1, p3, p5) or the ending point (p2, p3, p6) of each virtual processor thread entering the guest mode and the time p7, the corresponding weighting coefficient is obtained. For example, as shown in the figure, the weighting coefficient corresponding to the sub-occupancy duration A is 0.2, the weighting coefficient corresponding to the sub-occupancy duration B is 0.3, and the weighting coefficient corresponding to the sub-occupancy duration C is 0.5. Finally, the sub-occupancy duration A, the sub-occupancy duration B and the sub-occupancy duration C are weighted and summed to obtain the first occupation duration = 0.2A + 0.3B + 0.5C. Among them, the specific method for determining the weighting coefficient can be set as needed based on the time distance that is inversely proportional to the weighting coefficient, and the specific calculation method is not limited here. Among them, the time distance is the distance between the time of entering the guest mode or the time of leaving the guest mode and the current time.
[0050] In this embodiment, by calculating the sub-occupancy times corresponding to multiple entries into the visitor mode and performing weighted calculation based on the time distance corresponding to the sub-occupancy times, the weight of the sub-occupancy times close to the current moment can be increased, thereby improving the real-time and accuracy of the operating load obtained based on the occupancy time.
[0051] Step S103: Obtain the operating load of the target virtual machine according to the first occupancy duration and the proportion in the first detection period.
[0052] For example, after obtaining a first occupied duration representing the total cumulative time that a virtual processor thread is in a running state, the proportion of the target virtual machine's virtual processor thread that is in a running state, i.e., the target virtual machine's virtual processor occupancy rate, can be obtained based on the proportion of the first occupied duration in the first detection period. For example, if the first detection period is 2 seconds, and the first occupied duration is divided by the base frequency of the virtual processor thread to obtain a first actual occupied duration of 1 second, then the virtual processor thread occupancy rate is 1 / 2, i.e., 50%.
[0053] Furthermore, based on the occupancy rate of the virtual processors of the target processor, the target virtual machine's operating load can be obtained. Furthermore, when the target virtual machine has multiple virtual processors, the occupancy rate corresponding to each virtual processor can be obtained through the above steps. The operating load of the target virtual machine can then be further calculated by further processing the occupancy rate of each virtual processor, such as calculating the average occupancy rate of multiple virtual processors or selecting the maximum occupancy rate of multiple virtual processors.
[0054] Furthermore, in one possible implementation, the target virtual machine's virtual processor occupancy rate can be directly used as the target virtual machine's operating load. In another possible implementation, the target virtual machine's virtual processor occupancy rate can be further combined with other resources, such as memory usage resources and network bandwidth resources, to perform a weighted calculation to obtain the target virtual machine's operating load. This can be set as needed and will not be further described here.
[0055] In this embodiment, a virtual processor thread corresponding to a target virtual machine is obtained, where the virtual processor thread is a dedicated thread of the target virtual machine; a first occupancy time of the virtual processor thread in guest mode during a first detection period is obtained, wherein the virtual processor thread in guest mode is used to execute the task request of the target virtual machine, and the first occupancy time represents the length of time the virtual processor thread is in a state of executing the task request of the target virtual machine; and the operating load of the target virtual machine is obtained based on the first occupancy time and its proportion within the first detection period. By obtaining the first occupancy time of the virtual processor thread in guest mode and determining the operating load of the target virtual machine based on the proportion of the first occupancy time within the first detection period, the purpose of determining the operating load of the virtual machine based on the proportion of the occupied time of the virtual processor thread in guest mode is achieved. On the one hand, the problem of being unable to perform out-of-band detection of the virtual machine load for a virtual machine with a dedicated thread is solved. On the other hand, because the calculation is performed based on the first occupancy time corresponding to the guest mode, the time consumption caused by the resource overhead of the virtualization layer is eliminated, thereby improving the accuracy of load detection.
[0056] refer to Figure 6 , Figure 6 Schematic diagram of the process of the virtual machine load detection method provided in the embodiment of the present disclosure Figure 2 In this embodiment Figure 2 Based on the embodiment shown, step S102 is further refined, and the virtual machine load detection method includes:
[0057] Step S201: Acquire a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine.
[0058] Step S202: After the first detection cycle begins, at a first moment before detecting that the virtual processor thread enters the guest mode, a first state value is obtained, where the first state value represents the number of clock cycles that the virtual processor thread has been in the running state at the first moment.
[0059] Step S203: At a second moment after detecting that the virtual processor thread leaves the guest mode, a second state value is obtained, where the second state value represents the number of clock cycles that the virtual processor thread has been in the running state at the second moment.
[0060] Exemplarily, after the start of the first detection cycle, at the first moment before the virtual processor thread enters the guest mode, a count value representing the number of clock cycles that the virtual processor thread has been in the running state at the current (first moment) is obtained, that is, a first state value. The first state value can be stored in a register corresponding to the virtual processor thread, and the first state value is obtained by reading the register. Correspondingly, at the second moment after the virtual processor thread is detected to have left the guest mode, a count value representing the number of clock cycles that the virtual processor thread has been in the running state at the current (second moment) is obtained by reading the content in the same register. In addition to the usual method of reading the register mentioned above, the first state value and the second state value can also be obtained by other means, such as accessing a pre-running timing service, program, etc., which are not specifically limited here.
[0061] More specifically, exemplarily, the method provided in this embodiment can be run on a CPU platform based on the X86 architecture, that is, the physical machine provides a virtual processor thread for the virtual machine through the CPU of the X86 architecture. In this application scenario, exemplarily, the specific implementation of step S202 includes: when the first instruction for entering the guest mode is detected, the first exclusive register of the virtual processor thread is read to obtain a first state value, wherein the first exclusive register is used to record the real-time cumulative number of clock cycles of the virtual processor thread in the running state after the operating system is started. Correspondingly, the specific implementation of step S203 includes: when the second instruction for leaving the guest mode is detected, the first exclusive register of the virtual processor thread is read to obtain a second state value.
[0062] For example, a CPU based on the X86 architecture provides a series of registers (MSRs) that are exclusively used by the CPU core (per-CPU), i.e., exclusive registers. The first exclusive register in this embodiment is the MSR_IA32_MPERF register. This register can record the cumulative total time that the virtual processor thread (CPU core) has been in the C0 state (i.e., running state) since the operating system was started. This cumulative total time is expressed in clock cycles, i.e., the cumulative total time is divided by the base frequency of the CPU core to obtain the corresponding actual running time.
[0063] Figure 7 A schematic diagram of a process for obtaining a first state value and a second state value provided by an embodiment of the present disclosure is shown as follows: Figure 7 As shown, when a first instruction for entering guest mode (shown as sched_in in the figure) is detected, the MSR_IA32_MPERF register of the virtual processor thread is read to obtain a corresponding first state value (shown as Mperf1 in the figure). After that, the virtual processor thread enters guest mode, executes the task request of the target virtual machine, and is correspondingly in a running state (shown as C0 in the figure) or an idle state (shown as Cx in the figure). Thereafter, when a second instruction for leaving guest mode (shown as sched_out in the figure) is detected, the MSR_IA32_MPERF register of the virtual processor thread is read again to obtain a corresponding second state value (shown as Mperf2 in the figure).
[0064] Step S204: obtaining a first occupancy time of the virtual processor thread in the guest mode during the first detection period according to the difference between the second state value and the first state value.
[0065] For example, after obtaining the second state value and the first state value, based on the difference between the second state value and the first state value, the first occupancy time of the virtual processor thread in the guest mode during a single time in the guest mode can be obtained, that is, Figure 4 In the illustrated embodiment, if more than one sub-occupancy duration is obtained in the first detection cycle, that is, the virtual processor thread is in the guest mode multiple times, then the corresponding sub-occupancy duration is obtained based on the difference between the second state value and the first state value obtained after each exit from the guest mode, and the multiple sub-occupancy durations are added together to obtain the first occupancy duration of the virtual processor thread in the guest mode during the first detection cycle.
[0066] In one possible implementation, Figure 8 As shown, illustratively, the specific implementation of step S204 includes:
[0067] Step S2041: Obtain a first running time according to the difference between the second state value and the first state value, and write the first running time into a second exclusive register of the virtual processor thread. The second exclusive register is used to accumulate the first running time to generate a second running time.
[0068] Step S2042: After the first detection cycle ends, read the second running time in the second exclusive register to obtain the first occupancy time of the virtual processor thread in the guest mode during the first detection cycle.
[0069] Exemplarily, each time the virtual processor thread leaves the access mode and obtains the second state value, the second state value is subtracted from the first state value obtained when entering the access mode to obtain the first running time, i.e., the sub-occupancy time, and the first running time is written into the second exclusive register of the virtual processor thread. The second exclusive register is used to accumulate the first running time to generate the second running time after the first detection cycle ends. Specifically, for example, after the virtual processor thread leaves the guest mode for the first time, the difference between the second state value and the first state value is calculated to obtain the first running time t1, and the second running time is written into the second exclusive register for accumulation. At this time, the second running time in the second exclusive register = t1; similarly, after the virtual processor thread leaves the guest mode for the second time, the difference between the second state value and the first state value is calculated to obtain the first running time t2, and the second running time is written into the second exclusive register for accumulation. At this time, the second running time in the second exclusive register = t1 + t2. The above steps are executed in a loop until the first detection cycle ends, and the second running time in the second exclusive register is read, for example, t1+t2+…+tn, as the first occupancy time of the virtual processor thread in the guest mode during the first detection cycle.
[0070] Optionally, the method provided in this embodiment further includes:
[0071] Step S205: at a first moment, read the third exclusive register of the virtual processor thread to obtain a first clock cycle number, where the third exclusive register is used to record the real-time accumulated clock cycle number of the virtual processor thread after the operating system is started.
[0072] Step S206: At the second moment, read the third exclusive register of the virtual processor thread to obtain a second clock cycle number.
[0073] Step S207: obtaining an actual detection period based on the difference between the second clock cycle number and the first clock cycle number.
[0074] For example, after the start of the first detection cycle, at the first moment before the virtual processor thread enters guest mode, in addition to obtaining the first state value representing the cumulative number of clock cycles in the running state of the virtual processor thread at the first moment, the third exclusive register of the virtual processor thread is read to obtain the first clock cycle number. The third exclusive register is used to record the real-time cumulative number of clock cycles of the virtual processor thread after the operating system is started. Specifically, the third exclusive register is a timestamp counter that records the cumulative number of clock cycles consumed since the virtual processor thread (CPU core) was started. Therefore, the obtained first clock cycle number represents a timestamp of the virtual processor thread at the current moment (the first moment). Similarly, at the second moment after the virtual processor thread leaves guest mode, the third exclusive register of the virtual processor thread is read to obtain a second clock cycle number, representing another timestamp of the virtual processor thread at the current moment (the second moment). Afterwards, based on the difference between the second clock cycle number and the first clock cycle number, the actual consumption time of the virtual processor thread in the guest mode is obtained. Furthermore, when the virtual processor thread enters and leaves the access mode multiple times within the first detection cycle, an actual consumption time can be obtained each time it leaves the access mode. By adding up the actual consumption time obtained after each exit from the access mode, the total detection time for the guest mode, that is, the actual detection cycle, can be obtained.
[0075] Step S208: Obtain the operating load of the target virtual machine according to the ratio of the first occupancy time to the actual detection period.
[0076] After obtaining the first occupied time and the actual detection period, the operating load of the target virtual machine can be obtained based on the ratio of the first occupied time and the actual detection period. The specific implementation method is the same as Figure 2 The implementation process of step S103 in the illustrated embodiment is similar and will not be repeated here. It should be noted that the actual detection period is expressed based on the number of clock cycles, which is the same as the representation of the first occupied duration. Therefore, the operating load of the target virtual machine can be obtained by directly calculating the ratio of the first occupied duration to the actual detection period.
[0077] In this embodiment, the actual detection period is obtained by synchronously reading the third exclusive register at the first moment and the second moment, and the actual running load of the target virtual machine is calculated based on the ratio of the first occupancy time and the actual detection period. Compared with the method of directly using the first occupancy time and the period length of the first detection period for calculation, the influence of the time consumption of the virtualization layer on the total detection time is eliminated, and thus the accuracy of the running load can be further improved.
[0078] Optionally, the method provided in this embodiment further includes:
[0079] Step S209: Obtain a second occupancy time of the virtual processor thread in the host mode during the first detection cycle, wherein the virtual processor thread in the host mode is used to execute the task request of the physical machine, and the second occupancy time represents the time length that the virtual processor thread is in the state of executing the task request of the physical machine.
[0080] For example, in this embodiment, during the first detection cycle, while calculating the target virtual machine's operating load by detecting the first occupancy duration of the virtual processor thread in guest mode, the second occupancy duration of the virtual processor thread in host mode is also detected, i.e., the duration during which the virtual processor thread is executing a task requested by the physical machine. This allows for detection of the operating load of the virtualization layer on the physical machine.
[0081] For example, Figure 9 As shown, the specific implementation of step S209 includes:
[0082] Step S2091: After the first detection cycle starts, at a third time after detecting that the virtual processor thread leaves the guest mode, a third state value is obtained, where the third state value represents the number of clock cycles that the virtual processor thread has been in the running state at the third time.
[0083] Step S2092: At a fourth moment before detecting that the virtual processor thread enters the guest mode, a fourth state value is obtained, where the fourth state value represents the number of clock cycles that the virtual processor thread has been in the running state at the fourth moment.
[0084] Step S2093: Obtain a second occupancy time of the virtual processor thread in the host mode within the first detection period according to the difference between the fourth state value and the third state value.
[0085] For example, refer to Figure 7 The process diagram of obtaining the first state value and the second state value is shown in the figure. At the third moment after detecting that the virtual processor thread leaves the guest mode, a third state value representing the number of clock cycles accumulated by the virtual processor thread in the running state at the third moment is obtained, wherein the third moment can be Figure 7The second moment in the corresponding embodiment is the same, and the method for obtaining the third state value can be the same as the method for obtaining the second state value (reading the first exclusive register). Therefore, the third state value can be the same as the second state value. Afterwards, when the first instruction is detected next time, that is, at the fourth moment before the virtual processor thread is detected to enter the guest mode, the fourth state value is obtained. The fourth state value is obtained in the same way as the first state value (reading the first exclusive register), and will not be repeated. Afterwards, the fourth state value is subtracted from the third state value to obtain the second occupancy time of the virtual processor thread in the host mode during the first detection cycle. The second occupancy time is the running time consumed by the virtual processor thread in the virtualization layer of the physical machine.
[0086] Step S210: Obtain the operating load of the virtualization layer corresponding to the target virtual machine according to the proportion of the second occupancy duration in the first detection period.
[0087] For example, the operating load of the virtualization layer corresponding to the target virtual machine can be obtained by calculating the proportion of the second occupancy duration within the first detection period. The specific implementation method is similar to the process of calculating the operating load of the target virtual machine in step S103 and is not repeated here. It should be noted that the method for calculating the second occupancy duration can refer to the method for calculating the first occupancy duration in steps S202-S204 above and is not repeated here.
[0088] In this embodiment, by calculating the proportion of the second occupancy time in the first detection period, the operating load of the virtualization layer corresponding to the target virtual machine is obtained, and the operating load calculation of the virtual machine layer located on the physical machine side corresponding to the target virtual machine is realized, thereby realizing a multi-dimensional virtual machine operating load query function and improving the efficiency of virtual machine management and configuration.
[0089] In this embodiment, the implementation of step S201 is the same as that of the present disclosure. Figure 2 The implementation of step S101 in the illustrated embodiments is the same and will not be described in detail here.
[0090] Corresponding to the virtual machine load detection method of the above embodiment, Figure 10 This is a structural block diagram of a virtual machine load detection device provided by an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Figure 10 , the virtual machine load detection device 3 includes:
[0091] An acquisition module 31 is configured to acquire a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is a dedicated thread of the target virtual machine.
[0092] a processing module 32 configured to obtain a first occupancy duration of a virtual processor thread in guest mode during a first detection period, wherein the virtual processor thread in guest mode is used to execute a task request of a target virtual machine, and the first occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the target virtual machine;
[0093] The detection module 33 is configured to obtain the operating load of the target virtual machine according to the first occupancy duration and the proportion in the first detection period.
[0094] In one embodiment of the present disclosure, the processing module 32 is specifically configured to: after the start of a first detection cycle, at a first moment before detecting that the virtual processor thread enters the guest mode, obtain a first state value, the first state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the first moment; at a second moment after detecting that the virtual processor thread leaves the guest mode, obtain a second state value, the second state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the second moment; and obtain a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle based on the difference between the second state value and the first state value.
[0095] In one embodiment of the present disclosure, when the processing module 32 obtains the first status value at the first moment before detecting that the virtual processor thread enters the guest mode, the processing module 32 is specifically used to: when detecting the first instruction for entering the guest mode, read the first exclusive register of the virtual processor thread to obtain the first status value, wherein the first exclusive register is used to record the real-time accumulated number of clock cycles of the virtual processor thread in the running state after the operating system is started; when the processing module 32 obtains the second status value at the second moment after detecting that the virtual processor thread leaves the guest mode, the processing module 32 is specifically used to: when detecting the second instruction for leaving the guest mode, read the first exclusive register of the virtual processor thread to obtain the second status value.
[0096] In one embodiment of the present disclosure, the first exclusive register is the MSR_IA32_MPERF register.
[0097] In one embodiment of the present disclosure, when the processing module 32 obtains the first occupancy time of the virtual processor thread in the guest mode during the first detection cycle based on the difference between the second state value and the first state value, it is specifically used to: obtain the first running time based on the difference between the second state value and the first state value, and write the first running time into the second exclusive register of the virtual processor thread, the second exclusive register being used to accumulate the first running time to generate the second running time; after the first detection cycle ends, read the second running time in the second exclusive register to obtain the first occupancy time of the virtual processor thread in the guest mode during the first detection cycle.
[0098] In one embodiment of the present disclosure, the processing module 32 is further used to: at a first moment, read the third exclusive register of the virtual processor thread to obtain a first clock cycle number, where the third exclusive register is used to record the real-time accumulated clock cycle number of the virtual processor thread after the operating system is started; at a second moment, read the third exclusive register of the virtual processor thread to obtain a second clock cycle number; and obtain an actual detection period based on the difference between the second clock cycle number and the first clock cycle number; the detection module 33 is specifically used to: obtain the running load of the target virtual machine based on the ratio of the first occupancy time and the actual detection period.
[0099] In one embodiment of the present disclosure, the processing module 32 is specifically configured to: obtain at least two occupancy sub-durations within a first detection cycle, where the occupancy sub-duration represents the duration of time that the virtual processor thread is in a state of executing a task request of a target virtual machine during a single time in guest mode; and obtain the occupancy duration based on a weighted sum of the at least two occupancy sub-durations, where a weighting coefficient corresponding to the occupancy sub-duration is related to the time of entering the guest mode corresponding to the occupancy sub-duration.
[0100] In one embodiment of the present disclosure, the processing module 32 is further used to: obtain a second occupancy time of the virtual processor thread in the host mode within the first detection cycle, wherein the virtual processor thread in the host mode is used to execute the task request of the physical machine, and the second occupancy time represents the time length during which the virtual processor thread is in the state of executing the task request of the physical machine; the detection module 33 is further used to: obtain the running load of the virtualization layer corresponding to the target virtual machine based on the proportion of the second occupancy time in the first detection cycle.
[0101] In one embodiment of the present disclosure, when obtaining the second occupancy time of the virtual processor thread in the host mode within the first detection cycle, the processing module 32 is specifically used to: after the start of the first detection cycle, at a third moment after detecting that the virtual processor thread leaves the guest mode, obtain a third state value, the third state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the third moment; at a fourth moment before detecting that the virtual processor thread enters the guest mode, obtain a fourth state value, the fourth state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the fourth moment; and obtain the second occupancy time of the virtual processor thread in the host mode within the first detection cycle based on the difference between the fourth state value and the third state value.
[0102] The acquisition module 31, processing module 32 and detection module 33 are connected in sequence. The virtual machine load detection 3 provided in this embodiment can implement the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0103] Figure 11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure is shown in FIG. Figure 11 As shown, the electronic device 4 includes:
[0104] A processor 41, and a memory 42 communicatively connected to the processor 41;
[0105] Memory 42 stores computer-executable instructions;
[0106] The processor 41 executes the computer execution instructions stored in the memory 42 to implement the following Figure 2-Figure 9 The virtual machine load detection method in the illustrated embodiment.
[0107] Optionally, the processor 41 and the memory 42 are connected via a bus 43 .
[0108] For related instructions, please refer to Figure 2-Figure 9 The relevant descriptions and effects corresponding to the steps in the corresponding embodiments can be understood, and no further details are given here.
[0109] The present invention provides a computer-readable storage medium that stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the computer-executable instructions are used to implement the present invention. Figure 2-Figure 9 The virtual machine load detection method provided in any one of the corresponding embodiments.
[0110] The present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the following Figure 2-Figure 9 The virtual machine load detection method in the illustrated embodiment.
[0111] refer to Figure 12 , which shows a schematic structural diagram of an electronic device 900 suitable for implementing the embodiments of the present disclosure. The electronic device 900 may be a terminal device or a server. The terminal device may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 12 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.
[0112] like Figure 12As shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 into a random access memory (RAM) 903. Various programs and data required for the operation of the electronic device 900 are also stored in the RAM 903. The processing device 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0113] Typically, the following devices may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 12 The electronic device 900 is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.
[0114] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network via the communication device 909, or installed from the storage device 908, or installed from the ROM 902. When the computer program is executed by the processing device 901, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.
[0115] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0116] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0117] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0118] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0119] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0120] The units involved in the embodiments described in this disclosure may be implemented in software or hardware. In some cases, the name of a unit does not limit the unit itself. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses."
[0121] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0122] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0123] In a first aspect, according to one or more embodiments of the present disclosure, a method for detecting a virtual machine load is provided, comprising:
[0124] Obtain a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine; obtain a first occupancy time of the virtual processor thread in guest mode within a first detection cycle, wherein the virtual processor thread in guest mode is used to execute a task request of the target virtual machine, and the first occupancy time represents a length of time that the virtual processor thread is in a state of executing the task request of the target virtual machine; and obtain an operating load of the target virtual machine based on the first occupancy time and a proportion within the first detection cycle.
[0125] According to one or more embodiments of the present disclosure, obtaining the first occupancy duration of the virtual processor thread in guest mode during a first detection cycle includes: obtaining a first status value at a first moment after the start of the first detection cycle and before detecting that the virtual processor thread enters guest mode, the first status value representing the cumulative number of clock cycles that the virtual processor thread is in a running state at the first moment; obtaining a second status value at a second moment after detecting that the virtual processor thread leaves guest mode, the second status value representing the cumulative number of clock cycles that the virtual processor thread is in a running state at the second moment; and obtaining the first occupancy duration of the virtual processor thread in guest mode during the first detection cycle based on the difference between the second status value and the first status value.
[0126] According to one or more embodiments of the present disclosure, obtaining a first status value at a first moment before detecting that the virtual processor thread enters guest mode includes: upon detecting a first instruction for entering guest mode, reading a first exclusive register of the virtual processor thread to obtain the first status value, wherein the first exclusive register is used to record the real-time accumulated number of clock cycles in which the virtual processor thread is in a running state after the operating system is started; obtaining a second status value at a second moment after detecting that the virtual processor thread leaves guest mode includes: upon detecting a second instruction for leaving guest mode, reading the first exclusive register of the virtual processor thread to obtain the second status value.
[0127] According to one or more embodiments of the present disclosure, the first exclusive register is the MSR_IA32_MPERF register.
[0128] According to one or more embodiments of the present disclosure, obtaining the first occupancy duration of the virtual processor thread in guest mode during the first detection cycle based on the difference between the second state value and the first state value includes: obtaining a first running duration based on the difference between the second state value and the first state value, and writing the first running duration into a second exclusive register of the virtual processor thread, the second exclusive register being used to accumulate the first running duration to generate a second running duration; after the first detection cycle ends, reading the second running duration in the second exclusive register to obtain the first occupancy duration of the virtual processor thread in guest mode during the first detection cycle.
[0129] According to one or more embodiments of the present disclosure, the method further includes: at the first moment, reading the third exclusive register of the virtual processor thread to obtain a first clock cycle number, wherein the third exclusive register is used to record the real-time accumulated clock cycle number of the virtual processor thread after the operating system is started; at the second moment, reading the third exclusive register of the virtual processor thread to obtain a second clock cycle number; obtaining an actual detection period based on the difference between the second clock cycle number and the first clock cycle number; obtaining the running load of the target virtual machine based on the first occupancy time and the proportion in the first detection period, including: obtaining the running load of the target virtual machine based on the ratio of the first occupancy time and the actual detection period.
[0130] According to one or more embodiments of the present disclosure, obtaining the first occupancy duration of the virtual processor thread in the guest mode during the first detection cycle includes: obtaining at least two occupancy sub-durations during the first detection cycle, the occupancy sub-durations representing the time duration that the virtual processor thread is in a state of executing the task request of the target virtual machine during a single time in the guest mode; obtaining the occupancy duration based on a weighted sum of the at least two occupancy sub-durations, wherein the weighting coefficient corresponding to the occupancy sub-duration is related to the time of entering the guest mode corresponding to the occupancy sub-duration.
[0131] According to one or more embodiments of the present disclosure, the method further includes: obtaining a second occupancy time of the virtual processor thread in host mode within a first detection cycle, wherein the virtual processor thread in the host mode is used to execute a task request of a physical machine, and the second occupancy time represents the time length during which the virtual processor thread is in a state of executing the task request of the physical machine; and obtaining the operating load of the virtualization layer corresponding to the target virtual machine based on the proportion of the second occupancy time in the first detection cycle.
[0132] According to one or more embodiments of the present disclosure, obtaining the second occupancy duration of the virtual processor thread in host mode during the first detection cycle includes: after the start of the first detection cycle, at a third moment after detecting that the virtual processor thread leaves the guest mode, obtaining a third state value, the third state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the third moment; obtaining a fourth state value at a fourth moment before detecting that the virtual processor thread enters the guest mode, the fourth state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the fourth moment; and obtaining the second occupancy duration of the virtual processor thread in host mode during the first detection cycle based on the difference between the fourth state value and the third state value.
[0133] In a second aspect, according to one or more embodiments of the present disclosure, a virtual machine load detection device is provided, comprising:
[0134] An acquisition module is used to acquire a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine;
[0135] a processing module, configured to obtain a first occupancy duration of the virtual processor thread in the guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used to execute the task request of the target virtual machine, and the first occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the target virtual machine;
[0136] A detection module is used to obtain the operating load of the target virtual machine according to the first occupancy time and the proportion in the first detection period.
[0137] According to one or more embodiments of the present disclosure, the processing module is specifically used to: obtain a first state value at a first moment after the start of the first detection cycle and before detecting that the virtual processor thread enters the guest mode, the first state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the first moment; obtain a second state value at a second moment after detecting that the virtual processor thread leaves the guest mode, the second state value representing the cumulative number of clock cycles that the virtual processor thread is in the running state at the second moment; and obtain a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle based on the difference between the second state value and the first state value.
[0138] According to one or more embodiments of the present disclosure, when the processing module obtains the first status value at the first moment before detecting that the virtual processor thread enters the guest mode, the processing module is specifically used to: when detecting the first instruction for entering the guest mode, read the first exclusive register of the virtual processor thread to obtain the first status value, wherein the first exclusive register is used to record the real-time accumulated number of clock cycles of the virtual processor thread in the running state after the operating system is started; when the processing module obtains the second status value at the second moment after detecting that the virtual processor thread leaves the guest mode, the processing module is specifically used to: when detecting the second instruction for leaving the guest mode, read the first exclusive register of the virtual processor thread to obtain the second status value.
[0139] According to one or more embodiments of the present disclosure, the first exclusive register is the MSR_IA32_MPERF register.
[0140] According to one or more embodiments of the present disclosure, when the processing module obtains the first occupancy duration of the virtual processor thread in the guest mode during the first detection cycle based on the difference between the second state value and the first state value, the processing module is specifically used to: obtain the first running duration based on the difference between the second state value and the first state value, and write the first running duration into the second exclusive register of the virtual processor thread, the second exclusive register being used to accumulate the first running duration to generate the second running duration; after the first detection cycle ends, read the second running duration in the second exclusive register to obtain the first occupancy duration of the virtual processor thread in the guest mode during the first detection cycle.
[0141] According to one or more embodiments of the present disclosure, the processing module is further used to: at the first moment, read the third exclusive register of the virtual processor thread to obtain a first clock cycle number, and the third exclusive register is used to record the real-time accumulated clock cycle number of the virtual processor thread after the operating system is started; at the second moment, read the third exclusive register of the virtual processor thread to obtain a second clock cycle number; based on the difference between the second clock cycle number and the first clock cycle number, obtain an actual detection cycle; the detection module is specifically used to: obtain the running load of the target virtual machine according to the ratio of the first occupancy time and the actual detection cycle.
[0142] According to one or more embodiments of the present disclosure, the processing module is specifically configured to: obtain at least two occupancy sub-durations within the first detection cycle, where the occupancy sub-durations represent the duration of time that the virtual processor thread is in a state of executing a task request of the target virtual machine during a single time in guest mode; obtain the occupancy duration based on a weighted sum of at least two of the occupancy sub-durations, wherein a weighting coefficient corresponding to the occupancy sub-duration is related to the time of entering the guest mode corresponding to the occupancy sub-duration.
[0143] According to one or more embodiments of the present disclosure, the processing module is further used to: obtain the second occupancy time of the virtual processor thread in the host mode within the first detection cycle, wherein the virtual processor thread in the host mode is used to execute the task request of the physical machine, and the second occupancy time represents the time length during which the virtual processor thread is in the state of executing the task request of the physical machine; the detection module is further used to: obtain the running load of the virtualization layer corresponding to the target virtual machine based on the proportion of the second occupancy time in the first detection cycle.
[0144] According to one or more embodiments of the present disclosure, when obtaining the second occupancy time of the virtual processor thread in the host mode within the first detection cycle, the processing module is specifically used to: after the start of the first detection cycle, at a third moment after detecting that the virtual processor thread leaves the guest mode, obtain a third state value, the third state value representing the cumulative number of clock cycles of the virtual processor thread in the running state at the third moment; at a fourth moment before detecting that the virtual processor thread enters the guest mode, obtain a fourth state value, the fourth state value representing the cumulative number of clock cycles of the virtual processor thread in the running state at the fourth moment; and obtain the second occupancy time of the virtual processor thread in the host mode within the first detection cycle based on the difference between the fourth state value and the third state value.
[0145] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0146] The memory stores computer-executable instructions;
[0147] The processor executes the computer-executable instructions stored in the memory to implement the virtual machine load detection method as described in the first aspect and various possible designs of the first aspect.
[0148] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When the processor executes the computer execution instructions, the virtual machine load detection method described in the first aspect and various possible designs of the first aspect is implemented.
[0149] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the virtual machine load detection method described in the first aspect and various possible designs of the first aspect.
[0150] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also includes other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.
[0151] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details have been included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0152] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.
Claims
1. A virtual machine load detection method, characterized in that: include: Obtaining a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine; Obtaining a first occupancy duration of the virtual processor thread in the guest mode within a first detection cycle, wherein the virtual processor thread in the guest mode is used to execute a task request of the target virtual machine, and the first occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the target virtual machine; The operating load of the target virtual machine is obtained according to the first occupancy time and the proportion in the first detection period.
2. The method according to claim 1, characterized in that The obtaining of a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle includes: After the first detection cycle begins and at a first moment before detecting that the virtual processor thread enters the guest mode, obtaining a first state value, the first state value representing a cumulative number of clock cycles that the virtual processor thread is in a running state at the first moment; At a second moment after detecting that the virtual processor thread leaves the guest mode, obtaining a second state value, the second state value representing a cumulative number of clock cycles in which the virtual processor thread is in a running state at the second moment; A first occupancy time of the virtual processor thread in the guest mode during the first detection period is obtained according to a difference between the second state value and the first state value.
3. The method according to claim 2, characterized in that The obtaining of a first state value at a first moment before detecting that the virtual processor thread enters the guest mode includes: When a first instruction for entering guest mode is detected, reading a first exclusive register of the virtual processor thread to obtain the first state value, wherein the first exclusive register is used to record the real-time accumulated clock cycles of the virtual processor thread in the running state after the operating system is started; The acquiring a second state value at a second moment after detecting that the virtual processor thread leaves the guest mode includes: When a second instruction for leaving the guest mode is detected, the first exclusive register of the virtual processor thread is read to obtain the second state value.
4. The method according to claim 3, characterized in that The first exclusive register is the MSR_IA32_MPERF register.
5. The method according to claim 2, characterized in that The obtaining, according to the difference between the second state value and the first state value, a first occupancy time of the virtual processor thread in the guest mode during the first detection period includes: Obtaining a first running time according to a difference between the second state value and the first state value, and writing the first running time into a second exclusive register of the virtual processor thread, where the second exclusive register is used to accumulate the first running time to generate a second running time; After the first detection cycle ends, the second running time in the second exclusive register is read to obtain a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle.
6. The method according to claim 2, characterized in that The method further comprises: At the first moment, reading a third exclusive register of the virtual processor thread to obtain a first clock cycle number, the third exclusive register being used to record a real-time accumulated clock cycle number of the virtual processor thread after the operating system is started; At the second moment, reading a third exclusive register of the virtual processor thread to obtain a second clock cycle number; Obtaining an actual detection period based on a difference between the second clock cycle number and the first clock cycle number; The obtaining, according to the first occupancy duration and the proportion within the first detection period, the operating load of the target virtual machine includes: The operating load of the target virtual machine is obtained according to the ratio of the first occupancy time to the actual detection period.
7. The method according to claim 1, characterized in that The obtaining of a first occupancy time of the virtual processor thread in the guest mode during the first detection cycle includes: In the first detection cycle, at least two occupancy sub-durations are obtained, where the occupancy sub-durations represent a duration during which the virtual processor thread is in a state of executing a task request of the target virtual machine during a single time of being in guest mode; The occupied duration is obtained according to a weighted sum of at least two of the occupied sub-durations, wherein the weighted coefficient corresponding to the occupied sub-duration is related to the time of entering the visitor mode corresponding to the occupied sub-duration.
8. The method according to claim 1, characterized in that The method further comprises: Obtaining a second occupancy duration of the virtual processor thread in the host mode within the first detection cycle, wherein the virtual processor thread in the host mode is used to execute a task request of the physical machine, and the second occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the physical machine; The operating load of the virtualization layer corresponding to the target virtual machine is obtained according to the proportion of the second occupancy time in the first detection period.
9. The method according to claim 8, characterized in that The obtaining of a second occupancy time of the virtual processor thread in the host mode during the first detection cycle includes: After the first detection cycle begins, at a third moment after detecting that the virtual processor thread leaves the guest mode, obtaining a third state value, the third state value representing a cumulative number of clock cycles that the virtual processor thread is in a running state at the third moment; At a fourth moment before detecting that the virtual processor thread enters the guest mode, obtaining a fourth state value, the fourth state value representing a cumulative number of clock cycles in which the virtual processor thread is in a running state at the fourth moment; A second occupancy time of the virtual processor thread in the host mode within the first detection period is obtained according to a difference between the fourth state value and the third state value.
10. A virtual machine load detection device, characterized in that: include: An acquisition module is used to acquire a virtual processor thread corresponding to a target virtual machine, where the virtual processor thread is an exclusive thread of the target virtual machine; a processing module, configured to obtain a first occupancy duration of the virtual processor thread in the guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used to execute the task request of the target virtual machine, and the first occupancy duration represents a duration during which the virtual processor thread is in a state of executing the task request of the target virtual machine; A detection module is used to obtain the operating load of the target virtual machine according to the first occupancy time and the proportion in the first detection period.
11. An electronic device, characterized in that: include: a processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the virtual machine load detection method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the virtual machine load detection method according to any one of claims 1 to 9 is implemented.
13. A computer program product, characterized in that The invention comprises a computer program, which implements the virtual machine load detection method according to any one of claims 1 to 9 when executed by a processor.
Citation Information
Patent Citations
Virtual machine hot upgrade method, host device and storage medium
CN113296802A
Load adjustment method and device, electronic equipment and storage medium
CN114564313A