CN108255572A - A kind of VCPU switching methods and physical host - Google Patents
A kind of VCPU switching methods and physical host Download PDFInfo
- Publication number
- CN108255572A CN108255572A CN201611245500.7A CN201611245500A CN108255572A CN 108255572 A CN108255572 A CN 108255572A CN 201611245500 A CN201611245500 A CN 201611245500A CN 108255572 A CN108255572 A CN 108255572A
- Authority
- CN
- China
- Prior art keywords
- vcpu
- queues
- run
- busy
- selection
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The embodiment of the invention discloses a kind of VCPU switching methods and physical hosts.The physical host includes at least one VCPU queues, each VCPU queue includes at least one VCPU, and at least one VCPU queues are managed by least one thread;The method includes:The state of the first VCPU is preserved, the first VCPU is currently running VCPU;It is VCPU to be run that the 2nd VCPU, the 2nd VCPU are determined from the VCPU queues where the first VCPU;Restore the state of the 2nd VCPU.The technical solution that the embodiment of the present invention is provided is omitted the process of conventional VCPU toggle midlines journey switching, so as to save a large amount of time loss, improves VCPU switching efficiencies.
Description
Technical field
The present invention relates to computer virtualized technology field more particularly to a kind of VCPU switching methods and physical host.
Background technology
Virtualization refers on the physical devices, by segmentation spatially and temporal timesharing and simulation, by physical machine
A resource on device is abstracted into more parts.Virtual machine (Virtual Machine) is the independent virtual meter provided by virtualization layer
Calculation machine system, each virtual machine are owned by the virtual hardware of oneself, including CPU, memory and IO (Input/Output, input/defeated
Go out) equipment etc., by the simulation of virtualization layer, virtual machine is exactly a true physical equipment in upper layer software (applications).
Virtualization layer is commonly referred to as monitor of virtual machine (Virtual Machine Monitor, VMM).It is virtualized in VMM
During machine hardware resource, CPU virtualizations are a mostly important links.CPU virtually turns to each virtual machine creating
One or more VCPU (Virtual CPU, i.e. VCPU), multiple VCPU time-sharing multiplexes/spatial reuse physical cpus.VMM is more
A VCPU distribution times piece/space and the state for safeguarding all VCPU need to switch when timeslice/space of a VCPU is finished
When, the state of current operation VCPU is preserved, and restore the state of target VCPU (VCPU that will be switched to), that is, by mesh
The state for marking VCPU is loaded into physical cpu.The state of VCPU refers to the context of VCPU, and the context refers to sometime point VCPU and exists
The content of register and program counter.
CPU is virtualized each VCPU and Host OS (operation systems of host operating system, i.e. physical equipment itself
System) thread one-to-one correspondence, VCPU is called by Host OS threads.Fig. 1 is prior art VCPU handoff procedure exemplary plots, when need
When switching to another VCPU (being set as VCPUB) from a VCPU (being set as VCPUA), first the state of VCPUA is stored in interior
It deposits;Then the corresponding threads of VCPUA are switched to another thread corresponding with VCPU by Host OS according to Thread Scheduling Algorithms,
The corresponding VCPU of thread being switched to so just becomes target VCPU (VCPUB) naturally;The context of VCPUB is retrieved again and is incited somebody to action
Its context restores.(Kernel-based Virtual Machine, are based on KVM of the example shown in Fig. 1 based on LINUX system
The virtual machine of kernel), wherein, program A corresponds to VCPUA, and program B corresponds to VCPUB, and program is in GUEST sides, and thread is in HOST sides.
Therefore, the handoff procedure of VCPU had both included preserving VCPUA states and had restored the time of VCPUB states, to further include
Switching time of Host OS threads, and the switching time of Host OS threads is usually very long, and the switching of Host OS threads by
The thread scheduling policies management of Host OS so that handover delay is limited to the thread scheduling frame and dispatching algorithm of Host OS,
So as to cause VCPU switchings efficiency is low, time overhead is big.
Invention content
An embodiment of the present invention provides a kind of VCPU switching methods and physical hosts, are switched with solving VCPU in the prior art
The problem of efficiency is low.
In a first aspect, the embodiment of the present invention provides a kind of VCPU switching methods, the method, which is applied to operation, at least one
The physical host of a VCPU, the physical host include at least one VCPU queues, each VCPU queue includes at least one
VCPU, and at least one VCPU queues are managed by least one thread;The method includes:Preserve the shape of the first VCPU
State, the first VCPU are currently running VCPU;The 2nd VCPU, institute are determined from the VCPU queues where the first VCPU
The 2nd VCPU is stated as VCPU to be run;Restore the state of the 2nd VCPU.The method is performed by the thread, the thread
It is bound with VCPU queues.The method is not required to switch threads, but thread determines a target from the VCPU queues of binding
Then VCPU, that is, the 2nd VCPU preserve the state of current operation VCPU, restore the state of target VCPU, complete VCPU's
Switching so as to greatly reduce the time delay of VCPU switchings, improves VCPU switching efficiencies.
It is described that the 2nd VCPU, packet are determined from the queue of VCPU where the first VCPU in a kind of possible design
It includes:If there is VCPU to be run in the VCPU queues where the first VCPU, VCPU to be run described in selection one is described
2nd VCPU;If there is no VCPU to be run in the VCPU queues where the first VCPU, selected from other VCPU queues
A VCPU to be run is taken, selected VCPU to be run is migrated into the VCPU queues where the first VCPU, the choosing
The VCPU to be run taken is the 2nd VCPU.
In a kind of possible design, the 2nd VCPU, packet are determined in the VCPU queues from where the first VCPU
It includes:If it waits to run higher than the preferred of all VCPU to be run in the VCPU queues where the first VCPU there are priority
VCPU then selects one as selected VCPU, and the selected VCPU is migrated to described from the preferably VCPU to be run
In VCPU queues where first VCPU, the selected VCPU is the 2nd VCPU;If it preferably waits to run there is no described
VCPU, the VCPU to be run in VCPU queues where selection the first VCPU is the 2nd VCPU.VCPU's is excellent
First grade is set when VCPU is created, and the high VCPU of priority is first used.
Specifically, in a kind of possible design, second is determined in the VCPU queues from where the first VCPU
VCPU can include:Judge in the VCPU queues where the first VCPU with the presence or absence of VCPU to be run;If described first
There is VCPU to be run in VCPU queues where VCPU, judge other except the VCPU queues where the first VCPU
In VCPU queues, if treated there are priority higher than the preferred of all VCPU to be run in VCPU queues where the first VCPU
Run VCPU;If there are the preferably VCPU to be run, selection one is used as selected VCPU from the preferably VCPU to be run,
And migrate the selected VCPU into the VCPU queues where the first VCPU, the selected VCPU is described second
VCPU;If there is no the preferably VCPU to be run, choose and wait to operate to the 2nd VCPU described in one;If described first
There is no VCPU to be run in VCPU queues where VCPU, then a VCPU to be run are chosen from other VCPU queues, by institute
The VCPU to be run chosen is migrated into the VCPU queues where the first VCPU, and selected VCPU to be run is target
VCPU。
It is described if there is VCPU to be run in VCPU queues where the first VCPU in a kind of possible design
It is the 2nd VCPU to choose VCPU to be run described in one, including:One of described VCPU to be run is randomly selected as institute
State the 2nd VCPU;Or the VCPU of highest priority is the 2nd VCPU in VCPU to be run described in choosing;Or it chooses most
The VCPU to be run of the VCPU queues is introduced into as the 2nd VCPU, in this way can the free times of the VCPU in a manner of it is long.
In a kind of possible design, if there are the preferably VCPU to be run, migrated by the selected VCPU to institute
Before stating in the VCPU queues where the first VCPU, further include:If the VCPU queues where the first VCPU have been expired, institute is removed
State one or more VCPU in addition to the first VCPU in VCPU queues;If the VCPU queues where the first VCPU are not
It is full, the selected VCPU is migrated into the corresponding VCPU queues of the first VCPU.So as to prevent because of the VCPU queues
Expire and cannot use more higher VCPU than VCPU priority all in the VCPU queues.
In a kind of possible design, one or more removed in the VCPU queues in addition to the first VCPU
A VCPU, including:One or more VCPU in addition to the first VCPU in the VCPU queues are removed at random;Alternatively, it moves
Except in the VCPU queues in addition to the first VCPU a minimum VCPU of priority;Alternatively, remove the VCPU queues
In in addition to the first VCPU minimum multiple VCPU of priority;Wherein, it is described to remove to delete VCPU or moving VCPU
It moves in other VCPU queues except the VCPU queues where the first VCPU, other described VCPU queues are less than
VCPU queues.
It is unbalanced between VCPU queues to avoid in a kind of possible design, that is, in certain VCPU queues
VCPU is excessive and the VCPU in other VCPU queues is very few so that the corresponding thread of certain VCPU queues it is busy and other
The corresponding thread relative free of VCPU queues, the VCPU switching methods further include:If there are VCPU numbers to be less than pre-determined lower limit
Idle VCPU queues, and there are the busy VCPU queues that VCPU numbers are more than preset upper limit, choose in the busy VCPU queues
N VCPU to be run;The n of selection VCPU to be run are migrated into the free time VCPU queues;Wherein, n is equal to described
The number of VCPU subtracts the preset upper limit in busy VCPU queues.
In a kind of possible design, the n chosen in the busy VCPU queues the VCPU to be run, including:With
Machine chooses n VCPU to be run in the busy VCPU queues;It is alternatively, excellent by VCPU to be run in the busy VCPU queues
The sequence of first grade from big to small, n VCPU to be run before interception.
Second aspect, the embodiment of the present invention provide a kind of physical host, and the physical host includes:Hardware layer operates in
Virtual machine monitor VMM on the hardware layer and virtual machine on the VMM is operated in, the virtual machine includes
VCPU can also include virtual memory and virtual hard disk etc..The hardware layer includes at least one processor and storage device, institute
It states storage device and includes physical memory, physical hard disk can also be included.The VMM includes at least one VCPU queues and one
VCPU queue management modules, wherein, at least one VCPU is stored in the VCPU queues, the VCPU is used for using processor
Resource runs program.
The VCPU queue management modules are used to manage VCPU queues corresponding with the VCPU queue management modules,
In, the VCPU queue management modules are specifically used for:The state of the first VCPU is preserved, the first VCPU is currently running
VCPU, VCPU queue management module preserve the state of the first VCPU to physical memory;VCPU where the first VCPU
It is VCPU to be run that the 2nd VCPU, the 2nd VCPU are determined in queue;Restore the state of the 2nd VCPU, VCPU queue pipes
Reason module recovery is stored in the state of the 2nd VCPU in physical memory.
In a kind of possible design, the VCPU queue management modules are for from the VCPU where the first VCPU
When two VCPU is determined in queue, it is specifically used for:If there is VCPU to be run in the VCPU queues where the first VCPU, choosing
It is the 2nd VCPU to take VCPU to be run described in one;If there is no wait to run in the VCPU queues where the first VCPU
VCPU then chooses a VCPU to be run from other VCPU queues, selected VCPU to be run is migrated to described first
In VCPU queues where VCPU, the VCPU to be run of the selection is the 2nd VCPU.
In a kind of possible design, the VCPU queue management modules are for from VCPU teams where the first VCPU
When two VCPU is determined in row, it is specifically used for:If needed in VCPU queues where being higher than the first VCPU there are priority
The preferred VCPU to be run of VCPU is run, then selects one as selected VCPU from the preferred VCPU to be run, and by institute
It states selected VCPU to migrate into the VCPU queues where the first VCPU, the selected VCPU is the 2nd VCPU;If no
There are the preferably VCPU to be run, and the VCPU to be run in VCPU queues where selection the first VCPU is described
2nd VCPU.
Specifically, in a kind of possible design, the VCPU queue management modules are for from the first VCPU institutes
When two VCPU is determined in VCPU queues, it is specifically used for:Judge to whether there is in the VCPU queues where the first VCPU
VCPU to be run;If there is VCPU to be run in the VCPU queues where the first VCPU, the first VCPU places are judged
VCPU queues except other VCPU queues in, if there are priority higher than institute in VCPU queues where the first VCPU
Need to be run the preferred VCPU to be run of VCPU;If there are the preferably VCPU to be run, from the preferably VCPU to be run
One is chosen as selected VCPU, and the selected VCPU is migrated into the VCPU queues where the first VCPU, it is described
Selected VCPU is the 2nd VCPU;If there is no preferably VCPU run, wait to operate to described the described in selection one
Two VCPU;If there is no VCPU to be run in the VCPU queues where the first VCPU, chosen from other VCPU queues
One VCPU to be run migrates selected VCPU to be run into the VCPU queues where the first VCPU, selected
VCPU to be run is target VCPU.
It is described if there is VCPU to be run in VCPU queues where the first VCPU in a kind of possible design
VCPU queue management modules choose one described in wait run VCPU be two VCPU when, be specifically used for:Randomly select described treat
It is the 2nd VCPU to run one of VCPU;Or the VCPU of highest priority is described in VCPU to be run described in choosing
2nd VCPU;Or it is at first the 2nd VCPU into the VCPU to be run of the VCPU queues to choose.
In a kind of possible design, if there are the preferably VCPU to be run, the VCPU queue management modules are being incited somebody to action
Before the selected VCPU is migrated into the VCPU queues where the first VCPU, it is additionally operable to:If where the first VCPU
VCPU queues expired, remove one or more VCPU in addition to the first VCPU in the VCPU queues;If described
VCPU queues where one VCPU are less than, and the selected VCPU is migrated into the VCPU queues where the first VCPU.
In a kind of possible design, the VCPU queue management modules remove described first in the VCPU queues are removed
During one or more VCPU except VCPU, it is specifically used for:It removes at random in the VCPU queues in addition to the first VCPU
One or more VCPU;Alternatively, remove priority is minimum in addition to the first VCPU in the VCPU queues one
VCPU;Alternatively, remove in the VCPU queues the minimum multiple VCPU of priority in addition to the first VCPU;Wherein, it is described
It removes to delete VCPU or migrating VCPU into other VCPU queues except VCPU queues where the first VCPU, institute
Other VCPU queues are stated as less than VCPU queues.
In a kind of possible design, the VCPU queue management modules are specifically additionally operable to:If it is less than there are VCPU numbers pre-
The idle VCPU queues of limit are set, and there are the busy VCPU queues that VCPU numbers are more than preset upper limit, choose the busy VCPU
N VCPU to be run in queue;The n of selection VCPU to be run are migrated into the free time VCPU queues;Wherein, n etc.
The number of VCPU subtracts the preset upper limit in the busy VCPU queues.
In a kind of possible design, the VCPU queue management modules n in the busy VCPU queues are chosen
When VCPU is run, it is specifically used for:Randomly select n VCPU to be run in the busy VCPU queues;Alternatively, by described busy
The sequence of VCPU priority to be run from big to small in commonplace VCPU queues, n VCPU to be run before interception.
The technical solution that the embodiment of the present invention is provided creates VCPU queues and ties up VCPU queues and at least one thread
Fixed, such a thread can be corresponding with multiple VCPU.When needing to carry out VCPU switchings, different from the prior art due to mesh
Mark VCPU it is unknown thus can only the switching of advanced line journey mode, the technical solution that the embodiment of the present invention is provided preserves in thread
After current operation VCPU states, a target VCPU, such mesh can be determined from the VCPU queues where current operation VCPU
Mark VCPU is to determine, and its corresponding thread is still the corresponding thread of VCPU queues where it, is not required to progress thread and is cut
It changes, the state of thread recovery target VCPU can complete the switching of VCPU, and target VCPU can be present in VCPU queues
VCPU to be run can be the VCPU to be run for migrating to come from other VCPU queues.The skill that the embodiment of the present invention is provided
The process of VCPU toggle midlines journey switching is omitted in art scheme, it is thus possible to save a large amount of time loss, improve VCPU switchings
Efficiency.
Description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, to embodiment or will show below
There is attached drawing needed in technology description to be briefly described, it should be apparent that, for those of ordinary skill in the art
Speech, without having to pay creative labor, can also be obtained according to these attached drawings other attached drawings.
Fig. 1 is prior art VCPU handoff procedure exemplary plots;
The structure diagram for the physical host that Fig. 2 is provided by the embodiment of the present invention;
The principle schematic of VCPU switching methods that Fig. 3 is provided by the embodiment of the present invention;
Fig. 4 shows the flow diagram of a kind of VCPU switching methods that the embodiment of the present invention is provided;
Fig. 5 shows a kind of flow diagram of embodiment of step S402;
Fig. 6 shows the flow diagram of the another embodiment of step S402;
Fig. 7 shows the flow diagram of another VCPU switching methods that the embodiment of the present invention is provided;
Fig. 8 shows the structure diagram of a kind of VCPU queue management modules that the embodiment of the present invention is provided;
Fig. 9 shows a kind of composition of target VCPU determination units U802;
Figure 10 shows another composition of target VCPU determination units U802;
Figure 11 shows the structure diagram of another VCPU queue management modules that the embodiment of the present invention is provided.
Specific embodiment
In the prior art when creating VCPU, each VCPU and thread is bound, and when VCPU switches, due to
Target VCPU is unknown, it is therefore necessary to by system thread dispatching algorithm elder generation switch threads, the target that then could be obtained and be switched to
The corresponding target VCPU of thread.Institute's providing method of the embodiment of the present invention and the principle of physical host are to create VCPU queues, will
VCPU is stored in VCPU queues, and a VCPU queue is at least bound with thread, thus thread can with it is multiple
VCPU is corresponded to, and for thread, only runs a VCPU every time, but its VCPU that can be run can have multiple and be stored in
In VCPU queues;When VCPU switchings occur, another VCPU conduct is chosen from the VCPU queues where current operation VCPU
Target VCPU can complete determining, and the corresponding threads of target VCPU are still original thread, therefore not for target VCPU
Need the switching for carrying out thread, so as to save VCPU switching times, improve VCPU switching efficiencies.
The structure diagram for the physical host that Fig. 2 is provided by the embodiment of the present invention.The physical host includes hardware layer
100, the virtual machine monitor (VMM) 200 that runs on the hardware layer and run on virtual machine (VM) 300 on VMM.
The hardware layer includes at least a physical cpu 110, further includes storage device, such as physical memory 120 and hard disk 130, may be used also
To include network interface device 140;The VMM includes at least one VCPU queue management modules 210, the VCPU queue managements
Its corresponding VCPU queue (being not drawn into figure) of module management;The VM includes at least one VCPU310, and the VM is usually also wrapped
Virtual memory 320 and virtual hard disk 330 are included, client operating system 340 can be run on the VM.In the physical host,
One VCPU queue management module performs body such as physical cpu, CORE (physical core of CPU) with a code or hyperthread is tied up
It is fixed, body binding can be specifically performed with the minimum code of physical host.VMM creates a VCPU queue and by itself and one
VCPU queue management modules are bound, and are then created VCPU and are stored in VCPU as the element of VCPU queues in VCPU queues,
Storing how many a VCPU in each VCPU queues can be randomly assigned by VMM, can also be by VMM according to preset allocation rule point
Match, for example, VCPU is distributed evenly in each VCPU queues.VCPU queue management modules refer to VCPU teams with VCPU queues binding
The pointer of row management module is directed toward VCPU queues, and VCPU queue management modules call VCPU teams when calling VCPU, by pointer
Some element (i.e. VCPU) in row;The VCPU queue management modules are specific to walk for performing VCPU switching correlation steps
Rapid the step of may refer to VCPU switching methods.Wherein, the minimum code, which performs body, may be hyperthread for CORE,
Depending on present physical host reality minimum code perform body depending on, compared to non-minimum code perform body binding, by thread with
Minimum code performs body binding and is conducive to improve program runnability and cpu busy percentage.
When carrying out VCPU switchings, the state of VCPU to be run is stored in physical memory by VCPU queue management modules,
Then a target VCPU is determined from the VCPU queues where VCPU to be run, then restores the state of target VCPU, also
It is to obtain the state of target VCPU preserved in physical memory, and the state of target VCPU is loaded into physical cpu, target VCPU
The resource of physical cpu is then begun to use to run corresponding program, described program is the program being installed on virtual machine, each VCPU
Which corresponding program runs related algorithm according to program by the system of physical host and determines.Wherein, VCPU queue management modules are
The thread of physical host.
The principle schematic of VCPU switching methods that Fig. 3 is provided by the embodiment of the present invention, the VCPU switching methods should
For above-mentioned physical host.In Fig. 2, CORE is that minimum code performs body, and each CORE corresponds to a VCPU Queue (VCPU team
Row) and a Host thread (the Host Thread i.e. in figure), each VCPU queues are by a thread management, each VCPU teams
There can be multiple VCPU in row, as there is VCPU0-VCPU3 in first VCPU queue in Fig. 3, have in second VCPU queue
VCPU4-VCPU6 has VCPU7 and VCPU8 in third VCPU queues;VCPU queues are managed by VMM, in Host sides, VCPU teams
In row, it may be used and in operating status there are one VCPU;VCPU is then in Guest sides, VCPU queues binding where it
Thread dispatching.
It in the prior art, will according to dispatching algorithm selection by System Scheduler when system judgement needs to carry out VCPU switchings
The subject thread being switched to, then current thread is switched to subject thread, then subject thread calls the VCPU that it is bound.This hair
In the physical host that bright embodiment is provided, when system judgement needs to carry out VCPU switchings, by calling current operation VCPU's
The thread of VCPU queues binding where thread, that is, current operation VCPU preserves the state of current operation VCPU, from current fortune
Target VCPU is determined in VCPU queues where row VCPU, after determining target VCPU, since target VCPU is in the VCPU queues,
Thread can directly restore the state of target VCPU, and so as to complete the switching of VCPU, this process is not required to switch threads, thus energy
Enough reduce the time loss of VCPU switchings.
Specifically, in the prior art, thread directly performs after system handover request is obtained and preserves its VCPU's bound
The program code of state then switches to subject thread, then the state for the VCPU for restoring its binding is directly performed by subject thread
Code.In the physical host that the embodiment of the present application is provided, in the execution code of thread, current operation VCPU shapes are being preserved
After the code of state, increase and complete determining for target VCPU using VCPU queues and VCPU queue element (QE)s as the function of object;
After determining target VCPU, restore VCPU states and call VCPU code object for target VCPU rather than before work as
Preceding operation VCPU, and target VCPU and the current operation VCPU are the elements in VCPU queues;If thread obtain less than
Target VCPU can not determine target VCPU, then thread enters sleep state.
The VCPU switching methods that the embodiment of the present invention is provided are based on above-mentioned physical host.Fig. 4 shows implementation of the present invention
The flow diagram of a kind of VCPU switching methods that example is provided, as shown in figure 4, the method includes:
Step S401, preserves the state of the first VCPU, and the first VCPU is currently running VCPU;Step S402, from
It is VCPU to be run that the 2nd VCPU, the 2nd VCPU are determined in VCPU queues where first VCPU;
Step S403 restores the state of the 2nd VCPU.
Thread must first preserve the state of the first CPU when VCPU switches, that is, the first VCPU is in register and program meter
The content of number device, the first VCPU are current operation VCPU.Two VCPU, that is, target VCPU, target VCPU is wait to run
VCPU, thread restore the state of the target VCPU to be run after target VCPU is determined, where current operation VCPU
The thread of VCPU queues binding can stop calling to currently running VCPU, then invocation target VCPU.
Wherein target VCPU's determines to be realized by step S402, and Fig. 5 shows a kind of flows of embodiment of step S502
Schematic diagram, specifically, in one embodiment, as shown in figure 5, in the VCPU queues from where the first VCPU really
Fixed 2nd VCPU, including:
Step S5241 is judged in the VCPU queues where the first VCPU with the presence or absence of VCPU to be run;
Step S5242 if there is VCPU run in VCPU queues where the first VCPU, is treated described in selection one
Operation VCPU is the 2nd VCPU;
Step S5243, if there is no VCPU to be run in VCPU queues where the first VCPU, from other VCPU
A VCPU to be run is chosen in queue, selected VCPU to be run is migrated to the VCPU queues where the first VCPU
In, selected VCPU to be run is the 2nd VCPU.
Wherein, VCPU to be run is not used VCPU in VCPU queues.In VCPU switchings to be carried out, in VCPU queues
It may be stored with that multiple VCPU may also only storage be there are one VCPU, therefore, first judge the first VCPU, that is, currently run
VCPU whether there is VCPU to be run in the VCPU queues of place.If only storing a VCPU in the VCPU queues, this
A VCPU is exactly current operation VCPU, just VCPU not run in VCPU queues, if storing more than one in VCPU queues
VCPU then need to be run VCPU in addition to currently operation VCPU.If there is VCPU to be run in VCPU queues, choose one and treat
Operation VCPU is the 2nd VCPU, that is, is target VCPU.One of described VCPU to be run can be randomly selected as target
VCPU;Or the VCPU of highest priority is target VCPU in VCPU to be run described in choosing;Or it chooses at first into described
The VCPU to be run of VCPU queues is target VCPU.Wherein, in VCPU queues the priority of VCPU when creating VCPU by system
Algorithm is set, and the VCPU of high priority preferentially uses, if therefore VCPU set priority, can choose excellent in VCPU queues
The first highest VCPU to be run of grade is target VCPU.Refer in VCPU to be run into the VCPU to be run of VCPU queues at first,
It is stored in VCPU in VCPU queues at first after creating VCPU queues, choosing at first can be with into the VCPU to be run of VCPU queues
Prevent VCPU free times long.
If currently there is no VCPU to be run in the VCPU queues where operation VCPU, chosen from other VCPU queues
One VCPU to be run.Other described VCPU queues can be any VCPU teams in addition to VCPU queues where currently operation VCPU
Row;One VCPU to be run of the selection can be to randomly select one of VCPU to be run in other VCPU queues;Or
Choose the VCPU of highest priority in the VCPU to be run of other VCPU queues;Or it chooses in other VCPU queues and enters at first
The VCPU to be run of VCPU queues.Then selected VCPU to be run is moved to the VCPU queues where current operation VCPU
In, and using selected VCPU to be run as target VCPU, the migration can be to be added to selected VCPU to be run
In the chained list of VCPU queues where current operation VCPU.
If VCPU has priority, the high VCPU of priority is preferentially used.Work as if being higher than in other queues there are priority
The VCPU of VCPU to be run in VCPU queues where preceding VCPU waits to run even if then in VCPU queues where current VCPU existing
VCPU, can also be using the high VCPU of priority in other queues as target VCPU.Therefore step S402 is in another embodiment party
In formula, as shown in fig. 6, can include:
Step S4251 is judged in the VCPU queues where the first VCPU with the presence or absence of VCPU to be run;
Step S4252 if there is VCPU to be run in VCPU queues where the first VCPU, judges described first
In other VCPU queues except VCPU queues where VCPU, if there are priority higher than VCPU where the first VCPU
The preferred VCPU to be run of all VCPU to be run in queue;
If there are the preferably VCPU to be run, one conduct is chosen from the preferably VCPU to be run by step S4253
Selected VCPU, and the selected VCPU is migrated into the VCPU queues where the first VCPU, the selected VCPU is institute
State the 2nd VCPU.
If namely currently although VCPU queues where operation VCPU need to be run VCPU, but other VCPU the first VCPU
There are all higher VCPU to be run of VCPU priority to be run in VCPU queues where VCPU is run than currently in queue, then it is excellent
First select the higher VCPU to be run of the priority.VCPU priority to be run in VCPU queues where VCPU is run than currently
High VCPU to be run VCPU referred to as preferably to be run, if there is preferred VCPU to be run in other described VCPU queues, from
It is preferred that choosing one in VCPU to be run as selected VCPU, specifically, can randomly select first, choosing preferably to be shipped
Using the preferred VCPU to be run of selection as selected VCPU, selected VCPU is moved to currently for highest priority in row VCPU
It runs in the VCPU queues where VCPU, the selected VCPU is exactly the 2nd VCPU, that is, target VCPU.In this way, just
The high VCPU of preferential use priority can be switched by VCPU, preferably utilize system resource.
For step S4253, selected VCPU is being migrated to before the VCPU queues where the first VCPU, it can be with
Include the following steps:
(a1) whether the VCPU queues where judging the first VCPU have expired;
(a2) it if the VCPU queues where the first VCPU have been expired, removes and the first VCPU is removed in the VCPU queues
Except one or more VCPU;
(a3) if the VCPU queues where the first VCPU are less than, the selected VCPU is migrated to the first VCPU
In the VCPU queues at place.
When creating VCPU queues, the space size of VCPU queues can be set, that is, setting VCPU queues can deposit
The maximum number of the VCPU of storage, under normal circumstances VCPU queues will not be filled, but to prevent VCPU queue overflows, will be chosen
Before VCPU moves to the VCPU queues where the first VCPU (i.e. currently operation VCPU), where first judging current operation VCPU
Whether VCPU queues have expired, such as judge whether the chain table size of the currently VCPU queues where operation VCPU is equal to the VCPU
The size in the setting space of queue, if being equal to, the VCPU queues where current operation VCPU have been expired, otherwise, current to run
VCPU queues where VCPU are less than.
If currently the VCPU queues where operation VCPU have been expired, in order to migrate into selected VCPU, need to remove
VCPU to be run in one or more VCPU queues, after its removal, selected VCPU is migrated into the VCPU queues,
The removal can be the one or more VCPU removed at random in the VCPU queues in addition to currently operation VCPU;Alternatively,
The minimum VCPU of priority in addition to currently operation VCPU is removed in the VCPU queues, alternatively, described in removing successively
In VCPU queues in addition to currently operation VCPU the minimum multiple VCPU of priority, that is, remove it is multiple, every time by the secondary institute
The minimum VCPU to be run of priority in VCPU queues is stated to remove.Specifically, it can be to delete to remove the VCPU in VCPU queues
The VCPU or VCPU that will be removed is moved in other less than VCPU queues, for currently running the VCPU teams where VCPU
Row remove VCPU to be run therein, are that the VCPU that will be removed is deleted or moved in other less than VCPU queues.
If the VCPU queues currently where operation VCPU are less than, directly selected VCPU is migrated to the VCPU where current operation VCPU
In queue.
Step (a1), which can also replace with, judges whether VCPU number in the VCPU queues has reached the preset upper limit,
Although VCPU queues described in this way are less than, but if the VCPU number has reached the preset upper limit, then the VCPU teams are removed
After one or more VCPU in row in addition to currently operation VCPU, then selected VCPU migrated corresponding to current operation VCPU
In VCPU queues.This mode can reduce the number of busy VCPU queues, and the busy VCPU queues refer to VCPU number and reach
The VCPU queues of certain upper limit, enable the preset upper limit be equal to the judgement upper limit of busy VCPU queues, can prevent will be idle
VCPU queues become busy VCPU queues.
If step S4254 there is no the preferably VCPU to be run, chooses and waits to operate to described second described in one
VCPU;
Step S4255, if there is no VCPU to be run in VCPU queues where the first VCPU, from other VCPU
A VCPU to be run is chosen in queue, selected VCPU to be run is migrated to the VCPU queues where the first VCPU
In, selected VCPU to be run is target VCPU.
If in other VCPU queues except VCPU queues where the first VCPU (i.e. currently operation VCPU), without preferred
VCPU to be run, then the VCPU to be run directly chosen in the currently VCPU queues where operation VCPU is described second
VCPU, two VCPU, that is, target VCPU, for example, randomly select one of described VCPU run be target VCPU or
The VCPU of highest priority is target VCPU or chooses at first into the VCPU queues in VCPU to be run described in selection
VCPU to be run is target VCPU.Step 3455 is then identical with step 3443.
The VCPU switching methods that the embodiment of the present invention is provided, the current VCPU and target VCPU that runs is in a VCPU queue
In, it can easily determine target VCPU, only target VCPU need to be used to replace current operation with the thread of VCPU queues binding
VCPU can complete the switching of VCPU, not be related to the switching of thread, it is thus possible to reduce the time overhead of VCPU switchings, drop
Low VCPU handover delays.The VCPU switching methods that the embodiment of the present invention is provided, can be by VCPU in the actual measurement of ARM64 platforms
Handover delay is reduced to 2.5us from 4.5us, can meet the high switching requirements of VCPU in real time well.
The establishment of different VCPU queues be not necessarily and meanwhile, the space size of each VCPU queues is also not necessarily identical,
And created VCPU queues are needed according to different application, the wherein number of VCPU is also not necessarily identical, in addition, if there is
The migration or removal of VCPU, the number of VCPU stored in each VCPU queues may also can change, these above-mentioned situations
It may all cause unbalanced between VCPU queues, that is, VCPU in certain VCPU queues is excessive and other VCPU queues
In VCPU it is very few so that the corresponding thread of certain VCPU queues is busy and other corresponding threads of VCPU queues are relatively empty
Spare time causes system resource to apply unbalanced.Fig. 7 shows another VCPU switching methods that the embodiment of the present invention is provided
Flow diagram, the method also carry out equilibrium after VCPU switchings to VCPU queues, as shown in fig. 7, the method includes:
Step S701, preserves the state of the first VCPU, and the first VCPU is currently running VCPU;
Step S702 determines the 2nd VCPU from the VCPU queues where the first VCPU, and the 2nd VCPU is treats
Run VCPU;
Step S703 restores the state of the 2nd VCPU.
Wherein, step S701 to step S703 is identical to step S403 with step S401.
Step S704 judges whether that VCPU numbers are less than the idle VCPU queues of pre-determined lower limit and whether there is
VCPU numbers are more than the busy VCPU queues of preset upper limit;
Step S705, if there are the idle VCPU queues that VCPU numbers are less than pre-determined lower limit, and be more than there are VCPU numbers and preset
N VCPU to be run in the busy VCPU queues are chosen in the busy VCPU queues of the upper limit;
Step S706 migrates the n of selection VCPU to be run into the free time VCPU queues;
Wherein, n subtracts the preset upper limit equal to the number of VCPU in the busy VCPU queues.
In step S704, each VCPU queues are scanned, the number situation of VCPU in each VCPU queues is scanned, sentences
It is disconnected to be less than the idle VCPU queues of pre-determined lower limit with the presence or absence of VCPU numbers and be more than the busy of preset upper limit with the presence or absence of VCPU numbers
Commonplace VCPU queues.The scanning can be for periodic scan or by setting time spot scan.The pre-determined lower limit and preset upper limit
It can be set by user according to system processing power, to ensure that it is busy that a free time VCPU queue has sufficient space to receive some
The VCPU to be run that VCPU queues migration comes, each VCPU queue lengths (i.e. the number of VCPU in VCPU queues) subtract default
Maximum value in difference obtained by the upper limit is less than each VCPU queue lengths and subtracts minimum value in difference obtained by pre-determined lower limit.
The VCPU queues that VCPU numbers are less than pre-determined lower limit are known as free time VCPU queues, and VCPU numbers are more than the VCPU of preset upper limit
Queue is known as busy VCPU queues.If only existing idle VCPU queues, busy VCPU queues are had no, to reduce equalization operation time
Number, prevents number from excessively occupying too many system resource, then is not required to carry out equilibrium to VCPU queues, if only existing busy VCPU teams
It arranges without idle VCPU queues, then can not carry out VCPU queues equilibrium.Only not only there are busy VCPU queues but also in the presence of idle
In the case of VCPU queues, equilibrium is carried out, that is, the part VCPU to be run in busy VCPU queues is moved to VCPU queues
It moves in idle VCPU queues.
If the number of free time VCPU queues is greater than or equal to the number of busy VCPU queues, for each busy VCPU teams
Row, randomly select a free time VCPU queue, which part VCPU to be run are migrated to the idle VCPU queues of selection;It is if empty
The number of not busy VCPU queues is less than the number of busy VCPU queues, then randomly selects m busy VCPU queues, busy to m
Each in VCPU queues, randomly selects a free time VCPU queue, by the part VCPU to be run in busy VCPU queues
It migrates to the idle VCPU queues of selection, wherein, m is the number of free time VCPU queues.Wherein, by part in busy VCPU queues
VCPU to be run is migrated into the idle VCPU of selection, and the part VCPU to be run can be k VCPU, and k is is less than or waits
In the arbitrary number of " VCPU queue lengths -1 ", if but migration number it is excessive, may cause instead it is new unbalanced, therefore can be with
N VCPU to be run in busy VCPU queues are chosen, n subtracts described pre- equal to the number of VCPU in the busy VCPU queues
If the upper limit, the number of VCPU queues busy in this way VCPU therein after migration is equal to preset upper limit, so as to avoid migration number
It is excessive.Specifically, n VCPU to be run in busy VCPU queues are chosen, can be to randomly select the busy VCPU queues
In n VCPU to be run;Alternatively, by the sequence of VCPU priority to be run from big to small in the busy VCPU queues, cut
N VCPU to be run before taking.
It should be noted that step S704 to step S706 is not limited in performing after VCPU switchings, it can also be
It is performed before VCPU switchings.Other balanced ways can also be used in equilibrium between VCPU queues, such as equalize balanced way, also
It is after each scanning VCPU queues, if the number of VCPU is each unequal in VCPU queues, calculates VCPU total numbers divided by VCPU
The average of queue number, using VCPU queue of the VCPU number more than the average as VCPU queues of moving out, by VCPU
VCPU queue of the number less than the average, which is used as, moves into VCPU queues, and part VCPU is then removed from VCPU queues of moving out,
The number of VCPU in VCPU queues that makes to move out is equal to the average, then migrates the VCPU of removal to moving into VCPU queues
In, it each moves into before the number of the VCPU migrated into VCPU queues subtracts migration less than or equal to the average and moves into
VCPU number of VCPU queues.
Fig. 8 shows the structure diagram of a kind of VCPU queue management modules that the embodiment of the present invention is provided, such as Fig. 8 institutes
Show, the VCPU queue management modules include:
State storage unit U801, for preserving the state of the first VCPU, the first VCPU is currently running VCPU;
Target VCPU determination unit U802, for determining the 2nd VCPU from the VCPU queues where the first VCPU,
2nd VCPU is VCPU to be run;
State recovery unit U803, for restoring the state of the 2nd VCPU.
State storage unit U801 first by the state of the first VCPU (i.e. currently operation VCPU), that is, preserves VCPU in register
With the content of program counter, it is saved in physical memory.State recovery unit U803 then determines in target VCPU determination units
After two VCPU (i.e. target VCPU), restore the state of the target VCPU to be run from physical memory, the target VCPU starts
The corresponding programs of the target VCPU are run using the resource of physical cpu.
Fig. 9 shows a kind of composition of target VCPU determination units U802, as shown in figure 8, the target VCPU determines list
First U802, including:
VCPU judgment sub-units U901 to be run, for judging to whether there is in the VCPU queues where the first VCPU
VCPU to be run;
First object VCPU determination subelement U902, if for there are to be shipped in the VCPU queues where the first VCPU
Row VCPU, it is target VCPU to choose VCPU to be run described in one;
Second target VCPU determination subelement U903, if for there is no to treat in the VCPU queues where the first VCPU
VCPU is run, then a VCPU to be run is chosen from other VCPU queues, selected VCPU to be run is migrated to described the
In VCPU queues where one VCPU, selected VCPU to be run is the 2nd VCPU.
Wherein, VCPU to be run is not used VCPU in VCPU queues.VCPU judgment sub-units U801 to be run first sentences
With the presence or absence of VCPU to be run in the disconnected first VCPU namely currently VCPU queues where operation VCPU, if the VCPU
A VCPU is only stored in queue, then this VCPU is exactly current operation VCPU, does not just wait to run in the VCPU queues
VCPU if storing more than one VCPU in the VCPU queues, need to be run VCPU in addition to currently operation VCPU.If
In VCPU queues exist VCPU run, then first object VCPU determination subelements U902 randomly select described in VCPU to be run its
One of be the 2nd VCPU (i.e. target VCPU);Or the VCPU of highest priority is institute in VCPU to be run described in choosing
The 2nd VCPU is stated, preferably to utilize system resource;Or it is at first institute into the VCPU to be run of the VCPU queues to choose
The 2nd VCPU is stated, to prevent VCPU free times long.
If there is no VCPU to be run in the VCPU queues where the first VCPU, the second target VCPU determines sub single
First U903 chooses a VCPU to be run from other VCPU queues, and selected VCPU to be run then is moved to described first
In VCPU queues where VCPU, and using selected VCPU to be run as the 2nd VCPU, the migration can be for by institute
In the chained list of VCPU queues where the VCPU to be run chosen is added to the first VCPU.Other described VCPU queues can be
Any VCPU queues in addition to VCPU queues where the first VCPU;One VCPU to be run of the selection can be at other
One of VCPU to be run is randomly selected in VCPU queues;Or choose in other VCPU queues priority in VCPU to be run
Highest VCPU;Or choose the VCPU to be run for entering VCPU queues in other VCPU queues at first.
Figure 10 shows another composition of target VCPU acquiring units U1002, and as shown in Figure 10, the target VCPU is obtained
Unit U802 is taken, including:
VCPU judgment sub-units U1001 to be run, for judging whether deposited in the VCPU queues where the first VCPU
In VCPU to be run;
It is preferred that VCPU judgment sub-units U1002 to be run, if for existing in the VCPU queues where the first VCPU
VCPU to be run is judged in other VCPU queues except the VCPU queues where the first VCPU, if there are priority
Higher than the preferred VCPU to be run of all VCPU to be run in the VCPU queues where the first VCPU;
It is preferred that VCPU to be run chooses subelement U1003, if for there are preferably VCPU run, from described preferred
One is selected in VCPU to be run as selected VCPU.
Wherein, VCPU preferably to be run chooses subelement U1003 and can be randomly choosed from the preferably VCPU to be run
One is as selected VCPU or selects the preferred VCPU to be run of highest priority as selected VCPU.
Third target VCPU determination subelement U1004, for migrating the selected VCPU to where the first VCPU
VCPU queues in, the selected VCPU be the 2nd VCPU;
First object VCPU determination subelement U1005, if being treated for existing in the VCPU queues where the first VCPU
VCPU is run, and there is no the preferably VCPU to be run, it is the 2nd VCPU to choose VCPU to be run described in one;
Second target VCPU determination subelement U1006, if for being not present in the VCPU queues where the first VCPU
VCPU to be run then chooses a VCPU to be run from other VCPU queues, selected VCPU to be run is migrated to described
In VCPU queues where first VCPU, selected VCPU to be run is the 2nd VCPU.
Wherein, the first object VCPU determination subelements, can randomly select one of described VCPU to be run is
2nd VCPU i.e. target VCPU;Or the VCPU of highest priority is described second in VCPU to be run described in choosing
VCPU;Or it is at first the 2nd VCPU into the VCPU to be run of the VCPU queues to choose.
It is treated than VCPU priority to be run is high in the VCPU queues where the 2nd VCPU (i.e. currently operation VCPU)
Run VCPU VCPU referred to as preferably to be run.If currently although the VCPU queues where operation VCPU need to be run VCPU, but
Have in other VCPU queues higher more to be shipped than currently running all VCPU priority to be run in the VCPU queues where VCPU
Row VCPU then preferentially selects the higher VCPU to be run of priority.If the it is preferred that judgement of VCPU judgment sub-units U1002 to be run
The result is that there is preferred VCPU run in other VCPU queues, then VCPU selection subelement U1003 preferably to be run are from preferred
One is chosen in VCPU to be run as selected VCPU, specifically, can be randomly selected from preferred VCPU to be run first, or
Person chooses the preferred VCPU to be run of highest priority in preferably VCPU to be run.Using the preferred VCPU to be run of selection as quilt
VCPU is selected, then selected VCPU is moved to the VCPU where current operation VCPU by third target VCPU determination subelements U1004
In queue, and using the selected VCPU as the 2nd VCPU (i.e. target VCPU).In this way, it can be switched by VCPU preferential
The high VCPU of use priority, preferably utilizes system resource.
Wherein, the third target VCPU determination subelements, can include:
Judgment sub-unit, for judging whether the VCPU queues where the first VCPU have expired;
Subelement is removed, if the VCPU queues for where the first VCPU have been expired, removes and is removed in the VCPU queues
One or more VCPU except first VCPU;
Migrate subelement, if the VCPU queues for where the first VCPU are less than, by the selected VCPU migrate to
In VCPU queues where first VCPU, the selected VCPU is the 2nd VCPU.
Wherein, the removal subelement can remove the VCPU where the first VCPU (i.e. currently operation VCPU) at random
One or more VCPU in queue in addition to currently operation VCPU;Alternatively, it removes in the VCPU queues except current operation
A minimum VCPU of priority except VCPU;Alternatively, it removes successively excellent in addition to currently operation VCPU in the VCPU queues
The minimum multiple VCPU of first grade.Wherein, the removal for removing subelement is deletes VCPU or migrates VCPU to current fortune
In other VCPU queues except VCPU queues where row VCPU, other described VCPU queues are less than VCPU queues.
To prevent VCPU queue overflows, where selected VCPU to be moved to the first VCPU (i.e. currently operation VCPU)
VCPU queues before, whether the VCPU queues where judgment sub-unit first judges the first VCPU have expired.If described first
VCPU queues where VCPU have been expired, and in order to migrate into selected VCPU, are removed subelement and are removed one or more institutes
The VCPU to be run in VCPU queues is stated, after its removal, migration subelement again migrates selected VCPU into the VCPU queues.
The removal can be the one or more VCPU removed at random in the VCPU queues in addition to currently operation VCPU;Alternatively,
The minimum VCPU of priority in addition to currently operation VCPU is removed in the VCPU queues, alternatively, described in removing successively
In VCPU queues in addition to currently operation VCPU the minimum multiple VCPU of priority, that is, remove it is multiple, every time by the secondary institute
The minimum VCPU to be run of priority in VCPU queues is stated to remove.Specifically, it can be to delete to remove the VCPU in VCPU queues
The VCPU or VCPU that will be removed is moved in other less than VCPU queues.If the VCPU queues where the first VCPU
It is less than, then it migrates subelement and directly migrates selected VCPU into the VCPU queues where the first VCPU.
If in other VCPU queues except VCPU queues where the first VCPU, VCPU preferably not run,
One in VCPU queues where then first object VCPU determination subelements U1005 directly chooses the first VCPU is waited to run
VCPU is the 2nd VCPU (i.e. target VCPU), such as it is described second to randomly select one of described VCPU to be run
VCPU either choose described in VCPU to be run the VCPU of highest priority enter at first for the 2nd VCPU or choose
The VCPU to be run of the VCPU queues is the 2nd VCPU.
Figure 11 shows the structure diagram of another VCPU queue management modules that the embodiment of the present invention is provided, and such as schemes
Shown in 11, the VCPU queue management modules include:
State storage unit U1101, for preserving the state of the first VCPU, the first VCPU is currently running
VCPU;
Target VCPU determination unit U1102, for determining the 2nd VCPU from the VCPU queues where the first VCPU,
2nd VCPU is VCPU to be run;
State recovery unit U1103, for restoring the state of the 2nd VCPU;
Judging unit U1104, for judging whether that VCPU numbers are less than the idle VCPU queues of pre-determined lower limit, Yi Jishi
It is no that there are the busy VCPU queues that VCPU numbers are more than preset upper limit;
VCPU selection unit U1105, if for there are the idle VCPU queues that VCPU numbers are less than pre-determined lower limit, and exist
VCPU numbers are more than the busy VCPU queues of preset upper limit, choose n VCPU to be run in the busy VCPU queues;
Balanced unit U1106, for migrating the n of selection VCPU to be run into the free time VCPU queues;
Wherein, n subtracts the preset upper limit equal to the number of VCPU in the busy VCPU queues.
Wherein, the VCPU selection units can randomly select n VCPU to be run in the busy VCPU queues;Or
Person, by the sequence of VCPU priority to be run from big to small in the busy VCPU queues, n VCPU to be run before interception.
Judging unit U1104 is scanned each VCPU queues, scans the number situation of VCPU in each VCPU queues,
Judge whether that VCPU numbers are less than the idle VCPU queues of pre-determined lower limit and are more than preset upper limit with the presence or absence of VCPU numbers
Busy VCPU queues.The scanning can be periodic scan or by setting time spot scan, the pre-determined lower limit and it is default on
Limit can be set by user according to system processing power.Each VCPU queue lengths subtract the maximum in difference obtained by preset upper limit
Value is less than each VCPU queue lengths and subtracts minimum value in difference obtained by pre-determined lower limit, to ensure a free time VCPU team
It shows sufficient space and receives the VCPU to be run that some busy VCPU queues migration comes.
The VCPU queues that VCPU numbers are less than pre-determined lower limit are known as free time VCPU queues, and VCPU numbers are more than the VCPU of preset upper limit
Queue is known as busy VCPU queues.If only existing idle VCPU queues, busy VCPU queues are had no, to reduce equalization operation time
Number, prevents number from excessively occupying too many system resource, then without the use of U1106 pairs of VCPU selection units U1105 and balanced unit
VCPU queues carry out balanced.If only existing busy VCPU queues without idle VCPU queues, it is equal VCPU queues can not to be carried out
Weighing apparatus.Equilibrium not only there are busy VCPU queues but also in the case of there is free time VCPU queues, is only being carried out to VCPU queues, that is,
Part VCPU to be run in busy VCPU queues is migrated into idle VCPU queues.
If the number of free time VCPU queues be greater than or equal to busy VCPU queues number, balanced unit U1106 for
Each busy VCPU queues, randomly select a free time VCPU queue, which part VCPU to be run are migrated to the sky of selection
Not busy VCPU queues;If the number of free time VCPU queues is less than the number of busy VCPU queues, balanced unit U1106 is randomly selected
M busy VCPU queues to each in m busy VCPU queues, randomly select a free time VCPU queue, will be busy
Part VCPU to be run in VCPU queues is migrated to the idle VCPU queues of selection, wherein, m is of free time VCPU queues
Number.Wherein, part row VCPU to be shipped in busy VCPU queues is migrated into the idle VCPU of selection, the part waits to run
VCPU can be k VCPU, and k is the arbitrary number less than or equal to " VCPU queue lengths -1 ".But if the number of migration is excessive, instead
And may cause new unbalanced, therefore can choose in busy VCPU queues n of VCPU selection units U1105 wait to run
The number that VCPU, n are equal to VCPU in the busy VCPU queues subtracts the preset upper limit, and VCPU queues busy in this way are migrating
The number of VCPU therein is equal to preset upper limit afterwards, so as to avoid migration number excessive.
Specifically, VCPU selection units U1105 chooses n VCPU to be run in busy VCPU queues, can be random
Choose n VCPU to be run in the busy VCPU queues;It is alternatively, preferential by VCPU to be run in the busy VCPU queues
The sequence of grade from big to small, n VCPU to be run before interception.
Judging unit U1104, VCPU selection unit U1105 and balanced unit U1106, can be connected to state storage unit
After U1101, target VCPU determination units U1102 and state recovery unit U1103, state storage unit can also be connected to
Before U1101, target VCPU determination units U1102 and state recovery unit U1103.Equilibrium between VCPU queues can also be used
Other balanced ways, such as balanced way is equalized, that is, after each scannings of judging unit U1104, if in VCPU queues
The number of VCPU is each unequal, then calculates the average of VCPU total numbers divided by VCPU queue numbers, and VCPU number is more than institute
The VCPU queues of average are stated as VCPU queues of moving out, using VCPU queue of the VCPU number less than the average as moving into
VCPU queues, then VCPU selection units U1105 selected part VCPU from VCPU queues of moving out remove the part of selection
The number of VCPU is equal to the average in VCPU, VCPU queue.Then balanced unit U1106 is by VCPU selection units U1105
The part VCPU of selection migrate to moving into VCPU queues, each move into the VCPU migrated into VCPU queues number be less than or
VCPU number of VCPU queues is moved into before subtracting migration equal to the average.
It is required that those skilled in the art can be understood that the technology in the embodiment of the present invention can add by software
The mode of general hardware platform realize.Based on such understanding, the technical solution in the embodiment of the present invention substantially or
It says and the part that the prior art contributes can be embodied in the form of software product, which can deposit
Storage is in storage medium, such as ROM/RAM, magnetic disc, CD, and being used including some instructions (can be with so that computer equipment
Be personal computer, server either network equipment etc.) perform side described in certain parts of each embodiment or embodiment
Method.
Method, equipment and computer program product of the embodiment of the present invention etc. have used flowchart and/or the block diagram to retouch
It states.It should be understood that each flow and/or block that can be realized by computer program instructions in flowchart and/or the block diagram and
The combination of flow and/or box in flowchart and/or the block diagram.These computer program instructions can be provided to general-purpose computations
Machine, special purpose computer, Embedded Processor or other programmable data processing devices processor to generate a machine so that
The instruction generation performed by computer or the processor of other programmable data processing devices is used to implement in flow chart one
The equipment of function specified in flow or multiple flows and/or one box of block diagram or multiple boxes.
These computer program instructions, which may also be stored in, can guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works so that the instruction generation being stored in the computer-readable memory includes referring to
Enable the manufacture of equipment, the commander equipment realize in one flow of flow chart or multiple flows and/or one box of block diagram or
The function of being specified in multiple boxes.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that counted
Series of operation steps are performed on calculation machine or other programmable devices to generate computer implemented processing, so as in computer or
The instruction offer performed on other programmable devices is used to implement in one flow of flow chart or multiple flows and/or block diagram one
The step of function of being specified in a box or multiple boxes.
Each embodiment in this specification is described by the way of progressive, identical similar portion between each embodiment
Point just to refer each other, and the highlights of each of the examples are difference from other examples.Especially for equipment reality
For applying example, since it is substantially similar to embodiment of the method, so description is fairly simple, related part is referring to embodiment of the method
Part explanation.
Claims (16)
1. a kind of virtual center processor VCPU switching methods have the physical host of at least one VCPU applied to operation, special
Sign is that the physical host includes at least one VCPU queues, each VCPU queue includes at least one VCPU, and described
At least one VCPU queues are managed by least one thread;The method includes:
The state of the first VCPU is preserved, the first VCPU is currently running VCPU;
It is VCPU to be run that the 2nd VCPU, the 2nd VCPU are determined from the VCPU queues where the first VCPU;
Restore the state of the 2nd VCPU.
2. VCPU switching methods as described in claim 1, which is characterized in that the team from VCPU where the first VCPU
The 2nd VCPU is determined in row, including:
If there is VCPU to be run in the VCPU queues where the first VCPU, VCPU to be run described in selection one is described
2nd VCPU;
If there is no VCPU run in the VCPU queues where the first VCPU, from other VCPU queues selection one treat
VCPU is run, selected VCPU to be run is migrated into the VCPU queues where the first VCPU, the selection is treated
Operation VCPU is the 2nd VCPU.
3. VCPU switching methods as described in claim 1, which is characterized in that the VCPU teams from where the first VCPU
The 2nd VCPU is determined in row, including:
If it waits to run higher than the preferred of all VCPU to be run in the VCPU queues where the first VCPU there are priority
VCPU then selects one as selected VCPU, and the selected VCPU is migrated to described from the preferably VCPU to be run
In VCPU queues where first VCPU, the selected VCPU is the 2nd VCPU;
If there is no the preferably VCPU to be run, one in VCPU queues where selection the first VCPU waits to run
VCPU is the 2nd VCPU.
4. VCPU switching methods as claimed in claim 2, which is characterized in that if in VCPU queues where the first VCPU
In the presence of VCPU to be run, VCPU to be run described in the selection one is the 2nd VCPU, including:It randomly selects described to be shipped
One of row VCPU is the 2nd VCPU;Or the VCPU of highest priority is described the in VCPU run described in choosing
Two VCPU;Or it is at first the 2nd VCPU into the VCPU to be run of the VCPU queues to choose.
5. VCPU switching methods as claimed in claim 3, which is characterized in that if there are the preferably VCPU to be run, inciting somebody to action
Before the selected VCPU is migrated into the VCPU queues where the first VCPU, further include:
If the VCPU queues where the first VCPU have been expired, one in the VCPU queues in addition to the first VCPU is removed
A or multiple VCPU;
If the VCPU queues where the first VCPU are less than, the selected VCPU is migrated corresponding to the first VCPU
In VCPU queues.
6. VCPU switching methods as claimed in claim 5, which is characterized in that described to remove in the VCPU queues except described the
One or more VCPU except one VCPU, including:
One or more VCPU in addition to the first VCPU in the VCPU queues are removed at random;Alternatively,
Remove in the VCPU queues a minimum VCPU of priority in addition to the first VCPU;Alternatively,
Remove in the VCPU queues the minimum multiple VCPU of priority in addition to the first VCPU;
Wherein, it is described to remove to delete VCPU or migrating VCPU to its except the VCPU queues where the first VCPU
In his VCPU queues, other described VCPU queues are less than VCPU queues.
7. VCPU switching methods as described in claim 1, which is characterized in that further include:
If there are the idle VCPU queues that VCPU numbers are less than pre-determined lower limit, and there are the busy VCPU that VCPU numbers are more than preset upper limit
N VCPU to be run in the busy VCPU queues are chosen in queue;
The n of selection VCPU to be run are migrated into the free time VCPU queues;
Wherein, n subtracts the preset upper limit equal to the number of VCPU in the busy VCPU queues.
8. VCPU switching methods as claimed in claim 7, which is characterized in that the n chosen in the busy VCPU queues
A VCPU to be run, including:
Randomly select n VCPU to be run in the busy VCPU queues;Alternatively,
By the sequence of VCPU priority to be run from big to small in the busy VCPU queues, n VCPU to be run before interception.
9. a kind of physical host, including:Hardware layer operates in the virtual machine monitor VMM on the hardware layer and operation
Virtual machine on the VMM, the hardware layer include at least one processor and storage device, and the VMM includes at least one
A VCPU queues and a VCPU queue management module, wherein,
The VCPU queues include at least one VCPU, and the VCPU is used for the resource operation program using processor;
The VCPU queue management modules are used to manage VCPU queues corresponding with the VCPU queue management modules, wherein, institute
VCPU queue management modules are stated to be specifically used for:
The state of the first VCPU is preserved, the first VCPU is currently running VCPU;
It is VCPU to be run that the 2nd VCPU, the 2nd VCPU are determined from the VCPU queues where the first VCPU;
Restore the state of the 2nd VCPU.
10. physical host as claimed in claim 9, which is characterized in that the VCPU queue management modules are for from described
When two VCPU is determined in the VCPU queues where the first VCPU, it is specifically used for:
If there is VCPU to be run in the VCPU queues where the first VCPU, VCPU to be run described in selection one is described
2nd VCPU;
If there is no VCPU run in the VCPU queues where the first VCPU, from other VCPU queues selection one treat
VCPU is run, selected VCPU to be run is migrated into the VCPU queues where the first VCPU, the selection is treated
Operation VCPU is the 2nd VCPU.
11. physical host as claimed in claim 9, which is characterized in that the VCPU queue management modules are for from described
When two VCPU is determined in VCPU queues where the first VCPU, it is specifically used for:
If there are preferred to be run VCPU of the priority higher than all VCPU to be run in VCPU queues where the first VCPU,
Then one is selected as selected VCPU, and the selected VCPU is migrated to described first from the preferably VCPU to be run
In VCPU queues where VCPU, the selected VCPU is the 2nd VCPU;
If there is no the preferably VCPU to be run, one in VCPU queues where selection the first VCPU waits to run
VCPU is the 2nd VCPU.
12. physical host as claimed in claim 10, which is characterized in that if being deposited in VCPU queues where the first VCPU
In VCPU to be run, the VCPU queue management modules are being chosen described in one when it is two VCPU to run VCPU, specific to use
In:One of described VCPU to be run is randomly selected as the 2nd VCPU;It is or preferential in VCPU to be run described in choosing
The highest VCPU of grade is the 2nd VCPU;Or it is at first described second into the VCPU to be run of the VCPU queues to choose
VCPU。
13. physical host as claimed in claim 11, which is characterized in that if there are the preferably VCPU to be run, it is described
VCPU queue management modules are also used before the selected VCPU is migrated into the VCPU queues where the first VCPU
In:
If the VCPU queues where the first VCPU have been expired, one in the VCPU queues in addition to the first VCPU is removed
A or multiple VCPU;
If the VCPU queues where the first VCPU are less than, the selected VCPU is migrated to where the first VCPU
In VCPU queues.
14. physical host as claimed in claim 13, which is characterized in that the VCPU queue management modules are described in removal
In VCPU queues during one or more VCPU in addition to the first VCPU, it is specifically used for:
One or more VCPU in addition to the first VCPU in the VCPU queues are removed at random;Alternatively,
Remove in the VCPU queues a minimum VCPU of priority in addition to the first VCPU;Alternatively,
Remove in the VCPU queues the minimum multiple VCPU of priority in addition to the first VCPU;
Wherein, it is described to remove to delete VCPU or migrating VCPU to other except VCPU queues where the first VCPU
In VCPU queues, other described VCPU queues are less than VCPU queues.
15. physical host as claimed in claim 9, which is characterized in that the VCPU queue management modules are specifically additionally operable to:
If there are the idle VCPU queues that VCPU numbers are less than pre-determined lower limit, and there are the busy VCPU that VCPU numbers are more than preset upper limit
N VCPU to be run in the busy VCPU queues are chosen in queue;
The n of selection VCPU to be run are migrated into the free time VCPU queues;
Wherein, n subtracts the preset upper limit equal to the number of VCPU in the busy VCPU queues.
16. physical host as claimed in claim 15, which is characterized in that the VCPU queue management modules are choosing described do
N in commonplace VCPU queues are specifically used for when VCPU is run:
Randomly select n VCPU to be run in the busy VCPU queues;Alternatively,
By the sequence of VCPU priority to be run from big to small in the busy VCPU queues, n VCPU to be run before interception.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611245500.7A CN108255572A (en) | 2016-12-29 | 2016-12-29 | A kind of VCPU switching methods and physical host |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611245500.7A CN108255572A (en) | 2016-12-29 | 2016-12-29 | A kind of VCPU switching methods and physical host |
Publications (1)
Publication Number | Publication Date |
---|---|
CN108255572A true CN108255572A (en) | 2018-07-06 |
Family
ID=62719142
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611245500.7A Pending CN108255572A (en) | 2016-12-29 | 2016-12-29 | A kind of VCPU switching methods and physical host |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108255572A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108959020A (en) * | 2018-05-08 | 2018-12-07 | 华为技术有限公司 | A kind of calculation method and device of Computer CPU Utilization Ratio |
CN113238832A (en) * | 2021-05-20 | 2021-08-10 | 元心信息科技集团有限公司 | Scheduling method, device and equipment of virtual processor and computer storage medium |
CN113467884A (en) * | 2021-05-25 | 2021-10-01 | 阿里巴巴新加坡控股有限公司 | Resource allocation method and device, electronic equipment and computer readable storage medium |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101408853A (en) * | 2008-10-27 | 2009-04-15 | 中国科学院计算技术研究所 | Apparatus and method for scheduling virtual machine |
CN100511151C (en) * | 2007-12-05 | 2009-07-08 | 华为技术有限公司 | Multiple-path multiple-core server and CPU virtualization processing method thereof |
CN101493782A (en) * | 2008-01-23 | 2009-07-29 | 松下电器产业株式会社 | Virtual multiprocessor system |
US20100031254A1 (en) * | 2008-07-30 | 2010-02-04 | Microsoft Corporation | Efficient detection and response to spin waits in multi-processor virtual machines |
CN102822809A (en) * | 2010-05-14 | 2012-12-12 | 松下电器产业株式会社 | Computer system |
CN103226496A (en) * | 2013-03-15 | 2013-07-31 | 杭州华三通信技术有限公司 | Synchronous service processing method and multi-core equipment |
CN103744716A (en) * | 2014-01-15 | 2014-04-23 | 上海交通大学 | Dynamic interrupt balanced mapping method based on current virtual central processing unit (VCPU) scheduling state |
CN103870332A (en) * | 2012-12-13 | 2014-06-18 | 中国电信股份有限公司 | Virtual machine processor resource adjusting method and device and virtual machine system |
CN104125166A (en) * | 2014-07-31 | 2014-10-29 | 华为技术有限公司 | Queue scheduling method and computing system |
-
2016
- 2016-12-29 CN CN201611245500.7A patent/CN108255572A/en active Pending
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100511151C (en) * | 2007-12-05 | 2009-07-08 | 华为技术有限公司 | Multiple-path multiple-core server and CPU virtualization processing method thereof |
CN101493782A (en) * | 2008-01-23 | 2009-07-29 | 松下电器产业株式会社 | Virtual multiprocessor system |
US20100031254A1 (en) * | 2008-07-30 | 2010-02-04 | Microsoft Corporation | Efficient detection and response to spin waits in multi-processor virtual machines |
CN101408853A (en) * | 2008-10-27 | 2009-04-15 | 中国科学院计算技术研究所 | Apparatus and method for scheduling virtual machine |
CN102822809A (en) * | 2010-05-14 | 2012-12-12 | 松下电器产业株式会社 | Computer system |
CN103870332A (en) * | 2012-12-13 | 2014-06-18 | 中国电信股份有限公司 | Virtual machine processor resource adjusting method and device and virtual machine system |
CN103226496A (en) * | 2013-03-15 | 2013-07-31 | 杭州华三通信技术有限公司 | Synchronous service processing method and multi-core equipment |
CN103744716A (en) * | 2014-01-15 | 2014-04-23 | 上海交通大学 | Dynamic interrupt balanced mapping method based on current virtual central processing unit (VCPU) scheduling state |
CN104125166A (en) * | 2014-07-31 | 2014-10-29 | 华为技术有限公司 | Queue scheduling method and computing system |
Non-Patent Citations (1)
Title |
---|
彭海文,: "Android Web Services应用研究", 《电脑知识与技术》 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108959020A (en) * | 2018-05-08 | 2018-12-07 | 华为技术有限公司 | A kind of calculation method and device of Computer CPU Utilization Ratio |
CN113238832A (en) * | 2021-05-20 | 2021-08-10 | 元心信息科技集团有限公司 | Scheduling method, device and equipment of virtual processor and computer storage medium |
CN113467884A (en) * | 2021-05-25 | 2021-10-01 | 阿里巴巴新加坡控股有限公司 | Resource allocation method and device, electronic equipment and computer readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110134495B (en) | Container cross-host online migration method, storage medium and terminal equipment | |
CN106302663B (en) | Local cloud computing via network segmentation | |
CN111078363A (en) | NUMA node scheduling method, device, equipment and medium for virtual machine | |
JP2008191949A (en) | Multi-core system, and method for distributing load of the same | |
Zheng et al. | Comma: Coordinating the migration of multi-tier applications | |
CN108255572A (en) | A kind of VCPU switching methods and physical host | |
CN106681839B (en) | Elastic calculation dynamic allocation method | |
CN108140086A (en) | Perform the method and system of virtual machine safely by one group of interconnection programmable device | |
CN106445631B (en) | Method and system for deploying virtual machine and physical server | |
CN104199739A (en) | Speculation type Hadoop scheduling method based on load balancing | |
CN108268301B (en) | Virtual machine deployment method and device for virtual network function | |
CN106227469A (en) | Data-erasure method and system for distributed storage cluster | |
CN108829510A (en) | Thread binds treating method and apparatus | |
KR102499705B1 (en) | Method for detecting service of network and apparatus using the same | |
Komarasamy et al. | A novel approach for Dynamic Load Balancing with effective Bin Packing and VM Reconfiguration in cloud | |
CN111953732A (en) | Resource scheduling method and device in cloud computing system | |
EP3109758A1 (en) | Method and apparatus for scaling an application | |
Katangur et al. | Priority weighted round robin algorithm for load balancing in the cloud | |
RU2599945C2 (en) | System and method for database augmentation with objects antivirus inspection on a plurality of virtual machines | |
Liu et al. | Scheduling parallel jobs using migration and consolidation in the cloud | |
CN112231053A (en) | Load balancing service distribution method and device | |
Hsiao et al. | A usage-aware scheduler for improving MapReduce performance in heterogeneous environments | |
Goutam et al. | The performance evaluation of proactive fault tolerant scheme over cloud using CloudSim simulator | |
Nair et al. | Performance degradation assessment and VM placement policy in cloud | |
Chen et al. | Network-aware coordination of virtual machine migrations in enterprise data centers and clouds |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |