Skip to content

Commit

Permalink
hv: vcpu: wait and signal vcpu event support
Browse files Browse the repository at this point in the history
Introduce two kinds of events for each vcpu,
  VCPU_EVENT_IOREQ: for vcpu waiting for IO request completion
  VCPU_EVENT_VIRTUAL_INTERRUPT: for vcpu waiting for virtual interrupts events
vcpu can wait for such events, and resume to run when the
event get signalled.

This patch also change IO request waiting/notifying to this way.

Tracked-On: #4329
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
Shuo A Liu authored and wenlingz committed Jan 7, 2020
1 parent 1f23fe3 commit e3c3033
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 4 additions & 1 deletion hypervisor/arch/x86/guest/vcpu.c
Expand Up @@ -802,7 +802,7 @@ void launch_vcpu(struct acrn_vcpu *vcpu)
/* help function for vcpu create */
int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
{
int32_t ret;
int32_t ret, i;
struct acrn_vcpu *vcpu = NULL;
char thread_name[16];

Expand All @@ -818,6 +818,9 @@ int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
vcpu->thread_obj.switch_out = context_switch_out;
vcpu->thread_obj.switch_in = context_switch_in;
init_thread_data(&vcpu->thread_obj);
for (i = 0; i < VCPU_EVENT_NUM; i++) {
init_event(&vcpu->events[i]);
}
}

return ret;
Expand Down
3 changes: 2 additions & 1 deletion hypervisor/common/hypercall.c
Expand Up @@ -553,8 +553,9 @@ int32_t hcall_notify_ioreq_finish(uint16_t vmid, uint16_t vcpu_id)
} else {
vcpu = vcpu_from_vid(target_vm, vcpu_id);
if (!vcpu->vm->sw.is_completion_polling) {
ret = resume_vcpu(vcpu);
signal_event(&vcpu->events[VCPU_EVENT_IOREQ]);
}
ret = 0;
}
}

Expand Down
12 changes: 1 addition & 11 deletions hypervisor/dm/io_req.c
Expand Up @@ -103,14 +103,6 @@ int32_t acrn_insert_request(struct acrn_vcpu *vcpu, const struct io_request *io_
}
clac();

/* pause vcpu in notification mode , wait for VHM to handle the MMIO request.
* TODO: when pause_vcpu changed to switch vcpu out directlly, we
* should fix the race issue between req.processed update and vcpu pause
*/
if (!is_polling) {
pause_vcpu(vcpu, VCPU_PAUSED);
}

/* Before updating the vhm_req state, enforce all fill vhm_req operations done */
cpu_write_memory_barrier();

Expand All @@ -136,10 +128,8 @@ int32_t acrn_insert_request(struct acrn_vcpu *vcpu, const struct io_request *io_
schedule();
}
}
} else if (need_reschedule(pcpuid_from_vcpu(vcpu))) {
schedule();
} else {
ret = -EINVAL;
wait_event(&vcpu->events[VCPU_EVENT_IOREQ]);
}
} else {
ret = -EINVAL;
Expand Down
7 changes: 7 additions & 0 deletions hypervisor/include/arch/x86/guest/vcpu.h
Expand Up @@ -22,6 +22,7 @@
#include <vlapic.h>
#include <vmtrr.h>
#include <schedule.h>
#include <event.h>
#include <io_req.h>
#include <msr.h>
#include <cpu.h>
Expand Down Expand Up @@ -145,6 +146,10 @@ enum vm_cpu_mode {
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
};

#define VCPU_EVENT_IOREQ 0
#define VCPU_EVENT_VIRTUAL_INTERRUPT 1
#define VCPU_EVENT_NUM 2

enum reset_mode;

/* 2 worlds: 0 for Normal World, 1 for Secure World */
Expand Down Expand Up @@ -260,6 +265,8 @@ struct acrn_vcpu {

uint64_t reg_cached;
uint64_t reg_updated;

struct sched_event events[VCPU_EVENT_NUM];
} __aligned(PAGE_SIZE);

struct vcpu_dump {
Expand Down

0 comments on commit e3c3033

Please sign in to comment.