From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301490; cv=none; d=zohomail.com; s=zohoarc; b=LI+fEOhhwFNZwA+ldA/nQOeQlUdAtRgHugZLRqbkmJi+p07ctir50UabG9vgmhChfB3GGOjABQA4FHirC1v1Wn1n5qV9rkGVm7LNl+G4taakroY0fExfR761XSasViJsbp197fIjLMTs35m1KoeoR90zDl/jJJbAZBH0LXemAx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301490; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mXnwdtTVR8iXPHkftY93JoueAV9w+gERgLcoDNLqaS8=; b=Mbl2KoR04SZhqV+d7gHi0NYdR4AljKfrWo+jMgcV/slkZePzSEEUAoDj3J3ZL0QrBCdNlw5phzO2s5H/3Ur8fY5/9lTQVTcRh7RcPmIzipRKBgqmzOpl0prsJg3NzWhvdSGpdx07C8FzrQQblIWem87gYfZjx0F9tR9VxxJxbLo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161830148999462.156019303391304; Tue, 13 Apr 2021 01:11:29 -0700 (PDT) Received: from localhost ([::1]:44250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWE8u-0000kN-Pu for importer@patchew.org; Tue, 13 Apr 2021 04:11:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5m-00048x-BZ; Tue, 13 Apr 2021 04:08:14 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5h-0006Pu-8t; Tue, 13 Apr 2021 04:08:14 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8H320rzlXcY; Tue, 13 Apr 2021 16:06:07 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:49 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 1/6] device_tree: Add qemu_fdt_add_path Date: Tue, 13 Apr 2021 16:07:40 +0800 Message-ID: <20210413080745.33004-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andrew Jones qemu_fdt_add_path() works like qemu_fdt_add_subnode(), except it also adds any missing subnodes in the path. We also tweak an error message of qemu_fdt_add_subnode(). We'll make use of this new function in a coming patch. Signed-off-by: Andrew Jones Signed-off-by: Yanan Wang --- include/sysemu/device_tree.h | 1 + softmmu/device_tree.c | 45 ++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index 8a2fe55622..ef060a9759 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -121,6 +121,7 @@ uint32_t qemu_fdt_get_phandle(void *fdt, const char *pa= th); uint32_t qemu_fdt_alloc_phandle(void *fdt); int qemu_fdt_nop_node(void *fdt, const char *node_path); int qemu_fdt_add_subnode(void *fdt, const char *name); +int qemu_fdt_add_path(void *fdt, const char *path); =20 #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) = \ do { = \ diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index 2691c58cf6..8592c7aa1b 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -541,8 +541,8 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) =20 retval =3D fdt_add_subnode(fdt, parent, basename); if (retval < 0) { - error_report("FDT: Failed to create subnode %s: %s", name, - fdt_strerror(retval)); + error_report("%s: Failed to create subnode %s: %s", + __func__, name, fdt_strerror(retval)); exit(1); } =20 @@ -550,6 +550,47 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) return retval; } =20 +/* + * Like qemu_fdt_add_subnode(), but will add all missing + * subnodes in the path. + */ +int qemu_fdt_add_path(void *fdt, const char *path) +{ + char *dupname, *basename, *p; + int parent, retval =3D -1; + + if (path[0] !=3D '/') { + return retval; + } + + parent =3D fdt_path_offset(fdt, "/"); + p =3D dupname =3D g_strdup(path); + + while (p) { + *p =3D '/'; + basename =3D p + 1; + p =3D strchr(p + 1, '/'); + if (p) { + *p =3D '\0'; + } + retval =3D fdt_path_offset(fdt, dupname); + if (retval < 0 && retval !=3D -FDT_ERR_NOTFOUND) { + error_report("%s: Invalid path %s: %s", + __func__, path, fdt_strerror(retval)); + exit(1); + } else if (retval =3D=3D -FDT_ERR_NOTFOUND) { + retval =3D fdt_add_subnode(fdt, parent, basename); + if (retval < 0) { + break; + } + } + parent =3D retval; + } + + g_free(dupname); + return retval; +} + void qemu_fdt_dumpdtb(void *fdt, int size) { const char *dumpdtb =3D current_machine->dumpdtb; --=20 2.19.1 From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301387; cv=none; d=zohomail.com; s=zohoarc; b=jUBXXU7XZ97dMpFKb2wgGTWmDpcA8t324/fKbBX1KLdOTf8UYAU2X5NOSWLgBfJoIHeNoGNS5Y7KDEjAkTxvURYvpfXGUjagN2UhUZePaM3iy8kff4SQMebYflx9+nT8wX8Lww4ABVS/3rhHdENhnM6IhHbE6pJZMhkCBxP224o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301387; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WXVQ757f6lIkHmGNpqS4rvuSZ+VxegVoRpzBhZQIpUI=; b=S9WD77OkK1ewDZbnouBU6nPxG73mL8WSCeYkv7Dd1DJYPNRNUn76g0s2heu5/zhDxBdDa5kDAYdWxooVEEo2reE7DVIYzykk8Gpvl8rNO880fW/jqkpTf/vHvvpMDcQC2MFL7ZbEw5iIvUl5n4SWZeJyMaIJD46zoC9biVWF+hw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618301387994503.06408797681; Tue, 13 Apr 2021 01:09:47 -0700 (PDT) Received: from localhost ([::1]:37048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWE7G-0006EF-TO for importer@patchew.org; Tue, 13 Apr 2021 04:09:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5m-00049k-M5; Tue, 13 Apr 2021 04:08:14 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5h-0006Pv-Fc; Tue, 13 Apr 2021 04:08:14 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8H2l5fzlXcW; Tue, 13 Apr 2021 16:06:07 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:51 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 2/6] hw/arm/virt: DT: Add cpu-map Date: Tue, 13 Apr 2021 16:07:41 +0800 Message-ID: <20210413080745.33004-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andrew Jones Support device tree CPU topology descriptions. Signed-off-by: Andrew Jones Signed-off-by: Yanan Wang --- hw/arm/virt.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 9f01d9041b..f4ae60ded9 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -352,10 +352,11 @@ static void fdt_add_cpu_nodes(const VirtMachineState = *vms) int cpu; int addr_cells =3D 1; const MachineState *ms =3D MACHINE(vms); + const VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(vms); int smp_cpus =3D ms->smp.cpus; =20 /* - * From Documentation/devicetree/bindings/arm/cpus.txt + * See Linux Documentation/devicetree/bindings/arm/cpus.yaml * On ARM v8 64-bit systems value should be set to 2, * that corresponds to the MPIDR_EL1 register size. * If MPIDR_EL1[63:32] value is equal to 0 on all CPUs @@ -408,8 +409,45 @@ static void fdt_add_cpu_nodes(const VirtMachineState *= vms) ms->possible_cpus->cpus[cs->cpu_index].props.node_id); } =20 + if (ms->smp.cpus > 1 && !vmc->no_cpu_topology) { + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", + qemu_fdt_alloc_phandle(ms->fdt)); + } + g_free(nodename); } + + if (ms->smp.cpus > 1 && !vmc->no_cpu_topology) { + /* + * See Linux Documentation/devicetree/bindings/cpu/cpu-topology.txt + * In a SMP system, the hierarchy of CPUs is defined through four + * entities that are used to describe the layout of physical CPUs + * in the system: socket/cluster/core/thread. + */ + qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map"); + + for (cpu =3D ms->smp.cpus - 1; cpu >=3D 0; cpu--) { + char *cpu_path =3D g_strdup_printf("/cpus/cpu@%d", cpu); + char *map_path; + + if (ms->smp.threads > 1) { + map_path =3D g_strdup_printf( + "/cpus/cpu-map/%s%d/%s%d/%s%d", + "socket", cpu / (ms->smp.cores * ms->smp.threads), + "core", (cpu / ms->smp.threads) % ms->smp.cores, + "thread", cpu % ms->smp.threads); + } else { + map_path =3D g_strdup_printf( + "/cpus/cpu-map/%s%d/%s%d", + "socket", cpu / ms->smp.cores, + "core", cpu % ms->smp.cores); + } + qemu_fdt_add_path(ms->fdt, map_path); + qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path); + g_free(map_path); + g_free(cpu_path); + } + } } =20 static void fdt_add_its_gic_node(VirtMachineState *vms) @@ -2769,6 +2807,7 @@ static void virt_machine_5_2_options(MachineClass *mc) virt_machine_6_0_options(mc); compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len); vmc->no_secure_gpio =3D true; + vmc->no_cpu_topology =3D true; } DEFINE_VIRT_MACHINE(5, 2) =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 921416f918..4a4b98e4a7 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -129,6 +129,7 @@ struct VirtMachineClass { bool no_kvm_steal_time; bool acpi_expose_flash; bool no_secure_gpio; + bool no_cpu_topology; }; =20 struct VirtMachineState { --=20 2.19.1 From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301376; cv=none; d=zohomail.com; s=zohoarc; b=JPAmv5pmz0C5hMHv/hDZBwFb45444+CuulaYNH/LGKPXCjP1BQGuoYOTzbBY58/DFaJ5bt71AjVCw728x5KUHcJqnHgFSrohaHOphyVo4O7+6rWTsl9oRUp6jMXO9XxGpRODxRPrgY5kX8hYscKoW+rXun3tTS9Qy+aKXMX92DU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301376; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uSE7BU2bJDqPtvwLkY+3tdx4RJTr5NonBI7q1u0QE18=; b=FIXKhAFpBC6s3cDU9zrI9gcKi8b3zRxYBuUpC/BFwbGjjUyUdCXnDtazPPgY/9XjmXTLwW6tNWrsXb58FeOk/yttHX6S8fdv+uyMdp+/acSC2mnDk/YFt9+iDEopcJIlAsl4kV5Adrbe4YjyXyT9MQzpPgAPXJI8zSDKM5o0oGI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618301376292301.6289408758985; Tue, 13 Apr 2021 01:09:36 -0700 (PDT) Received: from localhost ([::1]:35878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWE75-0005k3-4y for importer@patchew.org; Tue, 13 Apr 2021 04:09:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5k-00045x-Gj; Tue, 13 Apr 2021 04:08:12 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5h-0006Qh-77; Tue, 13 Apr 2021 04:08:12 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8H3Jb8zlXd8; Tue, 13 Apr 2021 16:06:07 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:52 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 3/6] hw/arm/virt-acpi-build: Distinguish possible and present cpus Date: Tue, 13 Apr 2021 16:07:42 +0800 Message-ID: <20210413080745.33004-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , Ying Fang , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ying Fang When building ACPI tables regarding CPUs we should always build them for the number of possible CPUs, not the number of present CPUs. We then ensure only the present CPUs are enabled in MADT. Furthermore, it is also needed if we are going to support CPU hotplug in the future. This patch is a rework based on Andrew Jones's contribution at https://lists.gnu.org/archive/html/qemu-arm/2018-07/msg00076.html Signed-off-by: Ying Fang Signed-off-by: Yanan Wang --- hw/arm/virt-acpi-build.c | 14 ++++++++++---- hw/arm/virt.c | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index f5a2b2d4cb..2ad5dad1bf 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -61,13 +61,16 @@ =20 static void acpi_dsdt_add_cpus(Aml *scope, VirtMachineState *vms) { - MachineState *ms =3D MACHINE(vms); + CPUArchIdList *possible_cpus =3D MACHINE(vms)->possible_cpus; uint16_t i; =20 - for (i =3D 0; i < ms->smp.cpus; i++) { + for (i =3D 0; i < possible_cpus->len; i++) { Aml *dev =3D aml_device("C%.03X", i); aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0007"))); aml_append(dev, aml_name_decl("_UID", aml_int(i))); + if (possible_cpus->cpus[i].cpu =3D=3D NULL) { + aml_append(dev, aml_name_decl("_STA", aml_int(0))); + } aml_append(scope, dev); } } @@ -479,6 +482,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) const int *irqmap =3D vms->irqmap; AcpiMadtGenericDistributor *gicd; AcpiMadtGenericMsiFrame *gic_msi; + CPUArchIdList *possible_cpus =3D MACHINE(vms)->possible_cpus; int i; =20 acpi_data_push(table_data, sizeof(AcpiMultipleApicTable)); @@ -489,7 +493,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) gicd->base_address =3D cpu_to_le64(memmap[VIRT_GIC_DIST].base); gicd->version =3D vms->gic_version; =20 - for (i =3D 0; i < MACHINE(vms)->smp.cpus; i++) { + for (i =3D 0; i < possible_cpus->len; i++) { AcpiMadtGenericCpuInterface *gicc =3D acpi_data_push(table_data, sizeof(*gicc)); ARMCPU *armcpu =3D ARM_CPU(qemu_get_cpu(i)); @@ -504,7 +508,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) gicc->cpu_interface_number =3D cpu_to_le32(i); gicc->arm_mpidr =3D cpu_to_le64(armcpu->mp_affinity); gicc->uid =3D cpu_to_le32(i); - gicc->flags =3D cpu_to_le32(ACPI_MADT_GICC_ENABLED); + if (possible_cpus->cpus[i].cpu !=3D NULL) { + gicc->flags =3D cpu_to_le32(ACPI_MADT_GICC_ENABLED); + } =20 if (arm_feature(&armcpu->env, ARM_FEATURE_PMU)) { gicc->performance_interrupt =3D cpu_to_le32(PPI(VIRTUAL_PMU_IR= Q)); diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f4ae60ded9..3e5d9b6f26 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2063,6 +2063,9 @@ static void machvirt_init(MachineState *machine) } =20 qdev_realize(DEVICE(cpuobj), NULL, &error_fatal); + + /* Initialize cpu member here since cpu hotplug is not supported y= et */ + machine->possible_cpus->cpus[n].cpu =3D cpuobj; object_unref(cpuobj); } fdt_add_timer_nodes(vms); --=20 2.19.1 From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301405; cv=none; d=zohomail.com; s=zohoarc; b=kqEu46GW/KKfIrjF+KozLd0gDokkA1VwP7TyXGvtTcLa5MXVPPzf9ptv+fWUWDGzevy1IJ59/RoYsP+ysbKKI6JhTuqt+QzXZTpa8s4rqVMSYMOoBFCKYUukxYqS9qUHT+DlDDN7WdJVFfrLobMjw52X9YyjzZKTjbxyStgAIkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301405; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lennog0npifSKbmkMMLct6lUHtl2GmhSkzuk2UOAo8U=; b=GmkzIUebHQgMUrOl/2UtVQD2JMzhUTdZy0Dcq/AhykXrHAgktkQ/7cL8WtfTSFLGwpRWprbO5D4b1Py0yOCcdplkt/qrCm7+Z665IFH15tTlv0lpXO61Z/QYxpda637K8VBBeO5UXoZJQAjcHC1T4vmexkwuR2f03UXrBdAJ/MY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618301405411951.2131804157134; Tue, 13 Apr 2021 01:10:05 -0700 (PDT) Received: from localhost ([::1]:38462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWE7Y-0006mY-Af for importer@patchew.org; Tue, 13 Apr 2021 04:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5n-0004Cr-Uy; Tue, 13 Apr 2021 04:08:15 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5h-0006RR-FY; Tue, 13 Apr 2021 04:08:15 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8N2cm5zlXbH; Tue, 13 Apr 2021 16:06:12 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:54 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 4/6] hw/acpi/aml-build: Add processor hierarchy node structure Date: Tue, 13 Apr 2021 16:07:43 +0800 Message-ID: <20210413080745.33004-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Henglong Fan , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , Ying Fang , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a generic API to build Processor Hierarchy Node Structure(Type 0), which is strictly consistent with descriptions in ACPI 6.3: 5.2.29.1. This function will be used to build ACPI PPTT table for cpu topology. Signed-off-by: Ying Fang Signed-off-by: Henglong Fan Signed-off-by: Yanan Wang --- hw/acpi/aml-build.c | 27 +++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index d33ce8954a..75e01aea17 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1916,6 +1916,33 @@ void build_slit(GArray *table_data, BIOSLinker *link= er, MachineState *ms, table_data->len - slit_start, 1, oem_id, oem_table_id); } =20 +/* + * ACPI 6.3: 5.2.29.1 Processor Hierarchy Node Structure (Type 0) + */ +void build_processor_hierarchy_node(GArray *tbl, uint32_t flags, + uint32_t parent, uint32_t id, + uint32_t *priv_rsrc, uint32_t priv_num) +{ + int i; + + build_append_byte(tbl, 0); /* Type 0 - processor */ + build_append_byte(tbl, 20 + priv_num * 4); /* Length */ + build_append_int_noprefix(tbl, 0, 2); /* Reserved */ + build_append_int_noprefix(tbl, flags, 4); /* Flags */ + build_append_int_noprefix(tbl, parent, 4); /* Parent */ + build_append_int_noprefix(tbl, id, 4); /* ACPI processor ID */ + + /* Number of private resources */ + build_append_int_noprefix(tbl, priv_num, 4); + + /* Private resources[N] */ + if (priv_num > 0 && priv_rsrc !=3D NULL) { + for (i =3D 0; i < priv_num; i++) { + build_append_int_noprefix(tbl, priv_rsrc[i], 4); + } + } +} + /* build rev1/rev3/rev5.1 FADT */ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f, const char *oem_id, const char *oem_table_id) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 471266d739..ea74b8f6ed 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -462,6 +462,10 @@ void build_srat_memory(AcpiSratMemoryAffinity *numamem= , uint64_t base, void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms, const char *oem_id, const char *oem_table_id); =20 +void build_processor_hierarchy_node(GArray *tbl, uint32_t flags, + uint32_t parent, uint32_t id, + uint32_t *priv_rsrc, uint32_t priv_num= ); + void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f, const char *oem_id, const char *oem_table_id); =20 --=20 2.19.1 From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301643; cv=none; d=zohomail.com; s=zohoarc; b=AcGl9qWuk95Cj1V5NiMoz8E9UunGtbPhqps71/jYcU8TurlKHQPfA55t2+3jNVa5A10b/MHacNlgSVrgGsIzxcBcJk4nQFv3Qq4/BkgY5YVqeAbqdMK30vmmW7TDSHwYPOgeEp2OgWbe7sywzdrgco4yRtIr2PE3fYrzKovJ2fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301643; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dp9f41L2KQ6bSgapyQUPNDUtxn44ml5XMPfF4TMh5mU=; b=Z5ztbwhw7DA/x3WIU58kP0zCA3yaITBKOuhuD/UHZh+yQLMA8ysT9Q4PVo90FX8UFbCyGDAEZIh6ZP+mPqgdnc91aTUTPU8h69j1hQrRRZDhomYTixzWsBulEuluv9Xlbd6fMUk/7jDL12kEIEGSSPBieEYUwtEKoX0MKmxXUc0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618301643688689.5964067346816; Tue, 13 Apr 2021 01:14:03 -0700 (PDT) Received: from localhost ([::1]:50068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWEBO-0003Hb-G9 for importer@patchew.org; Tue, 13 Apr 2021 04:14:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5p-0004He-Kw; Tue, 13 Apr 2021 04:08:17 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5034) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5m-0006Yi-Jk; Tue, 13 Apr 2021 04:08:17 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8N30PtzlXdW; Tue, 13 Apr 2021 16:06:12 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:55 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 5/6] hw/arm/virt-acpi-build: Add PPTT table Date: Tue, 13 Apr 2021 16:07:44 +0800 Message-ID: <20210413080745.33004-6-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , Ying Fang , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the Processor Properties Topology Table (PPTT) to present CPU topology information to ACPI guests. Note, while a DT boot Linux guest with a non-flat CPU topology will see socket and core IDs being sequential integers starting from zero, e.g. with -smp 4,sockets=3D2,cores=3D2,threads=3D1 a DT boot produces cpu: 0 package_id: 0 core_id: 0 cpu: 1 package_id: 0 core_id: 1 cpu: 2 package_id: 1 core_id: 0 cpu: 3 package_id: 1 core_id: 1 an ACPI boot produces cpu: 0 package_id: 36 core_id: 0 cpu: 1 package_id: 36 core_id: 1 cpu: 2 package_id: 96 core_id: 2 cpu: 3 package_id: 96 core_id: 3 This is due to several reasons: 1) DT cpu nodes do not have an equivalent field to what the PPTT ACPI Processor ID must be, i.e. something equal to the MADT CPU UID or equal to the UID of an ACPI processor container. In both ACPI cases those are platform dependant IDs assigned by the vendor. 2) While QEMU is the vendor for a guest, if the topology specifies SMT (> 1 thread), then, with ACPI, it is impossible to assign a core-id the same value as a package-id, thus it is not possible to have package-id=3D0 and core-id=3D0. This is because package and core containers must be in the same ACPI namespace and therefore must have unique UIDs. 3) ACPI processor containers are not required for PPTT tables to be used and, due to the limitations of which IDs are selected described above in (2), they are not helpful for QEMU, so we don't build them with this patch. In the absence of them, Linux assigns its own unique IDs. The maintainers have chosen not to use counters from zero, but rather ACPI table offsets, which explains why the numbers are so much larger than with DT. 4) When there is no SMT (threads=3D1) the core IDs for ACPI boot guests match the logical CPU IDs, because these IDs must be equal to the MADT CPU UID (as no processor containers are present), and QEMU uses the logical CPU ID for these MADT IDs. Tested-by: Jiajie Li Signed-off-by: Andrew Jones Signed-off-by: Ying Fang Signed-off-by: Yanan Wang --- hw/arm/virt-acpi-build.c | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 2ad5dad1bf..03fd812d5a 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -436,6 +436,64 @@ build_srat(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) vms->oem_table_id); } =20 +/* PPTT */ +static void +build_pptt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) +{ + int pptt_start =3D table_data->len; + int uid =3D 0, cpus =3D 0, socket =3D 0; + MachineState *ms =3D MACHINE(vms); + unsigned int smp_cores =3D ms->smp.cores; + unsigned int smp_threads =3D ms->smp.threads; + + acpi_data_push(table_data, sizeof(AcpiTableHeader)); + + for (socket =3D 0; cpus < ms->possible_cpus->len; socket++) { + uint32_t socket_offset =3D table_data->len - pptt_start; + int core; + + build_processor_hierarchy_node( + table_data, 1, /* Physical package */ + 0, socket, /* No parent */ + NULL, 0); /* No private resources */ + + for (core =3D 0; core < smp_cores; core++) { + uint32_t core_offset =3D table_data->len - pptt_start; + int thread; + + if (smp_threads <=3D 1) { + build_processor_hierarchy_node( + table_data, + (1 << 1) | /* ACPI Processor ID valid */ + (1 << 3), /* ACPI 6.3 - Node is a Leaf */ + socket_offset, uid++, /* Parent is a Socket */ + NULL, 0); /* No private resources */ + } else { + build_processor_hierarchy_node( + table_data, 0, + socket_offset, core, /* Parent is a Socket */ + NULL, 0); /* No private resources */ + + for (thread =3D 0; thread < smp_threads; thread++) { + build_processor_hierarchy_node( + table_data, + (1 << 1) | /* ACPI Processor ID valid */ + (1 << 2) | /* ACPI 6.3 - Processor is a Thread */ + (1 << 3), /* ACPI 6.3 - Node is a Leaf */ + core_offset, uid++, /* Parent is a Core */ + NULL, 0); /* No private resources */ + } + } + } + cpus +=3D smp_cores * smp_threads; + } + + build_header(linker, table_data, + (void *)(table_data->data + pptt_start), "PPTT", + table_data->len - pptt_start, 2, + vms->oem_id, vms->oem_table_id); +} + /* GTDT */ static void build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) @@ -707,6 +765,11 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildT= ables *tables) acpi_add_table(table_offsets, tables_blob); build_madt(tables_blob, tables->linker, vms); =20 + if (ms->smp.cpus > 1 && !vmc->no_cpu_topology) { + acpi_add_table(table_offsets, tables_blob); + build_pptt(tables_blob, tables->linker, vms); + } + acpi_add_table(table_offsets, tables_blob); build_gtdt(tables_blob, tables->linker, vms); =20 --=20 2.19.1 From nobody Sat May 18 18:27:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1618301539; cv=none; d=zohomail.com; s=zohoarc; b=N/+evtyaZOPfyTDF4xJsBECHW9Ay6R5u7bK83idUBHmBb8mbTQL1vGSL679/v6Hc1bYh4z1dlGS74cucXcRNXBWja7j6/GvzLPCd3UdVkFhIy2rJDmHfSieiyId3+bSOmHIp5zmxHD3Rszq1jWonguMRMrC4DCmJQi++T5cXNmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618301539; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7fPh6pto7IIcyip6WFWo4MJmHZ8/gfa7GTtrHIa6wyk=; b=D5qGk7qThvZBNU3kDx6+z6tnatJdvggiRgOjMs+QrCVNHopgz6Et+/RqrKCfp8NkEHhrVhaJR9aEiXpq0KJBtIWqch+4ACpg5FO0lDVkVvrQhUt87Lv7vDDi/NaFM9BWs5FYHD9z6xY+Cs4fubShk49N4tPmKBn18h94emEAhes= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618301539350341.89819882061465; Tue, 13 Apr 2021 01:12:19 -0700 (PDT) Received: from localhost ([::1]:45726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWE9i-0001Jt-Ab for importer@patchew.org; Tue, 13 Apr 2021 04:12:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5o-0004FT-UN; Tue, 13 Apr 2021 04:08:16 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:5035) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWE5m-0006Yj-Hx; Tue, 13 Apr 2021 04:08:16 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FKJ8N2FqwzlXZs; Tue, 13 Apr 2021 16:06:12 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 16:07:56 +0800 From: Yanan Wang To: , Subject: [RFC PATCH v2 6/6] hw/arm/virt: Replace smp_parse with one that prefers cores Date: Tue, 13 Apr 2021 16:07:45 +0800 Message-ID: <20210413080745.33004-7-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210413080745.33004-1-wangyanan55@huawei.com> References: <20210413080745.33004-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=wangyanan55@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Yanan Wang , Shannon Zhao , Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andrew Jones The virt machine type has never used the CPU topology parameters, other than number of online CPUs and max CPUs. When choosing how to allocate those CPUs the default has been to assume cores. In preparation for using the other CPU topology parameters let's use an smp_parse that prefers cores over sockets. We can also enforce the topology matches max_cpus check because we have no legacy to preserve. Signed-off-by: Andrew Jones Signed-off-by: Yanan Wang --- hw/arm/virt.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 3e5d9b6f26..57ef961cb5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -79,6 +79,8 @@ #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" #include "qemu/guest-random.h" +#include "qapi/qmp/qerror.h" +#include "sysemu/replay.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -2625,6 +2627,79 @@ static int virt_kvm_type(MachineState *ms, const cha= r *type_str) return fixed_ipa ? 0 : requested_pa_size; } =20 +/* + * Unlike smp_parse() in hw/core/machine.c, we prefer cores over sockets, + * e.g. '-smp 8' creates 1 socket with 8 cores. Whereas '-smp 8' with + * hw/core/machine.c's smp_parse() creates 8 sockets, each with 1 core. + * Additionally, we can enforce the topology matches max_cpus check, + * because we have no legacy to preserve. + */ +static void virt_smp_parse(MachineState *ms, QemuOpts *opts) +{ + if (opts) { + unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); + unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); + unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + + /* + * Compute missing values; prefer cores over sockets and + * sockets over threads. + */ + if (cpus =3D=3D 0 || cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + if (cpus =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + cpus =3D cores * threads * sockets; + } else { + ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", = cpus); + cores =3D ms->smp.max_cpus / (sockets * threads); + } + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D cpus / (cores * threads); + sockets =3D sockets > 0 ? sockets : 1; + } else if (threads =3D=3D 0) { + threads =3D cpus / (cores * sockets); + threads =3D threads > 0 ? threads : 1; + } else if (sockets * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, cores, threads, cpus); + exit(1); + } + + ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); + + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); + } + + if (sockets * cores * threads !=3D ms->smp.max_cpus) { + error_report("cpu topology: " + "sockets (%u) * cores (%u) * threads (%u)" + "!=3D maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + exit(1); + } + + ms->smp.cpus =3D cpus; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.sockets =3D sockets; + } + + if (ms->smp.cpus > 1) { + Error *blocker =3D NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } +} + static void virt_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -2650,6 +2725,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->cpu_index_to_instance_props =3D virt_cpu_index_to_props; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a15"); mc->get_default_cpu_node_id =3D virt_get_default_cpu_node_id; + mc->smp_parse =3D virt_smp_parse; mc->kvm_type =3D virt_kvm_type; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler =3D virt_machine_get_hotplug_handler; --=20 2.19.1