Skip to content

Commit

Permalink
add hypercall hc_sos_offline_cpu support
Browse files Browse the repository at this point in the history
SOS boot with all physicall cpus, before running UOS, it should free
CPU resource by offline not used cpus
- first do standard cpu offline flow
- then call hcall_sos_offline_cpu hypercall to release cpu resource really

Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
JasonChenCJ authored and lijinxia committed Jul 25, 2018
1 parent 589c723 commit 2dca23c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hypervisor/arch/x86/guest/vmcall.c
Expand Up @@ -38,6 +38,9 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)

/* Dispatch the hypercall handler */
switch (hypcall_id) {
case HC_SOS_OFFLINE_CPU:
ret = hcall_sos_offline_cpu(vm, param1);
break;
case HC_GET_API_VERSION:
#ifdef CONFIG_VM0_DESC
/* vm0 will call HC_GET_API_VERSION as first hypercall, fixup
Expand Down
24 changes: 24 additions & 0 deletions hypervisor/common/hypercall.c
Expand Up @@ -25,6 +25,30 @@ bool is_hypercall_from_ring0(void)
return false;
}

int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid)
{
struct vcpu *vcpu;
int i;

if (!is_vm0(vm))
return -1;

pr_info("sos offline cpu with lapicid %lld", lapicid);

foreach_vcpu(i, vm, vcpu) {
if (vlapic_get_apicid(vcpu->arch_vcpu.vlapic) == lapicid) {
/* should not offline BSP */
if (vcpu->vcpu_id == 0)
return -1;
pause_vcpu(vcpu, VCPU_ZOMBIE);
reset_vcpu(vcpu);
destroy_vcpu(vcpu);
}
}

return 0;
}

int32_t hcall_get_api_version(struct vm *vm, uint64_t param)
{
struct hc_api_version version;
Expand Down
12 changes: 12 additions & 0 deletions hypervisor/include/common/hypercall.h
Expand Up @@ -24,6 +24,18 @@ bool is_hypercall_from_ring0(void);
* @{
*/

/**
* @brief offline vcpu from SOS
*
* The function offline specific vcpu from SOS.
*
* @param vm Pointer to VM data structure
* @param lapicid lapic id of the vcpu which wants to offline
*
* @return 0 on success, non-zero on error.
*/
int32_t hcall_sos_offline_cpu(struct vm *vm, uint64_t lapicid);

/**
* @brief Get hypervisor api version
*
Expand Down
1 change: 1 addition & 0 deletions hypervisor/include/public/acrn_hv_defs.h
Expand Up @@ -26,6 +26,7 @@
/* general */
#define HC_ID_GEN_BASE 0x0UL
#define HC_GET_API_VERSION _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00UL)
#define HC_SOS_OFFLINE_CPU _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01UL)

/* VM management */
#define HC_ID_VM_BASE 0x10UL
Expand Down

0 comments on commit 2dca23c

Please sign in to comment.