From 02b51afb7e6b250b4cd964cd447e71bd4f31236d Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Wed, 9 Apr 2014 16:01:58 +0200 Subject: kvm, x86: Add initial support for multicore simulation Simulating a SMP or multicore requires devices to be shared between multiple KVM vCPUs. This means that locking is required when accessing devices. This changeset adds the necessary locking to allow devices to execute correctly. It is implemented by temporarily migrating the KVM CPU to the VM's (and devices) event queue when handling MMIO. Similarly, the VM migrates to the interrupt controller's event queue when delivering an interrupt. The support for fast-forwarding of multicore simulations added by this changeset assumes that all devices in a system are simulated in the same thread and each vCPU has its own thread. Special care must be taken to ensure that devices living under the CPU in the object hierarchy (e.g., the interrupt controller) do not inherit the parent CPUs thread and are assigned to device thread. The KvmVM object is assumed to live in the same thread as the other devices in the system. --- src/cpu/kvm/x86_cpu.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/cpu/kvm/x86_cpu.cc') diff --git a/src/cpu/kvm/x86_cpu.cc b/src/cpu/kvm/x86_cpu.cc index ea8c47082..3e736a913 100644 --- a/src/cpu/kvm/x86_cpu.cc +++ b/src/cpu/kvm/x86_cpu.cc @@ -1134,10 +1134,20 @@ X86KvmCPU::updateThreadContextMSRs() void X86KvmCPU::deliverInterrupts() { + Fault fault; + syncThreadContext(); - Fault fault(interrupts->getInterrupt(tc)); - interrupts->updateIntrInfo(tc); + { + // Migrate to the interrupt controller's thread to get the + // interrupt. Even though the individual methods are safe to + // call across threads, we might still lose interrupts unless + // they are getInterrupt() and updateIntrInfo() are called + // atomically. + EventQueue::ScopedMigration migrate(interrupts->eventQueue()); + fault = interrupts->getInterrupt(tc); + interrupts->updateIntrInfo(tc); + } X86Interrupt *x86int(dynamic_cast(fault.get())); if (dynamic_cast(fault.get())) { @@ -1340,6 +1350,10 @@ X86KvmCPU::handleKvmExitIO() dataMasterId()); const MemCmd cmd(isWrite ? MemCmd::WriteReq : MemCmd::ReadReq); + // Temporarily lock and migrate to the event queue of the + // VM. This queue is assumed to "own" all devices we need to + // access if running in multi-core mode. + EventQueue::ScopedMigration migrate(vm.eventQueue()); for (int i = 0; i < count; ++i) { Packet pkt(&io_req, cmd); -- cgit v1.2.3