From 429f9bdbd495141b8738f092d5e99340a090345b Mon Sep 17 00:00:00 2001 From: Alexander Kudryavtsev Date: Fri, 23 Sep 2011 23:10:54 +0400 Subject: [PATCH 03/32] Support for real APIC ID retrieving from host OS. Note: os_hooks interface is changed! --- palacios/include/palacios/vmm.h | 13 +++++++++++-- palacios/src/palacios/vmm.c | 10 ++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index 4c95f2c..45cb736 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -176,7 +176,16 @@ struct guest_info; int ret = 0; \ extern struct v3_os_hooks * os_hooks; \ if ((os_hooks) && (os_hooks)->get_cpu) { \ - ret = (os_hooks)->get_cpu(); \ + ret = (os_hooks)->get_cpu(0); \ + } \ + ret; \ + }) + +#define V3_Get_CPU_APIC_ID() ({ \ + int ret = 0; \ + extern struct v3_os_hooks * os_hooks; \ + if ((os_hooks) && (os_hooks)->get_cpu) { \ + ret = (os_hooks)->get_cpu(1); \ } \ ret; \ }) @@ -297,7 +306,7 @@ struct v3_os_hooks { void (*mutex_lock)(void * mutex, int must_spin); void (*mutex_unlock)(void * mutex); - unsigned int (*get_cpu)(void); + unsigned int (*get_cpu)(int phys); diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 9e0fe08..b09cfb0 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -38,11 +38,14 @@ v3_cpu_arch_t v3_cpu_types[V3_CONFIG_MAX_CPUS]; struct v3_os_hooks * os_hooks = NULL; int v3_dbg_enable = 0; +// Map of logical CPU ID to corresponding APIC ID. +int v3_pcpu_to_apic_id[V3_CONFIG_MAX_CPUS]; static void init_cpu(void * arg) { uint32_t cpu_id = (uint32_t)(addr_t)arg; + v3_pcpu_to_apic_id[cpu_id] = V3_Get_CPU_APIC_ID(); #ifdef V3_CONFIG_SVM if (v3_is_svm_capable()) { @@ -199,11 +202,10 @@ static int start_core(void * p) { struct guest_info * core = (struct guest_info *)p; + PrintDebug("virtual core %u (on logical core %u, APIC ID %u): in start_core (RIP=%p)\n", + core->vcpu_id, core->pcpu_id, v3_pcpu_to_apic_id[core->pcpu_id], (void *)(addr_t)core->rip); - PrintDebug("virtual core %u (on logical core %u): in start_core (RIP=%p)\n", - core->vcpu_id, core->pcpu_id, (void *)(addr_t)core->rip); - - switch (v3_cpu_types[0]) { + switch (v3_cpu_types[core->pcpu_id]) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: -- 1.7.5.4