From 8a44067f8bf93f50ccfa0c8b0b859498765a747b Mon Sep 17 00:00:00 2001 From: Yuanyuan Zhao Date: Wed, 22 Dec 2021 21:21:31 +0800 Subject: [PATCH] dm: use lapic id to set cpu affinity. Cpu affinty was set by pcpu id which can't be obtained explictly by user. Use lapic id instead which can be easily read from `/proc/cpuinfo` as `apicid`. Tracked-On: #6690 Signed-off-by: Yuanyuan Zhao Acked-by: Wang Yu1 --- devicemodel/core/main.c | 5 +++-- devicemodel/core/vmmapi.c | 39 ++++++++------------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 90fd6b738..cf1cc65df 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -145,7 +145,7 @@ usage(int code) " %*s [--enable_trusty] [--intr_monitor param_setting]\n" " %*s [--acpidev_pt HID] [--mmiodev_pt MMIO_Regions]\n" " %*s [--vtpm2 sock_path] [--virtio_poll interval]\n" - " %*s [--cpu_affinity pCPUs] [--lapic_pt] [--rtvm] [--windows]\n" + " %*s [--cpu_affinity lapic_id] [--lapic_pt] [--rtvm] [--windows]\n" " %*s [--debugexit] [--logger_setting param_setting]\n" " %*s [--ssram] \n" " -B: bootargs for kernel\n" @@ -159,7 +159,8 @@ usage(int code) " -v: version\n" " --ovmf: ovmf file path\n" " --ssram: Congfiure Software SRAM parameters\n" - " --cpu_affinity: list of pCPUs assigned to this VM\n" + " --cpu_affinity: list of Service VM vCPUs assigned to this User VM, the vCPUs are" + " identified by their local APIC IDs.\n" " --enable_trusty: enable trusty for guest\n" " --debugexit: enable debug exit function\n" " --intr_monitor: enable interrupt storm monitor\n" diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 29a1a36c4..88f38068c 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -47,6 +47,7 @@ #include "pci_core.h" #include "log.h" #include "sw_load.h" +#include "acpi.h" #define MAP_NOCORE 0 #define MAP_ALIGNED_SUPER 0 @@ -93,15 +94,11 @@ static void add_one_pcpu(int pcpu_id) /* * example options: * --cpu_affinity 1,2,3 - * --cpu_affinity 1-3 - * --cpu_affinity 1,3,4-6 - * --cpu_affinity 1,3,4-6,9 */ int acrn_parse_cpu_affinity(char *opt) { char *str, *cp, *cp_opt; - int pcpu_id; - int pcpu_start, pcpu_end; + int lapic_id; cp_opt = cp = strdup(opt); if (!cp) { @@ -111,12 +108,12 @@ int acrn_parse_cpu_affinity(char *opt) /* white spaces within the commane line are invalid */ while (cp && isdigit(cp[0])) { - str = strpbrk(cp, ",-"); + str = strpbrk(cp, ","); - /* no more entries delimited by ',' or '-' */ + /* no more entries delimited by ',' */ if (!str) { - if (!dm_strtoi(cp, NULL, 10, &pcpu_id)) { - add_one_pcpu(pcpu_id); + if (!dm_strtoi(cp, NULL, 10, &lapic_id)) { + add_one_pcpu(lapic_to_pcpu(lapic_id)); } break; } else { @@ -125,30 +122,10 @@ int acrn_parse_cpu_affinity(char *opt) str = strsep(&cp, ","); /* parse the entry before ',' */ - if (dm_strtoi(str, NULL, 10, &pcpu_id)) { + if (dm_strtoi(str, NULL, 10, &lapic_id)) { goto err; } - add_one_pcpu(pcpu_id); - } - - if (*str == '-') { - str = strsep(&cp, "-"); - - /* parse the entry before and after '-' respectively */ - if (dm_strtoi(str, NULL, 10, &pcpu_start) || dm_strtoi(cp, NULL, 10, &pcpu_end)) { - goto err; - } - - if (pcpu_end <= pcpu_start) { - goto err; - } - - for (; pcpu_start <= pcpu_end; pcpu_start++) { - add_one_pcpu(pcpu_start); - } - - /* skip the ',' after pcpu_end */ - str = strsep(&cp, ","); + add_one_pcpu(lapic_to_pcpu(lapic_id)); } } }