Skip to content

Commit fbeafd5

Browse files
fyin1lijinxia
authored andcommitted
hv: add API to get the vcpu mapped to specific pcpu.
Per performance consideration, we don't flush vcpu context when doing vcpu swithing (because it's only swithing between vcpu and idle). But when enter S3, we need to call vmclear against all vcpus attached to APs. We need to know which vcpu is attached with which pcpu. This patch introduced API to get vcpu mapped to specific pcpu. Signed-off-by: Yin Fegnwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent 2dd4e8f commit fbeafd5

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern struct efi_ctx* efi_ctx;
1414

1515
vm_sw_loader_t vm_sw_loader;
1616

17+
struct vcpu *get_ever_run_vcpu(int pcpu_id)
18+
{
19+
return per_cpu(ever_run_vcpu, pcpu_id);
20+
}
21+
1722
/***********************************************************************
1823
* vcpu_id/pcpu_id mapping table:
1924
*
@@ -41,6 +46,7 @@ int create_vcpu(int cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
4146

4247
/* Initialize the physical CPU ID for this VCPU */
4348
vcpu->pcpu_id = cpu_id;
49+
per_cpu(ever_run_vcpu, cpu_id) = vcpu;
4450

4551
/* Initialize the parent VM reference */
4652
vcpu->vm = vm;
@@ -241,6 +247,7 @@ int destroy_vcpu(struct vcpu *vcpu)
241247
vlapic_free(vcpu);
242248
free(vcpu->arch_vcpu.vmcs);
243249
free(vcpu->guest_msrs);
250+
per_cpu(ever_run_vcpu, vcpu->pcpu_id) = NULL;
244251
free_pcpu(vcpu->pcpu_id);
245252
free(vcpu);
246253

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ struct vcpu {
253253
#define VCPU_RETAIN_RIP(vcpu) ((vcpu)->arch_vcpu.inst_len = 0)
254254

255255
/* External Interfaces */
256+
struct vcpu* get_ever_run_vcpu(int pcpu_id);
256257
int create_vcpu(int cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
257258
int start_vcpu(struct vcpu *vcpu);
258259
int shutdown_vcpu(struct vcpu *vcpu);

hypervisor/include/arch/x86/per_cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct per_cpu_region {
2121
struct dev_handler_node *timer_node;
2222
struct shared_buf *earlylog_sbuf;
2323
void *vcpu;
24+
void *ever_run_vcpu;
2425
#ifdef STACK_PROTECTOR
2526
struct stack_canary stack_canary;
2627
#endif

0 commit comments

Comments
 (0)