Each VM is assigned a weight and a cap. If the cap is 0, then
the VM can receive any extra CPU (WC-mode). A non-zero cap
(expressed as a percentage) limits the amount of CPU a VM receives
(NWC-mode). The Credit scheduler uses 30 ms time slices for CPU
allocation. A VM (VCPU) receives 30 ms before being preempted
to run another VM. Once every 30 ms, the priorities (credits) of all
runnable VMs are recalculated. The scheduler monitors resource
usage every 10 ms. To some degree, Credit’s computation of credits
resembles virtual time computation in BVT. However, BVT has a
context switch allowance C for defining a different size of the basic
time slice (time quantum), and an additional low-latency support (via
warp) for real-time applications.
In summary, Credit has the following features:
? non-preemptive, WC and NWC modes;
? global load balancing on multiprocessors.
In the next section, we present results of a performance study comparing
these schedulers and their features in more detail.
Domain有两种状态,UNDER和OVER。OVER表示虚拟机的credit值已用完,UNDER表示credit值还有剩余。在进行调度时,调度器只关心虚拟机所处的状态,而不会进一步关心其剩余的credit值,处于UNDER状态的虚拟机优先于OVER状态的虚拟机被调度,只有当UNDER状态的虚拟机都无法运行时才会调度到OVER状态的虚拟机,所以,只有当处理器空闲时才允许破坏credit的公平性调度策略。处于相同状态的虚拟机按照先进先出的方式运行,当处于队列首部的虚拟机被调度到时,在其credit值足够的情况下,允许其运行三个调度时长,即30ms。系统每隔10ms触发一次调度中断,当前正在运行的虚拟机会被减掉100个credit,当所有虚拟机的credit值总和变为负值时,为所有虚拟机重新分配credit:
1.每个物理CPU下面都有一个虚拟CPU的运行队列
2.每个运行队列中的VCPU都有一个credit值
3. credit表示VCPU的priority的价值
4.CPU调度的是最先入队的处于under状态下的VCPU
5.每10msec 为一个时间片,相应一次中断。如果被调度的VCPU的credit处于OVER状态那么它将不再被继续调度,重新计算credit值,调度后面的处于under状态下的第一个VCPU
6.如果进行了3个时间片也就是30msec时,原先的VCPU还是没有处于OVER状态,那么这个VCPU也将不被继续调度,credit值的重计算,同5后面的步骤
7.代码中的计算公式VCPU的credit = credit –CSCHED_CREDITS_PER_TICK (100)+30msec/n(VCPU的数)
8.处于OVER状态的VCPU credit的值不被增加。