From: "Casey Jeffery" Subject: Re: KVM and Perf Counters Date: Thu, 1 Feb 2007 10:43:50 -0500 Message-ID: References: <45A4B3E4.7090202@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Return-path: In-Reply-To: <45A4B3E4.7090202-atKUWr5tajBWk0Htik3J/w@public.gmane.org> Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org I wanted to give an update on a project I'm attempting with KVM. The goal is to implement a software-based lockstepping of two or more virtual guests. There are a number of applications of this, and the most related is the ReVirt project that was done with UML and Xen by Dunlap et al. The basic idea is to remove the non-deterministic events that occur in the system by giving each guest the same I/O values from external devices, tsc, etc. and only injecting interrupts at deterministic points in the instruction stream. I'm actually trying to get multiple guests to run simultaneously rather than storing the run of one guest and repeating it at a later time, but it's basically the same thing. The goal is to use the perf counters to trigger NMI's after a given number of events (e.g. 1k branches) and delivering all interrupts at those VMEXIT's in all guests. It is also necessary to buffer all external input from one guest and give the same input to all the others, as well as optionally check all external output for consistency. With a couple pointers from Avi, I have figured out how to make use of the performance counter MSR's in KVM to trigger NMI's that exit to the hypervisor at deterministic points in the guest. There is still an issue of delayed NMI delivery that causes the NMI to actually occur in root mode. This seems to occur if a perf counter overflows near another event that causes a VMEXIT, and by the time the NMI propagates up the pipeline, the CPU has already exited. I think this can be handled by using both perf counters and keeping a global event counter that is used to determine the point to inject interrupts. The main questions I have at the moment are the following: 1. What is the best way to start and ID multiple guests? I've just been configuring a script to start up two of them from the command-line and storing an ID in the kvm_vcpu structure. The first to get to get to vmc_run() is designated as the primary and the other is then the secondary that will replicate what the primary does. I'm open to ideas on automating the creation of multiple guests (with pinning to CPUs). 2. Where should the bulk of the buffering and synchronization be done? I've been putting everything in the hypervisor since it can see all the guests. It may make sense to put some things in the qemu code and make use of other IPC mechanisms for synchronization, though. 3. What is the best way to deal with I/O string/string_down calls that handle the I/O in kvmctl.c? I would guess it will be necessary to buffer the memory range somewhere and pass the address of that someone for the secondary guest to access when it gets to that point. 4. DMA? I haven't thought about this much yet and am using simple guests that don't do it. It will need to be handled eventually, though. There are many others, but these are the top things that I'm still not clear on. I'd appreciate any input from others experienced in this area. Thanks, Casey On 1/10/07, Avi Kivity wrote: > Casey Jeffery wrote: > > I've tried out the last few versions of KVM and think it's great. It's > > much easier to use and understand than Xen and performance is > > surprisingly good. > > > > One of the things I'd like to do is modify it to allow PMI generation > > based on the Intel performance counter facilities. Specifically, I'd > > like to be able to pin a guest to a CPU, program one of the IA32_PMCx > > MSR's to a count, configure the LVT to deliver an NMI on overflow, > > enable the PERF_EVT_SELx, and use the hardware-based MSR save/restore > > area to disable counting in root mode and re-enable when entering > > non-root. > > > > Ok. Note that there are two possible mutually exclusive uses for the > performance counters: > > 1. Allow the guest to program the performance counters as it sees fit, > for example to run oprofile internally. > 2. Let the host control the performance counters, for stuff like > deterministic record/replay. > > We should by default allow (1), with the option for (2). This is > somewhat similar to the hardware breakpoints, so you'd need some control > like KVM_DEBUG_GUEST to switch modes. > > > The questions I have now are the following: > > > > 1. It looks like the MSR save/restore area is set up already for EFER > > MSR and I assume that adding IA32_PMCx and IA32_PERFEVTSEL to the > > vmx_msr_index[] array would be enough to save/restore them. Is that > > correct? > > > > Yes. > > > 2. I don't completely follow the code from vmx.c > > > > save_msrs(vcpu->host_msrs, vcpu->nmsrs); > > > > This saves the host msrs to the host save area. > > > load_msrs(vcpu->guest_msrs, NR_BAD_MSRS); > > > > vmx has a bug where it corrupts a couple of msrs, so we load the first > NR_BAD_MSRS explicitly. > > > > ...VMLAUNCH/RESUME etc. ... > > > > This loads vcpu->nmsrs - NR_BAD_MSRS from the guest area. > > > .... > > ...VMEXIT... > > > > > > This saves vcpu->nmsrs - NR_BAD_MSRS into the guest area, and then loads > vcpu->nmsrs - NR_BAD_MSRS from the host area. > > > > save_msrs(vcpu->guest_msrs, NR_BAD_MSRS); > > load_msrs(vcpu->host_msrs, NR_BAD_MSRS); > > > > These two lines do the same for the vmx-incompatible msrs. > > > Does this mean the MSR values to be loaded on VM exit are initialized > > before leaving root mode while the VM_entry_load / VM_exit_store area > > is not touched? > > > > I'm not sure I understand the question, but host msrs are never saved > automatically, and there are a couple of msrs we load and save manually > for both host and guest. > > > 3. Is it possible to attribute counter ticks solely to a given KVM > > guest process and avoid counting ticks from other processes? I assume > > this isn't a problem since a VM exit should occur if the KVM process > > were to be pulled off the CPU by the kernel to do a context switch. > > > > Yes. > > -- > error compiling committee.c: too many arguments to function > > ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642