From 356bf1849188c4c673a4a89283feaf420fbf690d Mon Sep 17 00:00:00 2001 From: Kaige Fu Date: Thu, 9 May 2019 11:40:43 +0000 Subject: [PATCH] DM: Get max vcpu per vm from HV instead of hardcode This patch tries to fetch max vcpu per vm from HV instead of hardcode in DM. Tracked-On: #3116 Signed-off-by: Kaige Fu Acked-by: Yin Fengwei --- devicemodel/core/main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 5c6e9dc2d..5d1babf18 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "vmmapi.h" #include "sw_load.h" @@ -695,10 +696,20 @@ vm_loop(struct vmctx *ctx) static int num_vcpus_allowed(struct vmctx *ctx) { - /* TODO: add ioctl to get gerneric information including - * virtual cpus, now hardcode - */ - return VM_MAXCPU; + int err; + uint16_t max_cpu; + struct platform_info info; + + err = ioctl(ctx->fd, IC_GET_PLATFORM_INFO, &info); + if (err != 0) { + /* Use VM_MAXCPU as default */ + max_cpu = VM_MAXCPU; + printf("Failed to get max vcpu from HV, use default: %d. errno(%d)\n", max_cpu, err); + } else { + max_cpu = info.max_vcpus_per_vm; + } + + return max_cpu; } static void