Skip to contentSkip to conversation

Pin vcpu for VMX domain

PATCH In review Jiang, Yunhong 2 participants 2 messages Feb 8, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Pin vcpu for VMX domain

The patch fixed pin-vcpu issue for VMX domain.
The __vmpclear should be done on the last_launch LP. It also migrate the timers for vmx domain.

<mailto:[email protected]>

For SVM domain
=======
The operation for timers may be needed.

Thanks
Yunhong Jiang

xen/arch/x86/domain.c +6 -0
diff -r 859c8d66b203 xen/arch/x86/domain.c
@@ -807,6 +807,12 @@
     return switch_required;
 }
 
+void arch_vcpu_remove_affinity(struct vcpu *v, int new_processor)
+{
+    if (HVM_DOMAIN(v) && (v->arch.hvm_vmx.launch_cpu != new_processor))
+        hvm_vcpu_remove_affinity(v, new_processor);
+}
+
 void sync_vcpu_execstate(struct vcpu *v)
 {
     if ( cpu_isset(smp_processor_id(), v->vcpu_dirty_cpumask) )
xen/arch/x86/hvm/intercept.c +1 -1
diff -r 859c8d66b203 xen/arch/x86/hvm/intercept.c
@@ -348,7 +348,7 @@
 }
 
 /* hooks function for the PIT when the guest is active */
-static void pit_timer_fn(void *data)
+void pit_timer_fn(void *data)
 {
     struct vcpu *v = data;
     struct hvm_virpit *vpit = &(v->domain->arch.hvm_domain.vpit);
xen/arch/x86/hvm/vmx/vmcs.c +24 -3
diff -r 859c8d66b203 xen/arch/x86/hvm/vmx/vmcs.c
@@ -167,6 +167,7 @@
     host_env.tr_base = (unsigned long) &init_tss[cpu];
     error |= __vmwrite(HOST_TR_SELECTOR, host_env.tr_selector);
     error |= __vmwrite(HOST_TR_BASE, host_env.tr_base);
+    error |= __vmwrite(HOST_RSP, (unsigned long)get_stack_bottom());
 }
 
 static void vmx_do_launch(struct vcpu *v)
@@ -212,7 +213,6 @@
     shadow_direct_map_init(v);
     __vmwrite(GUEST_CR3, pagetable_get_paddr(v->domain->arch.phys_table));
     __vmwrite(HOST_CR3, pagetable_get_paddr(v->arch.monitor_table));
-    __vmwrite(HOST_RSP, (unsigned long)get_stack_bottom());
 
     v->arch.schedule_tail = arch_vmx_do_resume;
     v->arch.hvm_vmx.launch_cpu = smp_processor_id();
@@ -500,6 +500,27 @@
     __hvm_bug(guest_cpu_user_regs());
 }
 
+static void vmx_reinstall_timers(struct vcpu *v)
+{
+    struct hvm_virpit *vpit = &(v->domain->arch.hvm_domain.vpit);
+
+    ASSERT(v->arch.arch_vmx.launch_cpu != smp_processor_id());
+
+    ASSERT(!active_timer(&vpit->pit_timer));
+    ASSERT(!active_timer(&v->arch.hvm_vmx.hlt_timer));
+
+    /* vmx_do_resume will add pit_timer back */
+    init_timer(&vpit->pit_timer, pit_timer_fn, v, v->processor);
+
+    /* we dont need to set the hlt timer here */
+    init_timer(&v->arch.hvm_vmx.hlt_timer,
+                  hlt_timer_fn, v, v->processor);
+
+    if (hvm_apic_support(v->domain) && VLAPIC(v))
+       init_timer(&(VLAPIC(v))->vlapic_timer, vlapic_timer_fn,
+                     VLAPIC(v), v->processor);
+}
+
 void arch_vmx_do_resume(struct vcpu *v)
 {
     if ( v->arch.hvm_vmx.launch_cpu == smp_processor_id() )
@@ -510,10 +531,10 @@
     }
     else
     {
-        __vmpclear(virt_to_maddr(v->arch.hvm_vmx.vmcs));
         load_vmcs(&v->arch.hvm_vmx, virt_to_maddr(v->arch.hvm_vmx.vmcs));
+        vmx_set_host_env(v);
+        vmx_reinstall_timers(v);
         vmx_do_resume(v);
-        vmx_set_host_env(v);
         v->arch.hvm_vmx.launch_cpu = smp_processor_id();
         reset_stack_and_jump(vmx_asm_do_relaunch);
     }
xen/arch/x86/hvm/vmx/vmx.c +51 -1

70 lines not on this page · raw message

