[vbox-dev] About Virtual Box VM Scheduling mechanism
Nikolay.Igotti at Sun.COM
Mon Jul 5 01:46:36 PDT 2010
Suk Kyu Lee wrote:
> But I was wondering within the VMM, if there is any scheduling mechanism that might coordinate the work of each EMT that belongs to the VM. For example, EMT1 controls the CPU and while EMT1 is working, EMT2 is sleeping and etc.
That's up to host OS to schedule tasks/threads, including ones
belonging to the VMM.
> Maybe my knowledge is not sufficient, but what do you mean by the host OS schedules the EMTs? Is there any mechanism that coordinates the EMTs within the host machine?
EMT is just a thread (like one you create in your regular program with
pthread_create() or _beginthread()).
Host's kernel is what hypervisor runs on, we're Type 2 hypervisor.
> Likewise, within the Xen, I found out that there is a "Credit" Scheduler where it coordinates the CPU/IO resource amongst the VMs within the Xen VMM.
I'm not Xen expert, but guess you refer to this one
This one looks like some form of additional scheduler on top of (or
integrated into) OS scheduler , and surely has its own benefits.
VirtualBox doesn't do that, and rely on host scheduling policies.
> Because when I was looking over the VirtualBox code, I couldn't find the code that coordinates the EMT threads. I even disabled the HALT/Yield function within the VMM.cpp but it looks like there hasn't been any effect with/without these functions.
Yield just yields real CPU and it's up to host scheduler to decide what
to do next.
PS: I was also somewhat unclear in my previous mail: when running guest
code with hardware acceleration, even non-privileged guest code
execution is initiated from host's kernel context, so in some sense
inside HWACCMR0RunGuestCode() (see src/VBox/VMM/VMMR0/HWACCMR0.cpp),
for VT-x it's VMXR0RunGuestCode().
You can think about this function as of simple scheduler (and probably
Knut or Sander can shed more light on how exactly
scheduling decisions being made there).
> -----Original Message-----
> From: Nikolay.Igotti at Sun.COM [mailto:Nikolay.Igotti at Sun.COM]
> Sent: Monday, July 05, 2010 3:49 PM
> To: Christian Pötzsch
> Cc: VirtualBox developer's list; Suk Kyu Lee
> Subject: Re: [vbox-dev] About Virtual Box VM Scheduling mechanism
> Chris is correct that VM mostly executed in regular OS thread (called EMT - emulation thread), things gets somewhat non-trivial when we talk about priveledged guest execution. Guest R0 code is executed in virtualized R0 (technically, in host kernel, inside ioctl() performed by EMT), and in sense, R0 code has its own preemption mechanism (details depends on virtualization technology used). Device emulation code is also partially in R0, but probably not of much relevance here.
> Guest SMP spawns multiple threads of execution (thus can use multiple physical CPUs), and they interact via emulated interrupt controller (APIC) and indirectly via shared resources locks (such as device lock).
> Is there any specific problem you see?
> Christian Pötzsch пишет:
>> AFAIK, there is one EMT thread per VM and as different VM's are
>> executed as different processes they are scheduled by the host OS
>> scheduler. In the SMP case is more than one EMT thread, but these
>> threads are schedules by the OS as well.
>> I will resent this to the dev mailing list, cause there are people
>> which know that stuff much more. Please ask and answer there.
>> On 7/2/10 7:19 AM, Suk Kyu Lee wrote:
>>> My name is Suk Kyu Lee and I’m a graduate research assistant at Korea
>>> I’m currently doing a research regarding about virtualization and was
>>> using the VirtualBox OSE 3.1.6.
>>> I was wondering if it is possible to know the general idea of the how
>>> the VM scheduling mechanism within the Virtual Box.
>>> I was having some problem with the code and it appears that there are
>>> EMT thread within each VM, but couldn’t find the location within the
>>> code regarding about how the VMM schedules the VM.
>>> Thank you.
>>> Suk Kyu Lee
More information about the vbox-dev