# US 12,217,073 B2 · Method, an apparatus, an electronic device, and a storage medium for detecting virtual machine load

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,217,073 B2
- Document ID: US12217073B2
- Status: Granted
- Kind: B2
- Application number: 18/677,805
- Filed: 2024-05-29
- Published: 2024-12-05
- Granted: 2025-02-04
- Earliest claimed: 2023-06-01
- Assignees: Beijing Volcano Engine Technology Co., Ltd.
- Applicants: Beijing Volcano Engine Technology Co., Ltd.
- Inventors: Yang Zhang; Zhimin Feng
- Web page: https://patentgrep.com/patent/US12217073B2

## CPC

- G06F 9/45533: {Hypervisors; Virtual machine monitors}
- G06F 11/3423: {where the assessed time is active or idle time}
- G06F 9/30101: {Special purpose registers}
- G06F 9/3851: {from multiple instruction streams, e.g. multistreaming}
- G06F 9/505: {considering the load}
- G06F 11/3419: {by assessing time}
- G06F 11/3433: {for load management (allocation of a server based on load conditions G06F9/505; load rebalancing G06F9/5083; redistributing the load in a network by a load balancer H04L67/1029)}
- Y02D 10/00: Energy efficient computing, e.g. low power processors, power management or thermal management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- Y02D: CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE

## Abstract

Embodiments of the disclosure provide a method, an apparatus, an electronic device, and a storage medium for detecting virtual machine load. The method include: acquiring a virtual processor thread corresponding to a target virtual machine, wherein the virtual processor thread is an exclusive thread of the target virtual machine; acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used for executing a task request of the target virtual machine, and the first occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the target virtual machine; and obtaining a running load of the target virtual machine according to a proportion of the first occupation duration in the first detection period.

## Claims

### Claim 1

A method for detecting virtual machine load, comprising:
acquiring a virtual processor thread corresponding to a target virtual machine, wherein the virtual processor thread is an exclusive thread of the target virtual machine;
acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used for executing a task request of the target virtual machine, and the first occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the target virtual machine; and
obtaining a running load of the target virtual machine according to a proportion of the first occupation duration in the first detection period.

### Claim 2 (depends on 1)

The method of claim 1, wherein the acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period comprises:
after the first detection period is started, acquiring a first state value at a first moment before the virtual processor thread is detected to enter the guest mode, wherein the first state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the first moment;
acquiring a second state value at a second moment after the virtual processor thread is detected to exit the guest mode, wherein the second state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the second moment; and
obtaining, according to a difference between the second state value and the first state value, the first occupation duration of the virtual processor thread in the guest mode within the first detection period.

### Claim 3 (depends on 2)

The method of claim 2, wherein the acquiring a first state value at a first moment before the virtual processor thread is detected to enter the guest mode comprises:
in response to a first instruction for entering the guest mode being detected, reading a first exclusive register of the virtual processor thread to obtain the first state value, wherein the first exclusive register is used for recording the real-time accumulated number of clock periods of the virtual processor thread in the running state after an operating system is started; and
wherein the acquiring a second state value at a second moment after the virtual processor thread is detected to exit the guest mode comprises:
in response to a second instruction for exiting the guest mode is detected, reading the first exclusive register of the virtual processor thread to obtain the second state value.

### Claim 4 (depends on 3)

The method of claim 3, wherein the first exclusive register is an MSR_IA32_MPERF register.

### Claim 5 (depends on 2)

The method of claim 2, wherein the obtaining, according to the difference between the second state value and the first state value, the first occupation duration of the virtual processor thread in the guest mode within the first detection period comprises:
obtaining a first running duration according to 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, wherein the second exclusive register is used for accumulating the first running duration to generate a second running duration; and
after the first detection period ends, reading the second running duration in the second exclusive register, to obtain the first occupation duration of the virtual processor thread in the guest mode within the first detection period.

### Claim 6 (depends on 2)

