[vbox-dev] About Virtual Box VM Scheduling mechanism

Suk Kyu Lee sklee25 at korea.ac.kr
Tue Jul 6 00:08:32 PDT 2010

2010-07-05 오후 6:53, Knut St. Osmundsen 쓴 글:
> Suk Kyu Lee wrote:
>> Hello,
>> I'm sorry if you received this email twice. Somehow the email was
>> rejected. Thank you.
>> Here is the original context of the email:
>> Thank you very much for your reply.
>> Maybe I have misunderstood the context of the email. 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.
>> 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?
>> 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.
>> 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.
> I'm not quite sure if I understand what you're searching after, but if
> it's a thread scheduler you won't find it.  VirtualBox is, as Christian
> already pointed out, just an application and it is the host Operative
> System's job to schedule its threads.
> As you've probably figured out already, each EMT (EMulation Thread)
> corresponds to exactly one virtual guest CPU and the main task of an EMT
> is to execute guest code as that particular CPU.
> As part of the CPU virtualization, the EMTs will handle virtualization
> exceptions/exits and inject interrupts/exceptions/traps/faults.  These
> tasks are mostly handled in the inner loops in HWVMXR0.cpp and
> HWSVMR0.cpp, and in the trap handlers in TRPMGC.cpp (raw-mode only).
> The EMTs have some other tasks which is performed in the work loops
> found in EM.cpp, EMRaw.cpp and EMHwaccm.cpp.  These include running the
> timers (TM.cpp), work deferred from ring-0/raw-mode context, VM state
> changes, and more.
> The VMR3WaitHalted function is used by an EMT when the guest executes a
> HLT instruction.  All this does is to block the thread on some
> synchronization object provided by the host OS.  By default this is a
> kernel object, so it involves an ioctl() into VMMR0/GVMMR0.cpp.  The EMT
> will continue executing guest code when an emulated device raises an
> interrupt (usually via a timer or async I/O thread).  Timers are
> processed regularly while in the HLT state.  When async I/O threads
> raises interrupts, they will call VMR3NotifyCpuFFU/VMR3NotifyGlobalFFU
> and wake up the targeted EMTs, and the EMTs will inject the interrupts
> when scheduled by the host OS scheduler.
> Hope this was helpful.
> Kind Regards,
>   knut

Thank you for your reply.
It helped me a lot to understand the general scheduling policy within 
the VirtualBox.

I have some few more questions to ask.

1. I was wondering if there will be a way to actually implement a 
scheduling policy like the Xen's Credit Scheduler. As you have mentioned 
in the above context, I understand that the basic scheduling policy is 
done by the host machine. But I was wondering if there would be a spot 
within the VBox OSE to implement a custom scheduling policy for the EMTs.
I'm not sure if my knowledge is very sufficient to ask this, but based 
on my knowledge once the multiple threads(EMTs) are running, then I 
think there should be a way to actually coordinate the multiple EMTs to 
improve the performance of multiple VMs within the Virtual Box VMM.

2. I have been using the VBoxSDL to debug my work such as (./VBoxSDL 
–startvm Ubuntu_client1), but somehow it was rather difficult for me to 
see the debug message that I have implemented. For example, I was 
running two ubuntu guest machines, but I was having some hard time to 
see the cpu id nor some unique id that indicates the currently running 
VM within the VMM. I have used the
VMCPUID idCurCpu=VMMGetCpuId(); to display the CPU but the message that 
show up from two VMs were equal.
I was wondering if there is another way to see this kind of message.  Is 
there a way to actually see a debug message that shows that the VMM is 
coordinating multiple VMs?

Thank you very much in advance.

Suk Kyu Lee

More information about the vbox-dev mailing list