xen/common/sched_bvt.c +5 -1
diff -r 859c8d66b203 xen/common/sched_bvt.c
@@ -284,12 +284,16 @@
 
 static int bvt_set_affinity(struct vcpu *v, cpumask_t *affinity)
 {
+    int new_processor;
+
     if ( v == current )
         return cpu_isset(v->processor, *affinity) ? 0 : -EBUSY;
 
     vcpu_pause(v);
     v->cpu_affinity = *affinity;
-    v->processor = first_cpu(v->cpu_affinity);
+    new_processor = first_cpu(v->cpu_affinity);
+    arch_vcpu_remove_affinity(v, new_processor);
+    v->processor = new_processor;
     EBVT_INFO(v)->migrated = 1;
     vcpu_unpause(v);
 
xen/common/sched_sedf.c +5 -1
diff -r 859c8d66b203 xen/common/sched_sedf.c
@@ -1391,12 +1391,16 @@
 
 static int sedf_set_affinity(struct vcpu *v, cpumask_t *affinity)
 {
+    int new_processor;
+
     if ( v == current )
         return cpu_isset(v->processor, *affinity) ? 0 : -EBUSY;
 
     vcpu_pause(v);
     v->cpu_affinity = *affinity;
-    v->processor = first_cpu(v->cpu_affinity);
+    new_processor = first_cpu(v->cpu_affinity);
+    arch_vcpu_remove_affinity(v, new_processor);
+    v->processor = new_processor;
     vcpu_unpause(v);
 
     return 0;
xen/include/asm-x86/domain.h +1 -0
diff -r 859c8d66b203 xen/include/asm-x86/domain.h
@@ -170,6 +170,7 @@
 #define hvm_vmx         hvm_vcpu.u.vmx
 #define hvm_svm         hvm_vcpu.u.svm
 
+extern void arch_vcpu_remove_affinity(struct vcpu *v, int new_processor);
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/asm-x86/hvm/hvm.h +9 -1
diff -r 859c8d66b203 xen/include/asm-x86/hvm/hvm.h
@@ -37,7 +37,7 @@
      */
     int (*initialize_guest_resources)(struct vcpu *v);
     int (*relinquish_guest_resources)(struct vcpu *v);
-
+    int (*vcpu_remove_affinity)(struct vcpu *v, int new_processor);
     /*
      * Store and load guest state:
      * 1) load/store guest register state,
@@ -92,6 +92,14 @@
 {
     if (hvm_funcs.relinquish_guest_resources)
 	return hvm_funcs.relinquish_guest_resources(v);
+    return 0;
+}
+
+static inline int
+hvm_vcpu_remove_affinity(struct vcpu *v, int new_processor)
+{
+    if (hvm_funcs.vcpu_remove_affinity)
+        return hvm_funcs.vcpu_remove_affinity(v, new_processor);
     return 0;
 }
 
xen/include/asm-x86/hvm/io.h +1 -0
diff -r 859c8d66b203 xen/include/asm-x86/hvm/io.h
@@ -152,6 +152,7 @@
 extern void pic_irq_request(int *interrupt_request, int level);
 extern void hvm_pic_assist(struct vcpu *v);
 extern int cpu_get_interrupt(struct vcpu *v, int *type);
+extern void pit_timer_fn(void *data);
 
 // XXX - think about this, maybe use bit 30 of the mfn to signify an MMIO frame.
 #define mmio_space(gpa) (!VALID_MFN(get_mfn_from_gpfn((gpa) >> PAGE_SHIFT)))
xen/include/asm-x86/hvm/vlapic.h +1 -0
diff -r 859c8d66b203 xen/include/asm-x86/hvm/vlapic.h
@@ -250,4 +250,5 @@
 s_time_t get_apictime_scheduled(struct vcpu *v);
 int hvm_apic_support(struct domain *d);
 
+extern void vlapic_timer_fn(void *data);
 #endif /* __ASM_X86_HVM_VLAPIC_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 6 lines · Yunhong

The patch fixed pin-vcpu issue for VMX domain.
The __vmpclear should be done on the last_launch LP. It also migrate the timers for vmx domain.

You don't need to __vmpclear at the time the affinity is changed. You can still do it from within arch_vmx_do_resume() -- it is valid to call smp_call_function() there. That avoids having yet another HVM function, and avoids calling yet another arch_* function from common code.

Rather than calling vmx_remove_timers() from your SMP call function, can you not just call it from vmx_reinstall_timers()? You explain why the pit and hlt timers do not need to be re-activated in vmx_reinstall_timer() -- what about the APIC timer?

There's no need to check active_timer() before calling stop_timer() -- stop_timer does the check for you.

-- Keir