The method of claim 2, further comprising:
reading, at the first moment, a third exclusive register of the virtual processor thread to obtain a first number of clock periods, wherein the third exclusive register is used for recording the real-time cumulated number of clock periods of the virtual processor thread after the operating system is started;
reading, at the second moment, the third exclusive register of the virtual processor thread to obtain a second number of clock periods; and
obtaining an actual detection period based on a difference between the second number of clock periods and the first number of clock periods;
wherein the obtaining a running load of the target virtual machine according to the proportion of the first occupation duration in the first detection period comprises:
obtaining the running load of the target virtual machine according to a ratio of the first occupation duration to the actual detection period.

### Claim 7 (depends on 1)

The method of claim 1, wherein the acquiring a first occupation duration of the virtual processor thread in the guest mode within a first detection period comprises:
during the first detection period, obtaining at least two occupation sub-durations, wherein the occupation sub-durations represent durations in which the virtual processor thread is in a state of executing a task request of the target virtual machine during the virtual processor thread being in the guest mode only once; and
obtaining the occupation duration according to a weighted sum of the at least two occupation sub-durations, wherein a weighted coefficient corresponding to the occupation sub-duration is related to the time when the guest mode corresponding to the occupation sub-duration is entered.

### Claim 8 (depends on 1)

The method of claim 1, further comprising:
acquiring a second occupation duration of the virtual processor thread in a host mode within the first detection period, wherein the virtual processor thread in the host mode is used for executing a task request of a physical machine, and the second occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the physical machine; and
obtaining a running load of a virtualization layer corresponding to the target virtual machine according to a proportion of the second occupation duration in the first detection period.

### Claim 9 (depends on 8)

The method of claim 8, wherein the acquiring a second occupation duration of the virtual processor thread in the host mode within the first detection period comprises:
after the first detection period is started, acquiring a third state value at a third moment after the virtual processor thread is detected to exit the guest mode, wherein the third state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the third moment;
acquiring a fourth state value at a fourth moment before the virtual processor thread is detected to enter the guest mode, wherein the fourth state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the fourth moment; and
obtaining, according to a difference between the fourth state value and the third state value, the second occupation duration of the virtual processor thread in the host mode within the first detection period.

### Claim 10

An electronic device, comprising: a processor, and a memory communicatively connected with the processor;
the memory storing a computer execution instruction; and
the processor executing the computer executable instruction stored in the memory, to implement acts comprising:
acquiring a virtual processor thread corresponding to a target virtual machine, wherein the virtual processor thread is an exclusive thread of the target virtual machine;
acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used for executing a task request of the target virtual machine, and the first occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the target virtual machine; and
obtaining a running load of the target virtual machine according to a proportion of the first occupation duration in the first detection period.

### Claim 11 (depends on 10)

The electronic device of claim 10, wherein the acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period comprises:
after the first detection period is started, acquiring a first state value at a first moment before the virtual processor thread is detected to enter the guest mode, wherein the first state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the first moment;
acquiring a second state value at a second moment after the virtual processor thread is detected to exit the guest mode, wherein the second state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the second moment; and
obtaining, according to a difference between the second state value and the first state value, the first occupation duration of the virtual processor thread in the guest mode within the first detection period.

### Claim 12 (depends on 11)

The electronic device of claim 11, wherein the acquiring a first state value at a first moment before the virtual processor thread is detected to enter the guest mode comprises:
in response to a first instruction for entering the guest mode being detected, reading a first exclusive register of the virtual processor thread to obtain the first state value, wherein the first exclusive register is used for recording the real-time accumulated number of clock periods of the virtual processor thread in the running state after an operating system is started; and
wherein the acquiring a second state value at a second moment after the virtual processor thread is detected to exit the guest mode comprises:
in response to a second instruction for exiting the guest mode is detected, reading the first exclusive register of the virtual processor thread to obtain the second state value.

### Claim 13 (depends on 12)

The electronic device of claim 12, wherein the first exclusive register is an MSR_IA32_MPERF register.

### Claim 14 (depends on 11)

The electronic device of claim 11, wherein the obtaining, according to the difference between the second state value and the first state value, the first occupation duration of the virtual processor thread in the guest mode within the first detection period comprises:
obtaining a first running duration according to 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, wherein the second exclusive register is used for accumulating the first running duration to generate a second running duration; and
after the first detection period ends, reading the second running duration in the second exclusive register, to obtain the first occupation duration of the virtual processor thread in the guest mode within the first detection period.

### Claim 15 (depends on 11)

The electronic device of claim 11, further comprising:
reading, at the first moment, a third exclusive register of the virtual processor thread to obtain a first number of clock periods, wherein the third exclusive register is used for recording the real-time cumulated number of clock periods of the virtual processor thread after the operating system is started;
reading, at the second moment, the third exclusive register of the virtual processor thread to obtain a second number of clock periods; and
obtaining an actual detection period based on a difference between the second number of clock periods and the first number of clock periods;
wherein the obtaining a running load of the target virtual machine according to the proportion of the first occupation duration in the first detection period comprises:
obtaining the running load of the target virtual machine according to a ratio of the first occupation duration to the actual detection period.

### Claim 16 (depends on 10)

The electronic device of claim 10, wherein the acquiring a first occupation duration of the virtual processor thread in the guest mode within a first detection period comprises:
during the first detection period, obtaining at least two occupation sub-durations, wherein the occupation sub-durations represent durations in which the virtual processor thread is in a state of executing a task request of the target virtual machine during the virtual processor thread being in the guest mode only once; and
obtaining the occupation duration according to a weighted sum of the at least two occupation sub-durations, wherein a weighted coefficient corresponding to the occupation sub-duration is related to the time when the guest mode corresponding to the occupation sub-duration is entered.

### Claim 17 (depends on 10)

The electronic device of claim 10, further comprising:
acquiring a second occupation duration of the virtual processor thread in a host mode within the first detection period, wherein the virtual processor thread in the host mode is used for executing a task request of a physical machine, and the second occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the physical machine; and
obtaining a running load of a virtualization layer corresponding to the target virtual machine according to a proportion of the second occupation duration in the first detection period.

### Claim 18 (depends on 17)

The electronic device of claim 17, wherein the acquiring a second occupation duration of the virtual processor thread in the host mode within the first detection period comprises:
after the first detection period is started, acquiring a third state value at a third moment after the virtual processor thread is detected to exit the guest mode, wherein the third state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the third moment;
acquiring a fourth state value at a fourth moment before the virtual processor thread is detected to enter the guest mode, wherein the fourth state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the fourth moment; and
obtaining, according to a difference between the fourth state value and the third state value, the second occupation duration of the virtual processor thread in the host mode within the first detection period.

### Claim 19

A non-transitory computer readable storage medium, wherein the computer readable storage medium stores a computer executable instruction, the computer executable instruction, when executed by a processor, implementing the method comprising:
acquiring a virtual processor thread corresponding to a target virtual machine, wherein the virtual processor thread is an exclusive thread of the target virtual machine;
acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period, wherein the virtual processor thread in the guest mode is used for executing a task request of the target virtual machine, and the first occupation duration represents a duration in which the virtual processor thread is in a state of executing the task request of the target virtual machine; and
obtaining a running load of the target virtual machine according to a proportion of the first occupation duration in the first detection period.

### Claim 20 (depends on 19)

The non-transitory computer readable storage medium of claim 19, wherein the acquiring a first occupation duration of the virtual processor thread in a guest mode within a first detection period comprises:
after the first detection period is started, acquiring a first state value at a first moment before the virtual processor thread is detected to enter the guest mode, wherein the first state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the first moment;
acquiring a second state value at a second moment after the virtual processor thread is detected to exit the guest mode, wherein the second state value represents the accumulated number of clock periods of the virtual processor thread in a running state at the second moment; and
obtaining, according to a difference between the second state value and the first state value, the first occupation duration of the virtual processor thread in the guest mode within the first detection period.
