From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355034; cv=none; d=zohomail.com; s=zohoarc; b=McS8NoGNshUFvoEVLJwv7opMEAi9AZYYmg1PqEbcXxjUFt/h3af/gegQdzXloOTl4IveSsD4NDDEqXgXuG12y9sOzkBKbWzIYZm5E5lVtyvQHAzGX275sHXr/GXjTI0OfwTbwfuGKemewjo8iEDuYs+3FKiZLei9wsq7zfosoN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355034; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Mh5AYPt2XvJ2l2amFs/NXpXuRrrIbtSIYhnGvUCj4wE=; b=NOppcZJXH0YtfvR3ZuK6MCqI019LmuzQ32ZwgceIoq02zXPEvOBzezMY1pDpNNH/xSpKhMBctEYKdBxyZjn0UGDWl1QbQ7fOog97yy8OOvKLR1KlzF5NeDWDAFvnCZXpgRTHvxH+lDdPDUstG0w2iJvNBjJjrIl2kJRaBqeCqvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355034717775.5470262246819; Thu, 30 Nov 2023 06:37:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i4Z-0001RB-5r; Thu, 30 Nov 2023 09:31:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i46-0001KB-6N; Thu, 30 Nov 2023 09:30:54 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i40-0000yu-2Z; Thu, 30 Nov 2023 09:30:53 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:30:42 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:30:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354648; x=1732890648; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GonVMos5FsS7CHBj98lIck+6Zgp9gIFuSW7kS7bFSf0=; b=h956BNIBUfQbDjZD4GX8CoRJZ6W0c3Uz2QxtAYtCY8+Ihot0QBZhEjJW 3ugdrFBvoaFCrDIKYp3XfHR0cL1FL7Ox3q+/rv4xqGQccDAauE0mHnI0o 2le8WJWH/2mQ+ZPSXqpdvHjErNt8lm/R8rFAE2fPWscGSApjOD9D5cAdM BjguCF1uUkGjj4xy2VyuxhvJx5vZBy48sbCdPiwvkPWds3NqNaoavSc8R 648eNxGXzAXsZLyKoieemB+hC6swVnK6DMQxS35hp3rRxhhyWrqtDZoHA 3iNHtID4f8DdkB7H64UjCev5dGn9VANJpFWismSCIyMB2JD2GbT7L0wvf A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479530850" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479530850" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729601" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729601" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 01/41] qdev: Introduce new device category to cover basic topology device Date: Thu, 30 Nov 2023 22:41:23 +0800 Message-Id: <20231130144203.2307629-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355035511000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Topology devices are used to define CPUs and need to be created and realized before the board initialization. Use this new catogory to identify such special devices. Signed-off-by: Zhao Liu --- include/hw/qdev-core.h | 1 + system/qdev-monitor.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 151d9682380d..97b7cfd04e35 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -86,6 +86,7 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_SOUND, DEVICE_CATEGORY_MISC, DEVICE_CATEGORY_CPU, + DEVICE_CATEGORY_CPU_DEF, DEVICE_CATEGORY_WATCHDOG, DEVICE_CATEGORY_MAX } DeviceCategory; diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index a13db763e5dd..0f163b2d0310 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -173,6 +173,7 @@ static void qdev_print_devinfos(bool show_no_user) [DEVICE_CATEGORY_SOUND] =3D "Sound", [DEVICE_CATEGORY_MISC] =3D "Misc", [DEVICE_CATEGORY_CPU] =3D "CPU", + [DEVICE_CATEGORY_CPU_DEF] =3D "CPU Definition", [DEVICE_CATEGORY_WATCHDOG]=3D "Watchdog", [DEVICE_CATEGORY_MAX] =3D "Uncategorized", }; --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354985; cv=none; d=zohomail.com; s=zohoarc; b=Uy7TDRX9wXyN78fwbgQ9fLJTQVqrJlDIsCEz5+oWHezbsXFBzjrYPOGDYPyokwOg26kE3UPACP04T3DyCQ1rIJQLG7nYLtWe45dCZTAdXbFKzhrx4XJDid0LR3omhB773V5jfpUNCQtW9Nrdkool46i7doZYl0FRCbFNxhd986k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354985; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zlk6YC8xpWCO7VeZ16JtsW/aS23EN62LOIPiqtyPtGk=; b=fONbK1DErDJyRw4880tyV/c/PGZnfW1YPds5uMpoXnkYPqJWauo+uMxzvgTaype1dneuUMHmlUJwSrVskQwHpEcr5d6scYzpZWCwGmrQVGMUWMJ/9FWYKJPLo0MX1lxCZ2eePfdXlOrdxCDnLR+6W3SCUSpzXr/7PNURzM8g4kQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354985164668.889048900022; Thu, 30 Nov 2023 06:36:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i4Z-0001Rr-PI; Thu, 30 Nov 2023 09:31:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i4G-0001MC-RC; Thu, 30 Nov 2023 09:31:08 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i49-0000yu-Ms; Thu, 30 Nov 2023 09:31:04 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:30:52 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:30:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354657; x=1732890657; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LfXluGcV2XSbwSzs1A7j8csA0H78Hr7rImWxVfjhw/E=; b=QxCSX/aVhqp7pcSWQpm0s31u91lIaf7ODI3979nZV/0RkmUCCZRN01vq dymHX9SW3NYh2+4aKy+Iw5lWWtyvxt0zhey2GMYNp26GKrO71NYQa8ZfV pEh0evQ8O8RKsskiMQ67nKA56Q++dQbz+q2mQhK/Z65KruTMTvz0DMAsH WChAT+8Xp3XnIPvpw4C3BRvQwdVlXnjanjjq0xj3nvacaedtXZo4FgODX OZW3U3R6nrYng5cEa8dzEg+xfozaAm0nja1fAHZHuTBzG8mbG47+oTJCl VGv+dPHttNeslKpPJFHUA8WKLp76D4vJbwz+0wm8veqcgMVErJvoDm/LU w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479530893" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479530893" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729606" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729606" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 02/41] qdev: Allow qdev_device_add() to add specific category device Date: Thu, 30 Nov 2023 22:41:24 +0800 Message-Id: <20231130144203.2307629-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354987192000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Topology devices need to be created and realized before board initialization. Allow qdev_device_add() to specify category to help create topology devices early. Signed-off-by: Zhao Liu --- hw/net/virtio-net.c | 2 +- hw/usb/xen-usb.c | 3 ++- include/monitor/qdev.h | 4 ++-- system/qdev-monitor.c | 12 ++++++++---- system/vl.c | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 80c56f0cfcf1..fc225049ee30 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -965,7 +965,7 @@ static void failover_add_primary(VirtIONet *n, Error **= errp) return; } =20 - dev =3D qdev_device_add_from_qdict(n->primary_opts, + dev =3D qdev_device_add_from_qdict(n->primary_opts, NULL, n->primary_opts_from_json, &err); if (err) { diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 09ec326aeae5..bc00d47ff021 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -766,7 +766,8 @@ static void usbback_portid_add(struct usbback_info *usb= if, unsigned port, qdict_put_str(qdict, "hostport", portname); opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &error_abort); - usbif->ports[port - 1].dev =3D USB_DEVICE(qdev_device_add(opts, &local= _err)); + usbif->ports[port - 1].dev =3D USB_DEVICE( + qdev_device_add(opts, NULL, &local_er= r)); if (!usbif->ports[port - 1].dev) { qobject_unref(qdict); xen_pv_printf(&usbif->xendev, 0, diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 1d57bf657794..f5fd6e6c1ffc 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -8,8 +8,8 @@ void hmp_info_qdm(Monitor *mon, const QDict *qdict); void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); =20 int qdev_device_help(QemuOpts *opts); -DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); -DeviceState *qdev_device_add_from_qdict(const QDict *opts, +DeviceState *qdev_device_add(QemuOpts *opts, long *category, Error **errp); +DeviceState *qdev_device_add_from_qdict(const QDict *opts, long *category, bool from_json, Error **errp); =20 /** diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 0f163b2d0310..7ee33a50142a 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -617,7 +617,7 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) return prop->name; } =20 -DeviceState *qdev_device_add_from_qdict(const QDict *opts, +DeviceState *qdev_device_add_from_qdict(const QDict *opts, long *category, bool from_json, Error **errp) { ERRP_GUARD(); @@ -639,6 +639,10 @@ DeviceState *qdev_device_add_from_qdict(const QDict *o= pts, return NULL; } =20 + if (category && !test_bit(*category, dc->categories)) { + return NULL; + } + /* find bus */ path =3D qdict_get_try_str(opts, "bus"); if (path !=3D NULL) { @@ -731,12 +735,12 @@ err_del_dev: } =20 /* Takes ownership of @opts on success */ -DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) +DeviceState *qdev_device_add(QemuOpts *opts, long *category, Error **errp) { QDict *qdict =3D qemu_opts_to_qdict(opts, NULL); DeviceState *ret; =20 - ret =3D qdev_device_add_from_qdict(qdict, false, errp); + ret =3D qdev_device_add_from_qdict(qdict, category, false, errp); if (ret) { qemu_opts_del(opts); } @@ -858,7 +862,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, E= rror **errp) qemu_opts_del(opts); return; } - dev =3D qdev_device_add(opts, errp); + dev =3D qdev_device_add(opts, NULL, errp); =20 /* * Drain all pending RCU callbacks. This is done because diff --git a/system/vl.c b/system/vl.c index 2bcd9efb9a64..0be155b530b4 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1198,7 +1198,7 @@ static int device_init_func(void *opaque, QemuOpts *o= pts, Error **errp) { DeviceState *dev; =20 - dev =3D qdev_device_add(opts, errp); + dev =3D qdev_device_add(opts, NULL, errp); if (!dev && *errp) { error_report_err(*errp); return -1; @@ -2646,7 +2646,7 @@ static void qemu_create_cli_devices(void) * from the start, so call qdev_device_add_from_qdict() directly f= or * now. */ - dev =3D qdev_device_add_from_qdict(opt->opts, true, &error_fatal); + dev =3D qdev_device_add_from_qdict(opt->opts, NULL, true, &error_f= atal); object_unref(OBJECT(dev)); loc_pop(&opt->loc); } --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354744; cv=none; d=zohomail.com; s=zohoarc; b=iAUHUAMF5m5bvRUm+GAA+dEHDxjpFF72S/3uTE8KuRQ5F2U9mFradKgFzDt+YSbVy2Ix7QfkJzez62Lwqly6JVPVWG0Ojaf7T8VPb92zi3joV0zyWGYE63hgZn/kDh5SOpiUhf0P4yE7r+vDK5+oal/DWrva+eYj0EV/e5Kk/EI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354744; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y1KluPvB6T6+FK2U/+G/V/aKTIFxa1bokHonKpE74aM=; b=fVA9eLHrZtlxgbvJDhnEMc4YcWthS2sV/iIMk396Yd9CDE0ofzhoMWriHfk18BVqjAGF7vjQTXC/wUN9GQPJapV+3CsytZ0vjvgwgYciTq1oo4IN4E/LF8oeF1OKzVJDr64Nj3/+m22rBxVKqNUZORoTb+o1FnHKSz8B5CQ6ENI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354744247581.1561065159952; Thu, 30 Nov 2023 06:32:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i4p-0001Vs-L8; Thu, 30 Nov 2023 09:31:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i4m-0001UZ-K9; Thu, 30 Nov 2023 09:31:36 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i4k-00014B-U4; Thu, 30 Nov 2023 09:31:36 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:01 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:30:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354694; x=1732890694; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=50lNzU4oWEfgKNc9gIKf0MEOC0NyWyVi0AxeNokOwXU=; b=Kt/2N9Y3v/DtmsKN2swIPZRAC9T6INcdp8i6Tk0gM14FtaHo8CQr/Rqk D9iv4V5Hg7c0oQ8c2oSfwTEO59KpfRMsyJa6+SyVkdiT8LHN8DG7YpZ4b 0MvuRs6UFWN33dQ2il/EBmNqmhwG/mWWd5wYNEetLUdIOdqPeSOwK925L XVVSnQ5nDPE+Nmk4jEWPbr+m1LbuSzpUGcIQlH4o3XcMiufIAMrNzcqUV jYLg4kZBJ7aYY6PTlY625UxgR3K3DT7dBjGtimW0LN9YNP+Bh/7qm9g+g EWnTEELIeArwyr+2wtBdRDTIbogVddkq4H94QYISEymDv/3nYUzYei284 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479530953" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479530953" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729615" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729615" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 03/41] system: Create base category devices from cli before board initialization Date: Thu, 30 Nov 2023 22:41:25 +0800 Message-Id: <20231130144203.2307629-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354748468000007 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Topology devices are required to complete CPU topology building before *_init_cpus() in MachineClass.init(). Add a qemu_create_cli_base_devices() before board initialization to help create and realize topology devices from cli early. Signed-off-by: Zhao Liu --- system/vl.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/system/vl.c b/system/vl.c index 0be155b530b4..65add2fb2460 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1197,8 +1197,9 @@ static int device_help_func(void *opaque, QemuOpts *o= pts, Error **errp) static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; + long *category =3D opaque; =20 - dev =3D qdev_device_add(opts, NULL, errp); + dev =3D qdev_device_add(opts, category, errp); if (!dev && *errp) { error_report_err(*errp); return -1; @@ -2617,25 +2618,13 @@ static void qemu_init_board(void) realtime_init(); } =20 -static void qemu_create_cli_devices(void) +static void qemu_create_cli_devices(long *category) { DeviceOption *opt; =20 - soundhw_init(); - - qemu_opts_foreach(qemu_find_opts("fw_cfg"), - parse_fw_cfg, fw_cfg_find(), &error_fatal); - - /* init USB devices */ - if (machine_usb(current_machine)) { - if (foreach_device_config(DEV_USB, usb_parse) < 0) - exit(1); - } - - /* init generic devices */ rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), - device_init_func, NULL, &error_fatal); + device_init_func, category, &error_fatal); QTAILQ_FOREACH(opt, &device_opts, next) { DeviceState *dev; loc_push_restore(&opt->loc); @@ -2646,13 +2635,40 @@ static void qemu_create_cli_devices(void) * from the start, so call qdev_device_add_from_qdict() directly f= or * now. */ - dev =3D qdev_device_add_from_qdict(opt->opts, NULL, true, &error_f= atal); + dev =3D qdev_device_add_from_qdict(opt->opts, category, + true, &error_fatal); object_unref(OBJECT(dev)); loc_pop(&opt->loc); } rom_reset_order_override(); } =20 +static void qemu_create_cli_base_devices(void) +{ + long category =3D DEVICE_CATEGORY_CPU_DEF; + + qemu_opts_foreach(qemu_find_opts("fw_cfg"), + parse_fw_cfg, fw_cfg_find(), &error_fatal); + + /* init CPU topology devices which don't support hotplug. */ + qemu_create_cli_devices(&category); +} + +static void qemu_create_cli_periphery_devices(void) +{ + soundhw_init(); + + /* init USB devices */ + if (machine_usb(current_machine)) { + if (foreach_device_config(DEV_USB, usb_parse) < 0) { + exit(1); + } + } + + /* init generic devices */ + qemu_create_cli_devices(NULL); +} + static void qemu_machine_creation_done(void) { MachineState *machine =3D MACHINE(qdev_get_machine()); @@ -2701,8 +2717,9 @@ void qmp_x_exit_preconfig(Error **errp) return; } =20 + qemu_create_cli_base_devices(); qemu_init_board(); - qemu_create_cli_devices(); + qemu_create_cli_periphery_devices(); qemu_machine_creation_done(); =20 if (loadvm) { --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354852; cv=none; d=zohomail.com; s=zohoarc; b=Pu+Hs6V57iZ3oT8+nf2BrM7bxye1ier3ZaABHvFntLoO29u1MPFJB8+n84zCsGRZCBdHgd82snJIKbgB+HNOC+FirZgM4VQgTrO4MhAPMT7z0GmmlVtSoYym0b1CRt+rRrBCjmX4tXnva3BL6iSDuF/dlKSwKmC0S1cv0iwW95w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354852; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+QZbTWlSEbbogh5qu4EzEaVMOn+hl4OCPZwl+YIqUvQ=; b=Q9R4O4kPLPsu3gtyu1+XkRP13bMiJ06vxc4tqhnUbaOtL8Q2TxVnkImTu+pPzx3P0lHaKNVmY/YnzDCIcwhq/2arhhLV/3hXHrjF6Z4woXkNZkf3ATC/Jeft0VkyQ5BvmZJxFS79t94zXpxNRqlkieZLKAGJQy7v7Bh0AIMJ6sI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354852942561.720300432468; Thu, 30 Nov 2023 06:34:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i53-0001ah-4H; Thu, 30 Nov 2023 09:31:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i4y-0001YB-IE; Thu, 30 Nov 2023 09:31:48 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i4w-000157-Ab; Thu, 30 Nov 2023 09:31:48 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:11 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354706; x=1732890706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q8av5JpkyS6FnEIeBR5gNojelDu9V7STUz/Dtf8UH7E=; b=SXRPthXIKWLa7vnXnPXE7eXzXWzC6Rp5EpH7BMg9RdCE3R+U4c5GLN3w UNRaw+EcrhRvAS+qHjMgSwBYfd8JhT2ax3YFnkXbQ143V40Yus8ygxp0A IWaUrzfcJzJVRZZOyoCiwfzzGA8Q4sRaEA4pGauZhrV5wm2y/drOwHCit y396H48MPdJ7c1MOdEy2iOBrvffqoj2kDA7lrH/fKjOJvXKnBcQlVGKR+ KMT8x4UTXXm7owEf3ZoK/yBC5/LDu5iJJdYF3uvWfZrvDAxMmiX1uso4b 58psAnVf3ZBESpu5RHvGYAiRU83drUqdYriakl1iD5G6LzsEHoohQ3UWh A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531061" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531061" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729632" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729632" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent Date: Thu, 30 Nov 2023 22:41:26 +0800 Message-Id: <20231130144203.2307629-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354854724000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu When we support child<> property creation from cli, the peripheral container (/machine/peripheral) may not be the direct parent of the devices created from cli. For this case, add a helper to resolve path from non-direct parent. Signed-off-by: Zhao Liu --- include/qom/object.h | 15 +++++++++++++++ qom/object.c | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index afccd24ca7ab..494eef801be3 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1562,6 +1562,21 @@ Object *object_resolve_path_type(const char *path, c= onst char *typename, */ Object *object_resolve_path_at(Object *parent, const char *path); =20 +/** + * object_resolve_path_from: + * @parent: the object from which to resolve the path + * @path: the path to resolve + * @ambiguous: returns true if the path resolution failed because of an + * ambiguous match + * + * This is like object_resolve_path_at(), except @parent may be the + * partial parent of @path. + * + * Returns: The resolved object or NULL on path lookup failure. + */ +Object *object_resolve_path_from(Object *parent, const char *path, + bool *ambiguous); + /** * object_resolve_path_component: * @parent: the object in which to resolve the path diff --git a/qom/object.c b/qom/object.c index 95c0dc8285fe..da29e88816b5 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2192,6 +2192,24 @@ Object *object_resolve_path_at(Object *parent, const= char *path) return object_resolve_abs_path(parent, parts, TYPE_OBJECT); } =20 +Object *object_resolve_path_from(Object *parent, const char *path, + bool *ambiguousp) +{ + g_auto(GStrv) parts =3D NULL; + bool ambiguous =3D false; + Object *obj; + + parts =3D g_strsplit(path, "/", 0); + assert(parts); + + obj =3D object_resolve_partial_path(parent, parts, TYPE_OBJECT, + &ambiguous); + if (ambiguousp) { + *ambiguousp =3D ambiguous; + } + return obj; +} + typedef struct StringProperty { char *(*get)(Object *, Error **); --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354744; cv=none; d=zohomail.com; s=zohoarc; b=GERDqRvLewxIsv0QFcR3813GH7/O/QUNkNzl5+1UScBWfjoWi/tyX1dYNXGuiEzxnafHVI4MtLrpSx7Db2C0otHpeVyhcD+Y8itFqFO9gc9yndrPg0x/srzDcNG/VqlH2hNwfFHL0pX2bOhikbw2E7+Rs1FhXHXCd8FQ/4P72Zk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354744; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w83/n3empgceTkPoMm4A45im5C1+QxHglZQSpg6/p7M=; b=IuwEPG56bPs1xwnp9Ctavh+Wuyh0DK1qpiDf36m/D02GCxYMEd83P2HX17QQDbxq716VRgrgj1EM4SrrnmMaORMub0zIRlOBvUkpFcNlZyW9goAUO2MsbxZ+6NGA6bEqvX0B76zB44OVAxBBl9RbbFYr86JeWaSemYoE21KAU7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354744373445.7549003845314; Thu, 30 Nov 2023 06:32:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5B-0001fX-VU; Thu, 30 Nov 2023 09:32:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i54-0001d3-5x; Thu, 30 Nov 2023 09:31:54 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i52-000157-KU; Thu, 30 Nov 2023 09:31:53 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:20 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354712; x=1732890712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FvkKzJCE6FUWENQ9f97m08P62P/QoMoZpAQ1rnP03oI=; b=HtfMqBHHZUN7GgJRWat9fIWsFbhJkMP4kLDyPJrkFVSgc68P71B6J9KH h4MDq+Da2PJF8O8mzW2oB7HcQtW9oQaBJzWha7RJrHOxgHxUajKXquZ5+ k5SFchDNnnduvUwiL7l5Leg5heYe7kOS2aCbeACzpETnW/WU5jZiyR5CO ZByDc/4VqhgrTLErOHeCmuc1L954soYl7YZJ6bEQwOYnmhUVkeQ9dfZDQ Aj50DQIlBTJ64MBaIY+469zRzDq97JDKlDhbz187rR/cAOp7cM35d1N7y 5VF7AFFvaQfOsz6AT5X7J1LB9tt5XSvqXlKoIjfUcn9HOGsNw3es/4S0l w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531156" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531156" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729654" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729654" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 05/41] qdev: Set device parent and id after setting properties Date: Thu, 30 Nov 2023 22:41:27 +0800 Message-Id: <20231130144203.2307629-6-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354748274000005 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The properties setting does not conflict with the creation of child<> property. Pre-setting the device's properties can help the device's parent selection. Some topology devices (e.g., CPUs that support hotplug) usually define topology sub indexes as properties, and the selection of their parent needs to be based on these proteries. Move qdev_set_id() after properties setting to help the next user-child introduction. Signed-off-by: Zhao Liu --- system/qdev-monitor.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 7ee33a50142a..107411bb50cc 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -700,14 +700,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *o= pts, long *category, } } =20 - /* - * set dev's parent and register its id. - * If it fails it means the id is already taken. - */ id =3D g_strdup(qdict_get_try_str(opts, "id")); - if (!qdev_set_id(dev, id, errp)) { - goto err_del_dev; - } =20 /* set properties */ dev->opts =3D qdict_clone_shallow(opts); @@ -721,6 +714,14 @@ DeviceState *qdev_device_add_from_qdict(const QDict *o= pts, long *category, goto err_del_dev; } =20 + /* + * set dev's parent and register its id. + * If it fails it means the id is already taken. + */ + if (!qdev_set_id(dev, id, errp)) { + goto err_del_dev; + } + if (!qdev_realize(dev, bus, errp)) { goto err_del_dev; } --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355101; cv=none; d=zohomail.com; s=zohoarc; b=h9oTSPupQycIQ1swijumCqhKZtmaGgfqskK0GuGnE7bbzRfEIoaNUfXvwD/cavFqgy+xQjqtIfckpyb7SfwuSnDaOJ/pg1t8FjjkTsIDKMjwu5qY/zYCNSEMVgPlWqyUu7+wCvmcOk4TPs8YIegp0kfqswE3s4776FxMsrt4q9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355101; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KjSZ/wfBM79oEgKz1AQGUDHLr4Q0RYsd4RudUp23ac0=; b=mwxlDvg0Csq8CoEfJsIit9RLpmy67/POh/7ci99HYMXtNoU+GuwwrGTa9CpqZd57ggZFw9CPqYZltUK2Lh6s/OXQUyuANXALgFp3Q8IbiwGQi4kIs+UR5KtThSlH4C0y2/rbAaOhGwn/KtBqj4/oQRWWKvfHNkeS+7b7EHa/Zcw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355101498313.81045587783433; Thu, 30 Nov 2023 06:38:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5K-0001ie-GF; Thu, 30 Nov 2023 09:32:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5I-0001hu-7H; Thu, 30 Nov 2023 09:32:08 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5F-00018C-KC; Thu, 30 Nov 2023 09:32:07 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:29 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354725; x=1732890725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g5Zw3I63TJXvQFrzB5uJb/WUPaoeW0TH6JE9nfaHRvc=; b=DtFCgq5ZfYZZwboaVejjXjmZjq1YWiMV8Tyka3PX9RxF249nXPy4xBKJ eCjq9WonXpzxZiJFeJ0/2Xa26ejdFFf3d/uSxBpLyaXMwlVdoXCMb5YdV /Q56YliOUjfXnDS7fwn108iEbof8lbde/Dmfrmg5iQUQ3aHa37ufD/hXH FpgA4YhDtj+UwWU4uFqb0ktigdD451j4XDOP5uYgWQdEKDp0OVqXQ2w8C dLMEpJpTZq0i6T+wpi8sLuzv9BX1dg8ay9WRM6NndGmTKU9HQxvJOy+wF NT0EZyldHicXXXZV8w8LZfgxvcINVSBV2jWK5kdDsIWtuUDnfA2QMxnRX g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531263" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531263" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729699" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729699" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 06/41] qdev: Introduce user-child interface to collect devices from -device Date: Thu, 30 Nov 2023 22:41:28 +0800 Message-Id: <20231130144203.2307629-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355103655000019 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Topology relationship is based on child<> property, therefore introduce a new user-child interface to help bus-less devices create child<> property from cli. User-child interface works in qdev_set_id(), where the child<> property is created for cli devices. With several methods, user-child could provide the specific "parent" device other than the default peripheral/peripheral-anon container. The topology root (cpu-slot) could collect topology devices based on user-child implementation. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 + include/monitor/user-child.h | 57 +++++++++++++++++++++++ include/qom/object.h | 11 +++++ qom/object.c | 13 ++++++ system/meson.build | 1 + system/qdev-monitor.c | 89 +++++++++++++++++++++++++++++++++--- system/user-child.c | 72 +++++++++++++++++++++++++++++ 7 files changed, 239 insertions(+), 6 deletions(-) create mode 100644 include/monitor/user-child.h create mode 100644 system/user-child.c diff --git a/MAINTAINERS b/MAINTAINERS index 695e0bd34fbb..fdbabaa983cc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3208,12 +3208,14 @@ F: hw/core/bus.c F: hw/core/sysbus.c F: include/hw/qdev* F: include/monitor/qdev.h +F: include/monitor/user-child.h F: include/qom/ F: qapi/qom.json F: qapi/qdev.json F: scripts/coccinelle/qom-parent-type.cocci F: scripts/qom-cast-macro-clean-cocci-gen.py F: system/qdev-monitor.c +F: system/user-child.c F: stubs/qdev.c F: qom/ F: tests/unit/check-qom-interface.c diff --git a/include/monitor/user-child.h b/include/monitor/user-child.h new file mode 100644 index 000000000000..e246fcefe40a --- /dev/null +++ b/include/monitor/user-child.h @@ -0,0 +1,57 @@ +/* + * Child configurable interface header. + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef USER_CHILD_H +#define USER_CHILD_H + +#include "qom/object.h" + +#define TYPE_USER_CHILD "user-child" + +typedef struct UserChildClass UserChildClass; +DECLARE_CLASS_CHECKERS(UserChildClass, USER_CHILD, TYPE_USER_CHILD) +#define USER_CHILD(obj) INTERFACE_CHECK(UserChild, (obj), TYPE_USER_CHILD) + +typedef struct UserChild UserChild; + +/** + * UserChildClass: + * @get_parent: Method to get the default parent if user doesn't specify + * the parent in cli. + * @get_child_name: Method to get the default device id for this device + * if user doesn't specify id in cli. + * @check_parent: Method to check if the parent specified by user in cli + * is valid. + */ +struct UserChildClass { + /* */ + InterfaceClass parent_class; + + /* */ + Object *(*get_parent)(UserChild *uc, Error **errp); + char *(*get_child_name)(UserChild *uc, Object *parent); + bool (*check_parent)(UserChild *uc, Object *parent); +}; + +Object *uc_provide_default_parent(Object *obj, Error **errp); +char *uc_name_future_child(Object *obj, Object *parent); +bool uc_check_user_parent(Object *obj, Object *parent); + +#endif /* USER_CHILD_H */ diff --git a/include/qom/object.h b/include/qom/object.h index 494eef801be3..f725d9452c76 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1484,6 +1484,17 @@ Object *object_get_objects_root(void); */ Object *object_get_internal_root(void); =20 +/** + * object_is_child_from: + * @child: the object. + * @parent: the parent/non-direct parent object. + * + * Check whether @parent is the parent/non-direct parent of @child. + * + * Returns: true iff @parent is the parent/non-direct parent of @child. + */ +bool object_is_child_from(const Object *child, const Object *parent); + /** * object_get_canonical_path_component: * @obj: the object diff --git a/qom/object.c b/qom/object.c index da29e88816b5..d6f55aa59504 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2024,6 +2024,19 @@ object_property_add_const_link(Object *obj, const ch= ar *name, NULL, OBJ_PROP_LINK_DIRECT); } =20 +bool object_is_child_from(const Object *child, const Object *parent) +{ + Object *obj =3D child->parent; + + while (obj) { + if (obj =3D=3D parent) { + return true; + } + obj =3D obj->parent; + } + return false; +} + const char *object_get_canonical_path_component(const Object *obj) { ObjectProperty *prop =3D NULL; diff --git a/system/meson.build b/system/meson.build index 3a64dd89de1f..ac682a3ca9e1 100644 --- a/system/meson.build +++ b/system/meson.build @@ -24,6 +24,7 @@ system_ss.add(files( 'runstate-hmp-cmds.c', 'runstate.c', 'tpm-hmp-cmds.c', + 'user-child.c', 'vl.c', ), sdl, libpmem, libdaxctl) =20 diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 107411bb50cc..0261937b8462 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -22,6 +22,7 @@ #include "monitor/hmp.h" #include "monitor/monitor.h" #include "monitor/qdev.h" +#include "monitor/user-child.h" #include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" @@ -585,26 +586,93 @@ static BusState *qbus_find(const char *path, Error **= errp) return bus; } =20 +static Object *qdev_find_peripheral_parent(DeviceState *dev, + Error **errp) +{ + Object *parent_obj, *obj =3D OBJECT(dev); + + parent_obj =3D uc_provide_default_parent(obj, errp); + if (*errp) { + return NULL; + } + + if (parent_obj) { + /* + * Non-anonymous parents (under "/peripheral") are allowed to + * be accessed to create child<> properties. + */ + if (object_is_child_from(parent_obj, qdev_get_peripheral())) { + return parent_obj; + } + } + + return NULL; +} + +static bool qdev_pre_check_device_id(char *id, Error **errp) +{ + bool ambiguous =3D false; + Object *obj; + + if (!id) { + return true; + } + + obj =3D object_resolve_path_from(qdev_get_peripheral(), id, &ambiguous= ); + if (obj || ambiguous) { + error_setg(errp, "Duplicate device default ID '%s'. " + "Please specify another 'id'", id); + return false; + } + return true; +} + /* Takes ownership of @id, will be freed when deleting the device */ const char *qdev_set_id(DeviceState *dev, char *id, Error **errp) { + Object *parent_obj =3D NULL; ObjectProperty *prop; + UserChild *uc; =20 assert(!dev->id && !dev->realized); =20 + uc =3D (UserChild *)object_dynamic_cast(OBJECT(dev), TYPE_USER_CHILD); + + if (uc) { + parent_obj =3D qdev_find_peripheral_parent(dev, errp); + if (*errp) { + goto err; + } + + if (!id && parent_obj) { + /* + * Covert anonymous device with user-child interface to + * non-anonymous, then it will be insert under "/peripheral" + * path. + */ + id =3D uc_name_future_child(OBJECT(dev), parent_obj); + if (!qdev_pre_check_device_id(id, errp)) { + goto err; + } + } + } + /* * object_property_[try_]add_child() below will assert the device * has no parent */ if (id) { - prop =3D object_property_try_add_child(qdev_get_peripheral(), id, + if (!parent_obj) { + parent_obj =3D qdev_get_peripheral(); + } + + prop =3D object_property_try_add_child(parent_obj, id, OBJECT(dev), NULL); if (prop) { dev->id =3D id; } else { error_setg(errp, "Duplicate device ID '%s'", id); - g_free(id); - return NULL; + goto err; } } else { static int anon_count; @@ -615,6 +683,9 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) } =20 return prop->name; +err: + g_free(id); + return NULL; } =20 DeviceState *qdev_device_add_from_qdict(const QDict *opts, long *category, @@ -885,12 +956,18 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,= Error **errp) =20 static DeviceState *find_device_state(const char *id, Error **errp) { - Object *obj =3D object_resolve_path_at(qdev_get_peripheral(), id); + bool ambiguous =3D false; DeviceState *dev; + Object *obj; =20 + obj =3D object_resolve_path_from(qdev_get_peripheral(), id, &ambiguous= ); if (!obj) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", id); + if (ambiguous) { + error_setg(errp, "Device ID '%s' is ambiguous", id); + } else { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", id); + } return NULL; } =20 diff --git a/system/user-child.c b/system/user-child.c new file mode 100644 index 000000000000..1e667f09cc87 --- /dev/null +++ b/system/user-child.c @@ -0,0 +1,72 @@ +/* + * Child configurable interface. + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "monitor/user-child.h" + +Object *uc_provide_default_parent(Object *obj, Error **errp) +{ + UserChild *uc =3D USER_CHILD(obj); + UserChildClass *ucc =3D USER_CHILD_GET_CLASS(uc); + + if (ucc->get_parent) { + return ucc->get_parent(uc, errp); + } + + return NULL; +} + +char *uc_name_future_child(Object *obj, Object *parent) +{ + UserChild *uc =3D USER_CHILD(obj); + UserChildClass *ucc =3D USER_CHILD_GET_CLASS(uc); + + if (ucc->get_child_name) { + return ucc->get_child_name(uc, parent); + } + + return NULL; +} + +bool uc_check_user_parent(Object *obj, Object *parent) +{ + UserChild *uc =3D USER_CHILD(obj); + UserChildClass *ucc =3D USER_CHILD_GET_CLASS(uc); + + if (ucc->check_parent) { + ucc->check_parent(uc, parent); + } + + return true; +} + +static const TypeInfo user_child_interface_info =3D { + .name =3D TYPE_USER_CHILD, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(UserChildClass), +}; + +static void user_child_register_types(void) +{ + type_register_static(&user_child_interface_info); +} + +type_init(user_child_register_types) --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354895; cv=none; d=zohomail.com; s=zohoarc; b=TCRo300MvwM7VbgAwDzUHIvgb4APoaTFXUXoynLb83oTxw7JfWl3wCbFTD7JgTf5+/XOHaOowaJ+h2WiJgpk9Ln5/MyIBR0esJV53SaSMOiD2X1AXyONH8lg8kKbvzwKiG70T6rHoCE3Ocd0D1D1DROHJTodptZEaajGm2GzUpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354895; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mUPJ5SqK4srRxxomR4tbplrRs0HMKcgO8RlhqIvU96Y=; b=ODTpqZzx47gl4Q/gGgFz9HcXESAqx386uqWM4sGQr5X4fmCKQMBDHwcMJw0uRNHPvFZ6Ha9+TjECbdFE/MRgO7SqZo0271GCOSkRyw51+nMwlghZPJNXQ7NKcoAK6U9ceKSe2UTcN4WYNYloWgr8dtR2bmElYz9NiGd0mUd2OTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354895785580.4514769177864; Thu, 30 Nov 2023 06:34:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5R-0001lc-3b; Thu, 30 Nov 2023 09:32:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5O-0001k8-6X; Thu, 30 Nov 2023 09:32:14 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5L-00018C-4R; Thu, 30 Nov 2023 09:32:13 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:39 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354731; x=1732890731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vOtFxW4vj/U4kztv92p8xu/6iieeFFSa0l7Rf+yqZFI=; b=AhfhMEJUM+u9rmyvO32IPdp0wSYzhNAwN2WXM/wZ/RWr4kBSQd2eg/Wj BpZcqG6oGj4ExHNZDBK3IMUAmCSUVPz9U0DM7b8ajKczh9D7XlFdoXGBx QLAEmlzaUzldZY8fzqgw6+qX+GDNHKuEol+Fgs8L9mMM9fGyw0GQA8sUN UhFvCyOR+2y6PtX1WL8SoNPRkDaVHKD4LmhScBNWY6454m7tvaZsIvSaD vDU0xK+m0lCGqNqcN2NkIyVPNWdP3fWRvA53P/lmGxCBSMvq2R4Cl/MMm D2DYn+92Xx7CoNDmDe4rcCXKiD2A8jBLzQGMhpOQFudyShdR/T2GqRcf1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531333" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531333" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729711" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729711" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 07/41] qdev: Introduce parent option in -device Date: Thu, 30 Nov 2023 22:41:29 +0800 Message-Id: <20231130144203.2307629-8-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354897109000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Currently, the devices added by "-device" are linked via bus, and are set the parent as peripheral-anon or peripheral containers of the machine. But this is not enough for building CPU topology hierarchies as: 1. The relationship between different CPU hierarchies is child<> property other than link<> property, and they shouldn't be linked using the special bus. 2. The canonical path of device is built from the child<> property, and the well defined CPU topology hierarchies ask their canonical path to reflect the correct topological relationship. With these, the child<> property support is needed for QDev interface to allow user to configure proper parent in "-device". Introduce the "parent" option in "-device" to create the child<> property. This option asks for the device id of the parent device. Signed-off-by: Zhao Liu --- hw/xen/xen-legacy-backend.c | 2 +- include/monitor/qdev.h | 3 ++- system/qdev-monitor.c | 50 ++++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c index 124dd5f3d687..70ad11c6287e 100644 --- a/hw/xen/xen-legacy-backend.c +++ b/hw/xen/xen-legacy-backend.c @@ -184,7 +184,7 @@ static struct XenLegacyDevice *xen_be_get_xendev(const = char *type, int dom, object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); OBJECT(xendev)->free =3D g_free; qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev), - &error_fatal); + NULL, &error_fatal); qdev_realize(DEVICE(xendev), xen_sysbus, &error_fatal); object_unref(OBJECT(xendev)); =20 diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index f5fd6e6c1ffc..3d9d06158e5f 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -16,6 +16,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts= , long *category, * qdev_set_id: parent the device and set its id if provided. * @dev: device to handle * @id: id to be given to the device, or NULL. + * @parent: parent to be set for the device, or NULL. * * Returns: the id of the device in case of success; otherwise NULL. * @@ -34,6 +35,6 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts= , long *category, * returned string is owned by the corresponding child property and must * not be freed by the caller. */ -const char *qdev_set_id(DeviceState *dev, char *id, Error **errp); +const char *qdev_set_id(DeviceState *dev, char *id, char *parent, Error **= errp); =20 #endif diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 0261937b8462..8f56113eef65 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -587,22 +587,33 @@ static BusState *qbus_find(const char *path, Error **= errp) } =20 static Object *qdev_find_peripheral_parent(DeviceState *dev, + char *parent_id, Error **errp) { Object *parent_obj, *obj =3D OBJECT(dev); =20 - parent_obj =3D uc_provide_default_parent(obj, errp); - if (*errp) { - return NULL; - } + if (parent_id) { + parent_obj =3D object_resolve_path_from(qdev_get_peripheral(), + parent_id, NULL); + if (parent_obj) { + if (uc_check_user_parent(obj, parent_obj)) { + return parent_obj; + } + } + } else { + parent_obj =3D uc_provide_default_parent(obj, errp); + if (*errp) { + return NULL; + } =20 - if (parent_obj) { - /* - * Non-anonymous parents (under "/peripheral") are allowed to - * be accessed to create child<> properties. - */ - if (object_is_child_from(parent_obj, qdev_get_peripheral())) { - return parent_obj; + if (parent_obj) { + /* + * Non-anonymous parents (under "/peripheral") are allowed to + * be accessed to create child<> properties. + */ + if (object_is_child_from(parent_obj, qdev_get_peripheral())) { + return parent_obj; + } } } =20 @@ -628,7 +639,8 @@ static bool qdev_pre_check_device_id(char *id, Error **= errp) } =20 /* Takes ownership of @id, will be freed when deleting the device */ -const char *qdev_set_id(DeviceState *dev, char *id, Error **errp) +const char *qdev_set_id(DeviceState *dev, char *id, + char *parent, Error **errp) { Object *parent_obj =3D NULL; ObjectProperty *prop; @@ -639,7 +651,7 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) uc =3D (UserChild *)object_dynamic_cast(OBJECT(dev), TYPE_USER_CHILD); =20 if (uc) { - parent_obj =3D qdev_find_peripheral_parent(dev, errp); + parent_obj =3D qdev_find_peripheral_parent(dev, parent, errp); if (*errp) { goto err; } @@ -655,6 +667,11 @@ const char *qdev_set_id(DeviceState *dev, char *id, Er= ror **errp) goto err; } } + g_free(parent); + } else if (parent) { + error_setg(errp, "Only the device implemented user-child " + "interface supports `parent` option."); + goto err; } =20 /* @@ -684,6 +701,7 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) =20 return prop->name; err: + g_free(parent); g_free(id); return NULL; } @@ -694,7 +712,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, long *category, ERRP_GUARD(); DeviceClass *dc; const char *driver, *path; - char *id; + char *id, *parent; DeviceState *dev =3D NULL; BusState *bus =3D NULL; =20 @@ -772,12 +790,14 @@ DeviceState *qdev_device_add_from_qdict(const QDict *= opts, long *category, } =20 id =3D g_strdup(qdict_get_try_str(opts, "id")); + parent =3D g_strdup(qdict_get_try_str(opts, "parent")); =20 /* set properties */ dev->opts =3D qdict_clone_shallow(opts); qdict_del(dev->opts, "driver"); qdict_del(dev->opts, "bus"); qdict_del(dev->opts, "id"); + qdict_del(dev->opts, "parent"); =20 object_set_properties_from_keyval(&dev->parent_obj, dev->opts, from_js= on, errp); @@ -789,7 +809,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, long *category, * set dev's parent and register its id. * If it fails it means the id is already taken. */ - if (!qdev_set_id(dev, id, errp)) { + if (!qdev_set_id(dev, id, parent, errp)) { goto err_del_dev; } =20 --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354806; cv=none; d=zohomail.com; s=zohoarc; b=Fw14gsFN6BQmKaA0Wc3bOLj3XBpcDzk7kjlgXtq7pBYjV9PNwc/DpFsbNkWsSLWPVk1F/70mfO6TGrjeICMrNTowB+/9pEly9O7lboMXfObUMLOXEtDUAvaes0D5XGVqHUvm2J8uIeFm8VBViOGS4y3rdaFJQ+Awa8P/u540aUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354806; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zAA6Wrn4DxKQJWM8/1wruACjatIykstf7VTwuaQnU/8=; b=V28kMt6zrP5iegwnmYTKBwZaUrrrKxYIJ58nCahi9gf1DCaMZDtqLSfaT7O9gm6q8VP6hxkX6ciBY4UqzrgZontNke2PAaoxb4QxJ5Ehle6RRILbJK4ZK1GM48R7ViPiRoOp5l4zH199K8EpGwS3Dg+WOqfEVC2R3OwaBhHM8Jc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354806299468.7994475991974; Thu, 30 Nov 2023 06:33:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5Y-000255-4P; Thu, 30 Nov 2023 09:32:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5V-0001vV-JX; Thu, 30 Nov 2023 09:32:21 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5T-00018C-2m; Thu, 30 Nov 2023 09:32:21 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:48 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354739; x=1732890739; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0HgUkt24A8GDXQknSCYGY0tM/5gPDdFuKpTNl12j5yE=; b=ATYa529sz6DHIy+0chUCF3DcQdQ5ao/qjKYG9n7FgDoXWnXwbS/oSWXU 4ya5x/XjDxENInR29dipiz31rLWT+AAfWcbi3uawYAa8GN44+Ld51CE27 7RKBZcmzrPibkbe/sGSgeb6cqVxrnm3bgF8utQ04EDB2nIord+Hr2+QWb i0oUy4vdparRIaDZZJ4qEl3GarrTfdMnyZtHyZHxMpmPv8ukiSe0LfPgY WPGbywUXPIj579WWrPbKClt4FIprbrNH7/jGJ5esKgFXX/7r0yqdfVwQI +SXA+coVaKMf1I8tm6KmM2luiqaXBrsPu1VVsH43NKkce0gH9D2MqP/TN Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531399" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531399" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729736" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729736" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 08/41] hw/core/topo: Introduce CPU topology device abstraction Date: Thu, 30 Nov 2023 22:41:30 +0800 Message-Id: <20231130144203.2307629-9-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354806614000001 From: Zhao Liu To create more flexible CPU topologies (both symmetric and heterogeneous) via the "-device" interface, it is necessary to convert the current CPU topology hierarchies into the special CPU topology devices. The CPU topology will be built as a tree, and the device with the CPU_TOPO_ROOT level is the only root of this CPU topology tree. The different levels of CPU topology devices are connected in the "-device" cli with the child<> property, which in turn will be set the Object.parent through the qdev interface. And ultimately at the realize(), CPU topology devices will be linked to their topological parent based on the Object.parent field, and then be inserted into the topology tree. As the first step, introduce the basic CPU topology device abstraction, as well as the topology tree and topology hierarchy construction based on the CPU topology devices. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 + hw/core/cpu-topo.c | 201 +++++++++++++++++++++++++++++++++++++ hw/core/meson.build | 1 + include/hw/core/cpu-topo.h | 79 +++++++++++++++ 4 files changed, 283 insertions(+) create mode 100644 hw/core/cpu-topo.c create mode 100644 include/hw/core/cpu-topo.h diff --git a/MAINTAINERS b/MAINTAINERS index fdbabaa983cc..564cb776ae80 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1854,6 +1854,7 @@ R: Philippe Mathieu-Daud=C3=A9 R: Yanan Wang S: Supported F: hw/core/cpu.c +F: hw/core/cpu-topo.c F: hw/core/machine-qmp-cmds.c F: hw/core/machine.c F: hw/core/machine-smp.c @@ -1865,6 +1866,7 @@ F: qapi/machine-common.json F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h +F: include/hw/core/cpu-topo.h F: include/hw/cpu/cluster.h F: include/sysemu/numa.h F: tests/unit/test-smp-parse.c diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c new file mode 100644 index 000000000000..4428b979a5dc --- /dev/null +++ b/hw/core/cpu-topo.c @@ -0,0 +1,201 @@ +/* + * General CPU topology device abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" + +static const char *cpu_topo_level_to_string(CPUTopoLevel level) +{ + switch (level) { + case CPU_TOPO_UNKNOWN: + return "unknown"; + case CPU_TOPO_THREAD: + return "thread"; + case CPU_TOPO_CORE: + return "core"; + case CPU_TOPO_CLUSTER: + return "cluster"; + case CPU_TOPO_DIE: + return "die"; + case CPU_TOPO_SOCKET: + return "socket"; + case CPU_TOPO_BOOK: + return "book"; + case CPU_TOPO_DRAWER: + return "drawer"; + case CPU_TOPO_ROOT: + return "root"; + } + + return NULL; +} + +static void cpu_topo_build_hierarchy(CPUTopoState *topo, Error **errp) +{ + CPUTopoState *parent =3D topo->parent; + CPUTopoLevel level =3D CPU_TOPO_LEVEL(topo); + g_autofree char *name =3D NULL; + + if (!parent) { + return; + } + + if (parent->child_level =3D=3D CPU_TOPO_UNKNOWN) { + parent->child_level =3D level; + } else if (parent->child_level !=3D level) { + error_setg(errp, "cpu topo: the parent level %s asks for the " + "%s child, but current level is %s", + cpu_topo_level_to_string(CPU_TOPO_LEVEL(parent)), + cpu_topo_level_to_string(parent->child_level), + cpu_topo_level_to_string(level)); + return; + } + + if (parent->max_children && parent->max_children <=3D parent->num_chil= dren) { + error_setg(errp, "cpu topo: the parent limit the (%d) children, " + "currently it has %d children", + parent->max_children, + parent->num_children); + return; + } + + parent->num_children++; + QTAILQ_INSERT_TAIL(&parent->children, topo, sibling); +} + +static void cpu_topo_set_parent(CPUTopoState *topo, Error **errp) +{ + Object *obj =3D OBJECT(topo); + CPUTopoLevel level =3D CPU_TOPO_LEVEL(topo); + + if (!obj->parent) { + return; + } + + if (object_dynamic_cast(obj->parent, TYPE_CPU_TOPO)) { + CPUTopoState *parent =3D CPU_TOPO(obj->parent); + + if (level >=3D CPU_TOPO_LEVEL(parent)) { + error_setg(errp, "cpu topo: current level (%s) should be " + "lower than parent (%s) level", + object_get_typename(obj), + object_get_typename(OBJECT(parent))); + return; + } + topo->parent =3D parent; + } + + if (topo->parent) { + cpu_topo_build_hierarchy(topo, errp); + } +} + +static void cpu_topo_realize(DeviceState *dev, Error **errp) +{ + CPUTopoState *topo =3D CPU_TOPO(dev); + CPUTopoClass *tc =3D CPU_TOPO_GET_CLASS(topo); + + if (tc->level =3D=3D CPU_TOPO_UNKNOWN) { + error_setg(errp, "cpu topo: no level specified" + " type: %s", object_get_typename(OBJECT(dev))); + return; + } + + cpu_topo_set_parent(topo, errp); +} + +static void cpu_topo_destroy_hierarchy(CPUTopoState *topo) +{ + CPUTopoState *parent =3D topo->parent; + + if (!parent) { + return; + } + + QTAILQ_REMOVE(&parent->children, topo, sibling); + parent->num_children--; + + if (!parent->num_children) { + parent->child_level =3D CPU_TOPO_UNKNOWN; + } +} + +static void cpu_topo_unrealize(DeviceState *dev) +{ + CPUTopoState *topo =3D CPU_TOPO(dev); + + /* + * The specific unrealize method must consider the bottom-up, + * layer-by-layer unrealization implementation. + */ + g_assert(!topo->num_children); + + if (topo->parent) { + cpu_topo_destroy_hierarchy(topo); + } +} + +static void cpu_topo_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + /* All topology devices belong to CPU property. */ + set_bit(DEVICE_CATEGORY_CPU, dc->categories); + dc->realize =3D cpu_topo_realize; + dc->unrealize =3D cpu_topo_unrealize; + + /* + * The general topo device is not hotpluggable by default. + * If any topo device needs hotplug support, this flag must be + * overridden under arch-specific topo device code. + */ + dc->hotpluggable =3D false; + + tc->level =3D CPU_TOPO_UNKNOWN; +} + +static void cpu_topo_instance_init(Object *obj) +{ + CPUTopoState *topo =3D CPU_TOPO(obj); + QTAILQ_INIT(&topo->children); + + topo->child_level =3D CPU_TOPO_UNKNOWN; +} + +static const TypeInfo cpu_topo_type_info =3D { + .name =3D TYPE_CPU_TOPO, + .parent =3D TYPE_DEVICE, + .abstract =3D true, + .class_size =3D sizeof(CPUTopoClass), + .class_init =3D cpu_topo_class_init, + .instance_size =3D sizeof(CPUTopoState), + .instance_init =3D cpu_topo_instance_init, +}; + +static void cpu_topo_register_types(void) +{ + type_register_static(&cpu_topo_type_info); +} + +type_init(cpu_topo_register_types) diff --git a/hw/core/meson.build b/hw/core/meson.build index 67dad04de559..501d2529697e 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -23,6 +23,7 @@ else endif =20 common_ss.add(files('cpu-common.c')) +common_ss.add(files('cpu-topo.c')) common_ss.add(files('machine-smp.c')) system_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) system_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loade= r.c')) diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h new file mode 100644 index 000000000000..ebcbdd854da5 --- /dev/null +++ b/include/hw/core/cpu-topo.h @@ -0,0 +1,79 @@ +/* + * General CPU topology device abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef CPU_TOPO_H +#define CPU_TOPO_H + +#include "hw/qdev-core.h" +#include "qemu/queue.h" + +typedef enum CPUTopoLevel { + CPU_TOPO_UNKNOWN, + CPU_TOPO_THREAD, + CPU_TOPO_CORE, + CPU_TOPO_CLUSTER, + CPU_TOPO_DIE, + CPU_TOPO_SOCKET, + CPU_TOPO_BOOK, + CPU_TOPO_DRAWER, + CPU_TOPO_ROOT, +} CPUTopoLevel; + +#define TYPE_CPU_TOPO "cpu-topo" +OBJECT_DECLARE_TYPE(CPUTopoState, CPUTopoClass, CPU_TOPO) + +/** + * CPUTopoClass: + * @level: Topology level for this CPUTopoClass. + */ +struct CPUTopoClass { + /*< private >*/ + DeviceClass parent_class; + + /*< public >*/ + CPUTopoLevel level; +}; + +/** + * CPUTopoState: + * @num_children: Number of topology children under this topology device. + * @max_children: Maximum number of children allowed to be inserted under + * this topology device. + * @child_level: Topology level for children. + * @parent: Topology parent of this topology device. + * @children: Queue of topology children. + * @sibling: Queue node to be inserted in parent's topology queue. + */ +struct CPUTopoState { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + int num_children; + int max_children; + CPUTopoLevel child_level; + struct CPUTopoState *parent; + QTAILQ_HEAD(, CPUTopoState) children; + QTAILQ_ENTRY(CPUTopoState) sibling; +}; + +#define CPU_TOPO_LEVEL(topo) (CPU_TOPO_GET_CLASS(topo)->level) + +#endif /* CPU_TOPO_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354980; cv=none; d=zohomail.com; s=zohoarc; b=WfghJQ2DSbDIuFgkfB/DpXAJWARZj08WW4oJYh8UGwKZBEOx7G5FOcsjD9sOJu3SIlX/C0kjSU2HD/P8wp7Gd8/qtwdHcPfRKU8TiEp0l2F3ENSnHYsQcxTN9/QgSs98HU8194J+eJsgzO1SPW3AP/5WFK7MPWVOE2t0UFWac2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354980; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=egKEKzuYkZhiitXdPHNW6UEtM16vlgAvbgxAKTOu1yo=; b=an5y47Mc/VS3dGC0PVElZgN0urZTeEcrhkdD2SkkS1K6NID+j+l2zojRrh+iN1JNSwLFli1sLFCD/QKA+sjv4KOIRuTiIsVN/QReHwCTvjIgtDDaCA+P5Uh2TsqmG9prh4ETRyRpowoqUl/W0AwnNmXOyoLZSELnTziM3bSi9T4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354980742649.7511129875186; Thu, 30 Nov 2023 06:36:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5d-0002JO-QT; Thu, 30 Nov 2023 09:32:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5c-0002Ce-MQ; Thu, 30 Nov 2023 09:32:28 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5Z-00018C-R6; Thu, 30 Nov 2023 09:32:28 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:31:58 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354745; x=1732890745; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zcorAWDLgR7QueFdQsmIMfIxo58a5rqxmGG3Y6CdsHI=; b=BHQusIU/dLjU7NIEFO13j/KoSWNdsI89J3t8B9uBenczJR1PmTV8FBLm E+ahwlmHKBlzwa/iZqQxhUBjic7ds+AAPrO9R5H+q7O77VBGHJjTmswfd BTEbjWhbo3q3CqVZbQ4XINjGAu8BO549AFEZlGI3g6yCFb/bx6VvpMmUG cXpnY2RuaT07IlBdECwHVDfU+VbKPQGxfth0hudjh4wLdyASHe9LXoswi QJc1MBj7MaPiD/Oq6G7ODk4xQLtt73mMyalO6wxMisttEb8xw4F/xnPU6 6+8cg7H5cXSIcLhjUFbW2W1vKgDlbk2VKCyytVbSo8u6zagME+9U3J5ZQ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531490" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531490" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729745" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729745" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 09/41] hw/core/topo: Support topology index for topology device Date: Thu, 30 Nov 2023 22:41:31 +0800 Message-Id: <20231130144203.2307629-10-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354981215000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Topology index is used to identify the topology child under the same parent topology device. This field corresponds to the topology sub index (e.g., socket-id/ core-id/thread-id) used for addressing. Signed-off-by: Zhao Liu --- hw/core/cpu-topo.c | 77 ++++++++++++++++++++++++++++++++++++++ include/hw/core/cpu-topo.h | 6 +++ 2 files changed, 83 insertions(+) diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index 4428b979a5dc..3e0c183388d8 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -50,6 +50,66 @@ static const char *cpu_topo_level_to_string(CPUTopoLevel= level) return NULL; } =20 +static void cpu_topo_refresh_free_child_index(CPUTopoState *topo) +{ + CPUTopoState *child; + + /* + * Fast way: Assume that the index grows sequentially and that there + * are no "index hole" in the previous children. + * + * The previous check on num_children ensures that free_child_index + 1 + * does not hit the max_children limit. + */ + if (topo->free_child_index + 1 =3D=3D topo->num_children) { + topo->free_child_index++; + return; + } + + /* Slow way: Search the "index hole". The index hole must be found. */ + for (int index =3D 0; index < topo->num_children; index++) { + bool existed =3D false; + + QTAILQ_FOREACH(child, &topo->children, sibling) { + if (child->index =3D=3D index) { + existed =3D true; + break; + } + } + + if (!existed) { + topo->free_child_index =3D index; + return; + } + } +} + +static void cpu_topo_validate_index(CPUTopoState *topo, Error **errp) +{ + CPUTopoState *parent =3D topo->parent, *child; + + if (topo->index < 0) { + error_setg(errp, "Invalid topology index (%d).", + topo->index); + return; + } + + if (parent->max_children && topo->index >=3D parent->max_children) { + error_setg(errp, "Invalid topology index (%d): " + "The maximum index is %d.", + topo->index, parent->max_children); + return; + } + + QTAILQ_FOREACH(child, &topo->children, sibling) { + if (child->index =3D=3D topo->index) { + error_setg(errp, "Duplicate topology index (%d)", + topo->index); + return; + } + } +} + static void cpu_topo_build_hierarchy(CPUTopoState *topo, Error **errp) { CPUTopoState *parent =3D topo->parent; @@ -80,7 +140,18 @@ static void cpu_topo_build_hierarchy(CPUTopoState *topo= , Error **errp) } =20 parent->num_children++; + if (topo->index =3D=3D UNASSIGNED_TOPO_INDEX) { + topo->index =3D parent->free_child_index; + } else if (topo->index !=3D parent->free_child_index) { + /* The index has been set, then we need to validate it. */ + cpu_topo_validate_index(topo, errp); + if (*errp) { + return; + } + } + QTAILQ_INSERT_TAIL(&parent->children, topo, sibling); + cpu_topo_refresh_free_child_index(parent); } =20 static void cpu_topo_set_parent(CPUTopoState *topo, Error **errp) @@ -135,6 +206,10 @@ static void cpu_topo_destroy_hierarchy(CPUTopoState *t= opo) QTAILQ_REMOVE(&parent->children, topo, sibling); parent->num_children--; =20 + if (topo->index < parent->free_child_index) { + parent->free_child_index =3D topo->index; + } + if (!parent->num_children) { parent->child_level =3D CPU_TOPO_UNKNOWN; } @@ -180,6 +255,8 @@ static void cpu_topo_instance_init(Object *obj) CPUTopoState *topo =3D CPU_TOPO(obj); QTAILQ_INIT(&topo->children); =20 + topo->index =3D UNASSIGNED_TOPO_INDEX; + topo->free_child_index =3D 0; topo->child_level =3D CPU_TOPO_UNKNOWN; } =20 diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index ebcbdd854da5..c0dfff9dc63b 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -24,6 +24,8 @@ #include "hw/qdev-core.h" #include "qemu/queue.h" =20 +#define UNASSIGNED_TOPO_INDEX -1 + typedef enum CPUTopoLevel { CPU_TOPO_UNKNOWN, CPU_TOPO_THREAD, @@ -53,6 +55,8 @@ struct CPUTopoClass { =20 /** * CPUTopoState: + * @index: Topology index within parent's topology queue. + * @free_child_index: Cached free index to be specified for next child. * @num_children: Number of topology children under this topology device. * @max_children: Maximum number of children allowed to be inserted under * this topology device. @@ -66,6 +70,8 @@ struct CPUTopoState { DeviceState parent_obj; =20 /*< public >*/ + int index; + int free_child_index; int num_children; int max_children; CPUTopoLevel child_level; --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355033; cv=none; d=zohomail.com; s=zohoarc; b=NzZzl31V0nPW/85W2cFl0ntSyF+yd0nggpDt5ygCluaoA0db1YTOyS6vYmdzaocfroVssnBh8tzy/Jarspvv6rq/D4orOSUrCeeWqZtpusgUGCmYsYQAGDS0797HnK5/jmo8oeIdRBSyUFAhcAzDzHqBbrNnL5+Lnh3xZSXB7bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355033; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4Vtg8nuhFDKaL6AO7+xqdwzFixRs65nxKO/xum/WD+g=; b=ZFRdn8HPdHqTU/Af2ohG7GX42X+VLSZoEauWAzJ8byUCugtsTsdB67SNC5fHF+P6MPLe3FuTI7ZfgQw/6+050F41idk6B1oDEV0Y+aCN50rVoSJ/Jeyz9+mQaTZCHEXrW+5PJpw7K/ay65tvWFY8TvA7ihP7kdfTElX5oaO21Bk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355033579445.9201707513429; Thu, 30 Nov 2023 06:37:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5m-0002i9-98; Thu, 30 Nov 2023 09:32:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5j-0002di-VH; Thu, 30 Nov 2023 09:32:35 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5i-00018C-8E; Thu, 30 Nov 2023 09:32:35 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:08 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:31:58 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354754; x=1732890754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rfkBnAETWygr5TaDQC+NvTNqfHDXa5mpCuKsaH8rIdY=; b=Ag1XePDD2FePUzSKmuUDpE7NF4gT9yhn41TTfIMQ4aTp0bfemOeaE+B/ 9cvZUJiAZWbnvVhF3XG+topf0XVoZA98fk3uBeZk2Nzso4Li3BKpAEVJz RL6vEqgsFeuH+rza1o54AwS/r0gv0Fuia6rzbZAvZMsK2N60Qv3nyNk0b uwURKY9ChtNgvA7tYOWWiOU6dEX4BgMFNnPomTFcobqxyIjTpSJTiACX8 L5jRn99Mg8TGH0KEfrKXuna7B7Tw5le/iNU6EJobWWhqlxLdzM/hvshPy b6Vu4serM+JI3fWRftm/YSblHc04uI613usQYkthJ359MhteMaVfUXO+H Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531551" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531551" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729798" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729798" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 10/41] hw/core/topo: Add virtual method to update topology info for parent Date: Thu, 30 Nov 2023 22:41:32 +0800 Message-Id: <20231130144203.2307629-11-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355035516000002 Content-Type: text/plain; charset="utf-8" From: Zhao Liu When a new topology device is inserted into the topology tree, its'parents (including non-direct parent) need to update topology information. Add the virtual method to help parents on topology tree update topology information statistics. Signed-off-by: Zhao Liu --- hw/core/cpu-topo.c | 20 ++++++++++++++++++++ include/hw/core/cpu-topo.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index 3e0c183388d8..e244f0a3564e 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -154,6 +154,20 @@ static void cpu_topo_build_hierarchy(CPUTopoState *top= o, Error **errp) cpu_topo_refresh_free_child_index(parent); } =20 +static void cpu_topo_update_info(CPUTopoState *topo, bool is_realize) +{ + CPUTopoState *parent =3D topo->parent; + CPUTopoClass *tc; + + while (parent) { + tc =3D CPU_TOPO_GET_CLASS(parent); + if (tc->update_topo_info) { + tc->update_topo_info(parent, topo, is_realize); + } + parent =3D parent->parent; + } +} + static void cpu_topo_set_parent(CPUTopoState *topo, Error **errp) { Object *obj =3D OBJECT(topo); @@ -178,6 +192,11 @@ static void cpu_topo_set_parent(CPUTopoState *topo, Er= ror **errp) =20 if (topo->parent) { cpu_topo_build_hierarchy(topo, errp); + if (*errp) { + return; + } + + cpu_topo_update_info(topo, true); } } =20 @@ -203,6 +222,7 @@ static void cpu_topo_destroy_hierarchy(CPUTopoState *to= po) return; } =20 + cpu_topo_update_info(topo, false); QTAILQ_REMOVE(&parent->children, topo, sibling); parent->num_children--; =20 diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index c0dfff9dc63b..79cd8606feca 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -44,6 +44,8 @@ OBJECT_DECLARE_TYPE(CPUTopoState, CPUTopoClass, CPU_TOPO) /** * CPUTopoClass: * @level: Topology level for this CPUTopoClass. + * @update_topo_info: Method to update topology information statistics when + * new child (including direct child and non-direct child) is added. */ struct CPUTopoClass { /*< private >*/ @@ -51,6 +53,8 @@ struct CPUTopoClass { =20 /*< public >*/ CPUTopoLevel level; + void (*update_topo_info)(CPUTopoState *parent, CPUTopoState *child, + bool is_realize); }; =20 /** --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354787; cv=none; d=zohomail.com; s=zohoarc; b=ekqEuxtxjJHPD7c3q2igC3sD+SziRTS04eHM/37pwjzOdfohSx485ufNFb7NJ/p+MMq+7SiKTaSZxnY43HDlxGPEJ7izMnOaIPdxasnvk50Rgz15wVPbtQNvIzpUVqgV5bxmTWuBtfEPRZa5fqkD7gHa3yRhWIm9FYAO1l2TtYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354787; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ihp/jx5seYg7c0g5X0s3RsUl526zGV7js1rt+zrZCHs=; b=Y1oUCxlwedlV9r4/WuD/aRDK6CP65oA4+928e7ZA7fnzd7uuCPcEyp6RrxpeRwtWJl/xAoQXJRGrKwWPUdbKSxuuKVH+AhxQNK4h2IXjJrNY7udMhgJAVSdfRaKfxMBeq5UIHxV8RXJeAY0Z4l/1939NK5vBencF7A3AltFN3kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354787317149.60619947760426; Thu, 30 Nov 2023 06:33:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5q-0002uo-MW; Thu, 30 Nov 2023 09:32:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5o-0002lI-5O; Thu, 30 Nov 2023 09:32:40 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5m-00018C-Ff; Thu, 30 Nov 2023 09:32:39 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:17 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:07 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354758; x=1732890758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qW0hllcBGqseRYTHsmnEpW0X6HH9DmoP+0BU5Dr4Av4=; b=OWd4U0MN285ZMI0jhm1u6O/voRUZgeXxPDaArm2/dQWVEeNWFmMRPhJv dh1X4DD8oG9SmUCQVduTNbbz9ITX0zqOLy4KwTTDeSprzwLbw8R9d5edD P5aOnn0qdvtAjDuF/HD8fUXt9UVjUBs2SE/VsHuKiutzwKjSeznT9Qfv/ KRD3EjxUP8JYOTUoZM1cew2LoAZ57Q+EE2Go74s7qGKQM7P4PngYWiaAp VpGQSeV/0J2eXAia5QeAq3MLrMURqAmYnJyHisCXQBn2rmcopWVETDSRf 88AaxhWrzKXHWCAh4OnHMC/cejOVwqzg4vOsIzulj6J1NY0YdPeuLv0f9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531608" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531608" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729823" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729823" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 11/41] hw/core/topo: Add virtual method to check topology child Date: Thu, 30 Nov 2023 22:41:33 +0800 Message-Id: <20231130144203.2307629-12-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354788502000002 Content-Type: text/plain; charset="utf-8" From: Zhao Liu When a new topology child is to be inserted into the topology tree, its parents (including non-direct parents) need to check if this child is supported. Add the virtual method to allow topology device to check the support for their topology children. Signed-off-by: Zhao Liu --- hw/core/cpu-topo.c | 22 ++++++++++++++++++++++ include/hw/core/cpu-topo.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index e244f0a3564e..cba2dc747e74 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -168,6 +168,23 @@ static void cpu_topo_update_info(CPUTopoState *topo, b= ool is_realize) } } =20 +static void cpu_topo_check_support(CPUTopoState *topo, Error **errp) +{ + CPUTopoState *parent =3D topo->parent; + CPUTopoClass *tc; + + while (parent) { + tc =3D CPU_TOPO_GET_CLASS(parent); + if (tc->check_topo_child) { + tc->check_topo_child(parent, topo, errp); + if (*errp) { + return; + } + } + parent =3D parent->parent; + } +} + static void cpu_topo_set_parent(CPUTopoState *topo, Error **errp) { Object *obj =3D OBJECT(topo); @@ -191,6 +208,11 @@ static void cpu_topo_set_parent(CPUTopoState *topo, Er= ror **errp) } =20 if (topo->parent) { + cpu_topo_check_support(topo, errp); + if (*errp) { + return; + } + cpu_topo_build_hierarchy(topo, errp); if (*errp) { return; diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index 79cd8606feca..1ffdb0be6d38 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -46,6 +46,8 @@ OBJECT_DECLARE_TYPE(CPUTopoState, CPUTopoClass, CPU_TOPO) * @level: Topology level for this CPUTopoClass. * @update_topo_info: Method to update topology information statistics when * new child (including direct child and non-direct child) is added. + * @check_topo_child: Method to check the support for new child (including + * direct child and non-direct child) to be added. */ struct CPUTopoClass { /*< private >*/ @@ -55,6 +57,8 @@ struct CPUTopoClass { CPUTopoLevel level; void (*update_topo_info)(CPUTopoState *parent, CPUTopoState *child, bool is_realize); + void (*check_topo_child)(CPUTopoState *parent, CPUTopoState *child, + Error **errp); }; =20 /** --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354779; cv=none; d=zohomail.com; s=zohoarc; b=S2BAG1vtfzS2QC5M0k8P4hhuyDj7JZTlzzPDlwvKj+lzL2Te7QwiDIpLjagVV5JnX4Rw9JB4ayYe7+LYNR+32ndj8Q+2E6Mkz165vbK0iSgx5//WsYnG34aHsGPt8cGbtRRY4Pqlmx7VFezglvaN0tAhfGzEJScucf464QCB9FI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354779; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8fHZmOwnvs/K8ZQ2CmExFFPXoErkUG0bXhl59nNixrE=; b=LcDTA+Yf3vJo08+UY/IsbnUDBmmV3k41oRemKKuTylr8NGKGegdB+9DB7z7E6X2d6scC20Mc4E3/rQplMOcKU94XRA2e+tloWZ+7JYq2iKIuWIiYqt50ziAKz9U7tVUymMtbYamF8NoGLhI72zRc89o1qjAp5CWfMqL2q+Fnt10= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354779847320.2607103927046; Thu, 30 Nov 2023 06:32:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i5t-00033b-Mi; Thu, 30 Nov 2023 09:32:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5q-0002t0-2c; Thu, 30 Nov 2023 09:32:42 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i5o-0001BS-4M; Thu, 30 Nov 2023 09:32:41 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:26 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354760; x=1732890760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=giqm05kbC3tYOPrffoLra7vHI+bWgR59/qNt+YCSQ+8=; b=g02N2G6gMNbxuYTy/MpXvk/tCF1JtxcYvoqJjbqmKbsgNmt688e6H3nX 2fG5uXcRFQU9Rz50eLiXvJMFq98b1y0AcSRLfWyodbOACXXzWGir5EpX+ R9RqjNTy1TvtBxghMfQgkPqV3y9L3uX3PA1kITasQ3oc00KOsWhDUx/0q ug0cRclDm/C2DCWz6SEJTpGaenvklSoexfiB9zRUbiAo4tht7sLBlo94z BuiYla+2W+nzDhapsAYeW+OZc8fH5iaJab2RV42tBwOXjmOmCk1aFdzv7 GKoxFfYWknklgboGXWdDa+IziI2o18qG4mfwFYhcToQW+C/1a5sSgcpA+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531659" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531659" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729853" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729853" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree Date: Thu, 30 Nov 2023 22:41:34 +0800 Message-Id: <20231130144203.2307629-13-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354780444000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The topology devices will be organized as a topology tree. Each topology device may have many topology children with lower topology level. Add the helpers to traverse the CPU topology tree. Signed-off-by: Zhao Liu --- hw/core/cpu-topo.c | 41 ++++++++++++++++++++++++++++++++++++++ include/hw/core/cpu-topo.h | 13 ++++++++++++ 2 files changed, 54 insertions(+) diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index cba2dc747e74..687a4cc566ec 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -318,3 +318,44 @@ static void cpu_topo_register_types(void) } =20 type_init(cpu_topo_register_types) + +static int do_cpu_topo_child_foreach(CPUTopoState *topo, + unsigned long *levels, + topo_fn fn, void *opaque, + bool recurse) +{ + CPUTopoState *child; + int ret =3D TOPO_FOREACH_CONTINUE; + + QTAILQ_FOREACH(child, &topo->children, sibling) { + if (!levels || (levels && test_bit(CPU_TOPO_LEVEL(child), levels))= ) { + ret =3D fn(child, opaque); + if (ret =3D=3D TOPO_FOREACH_END || ret =3D=3D TOPO_FOREACH_ERR= ) { + break; + } else if (ret =3D=3D TOPO_FOREACH_SIBLING) { + continue; + } + } + + if (recurse) { + ret =3D do_cpu_topo_child_foreach(child, levels, fn, opaque, r= ecurse); + if (ret !=3D TOPO_FOREACH_CONTINUE) { + break; + } + } + } + return ret; +} + +int cpu_topo_child_foreach(CPUTopoState *topo, unsigned long *levels, + topo_fn fn, void *opaque) +{ + return do_cpu_topo_child_foreach(topo, levels, fn, opaque, false); +} + +int cpu_topo_child_foreach_recursive(CPUTopoState *topo, + unsigned long *levels, + topo_fn fn, void *opaque) +{ + return do_cpu_topo_child_foreach(topo, levels, fn, opaque, true); +} diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index 1ffdb0be6d38..453bacbb558b 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -90,4 +90,17 @@ struct CPUTopoState { =20 #define CPU_TOPO_LEVEL(topo) (CPU_TOPO_GET_CLASS(topo)->level) =20 +#define TOPO_FOREACH_SIBLING 2 +#define TOPO_FOREACH_END 1 +#define TOPO_FOREACH_CONTINUE 0 +#define TOPO_FOREACH_ERR -1 + +typedef int (*topo_fn)(CPUTopoState *topo, void *opaque); + +int cpu_topo_child_foreach(CPUTopoState *topo, unsigned long *levels, + topo_fn fn, void *opaque); +int cpu_topo_child_foreach_recursive(CPUTopoState *topo, + unsigned long *levels, + topo_fn fn, void *opaque); + #endif /* CPU_TOPO_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355104; cv=none; d=zohomail.com; s=zohoarc; b=lTkw+UccECwOcQoWQv9mMCQlXd+muidFgawzvp6s4VM06AUgP3ByBvu+rXIjBgFzOYFGLEmA3zdyGQsU6bZ6vHKNgZRE5t2uzV0ZVUmwbxWpWfKKCbmmdF7Z04aF8wb31V8nD7WqStr9cXsWo/x+kuiw9zzwbrpj2+WDC2TTqvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355104; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mcfNavNIfJF1Jh8YROim1Zq1MWbjYV/5adwJH68M0GU=; b=f0SRatxaD4epLdEXWYEiDPN7FeAJ7YInuHSP6qgLK0uTrGRplFuXVINwNcdqTIjp/QBo6ugLhewOAuvLdG32GyOXM3POV7l3ooRoyYEpmcTvVTgezc+ap4CGqAWdkFD7igeLaK7voe8NMTZshG/sLEf52Lq/mKJnQqSSA/jJyJ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355104811969.3879092343205; Thu, 30 Nov 2023 06:38:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6E-0003pw-HN; Thu, 30 Nov 2023 09:33:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6B-0003gj-Hk; Thu, 30 Nov 2023 09:33:03 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i65-0001EW-Ja; Thu, 30 Nov 2023 09:33:03 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:36 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354777; x=1732890777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rj2qhjfojWttufVsjPIiSdC7tmdmcTNlZ7nywO+2iko=; b=dO4Aez7JrHM7v38FGTfGLWF0uORB5obZxpc3iXPJf7dbriTn8K4H9FcD 6losTWfcMEH82P+iZs/jWXJHH1ummgG/PPkzxPs0Rorw43dUxq8zvYPJ0 VmW/FtwiGNf1Sv1yrR43JJBtseVV80M8cPYMDe+ETUkpFtE3zaeSRqlT+ tY2LcLshTuI2jUqMGMzt3Ose8jHnE0u1Rcbg6QPWvCW2y7wekVSxWwaSJ 9Vv+Pn+5qMIpvXCzFMD1IhWpghdUoh6SIitkAor7H04J3utXJXD/UhmJP ebzw45PAHCKFgHhLrhy3JKz1V1YEauijAX4OBl51nvuit2jmyP8msOk8M g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531720" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531720" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729870" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729870" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 13/41] hw/core/cpu: Convert CPU from general device to topology device Date: Thu, 30 Nov 2023 22:41:35 +0800 Message-Id: <20231130144203.2307629-14-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355105650000021 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Convert CPU to topology device then its parent topology devices could count the number of CPUs when new CPUs are added into topology tree. Note since CPUs are created from *_init_cpus() in MachineClass.init() or added from hotplug way, it depends on board initialization. Thus CPU topology device isn't marked as DEVICE_CATEGORY_CPU_DEF and it will only be created after board initialization. Signed-off-by: Zhao Liu --- accel/kvm/kvm-all.c | 4 ++-- hw/core/cpu-common.c | 25 +++++++++++++++++++++---- include/hw/core/cpu.h | 8 ++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index e39a810a4e92..2eee3eb95907 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3953,7 +3953,7 @@ static void query_stats(StatsResultList **result, Sta= tsTarget target, break; case STATS_TARGET_VCPU: add_stats_entry(result, STATS_PROVIDER_KVM, - cpu->parent_obj.canonical_path, + DEVICE(cpu)->canonical_path, stats_list); break; default: @@ -4045,7 +4045,7 @@ static void query_stats_cb(StatsResultList **result, = StatsTarget target, stats_args.names =3D names; stats_args.errp =3D errp; CPU_FOREACH(cpu) { - if (!apply_str_list_filter(cpu->parent_obj.canonical_path, tar= gets)) { + if (!apply_str_list_filter(DEVICE(cpu)->canonical_path, target= s)) { continue; } query_stats_vcpu(cpu, &stats_args); diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 82dae51a550b..e9ed84ff5386 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -195,6 +195,16 @@ static void cpu_common_realizefn(DeviceState *dev, Err= or **errp) { CPUState *cpu =3D CPU(dev); Object *machine =3D qdev_get_machine(); + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + /* + * The parent topology realize() must be completed before cpu_resume() + * where the CPU starts to run. + */ + cc->parent_realize(dev, errp); + if (*errp) { + return; + } =20 /* qdev_get_machine() can return something that's not TYPE_MACHINE * if this is one of the user-only emulators; in that case there's @@ -225,6 +235,7 @@ static void cpu_common_realizefn(DeviceState *dev, Erro= r **errp) static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu =3D CPU(dev); + CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 /* Call the plugin hook before clearing the cpu is fully unrealized */ if (tcg_enabled()) { @@ -233,6 +244,7 @@ static void cpu_common_unrealizefn(DeviceState *dev) =20 /* NOTE: latest generic point before the cpu is fully unrealized */ cpu_exec_unrealizefn(cpu); + cc->parent_unrealize(dev); } =20 static void cpu_common_initfn(Object *obj) @@ -275,6 +287,7 @@ static void cpu_class_init(ObjectClass *klass, void *da= ta) { DeviceClass *dc =3D DEVICE_CLASS(klass); ResettableClass *rc =3D RESETTABLE_CLASS(klass); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(klass); CPUClass *k =3D CPU_CLASS(klass); =20 k->parse_features =3D cpu_common_parse_features; @@ -282,9 +295,6 @@ static void cpu_class_init(ObjectClass *klass, void *da= ta) k->has_work =3D cpu_common_has_work; k->gdb_read_register =3D cpu_common_gdb_read_register; k->gdb_write_register =3D cpu_common_gdb_write_register; - set_bit(DEVICE_CATEGORY_CPU, dc->categories); - dc->realize =3D cpu_common_realizefn; - dc->unrealize =3D cpu_common_unrealizefn; rc->phases.hold =3D cpu_common_reset_hold; cpu_class_init_props(dc); /* @@ -292,11 +302,18 @@ static void cpu_class_init(ObjectClass *klass, void *= data) * IRQs, adding reset handlers, halting non-first CPUs, ... */ dc->user_creatable =3D false; + /* CPU is the minimum granularity for hotplug. */ + dc->hotpluggable =3D true; + device_class_set_parent_realize(dc, cpu_common_realizefn, + &k->parent_realize); + device_class_set_parent_unrealize(dc, cpu_common_unrealizefn, + &k->parent_unrealize); + tc->level =3D CPU_TOPO_THREAD; } =20 static const TypeInfo cpu_type_info =3D { .name =3D TYPE_CPU, - .parent =3D TYPE_DEVICE, + .parent =3D TYPE_CPU_TOPO, .instance_size =3D sizeof(CPUState), .instance_init =3D cpu_common_initfn, .instance_finalize =3D cpu_common_finalize, diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c0c8320413e5..a700f7c39140 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -20,6 +20,7 @@ #ifndef QEMU_CPU_H #define QEMU_CPU_H =20 +#include "hw/core/cpu-topo.h" #include "hw/qdev-core.h" #include "disas/dis-asm.h" #include "exec/cpu-common.h" @@ -146,7 +147,7 @@ struct SysemuCPUOps; */ struct CPUClass { /*< private >*/ - DeviceClass parent_class; + CPUTopoClass parent_class; /*< public >*/ =20 ObjectClass *(*class_by_name)(const char *cpu_model); @@ -191,6 +192,9 @@ struct CPUClass { int reset_dump_flags; int gdb_num_core_regs; bool gdb_stop_before_watchpoint; + + DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; }; =20 /* @@ -456,7 +460,7 @@ struct qemu_work_item; */ struct CPUState { /*< private >*/ - DeviceState parent_obj; + CPUTopoState parent_obj; /* cache to avoid expensive CPU_GET_CLASS */ CPUClass *cc; /*< public >*/ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354906; cv=none; d=zohomail.com; s=zohoarc; b=mtkCqolHo9OUiKOiqKWOVib4V0sBRsyC2W9nUEg9lzKU9MZp5GGVosKwvnQYjRDxid+NKrBYoGzjZ6MGLNeWZT3kMlabXSAPUw5V2uRzDBgnrbkaQNiQ5isbfAbxUm6QaFxnBDe/vyym0SLBjn8fAIJ1CLMKjC9ck3OfrE6aG+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354906; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cb8f+4ERS2LFmgEeqVriYNcoskNwV0iZz/vm+/T+QCU=; b=ZUzS9n7bXOn3qcx1wszf2cUx0LVHo+EQ8lrKaLu7IlFHfCoKPWcOYr+G5rRCQFLPJjRhWNDqzQZqVJWY7Oyd4XXDMxAFaQeyP2XKN1Rpef1y/xankVODkl7LR5TdwrrHib9g1ir0R7KWdTAHvvF7/zQ7uByl996JWm/UGaeqKkM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354906369395.1270972327891; Thu, 30 Nov 2023 06:35:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6G-0003wQ-PV; Thu, 30 Nov 2023 09:33:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6E-0003s2-Ve; Thu, 30 Nov 2023 09:33:07 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6C-0001Gr-16; Thu, 30 Nov 2023 09:33:06 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:46 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354784; x=1732890784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ISMaXqLtdhEuyYCRvB604LjEvb5pWdCfmnGTYVK8V4c=; b=ak11wZfzILl/gXjJYsuWOWKk5002A5CWfd+K9lASJZpcuOhANhyr71Dr oUwgOyPhXMS76DJ7f4SeznqoesvrsOq2nZ172ya0z94IAHgx1pP0jPg8O bzod8489bRaDtXz2eALg/H9GP7srVYEJsavXCU7om0FE2lgSD0qpgol+3 fFOLmbzL+aZWmiMo02wv9sMBGgOxOdOvZq9fGjbg+kf1e3oWue7GHTg7T ohKY2s7aotaR0FFHb5pm4OAaKuCyXwaTmvzMiWLO72hJVxDsXxh6/vWpQ SKSakEcAKpVAnpi1aeS4x25zzqEDTnp5s+NxLog3ESRR49pHSidkeTWeP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531735" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531735" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729902" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729902" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 14/41] PPC/ppc-core: Offload core-id to PPC specific core abstarction Date: Thu, 30 Nov 2023 22:41:36 +0800 Message-Id: <20231130144203.2307629-15-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354907058000006 Content-Type: text/plain; charset="utf-8" From: Zhao Liu PPC (spapr) supports hotplugs at the core granularity (spapr core) and treats core-id as the global id for all cores. But other architectures that support hotplugging at CPU granularity, use core-id as the local id to indicate the core within the parent topology container instand of the global index. To remove potential ambiguity and make the core abstraction available to other architectures, introduce the ppc core abstraction and define the "global" core-id over the ppc specific core. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 + hw/cpu/core.c | 29 ------------ hw/ppc/meson.build | 1 + hw/ppc/pnv.c | 6 +-- hw/ppc/pnv_core.c | 5 ++- hw/ppc/ppc_core.c | 79 +++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 28 +++++++----- hw/ppc/spapr_cpu_core.c | 6 +-- include/hw/cpu/core.h | 6 --- include/hw/ppc/pnv_core.h | 8 ++-- include/hw/ppc/ppc_core.h | 57 ++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 9 ++-- 12 files changed, 175 insertions(+), 61 deletions(-) create mode 100644 hw/ppc/ppc_core.c create mode 100644 include/hw/ppc/ppc_core.h diff --git a/MAINTAINERS b/MAINTAINERS index 564cb776ae80..89e350866d6a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1501,6 +1501,8 @@ F: include/hw/ppc/fdt.h F: hw/ppc/fdt.c F: include/hw/ppc/pef.h F: hw/ppc/pef.c +F: include/hw/ppc/ppc_core.h +F: hw/ppc/ppc_core.c F: pc-bios/slof.bin F: docs/system/ppc/pseries.rst F: docs/specs/ppc-spapr-* diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 495a5c30ffe1..7e274d6aebb7 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -14,33 +14,6 @@ #include "qapi/error.h" #include "qapi/visitor.h" =20 -static void core_prop_get_core_id(Object *obj, Visitor *v, const char *nam= e, - void *opaque, Error **errp) -{ - CPUCore *core =3D CPU_CORE(obj); - int64_t value =3D core->core_id; - - visit_type_int(v, name, &value, errp); -} - -static void core_prop_set_core_id(Object *obj, Visitor *v, const char *nam= e, - void *opaque, Error **errp) -{ - CPUCore *core =3D CPU_CORE(obj); - int64_t value; - - if (!visit_type_int(v, name, &value, errp)) { - return; - } - - if (value < 0) { - error_setg(errp, "Invalid core id %"PRId64, value); - return; - } - - core->core_id =3D value; -} - static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *= name, void *opaque, Error **errp) { @@ -82,8 +55,6 @@ static void cpu_core_class_init(ObjectClass *oc, void *da= ta) DeviceClass *dc =3D DEVICE_CLASS(oc); =20 set_bit(DEVICE_CATEGORY_CPU, dc->categories); - object_class_property_add(oc, "core-id", "int", core_prop_get_core_id, - core_prop_set_core_id, NULL, NULL); object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_th= reads, core_prop_set_nr_threads, NULL, NULL); } diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build index ea44856d43b0..2b40a91a4661 100644 --- a/hw/ppc/meson.build +++ b/hw/ppc/meson.build @@ -2,6 +2,7 @@ ppc_ss =3D ss.source_set() ppc_ss.add(files( 'ppc.c', 'ppc_booke.c', + 'ppc_core.c', )) ppc_ss.add(when: 'CONFIG_FDT_PPC', if_true: [files( 'fdt.c', diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 0297871bdd5d..6e92ff8b4f64 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1224,7 +1224,7 @@ static void pnv_chip_icp_realize(Pnv8Chip *chip8, Err= or **errp) /* Map the ICP registers for each thread */ for (i =3D 0; i < chip->nr_cores; i++) { PnvCore *pnv_core =3D chip->cores[i]; - int core_hwid =3D CPU_CORE(pnv_core)->core_id; + int core_hwid =3D POWERPC_CORE(pnv_core)->core_id; =20 for (j =3D 0; j < CPU_CORE(pnv_core)->nr_threads; j++) { uint32_t pir =3D pcc->core_pir(chip, core_hwid) + j; @@ -1443,7 +1443,7 @@ static void pnv_chip_quad_realize_one(PnvChip *chip, = PnvQuad *eq, const char *type) { char eq_name[32]; - int core_id =3D CPU_CORE(pnv_core)->core_id; + int core_id =3D POWERPC_CORE(pnv_core)->core_id; =20 snprintf(eq_name, sizeof(eq_name), "eq[%d]", core_id); object_initialize_child_with_props(OBJECT(chip), eq_name, eq, @@ -1983,7 +1983,7 @@ static void pnv_chip_core_realize(PnvChip *chip, Erro= r **errp) chip->cores[i] =3D pnv_core; object_property_set_int(OBJECT(pnv_core), "nr-threads", chip->nr_threads, &error_fatal); - object_property_set_int(OBJECT(pnv_core), CPU_CORE_PROP_CORE_ID, + object_property_set_int(OBJECT(pnv_core), POWERPC_CORE_PROP_CORE_I= D, core_hwid, &error_fatal); object_property_set_int(OBJECT(pnv_core), "pir", pcc->core_pir(chip, core_hwid), &error_fat= al); diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 8c7afe037f00..a90d1ec92bd8 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -267,6 +267,7 @@ static void pnv_core_realize(DeviceState *dev, Error **= errp) PnvCore *pc =3D PNV_CORE(OBJECT(dev)); PnvCoreClass *pcc =3D PNV_CORE_GET_CLASS(pc); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); + PowerPCCore *ppc =3D POWERPC_CORE(cc); const char *typename =3D pnv_core_cpu_typename(pc); Error *local_err =3D NULL; void *obj; @@ -299,7 +300,7 @@ static void pnv_core_realize(DeviceState *dev, Error **= errp) } } =20 - snprintf(name, sizeof(name), "xscom-core.%d", cc->core_id); + snprintf(name, sizeof(name), "xscom-core.%d", ppc->core_id); pnv_xscom_region_init(&pc->xscom_regs, OBJECT(dev), pcc->xscom_ops, pc, name, pcc->xscom_size); =20 @@ -392,7 +393,7 @@ static void pnv_core_class_init(ObjectClass *oc, void *= data) static const TypeInfo pnv_core_infos[] =3D { { .name =3D TYPE_PNV_CORE, - .parent =3D TYPE_CPU_CORE, + .parent =3D TYPE_POWERPC_CORE, .instance_size =3D sizeof(PnvCore), .class_size =3D sizeof(PnvCoreClass), .class_init =3D pnv_core_class_init, diff --git a/hw/ppc/ppc_core.c b/hw/ppc/ppc_core.c new file mode 100644 index 000000000000..4433b54af506 --- /dev/null +++ b/hw/ppc/ppc_core.c @@ -0,0 +1,79 @@ +/* + * Common PPC CPU core abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "hw/ppc/ppc_core.h" +#include "qapi/error.h" +#include "qapi/visitor.h" + +static void powerpc_core_prop_get_core_id(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + PowerPCCore *core =3D POWERPC_CORE(obj); + int64_t value =3D core->core_id; + + visit_type_int(v, name, &value, errp); +} + +static void powerpc_core_prop_set_core_id(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + PowerPCCore *core =3D POWERPC_CORE(obj); + int64_t value; + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + if (value < 0) { + error_setg(errp, "Invalid core id %"PRId64, value); + return; + } + + core->core_id =3D value; +} + +static void powerpc_core_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + object_class_property_add(oc, "core-id", "int", + powerpc_core_prop_get_core_id, + powerpc_core_prop_set_core_id, + NULL, NULL); +} + +static const TypeInfo powerpc_core_type_info =3D { + .name =3D TYPE_POWERPC_CORE, + .parent =3D TYPE_CPU_CORE, + .abstract =3D true, + .class_init =3D powerpc_core_class_init, + .instance_size =3D sizeof(PowerPCCore), +}; + +static void powerpc_core_register_types(void) +{ + type_register_static(&powerpc_core_type_info); +} + +type_init(powerpc_core_register_types) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index df09aa9d6a00..72e9f49da110 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2713,7 +2713,7 @@ static void spapr_init_cpus(SpaprMachineState *spapr) =20 object_property_set_int(core, "nr-threads", nr_threads, &error_fatal); - object_property_set_int(core, CPU_CORE_PROP_CORE_ID, core_id, + object_property_set_int(core, POWERPC_CORE_PROP_CORE_ID, core_= id, &error_fatal); qdev_realize(DEVICE(core), NULL, &error_fatal); =20 @@ -3889,7 +3889,8 @@ static void spapr_core_unplug(HotplugHandler *hotplug= _dev, DeviceState *dev) MachineState *ms =3D MACHINE(hotplug_dev); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc =3D CPU_CORE(dev); - CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, cc->core_id, NULL); + PowerPCCore *ppc =3D POWERPC_CORE(cc); + CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, ppc->core_id, NULL); =20 if (smc->pre_2_10_has_unused_icps) { SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); @@ -3915,10 +3916,11 @@ void spapr_core_unplug_request(HotplugHandler *hotp= lug_dev, DeviceState *dev, int index; SpaprDrc *drc; CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); =20 - if (!spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index)) { + if (!spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, &index)) { error_setg(errp, "Unable to find CPU core with core-id: %d", - cc->core_id); + ppc->core_id); return; } if (index =3D=3D 0) { @@ -3927,7 +3929,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, } =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, - spapr_vcpu_id(spapr, cc->core_id)); + spapr_vcpu_id(spapr, ppc->core_id)); g_assert(drc); =20 if (!spapr_drc_unplug_requested(drc)) { @@ -3985,6 +3987,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev) SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); SpaprCpuCore *core =3D SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); CPUState *cs; SpaprDrc *drc; CPUArchId *core_slot; @@ -3992,11 +3995,11 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev) bool hotplugged =3D spapr_drc_hotplugged(dev); int i; =20 - core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); + core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, = &index); g_assert(core_slot); /* Already checked in spapr_core_pre_plug() */ =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, - spapr_vcpu_id(spapr, cc->core_id)); + spapr_vcpu_id(spapr, ppc->core_id)); =20 g_assert(drc || !mc->has_hotpluggable_cpus); =20 @@ -4047,6 +4050,7 @@ static void spapr_core_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, MachineState *machine =3D MACHINE(OBJECT(hotplug_dev)); MachineClass *mc =3D MACHINE_GET_CLASS(hotplug_dev); CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); const char *base_core_type =3D spapr_get_cpu_core_type(machine->cpu_ty= pe); const char *type =3D object_get_typename(OBJECT(dev)); CPUArchId *core_slot; @@ -4063,8 +4067,8 @@ static void spapr_core_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, return; } =20 - if (cc->core_id % smp_threads) { - error_setg(errp, "invalid core id %d", cc->core_id); + if (ppc->core_id % smp_threads) { + error_setg(errp, "invalid core id %d", ppc->core_id); return; } =20 @@ -4080,14 +4084,14 @@ static void spapr_core_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, return; } =20 - core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); + core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, = &index); if (!core_slot) { - error_setg(errp, "core id %d out of range", cc->core_id); + error_setg(errp, "core id %d out of range", ppc->core_id); return; } =20 if (core_slot->cpu) { - error_setg(errp, "core %d already populated", cc->core_id); + error_setg(errp, "core %d already populated", ppc->core_id); return; } =20 diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 91fae56573ee..7c2ea1424747 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -292,7 +292,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMa= chineState *spapr, static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) { SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); - CPUCore *cc =3D CPU_CORE(sc); + PowerPCCore *ppc =3D POWERPC_CORE(sc); g_autoptr(Object) obj =3D NULL; g_autofree char *id =3D NULL; CPUState *cs; @@ -307,7 +307,7 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, = int i, Error **errp) * and the rest are explicitly started up by the guest using an RTAS c= all. */ cs->start_powered_off =3D true; - cs->cpu_index =3D cc->core_id + i; + cs->cpu_index =3D ppc->core_id + i; if (!spapr_set_vcpu_id(cpu, cs->cpu_index, errp)) { return NULL; } @@ -381,7 +381,7 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, = void *data) static const TypeInfo spapr_cpu_core_type_infos[] =3D { { .name =3D TYPE_SPAPR_CPU_CORE, - .parent =3D TYPE_CPU_CORE, + .parent =3D TYPE_POWERPC_CORE, .abstract =3D true, .instance_size =3D sizeof(SpaprCpuCore), .class_size =3D sizeof(SpaprCpuCoreClass), diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h index 98ab91647eb2..17f117bd5225 100644 --- a/include/hw/cpu/core.h +++ b/include/hw/cpu/core.h @@ -21,13 +21,7 @@ struct CPUCore { DeviceState parent_obj; =20 /*< public >*/ - int core_id; int nr_threads; }; =20 -/* Note: topology field names need to be kept in sync with - * 'CpuInstanceProperties' */ - -#define CPU_CORE_PROP_CORE_ID "core-id" - #endif diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h index 4db21229a68b..56c3f6b51f2f 100644 --- a/include/hw/ppc/pnv_core.h +++ b/include/hw/ppc/pnv_core.h @@ -20,9 +20,9 @@ #ifndef PPC_PNV_CORE_H #define PPC_PNV_CORE_H =20 -#include "hw/cpu/core.h" #include "target/ppc/cpu.h" #include "hw/ppc/pnv.h" +#include "hw/ppc/ppc_core.h" #include "qom/object.h" =20 #define TYPE_PNV_CORE "powernv-cpu-core" @@ -31,7 +31,7 @@ OBJECT_DECLARE_TYPE(PnvCore, PnvCoreClass, =20 struct PnvCore { /*< private >*/ - CPUCore parent_obj; + PowerPCCore parent_obj; =20 /*< public >*/ PowerPCCPU **threads; @@ -43,8 +43,10 @@ struct PnvCore { }; =20 struct PnvCoreClass { - DeviceClass parent_class; + /*< private >*/ + PowerPCCoreClass parent_class; =20 + /*< public >*/ const MemoryRegionOps *xscom_ops; uint64_t xscom_size; }; diff --git a/include/hw/ppc/ppc_core.h b/include/hw/ppc/ppc_core.h new file mode 100644 index 000000000000..bcc83e426e3f --- /dev/null +++ b/include/hw/ppc/ppc_core.h @@ -0,0 +1,57 @@ +/* + * Common PPC CPU core abstraction header + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_PPC_CORE_H +#define HW_PPC_CORE_H + +#include "hw/cpu/core.h" +#include "hw/qdev-core.h" +#include "qom/object.h" + +#define TYPE_POWERPC_CORE "powerpc-core" + +OBJECT_DECLARE_TYPE(PowerPCCore, PowerPCCoreClass, POWERPC_CORE) + +struct PowerPCCoreClass { + /*< private >*/ + CPUCoreClass parent_class; + + /*< public >*/ +}; + +struct PowerPCCore { + /*< private >*/ + CPUCore parent_obj; + + /*< public >*/ + /* + * The system-wide id for core, not the sub core-id within the + * parent container (which is above the core level). + */ + int core_id; +}; + +/* + * Note: topology field names need to be kept in sync with + * 'CpuInstanceProperties' + */ +#define POWERPC_CORE_PROP_CORE_ID "core-id" + +#endif /* HW_PPC_CORE_H */ diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_cor= e.h index 69a52e39b850..db3e515051ca 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -9,7 +9,7 @@ #ifndef HW_SPAPR_CPU_CORE_H #define HW_SPAPR_CPU_CORE_H =20 -#include "hw/cpu/core.h" +#include "hw/ppc/ppc_core.h" #include "hw/qdev-core.h" #include "target/ppc/cpu-qom.h" #include "target/ppc/cpu.h" @@ -23,7 +23,7 @@ OBJECT_DECLARE_TYPE(SpaprCpuCore, SpaprCpuCoreClass, =20 struct SpaprCpuCore { /*< private >*/ - CPUCore parent_obj; + PowerPCCore parent_obj; =20 /*< public >*/ PowerPCCPU **threads; @@ -32,7 +32,10 @@ struct SpaprCpuCore { }; =20 struct SpaprCpuCoreClass { - DeviceClass parent_class; + /*< private >*/ + PowerPCCoreClass parent_class; + + /*< public >*/ const char *cpu_type; }; =20 --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354902; cv=none; d=zohomail.com; s=zohoarc; b=LRiGZyz4q1zsMuUNd1SV0p1Jq/U0KEmMs8lNJt333XLn/jS+1QjS7Sdl9b8O4mPvSMxFhk6hUXUsR63HZblqdvwDScyVVAKSWtSqxIhzN+db7QO3zVHdTeDST0kgcOHbt/63a7r1W1AyW74CrQC2H4/QXzHsLiTLFLe4tXUwYNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354902; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s0FHlh5NocTVAQ8QPRfvhIq5od/9G9VD8e1wobWtIiw=; b=PC04gJsOF/QgStds1dbAPJqmlCn10WNzONx4GPfU56RjokZJ6IzIBRWHdw7n9RKZPey3UIQt+SRjlClA0H4CMLEfq1R6Ifb9uZvXs3C058RYH82z19nnDBR629I2u7sCGI5WsOZUSXKHOXmRXlwB46EkgWK6zd3sglnPpAqdsVo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354902923540.3854643214889; Thu, 30 Nov 2023 06:35:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6L-00047x-D1; Thu, 30 Nov 2023 09:33:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6H-0003yV-Fk; Thu, 30 Nov 2023 09:33:09 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6E-0001EW-Bs; Thu, 30 Nov 2023 09:33:09 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:54 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:45 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354786; x=1732890786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HQNocPVaV+DgJS+Ld4DvaS6hVw4IdYUlBhgQdcIl19Q=; b=h5Rfb6iQTuIroyQoXUynoGRMPvKTIQtOHQPuV1lnHfqnNQ86qvbjMtXw ldhiGhtkxtHxBk7RT0WFAIAsF95V8DXvVIpVsYCTaLuaWwW4JG5aSEwXX iCtoChT9EzqHXG8masEvnyeck122QSu+kHINuL1ZgupxUjT9qXhDyKKvR y0SeXvLY+BKDTgB4RNgGTWvltWd4ndAb1PV+m7C9owwg6Fx/UD/r0/CS4 Sl8MGNY+WOxBjAfV8udMcjd6RF003bZ5BN3meSQmWpxVn8cJtdvz9AQ6m F7jiMbwhadhBiC/yScfE3xBsp85SJKBeL8y7PzaUn67SjEwa+PgAyTXQy g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531806" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531806" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729932" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729932" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 15/41] hw/cpu/core: Allow to configure plugged threads for cpu-core Date: Thu, 30 Nov 2023 22:41:37 +0800 Message-Id: <20231130144203.2307629-16-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354904991000002 Content-Type: text/plain; charset="utf-8" From: Zhao Liu When the core abstraction is applied for the architecture support CPU hotplug, the plugged CPUs and unplugged CPUs are distributed among the cores created in the topology tree. Add plugged_threads field to help cpu-core decide to how many CPUs to create. Signed-off-by: Zhao Liu --- hw/cpu/core.c | 33 +++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 6 +++++- hw/ppc/spapr_cpu_core.c | 6 +++++- include/hw/cpu/core.h | 9 +++++++++ include/hw/ppc/pnv_core.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 2 ++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 7e274d6aebb7..15546b5b2339 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -36,6 +36,20 @@ static void core_prop_set_nr_threads(Object *obj, Visito= r *v, const char *name, core->nr_threads =3D value; } =20 +static void core_prop_set_plugged_threads(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CPUCore *core =3D CPU_CORE(obj); + int64_t value; + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + core->plugged_threads =3D value; +} + static void cpu_core_instance_init(Object *obj) { CPUCore *core =3D CPU_CORE(obj); @@ -48,6 +62,22 @@ static void cpu_core_instance_init(Object *obj) if (current_machine) { core->nr_threads =3D current_machine->smp.threads; } + + core->plugged_threads =3D -1; +} + +static void cpu_core_realize(DeviceState *dev, Error **errp) +{ + CPUCore *core =3D CPU_CORE(dev); + + if (core->plugged_threads > core->nr_threads) { + error_setg(errp, "Plugged threads (plugged-threads: %d) must " + "not be more than max threads (nr-threads: %d)", + core->plugged_threads, core->nr_threads); + return; + } else if (core->plugged_threads =3D=3D -1) { + core->plugged_threads =3D core->nr_threads; + } } =20 static void cpu_core_class_init(ObjectClass *oc, void *data) @@ -57,6 +87,9 @@ static void cpu_core_class_init(ObjectClass *oc, void *da= ta) set_bit(DEVICE_CATEGORY_CPU, dc->categories); object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_th= reads, core_prop_set_nr_threads, NULL, NULL); + object_class_property_add(oc, "plugged-threads", "int", NULL, + core_prop_set_plugged_threads, NULL, NULL); + dc->realize =3D cpu_core_realize; } =20 static const TypeInfo cpu_core_type_info =3D { diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index a90d1ec92bd8..8b75739697d1 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -276,6 +276,8 @@ static void pnv_core_realize(DeviceState *dev, Error **= errp) =20 assert(pc->chip); =20 + pcc->parent_realize(dev, errp); + pc->threads =3D g_new(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { PowerPCCPU *cpu; @@ -376,11 +378,13 @@ static void pnv_core_power10_class_init(ObjectClass *= oc, void *data) static void pnv_core_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); + PnvCoreClass *pcc =3D PNV_CORE_CLASS(oc); =20 - dc->realize =3D pnv_core_realize; dc->unrealize =3D pnv_core_unrealize; device_class_set_props(dc, pnv_core_properties); dc->user_creatable =3D false; + device_class_set_parent_realize(dc, pnv_core_realize, + &pcc->parent_realize); } =20 #define DEFINE_PNV_CORE_TYPE(family, cpu_model) \ diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 7c2ea1424747..5533a386f350 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -331,6 +331,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(), TYPE_SPAPR_MACHINE); SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); + SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); int i; =20 @@ -339,6 +340,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) return; } =20 + scc->parent_realize(dev, errp); + qemu_register_reset(spapr_cpu_core_reset_handler, sc); sc->threads =3D g_new0(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { @@ -363,11 +366,12 @@ static void spapr_cpu_core_class_init(ObjectClass *oc= , void *data) DeviceClass *dc =3D DEVICE_CLASS(oc); SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_CLASS(oc); =20 - dc->realize =3D spapr_cpu_core_realize; dc->unrealize =3D spapr_cpu_core_unrealize; dc->reset =3D spapr_cpu_core_reset; device_class_set_props(dc, spapr_cpu_core_properties); scc->cpu_type =3D data; + device_class_set_parent_realize(dc, spapr_cpu_core_realize, + &scc->parent_realize); } =20 #define DEFINE_SPAPR_CPU_CORE_TYPE(cpu_model) \ diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h index 17f117bd5225..87d50151ab01 100644 --- a/include/hw/cpu/core.h +++ b/include/hw/cpu/core.h @@ -21,7 +21,16 @@ struct CPUCore { DeviceState parent_obj; =20 /*< public >*/ + int core_id; + + /* Maximum number of threads contained in this core. */ int nr_threads; + + /* + * How many threads should be plugged in this core via + * "-device"/"device_add"? + */ + int plugged_threads; }; =20 #endif diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h index 56c3f6b51f2f..3b9edf69f9fb 100644 --- a/include/hw/ppc/pnv_core.h +++ b/include/hw/ppc/pnv_core.h @@ -49,6 +49,8 @@ struct PnvCoreClass { /*< public >*/ const MemoryRegionOps *xscom_ops; uint64_t xscom_size; + + DeviceRealize parent_realize; }; =20 #define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_cor= e.h index db3e515051ca..dabdbd4bcbc9 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -37,6 +37,8 @@ struct SpaprCpuCoreClass { =20 /*< public >*/ const char *cpu_type; + + DeviceRealize parent_realize; }; =20 const char *spapr_get_cpu_core_type(const char *cpu_type); --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354981; cv=none; d=zohomail.com; s=zohoarc; b=RGczKB1W7VuXdUVtYi9C40IUqx4Gj1pEFgv0V9MiC6mWLzaaI2xhXZUvfFnnOPayALJE6vQJTblLLQnI+WYodCEPNTGEQOsJZuvequ3DdOCSTBXpVnposPImsgpQCO6Z9ZNqv1aqInJb4fdRhqG+SMeBczWlfrm9qqoim5fMmaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354981; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U4LNWwiOs6ki2FoDEsFF1f0dT3yNScsGQRkBIApn0/k=; b=O7JnrAmNoinqK8cMutJkO8ppYgZAoxZZPi3KmKwq+PF1GDSwliwYb/uHKi9ChFmGnQyxUGvRbUM6ni7YDIi70iCwiu+VygE6WYl9JLgm1zBcNpyodKUSWbSCneTmWeIOyUuGhzfToUXRQCIcSiXbE2vqhByZd2Pfa3iCV31zrqk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354981158650.311213766761; Thu, 30 Nov 2023 06:36:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6N-0004O2-S6; Thu, 30 Nov 2023 09:33:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6J-00043R-Ar; Thu, 30 Nov 2023 09:33:11 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6H-0001I2-HS; Thu, 30 Nov 2023 09:33:10 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:04 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:54 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354789; x=1732890789; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/4XB1+0XSfZXJW6ggYvVG8+UQ24RT1LIudOfD5YSaJw=; b=HasYQyEUkyVg21haLFRHGDdWbARruYDFjMYrLUFCSDFA7i3axlx1zrdK fu3NPHtZCxTw3A5pJhlnvwjnGuzUMT2IdFV9kHEIWh+4RLOgmKpyxz+fV HUgT1/mGJ+MJLDM7Yso4qoj+MM9pgumfhXFdSzWkRGgKdLBGM3yb/7WA7 oM9DtHv+mt7dkM+lfQR1r5vcVeKEeZ4HtaEi/imu6Jp++uqNu4MPq4gxy RERmOGl/6JZCsCOg8h2ZqCXB7GP/sANyyIEGgHCrlThnXXmI2Jax3rhMa EFkvZfN5xrlNpmx4gfc2xTtjWaGooJ9RyU4Kks03V+K30LCwoJigisB/Q w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531860" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531860" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729971" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729971" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 16/41] PPC/ppc-core: Limit plugged-threads and nr-threads to be equal Date: Thu, 30 Nov 2023 22:41:38 +0800 Message-Id: <20231130144203.2307629-17-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354983207000013 Content-Type: text/plain; charset="utf-8" From: Zhao Liu PPC supports CPU hotplug at core granularity, thus ppc-core only accepts all CPUs in a core are plugged. Check if plugged_threads and nr_threads are equal when ppc-core realizes. Signed-off-by: Zhao Liu --- hw/ppc/ppc_core.c | 18 ++++++++++++++++++ include/hw/ppc/ppc_core.h | 1 + 2 files changed, 19 insertions(+) diff --git a/hw/ppc/ppc_core.c b/hw/ppc/ppc_core.c index 4433b54af506..3857f3150052 100644 --- a/hw/ppc/ppc_core.c +++ b/hw/ppc/ppc_core.c @@ -53,20 +53,38 @@ static void powerpc_core_prop_set_core_id(Object *obj, = Visitor *v, core->core_id =3D value; } =20 +static void powerpc_core_realize(DeviceState *dev, Error **errp) +{ + CPUCore *core =3D CPU_CORE(dev); + PowerPCCoreClass *ppc_class =3D POWERPC_CORE_GET_CLASS(dev); + + if (core->plugged_threads !=3D -1 && + core->nr_threads !=3D core->plugged_threads) { + error_setg(errp, "nr_threads and plugged-threads must be equal"); + return; + } + + ppc_class->parent_realize(dev, errp); +} + static void powerpc_core_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); + PowerPCCoreClass *ppc_class =3D POWERPC_CORE_CLASS(oc); =20 object_class_property_add(oc, "core-id", "int", powerpc_core_prop_get_core_id, powerpc_core_prop_set_core_id, NULL, NULL); + device_class_set_parent_realize(dc, powerpc_core_realize, + &ppc_class->parent_realize); } =20 static const TypeInfo powerpc_core_type_info =3D { .name =3D TYPE_POWERPC_CORE, .parent =3D TYPE_CPU_CORE, .abstract =3D true, + .class_size =3D sizeof(PowerPCCoreClass), .class_init =3D powerpc_core_class_init, .instance_size =3D sizeof(PowerPCCore), }; diff --git a/include/hw/ppc/ppc_core.h b/include/hw/ppc/ppc_core.h index bcc83e426e3f..1207d220872a 100644 --- a/include/hw/ppc/ppc_core.h +++ b/include/hw/ppc/ppc_core.h @@ -34,6 +34,7 @@ struct PowerPCCoreClass { CPUCoreClass parent_class; =20 /*< public >*/ + DeviceRealize parent_realize; }; =20 struct PowerPCCore { --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355189; cv=none; d=zohomail.com; s=zohoarc; b=ArC37oNyWuiU5ypLtPHnHWlObXVXXSjBHZqYXEmenRHPBtcVoUBnFaE3K0YqLyD4Ug6aKsowvN/oTiEIlPMYNDhJOHVJjsM1nNxOq3m3Pl2Al/V267fFQKv6S0msAOpDsDldJJ14MoA0qVfK+5/L7d+h/UBU4m2Gzxj2qOE7sb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355189; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PoXZj8aaDNB0evERxmuMyMPNmizNbKB+o/Ve6C0oTsk=; b=K3udFDHMCQqQBGXWs2H89eIu/72R5ofvFNwXA0NFc0KkWLsFGXQYu4fiQMHIcAHdngrQ9mNoRZ5PkWnqosIPM/iDK6q7hKeBWEZP/pP4a5Ubk47PtaTnTHum9hAezSSpBueHQGgA8+QK0KmELBGQRQun2WWqRZOL+aV/pl9g4sU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1701355189141286.1044690710636; Thu, 30 Nov 2023 06:39:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.644779.1006327 (Exim 4.92) (envelope-from ) id 1r8iCB-0004eb-F4; Thu, 30 Nov 2023 14:39:15 +0000 Received: by outflank-mailman (output) from mailman id 644779.1006327; Thu, 30 Nov 2023 14:39:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8iCA-0004aH-Q9; Thu, 30 Nov 2023 14:39:14 +0000 Received: by outflank-mailman (input) for mailman id 644779; Thu, 30 Nov 2023 14:33:17 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8i6P-0007xx-E2 for xen-devel@lists.xenproject.org; Thu, 30 Nov 2023 14:33:17 +0000 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 64de9b13-8f8d-11ee-9b0f-b553b5be7939; Thu, 30 Nov 2023 15:33:15 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:13 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:04 -0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 64de9b13-8f8d-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354795; x=1732890795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8LquYvv0CgMyC9ho8G2nSKazoduQFmRgmZ/sS4KE0RQ=; b=mFKfJZnepeTAdDZmmr//CV+28ud2/fbCn5VYsePxJoCljVmsKPr5Rgef tzSt/RKAcld8mO59A/+vFRDZ/O6GVg+J6Yo+1g9kvWnI7YcFJ3oC6XfT2 sY2l8Nog0KseuNlGXrwv+w5YouM8onbyJI7Ju1LctznJKwhbPAo3TjdF+ aub8U6L/F7iibjtuFFXoSqOvdb5vmQ+gyhwPBdn7JvR+PEt2MFAxNBIO7 YrXq7N19Ex4X1hGXIi58EOdYza7tx4HasDMPzzmlQaea66D5G2I+b64PJ KvKzlitNH95l+lZVGSUea8p1YvOjDr93HLAXNx0xcrcKq4wuamYrfc0Vw Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531889" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531889" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729990" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729990" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 17/41] hw/cpu/core: Convert cpu-core from general device to topology device Date: Thu, 30 Nov 2023 22:41:39 +0800 Message-Id: <20231130144203.2307629-18-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355190003000018 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Convert cpu-core to topology device then user could create core level topology from cli and later the cpu-cores could be added into topology tree. In addition, mark the common cpu-core as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. But since PPC supports CPU hotplug at core granularity, ppc-core should be created after board initialization. Thus, mask the category flag DEVICE_CATEGORY_CPU_DEF for ppc-core. Signed-off-by: Zhao Liu --- hw/cpu/core.c | 19 ++++++++++++++++--- hw/ppc/pnv_core.c | 6 +++++- hw/ppc/ppc_core.c | 5 +++++ hw/ppc/spapr_cpu_core.c | 7 ++++++- include/hw/cpu/core.h | 13 +++++++++++-- include/hw/ppc/pnv_core.h | 1 + include/hw/ppc/spapr_cpu_core.h | 1 + 7 files changed, 45 insertions(+), 7 deletions(-) diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 15546b5b2339..261b15fa8171 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -27,6 +27,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor= *v, const char *name, void *opaque, Error **errp) { CPUCore *core =3D CPU_CORE(obj); + CPUTopoState *topo =3D CPU_TOPO(obj); int64_t value; =20 if (!visit_type_int(v, name, &value, errp)) { @@ -34,6 +35,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor= *v, const char *name, } =20 core->nr_threads =3D value; + topo->max_children =3D core->nr_threads; } =20 static void core_prop_set_plugged_threads(Object *obj, Visitor *v, @@ -53,6 +55,7 @@ static void core_prop_set_plugged_threads(Object *obj, Vi= sitor *v, static void cpu_core_instance_init(Object *obj) { CPUCore *core =3D CPU_CORE(obj); + CPUTopoState *topo =3D CPU_TOPO(obj); =20 /* * Only '-device something-cpu-core,help' can get us there before @@ -64,11 +67,14 @@ static void cpu_core_instance_init(Object *obj) } =20 core->plugged_threads =3D -1; + /* Core's child can only be the thread. */ + topo->child_level =3D CPU_TOPO_THREAD; } =20 static void cpu_core_realize(DeviceState *dev, Error **errp) { CPUCore *core =3D CPU_CORE(dev); + CPUCoreClass *cc =3D CPU_CORE_GET_CLASS(core); =20 if (core->plugged_threads > core->nr_threads) { error_setg(errp, "Plugged threads (plugged-threads: %d) must " @@ -78,25 +84,32 @@ static void cpu_core_realize(DeviceState *dev, Error **= errp) } else if (core->plugged_threads =3D=3D -1) { core->plugged_threads =3D core->nr_threads; } + + cc->parent_realize(dev, errp); } =20 static void cpu_core_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + CPUCoreClass *cc =3D CPU_CORE_CLASS(oc); =20 - set_bit(DEVICE_CATEGORY_CPU, dc->categories); + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_th= reads, core_prop_set_nr_threads, NULL, NULL); object_class_property_add(oc, "plugged-threads", "int", NULL, core_prop_set_plugged_threads, NULL, NULL); - dc->realize =3D cpu_core_realize; + device_class_set_parent_realize(dc, cpu_core_realize, &cc->parent_real= ize); + + tc->level =3D CPU_TOPO_CORE; } =20 static const TypeInfo cpu_core_type_info =3D { .name =3D TYPE_CPU_CORE, - .parent =3D TYPE_DEVICE, + .parent =3D TYPE_CPU_TOPO, .abstract =3D true, .class_init =3D cpu_core_class_init, + .class_size =3D sizeof(CPUCoreClass), .instance_size =3D sizeof(CPUCore), .instance_init =3D cpu_core_instance_init, }; diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 8b75739697d1..315b823e7d38 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -334,6 +334,7 @@ static void pnv_core_unrealize(DeviceState *dev) { PnvCore *pc =3D PNV_CORE(dev); CPUCore *cc =3D CPU_CORE(dev); + PnvCoreClass *pcc =3D PNV_CORE_GET_CLASS(pc); int i; =20 qemu_unregister_reset(pnv_core_reset, pc); @@ -342,6 +343,8 @@ static void pnv_core_unrealize(DeviceState *dev) pnv_core_cpu_unrealize(pc, pc->threads[i]); } g_free(pc->threads); + + pcc->parent_unrealize(dev); } =20 static Property pnv_core_properties[] =3D { @@ -380,11 +383,12 @@ static void pnv_core_class_init(ObjectClass *oc, void= *data) DeviceClass *dc =3D DEVICE_CLASS(oc); PnvCoreClass *pcc =3D PNV_CORE_CLASS(oc); =20 - dc->unrealize =3D pnv_core_unrealize; device_class_set_props(dc, pnv_core_properties); dc->user_creatable =3D false; device_class_set_parent_realize(dc, pnv_core_realize, &pcc->parent_realize); + device_class_set_parent_unrealize(dc, pnv_core_unrealize, + &pcc->parent_unrealize); } =20 #define DEFINE_PNV_CORE_TYPE(family, cpu_model) \ diff --git a/hw/ppc/ppc_core.c b/hw/ppc/ppc_core.c index 3857f3150052..0a700d6a5b42 100644 --- a/hw/ppc/ppc_core.c +++ b/hw/ppc/ppc_core.c @@ -72,6 +72,11 @@ static void powerpc_core_class_init(ObjectClass *oc, voi= d *data) DeviceClass *dc =3D DEVICE_CLASS(oc); PowerPCCoreClass *ppc_class =3D POWERPC_CORE_CLASS(oc); =20 + /* + * PPC cores support hotplug and must be created after + * qemu_init_board(). + */ + clear_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); object_class_property_add(oc, "core-id", "int", powerpc_core_prop_get_core_id, powerpc_core_prop_set_core_id, diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 5533a386f350..c965c213ab14 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -235,6 +235,7 @@ static void spapr_delete_vcpu(PowerPCCPU *cpu) static void spapr_cpu_core_unrealize(DeviceState *dev) { SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); + SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); CPUCore *cc =3D CPU_CORE(dev); int i; =20 @@ -254,6 +255,8 @@ static void spapr_cpu_core_unrealize(DeviceState *dev) } g_free(sc->threads); qemu_unregister_reset(spapr_cpu_core_reset_handler, sc); + + scc->parent_unrealize(dev); } =20 static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr, @@ -366,12 +369,14 @@ static void spapr_cpu_core_class_init(ObjectClass *oc= , void *data) DeviceClass *dc =3D DEVICE_CLASS(oc); SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_CLASS(oc); =20 - dc->unrealize =3D spapr_cpu_core_unrealize; dc->reset =3D spapr_cpu_core_reset; device_class_set_props(dc, spapr_cpu_core_properties); + dc->hotpluggable =3D true; scc->cpu_type =3D data; device_class_set_parent_realize(dc, spapr_cpu_core_realize, &scc->parent_realize); + device_class_set_parent_unrealize(dc, spapr_cpu_core_unrealize, + &scc->parent_unrealize); } =20 #define DEFINE_SPAPR_CPU_CORE_TYPE(cpu_model) \ diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h index 87d50151ab01..591240861efb 100644 --- a/include/hw/cpu/core.h +++ b/include/hw/cpu/core.h @@ -10,15 +10,24 @@ #define HW_CPU_CORE_H =20 #include "hw/qdev-core.h" +#include "hw/core/cpu-topo.h" #include "qom/object.h" =20 #define TYPE_CPU_CORE "cpu-core" =20 -OBJECT_DECLARE_SIMPLE_TYPE(CPUCore, CPU_CORE) +OBJECT_DECLARE_TYPE(CPUCore, CPUCoreClass, CPU_CORE) + +struct CPUCoreClass { + /*< private >*/ + CPUTopoClass parent_class; + + /*< public >*/ + DeviceRealize parent_realize; +}; =20 struct CPUCore { /*< private >*/ - DeviceState parent_obj; + CPUTopoState parent_obj; =20 /*< public >*/ int core_id; diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h index 3b9edf69f9fb..ca04461c8531 100644 --- a/include/hw/ppc/pnv_core.h +++ b/include/hw/ppc/pnv_core.h @@ -51,6 +51,7 @@ struct PnvCoreClass { uint64_t xscom_size; =20 DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; }; =20 #define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_cor= e.h index dabdbd4bcbc9..46cf68fc8859 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -39,6 +39,7 @@ struct SpaprCpuCoreClass { const char *cpu_type; =20 DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; }; =20 const char *spapr_get_cpu_core_type(const char *cpu_type); --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354889; cv=none; d=zohomail.com; s=zohoarc; b=LcBXTMAyb+0PeOTdw3nAnlaa2TsycC62bTy2f30RI7J6tX+/GjFe0i+d3GSE4ypiwDtVG1v2PDIg2sRq/oMjw9DgvwUxQEraeifG2emJ8cLqtDwKd32B/5Qw2JVfGFJ53wpyVv1g0Pt673XOSlnipUUBx6vtmSgHxfUHqf+jTUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354889; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CB8r908FrVkxhhiNR7F1JCgcJK/De5QasJhN4UUCdLo=; b=hicrbAVE3LD/+gAWfRRg2Re3PoWF2b4v7XMa4+YXOkVDrqMMu/aAHUJ6P2pS84cDqodtvCxZkeCPbuKcWVJLSj41HX5TQ79zqjQFtZErtes3Ik0JKkAAX45M9/Rx1QtUOjnWLVJzfL60fXmoSGLyXE9SAv0mJ4V/qETfbl82uqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354889830284.76197786568457; Thu, 30 Nov 2023 06:34:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6f-0005n9-16; Thu, 30 Nov 2023 09:33:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6a-0005Zs-5H; Thu, 30 Nov 2023 09:33:28 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6Y-0001I2-0p; Thu, 30 Nov 2023 09:33:27 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:22 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354806; x=1732890806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UIctuJN57ff0cGtb6JQuQGzOnsVqrF/BvG/lcB/CLAU=; b=ikudpG28NQ0aL5uvIg4IVbk4L/60gA/hBg9FC4XM2pCHKXFzWOJKfQiU A36JEIy1CyJ/IaaxOui6LPNLu17LiL8oQa8sWyMgHAN16THmFtxFsCL+9 Z2po8C10Y572Aza7c6u4aUj8dovdLlw8GjsgNnlDvvKFuH2s+EyxF0Qwa sVA5Fly+o8m3nOPH1XG6uBiomCK/ZL/9fgWL59qnh5uFtVESI6+1D1TIR 1mAmnHicXWomN6DAB7co4TDfQJ/iBzudda3L6uLLnDaGR9cvp9BibKcQE tXj2wg3T6dF4m/s4nbGfKNcOfCjwGE/hVQTGP5YjpLOybMQRSS+SsbS1W g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531926" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531926" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730016" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730016" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 18/41] hw/cpu/cluster: Rename CPUClusterState to CPUCluster Date: Thu, 30 Nov 2023 22:41:40 +0800 Message-Id: <20231130144203.2307629-19-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354890887000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu To keep the same naming style as cpu-core, rename CPUClusterState to CPUCluster. Signed-off-by: Zhao Liu --- gdbstub/system.c | 2 +- hw/cpu/cluster.c | 8 ++++---- include/hw/arm/armsse.h | 2 +- include/hw/arm/xlnx-versal.h | 4 ++-- include/hw/arm/xlnx-zynqmp.h | 4 ++-- include/hw/cpu/cluster.h | 6 +++--- include/hw/riscv/microchip_pfsoc.h | 4 ++-- include/hw/riscv/sifive_u.h | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gdbstub/system.c b/gdbstub/system.c index 783ac140b982..1c0b55d3ebe7 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -277,7 +277,7 @@ static int find_cpu_clusters(Object *child, void *opaqu= e) { if (object_dynamic_cast(child, TYPE_CPU_CLUSTER)) { GDBState *s =3D (GDBState *) opaque; - CPUClusterState *cluster =3D CPU_CLUSTER(child); + CPUCluster *cluster =3D CPU_CLUSTER(child); GDBProcess *process; =20 s->processes =3D g_renew(GDBProcess, s->processes, ++s->process_nu= m); diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index 61289a840d46..fd978a543e40 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -26,12 +26,12 @@ #include "qapi/error.h" =20 static Property cpu_cluster_properties[] =3D { - DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0), + DEFINE_PROP_UINT32("cluster-id", CPUCluster, cluster_id, 0), DEFINE_PROP_END_OF_LIST() }; =20 typedef struct CallbackData { - CPUClusterState *cluster; + CPUCluster *cluster; int cpu_count; } CallbackData; =20 @@ -50,7 +50,7 @@ static int add_cpu_to_cluster(Object *obj, void *opaque) static void cpu_cluster_realize(DeviceState *dev, Error **errp) { /* Iterate through all our CPU children and set their cluster_index */ - CPUClusterState *cluster =3D CPU_CLUSTER(dev); + CPUCluster *cluster =3D CPU_CLUSTER(dev); Object *cluster_obj =3D OBJECT(dev); CallbackData cbdata =3D { .cluster =3D cluster, @@ -87,7 +87,7 @@ static void cpu_cluster_class_init(ObjectClass *klass, vo= id *data) static const TypeInfo cpu_cluster_type_info =3D { .name =3D TYPE_CPU_CLUSTER, .parent =3D TYPE_DEVICE, - .instance_size =3D sizeof(CPUClusterState), + .instance_size =3D sizeof(CPUCluster), .class_init =3D cpu_cluster_class_init, }; =20 diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h index 88b3b759c5a8..886586a3bed4 100644 --- a/include/hw/arm/armsse.h +++ b/include/hw/arm/armsse.h @@ -153,7 +153,7 @@ struct ARMSSE { =20 /*< public >*/ ARMv7MState armv7m[SSE_MAX_CPUS]; - CPUClusterState cluster[SSE_MAX_CPUS]; + CPUCluster cluster[SSE_MAX_CPUS]; IoTKitSecCtl secctl; TZPPC apb_ppc[NUM_INTERNAL_PPCS]; TZMPC mpc[IOTS_NUM_MPC]; diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h index b24fa64557fd..61bde52b6af5 100644 --- a/include/hw/arm/xlnx-versal.h +++ b/include/hw/arm/xlnx-versal.h @@ -58,7 +58,7 @@ struct Versal { struct { struct { MemoryRegion mr; - CPUClusterState cluster; + CPUCluster cluster; ARMCPU cpu[XLNX_VERSAL_NR_ACPUS]; GICv3State gic; } apu; @@ -88,7 +88,7 @@ struct Versal { MemoryRegion mr; MemoryRegion mr_ps_alias; =20 - CPUClusterState cluster; + CPUCluster cluster; ARMCPU cpu[XLNX_VERSAL_NR_RCPUS]; } rpu; =20 diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h index 96358d51ebb7..5eea765ea76c 100644 --- a/include/hw/arm/xlnx-zynqmp.h +++ b/include/hw/arm/xlnx-zynqmp.h @@ -98,8 +98,8 @@ struct XlnxZynqMPState { DeviceState parent_obj; =20 /*< public >*/ - CPUClusterState apu_cluster; - CPUClusterState rpu_cluster; + CPUCluster apu_cluster; + CPUCluster rpu_cluster; ARMCPU apu_cpu[XLNX_ZYNQMP_NUM_APU_CPUS]; ARMCPU rpu_cpu[XLNX_ZYNQMP_NUM_RPU_CPUS]; GICState gic; diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h index 53fbf36af542..644b87350268 100644 --- a/include/hw/cpu/cluster.h +++ b/include/hw/cpu/cluster.h @@ -55,7 +55,7 @@ */ =20 #define TYPE_CPU_CLUSTER "cpu-cluster" -OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER) +OBJECT_DECLARE_SIMPLE_TYPE(CPUCluster, CPU_CLUSTER) =20 /* * This limit is imposed by TCG, which puts the cluster ID into an @@ -64,13 +64,13 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER) #define MAX_CLUSTERS 255 =20 /** - * CPUClusterState: + * CPUCluster: * @cluster_id: The cluster ID. This value is for internal use only and sh= ould * not be exposed directly to the user or to the guest. * * State of a CPU cluster. */ -struct CPUClusterState { +struct CPUCluster { /*< private >*/ DeviceState parent_obj; =20 diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchi= p_pfsoc.h index daef086da602..c9ac14e35625 100644 --- a/include/hw/riscv/microchip_pfsoc.h +++ b/include/hw/riscv/microchip_pfsoc.h @@ -38,8 +38,8 @@ typedef struct MicrochipPFSoCState { DeviceState parent_obj; =20 /*< public >*/ - CPUClusterState e_cluster; - CPUClusterState u_cluster; + CPUCluster e_cluster; + CPUCluster u_cluster; RISCVHartArrayState e_cpus; RISCVHartArrayState u_cpus; DeviceState *plic; diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h index 0696f8594277..fda4a708e960 100644 --- a/include/hw/riscv/sifive_u.h +++ b/include/hw/riscv/sifive_u.h @@ -40,8 +40,8 @@ typedef struct SiFiveUSoCState { DeviceState parent_obj; =20 /*< public >*/ - CPUClusterState e_cluster; - CPUClusterState u_cluster; + CPUCluster e_cluster; + CPUCluster u_cluster; RISCVHartArrayState e_cpus; RISCVHartArrayState u_cpus; DeviceState *plic; --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355100; cv=none; d=zohomail.com; s=zohoarc; b=WfpDyMNSBGVG3ATrR4UVSy88NgF6MjVLcIswHxIVFzDlcKxwgZfme/uXZVoxUWF09LaqH2hpwBmh/X2+7BnM8gIBwGFp88OGJoghQZcII3QXkR4EA/OmEOQgfo9D96I514au3YGn7fmJ/vd/5PUP/sw5sUV5yPGFbLL/NRvoiaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355100; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=otuZ4A5xDRsI78OdpqRPKGDlC2fBE+12r54swMx5LHw=; b=jbrohXVk+K7cYrEw+YRxuEPP81kzoXexSVWRMlqQaodPgogHTEk/sGTEzn9UvsjtZjkMkLsXEZaUjk55RQbG/QzcTfveegXvwuCvXUUIXDok6uWoi3xeMOqQbhkHAyPEWhZnduggF5SNcMv4fAl7yMN8QTDtmkYxi+pQbhNv2o4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170135510001933.83769836996453; Thu, 30 Nov 2023 06:38:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7M-0006Q3-NT; Thu, 30 Nov 2023 09:34:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6k-0005qt-Iv; Thu, 30 Nov 2023 09:33:40 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6i-0001RT-8O; Thu, 30 Nov 2023 09:33:38 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:32 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354816; x=1732890816; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ewTMs2u73zZUV2zJblGAkkri1EYaJm+RSs7ZWl9w7g8=; b=ObtDTnZKhzx71/fy1sMds76oOx6R/DHFRvy3OH1z+Sp2VD4MufcayHji a4Zj4jiMJAHMnI45dfJ/b55phnK2IvSYIf/oDnr+qxKlkAzKJq9Tj1sy6 zj1YDYDEVxna9DyTxZi5r0C+bT5o2fjD47rVixkcR6Tm5fxOamoJKT7Hy IpimkBZk1OSXww1cVtblCRnvKIvkTPsrMYKYX3NuvNw34wBl+cyLRY7cE /McbdqOTHw2l3aZhLqJSlgI4VTE0h/4vrs1+ceSR10Jsv0d8GxtY7c+zB kI0/5BIrUJcFq7+4vyVUwuLIxBw1TiA1laMWmjKZYdP5NkDkfdJX/a/Mk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531981" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531981" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730032" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730032" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 19/41] hw/cpu/cluster: Wrap TCG related ops and props into CONFIG_TCG Date: Thu, 30 Nov 2023 22:41:41 +0800 Message-Id: <20231130144203.2307629-20-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355101637000007 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Currenltly cpu-cluster is used in TCG case to organize CPUs with the same type. Wrap 2 things into TCG specific areas: 1. cluster-id: The cluster-id in TCG case is global, since no higher topology container above cluster. To simplify the logic of cluster topology in virtualization, move the cluster-id into CONFIG_TCG, then it won't be exposed in cli. 2. CPU collection in realize(): In TCG case, the CPUs are added into cluster directly via child<> property. But in virtualization case, the CPU topology will be built via topology tree. Thus, wrap CPU collection as the TCG operation. Signed-off-by: Zhao Liu --- hw/cpu/cluster.c | 30 +++++++++++++++++++++++++----- include/hw/cpu/cluster.h | 22 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index fd978a543e40..340cfad9f8f1 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -26,7 +26,9 @@ #include "qapi/error.h" =20 static Property cpu_cluster_properties[] =3D { +#ifdef CONFIG_TCG DEFINE_PROP_UINT32("cluster-id", CPUCluster, cluster_id, 0), +#endif DEFINE_PROP_END_OF_LIST() }; =20 @@ -47,18 +49,17 @@ static int add_cpu_to_cluster(Object *obj, void *opaque) return 0; } =20 -static void cpu_cluster_realize(DeviceState *dev, Error **errp) +static void cpu_cluster_common_collect_cpus(CPUCluster *cluster, Error **e= rrp) { /* Iterate through all our CPU children and set their cluster_index */ - CPUCluster *cluster =3D CPU_CLUSTER(dev); - Object *cluster_obj =3D OBJECT(dev); + Object *cluster_obj =3D OBJECT(cluster); CallbackData cbdata =3D { .cluster =3D cluster, .cpu_count =3D 0, }; =20 - if (cluster->cluster_id >=3D MAX_CLUSTERS) { - error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS); + if (cluster->cluster_id >=3D MAX_TCG_CLUSTERS) { + error_setg(errp, "cluster-id must be less than %d", MAX_TCG_CLUSTE= RS); return; } =20 @@ -73,15 +74,34 @@ static void cpu_cluster_realize(DeviceState *dev, Error= **errp) assert(cbdata.cpu_count > 0); } =20 +static const struct TCGClusterOps common_cluster_tcg_ops =3D { + .collect_cpus =3D cpu_cluster_common_collect_cpus, +}; + +static void cpu_cluster_realize(DeviceState *dev, Error **errp) +{ + CPUCluster *cluster =3D CPU_CLUSTER(dev); + CPUClusterClass *cc =3D CPU_CLUSTER_GET_CLASS(dev); + + if (cc->tcg_clu_ops->collect_cpus) { + cc->tcg_clu_ops->collect_cpus(cluster, errp); + } +} + static void cpu_cluster_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); + CPUClusterClass *cc =3D CPU_CLUSTER_CLASS(klass); =20 device_class_set_props(dc, cpu_cluster_properties); dc->realize =3D cpu_cluster_realize; =20 /* This is not directly for users, CPU children must be attached by co= de */ dc->user_creatable =3D false; + +#ifdef CONFIG_TCG + cc->tcg_clu_ops =3D &common_cluster_tcg_ops; +#endif } =20 static const TypeInfo cpu_cluster_type_info =3D { diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h index 644b87350268..c038f05ddc9f 100644 --- a/include/hw/cpu/cluster.h +++ b/include/hw/cpu/cluster.h @@ -55,13 +55,31 @@ */ =20 #define TYPE_CPU_CLUSTER "cpu-cluster" -OBJECT_DECLARE_SIMPLE_TYPE(CPUCluster, CPU_CLUSTER) +OBJECT_DECLARE_TYPE(CPUCluster, CPUClusterClass, CPU_CLUSTER) =20 /* * This limit is imposed by TCG, which puts the cluster ID into an * 8 bit field (and uses all-1s for the default "not in any cluster"). */ -#define MAX_CLUSTERS 255 +#define MAX_TCG_CLUSTERS 255 + +struct TCGClusterOps { + /** + * @collect_cpus: Iterate children CPUs and set cluser_index. + * + * Called when the cluster is realized. + */ + void (*collect_cpus)(CPUCluster *cluster, Error **errp); +}; + +struct CPUClusterClass { + /*< private >*/ + DeviceClass parent_class; + + /*< public >*/ + /* when TCG is not available, this pointer is NULL */ + const struct TCGClusterOps *tcg_clu_ops; +}; =20 /** * CPUCluster: --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354979; cv=none; d=zohomail.com; s=zohoarc; b=a56lK3d3GELlNUBNbzWdHL9w7mQJWrxX+lv155GNH3jEp5fx55c2FW6XRBGLjhXldhJKAkfV4V6HwcaFxDAl+754pIAE0ikxjNOqJmoX/VJyadeaJhDunxAdwUJVZ5fIqSjGPTv+FyWSd4pgl6rH0891spu+aNz8r/H9GSCgrRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354979; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H0/HHxPul43ILHrjzXmJE45WyoGhVmQ9EcVwjgMPIwo=; b=H18TWb1Vs/of2HrKzNZr85h0k7STU/Kd/YTt9/yen6YuR8JzGJJihcz4a737LhkMWZL4pzJEHVPL5LqR8VoLPVb7y6X5uChaeex0yvjKI0UYVxjLr7lQX97lVHI3xwtsiq4EkE+ii29G0q8yrj0L6FrVIYZv8FHnnU0qr8BWlQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170135497998050.81976760631255; Thu, 30 Nov 2023 06:36:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7P-0006p3-QZ; Thu, 30 Nov 2023 09:34:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6x-0005zY-Vz; Thu, 30 Nov 2023 09:33:57 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6v-0001RT-7l; Thu, 30 Nov 2023 09:33:50 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:41 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354829; x=1732890829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tVF0CmmcOBEuYyYp6LOjwJOc13qp/jolnKC9SQQ9zpo=; b=iuRtElay4mAE7FyVUEtPe003Cf8Glto2UManH4hBv2JTPkrSKS9YMaKI xfJt8lWvuI/QXcpxWhfuMHigIHrhxc9yWASysSlrpti/JKbWxgyZIWQVU WkI46x5IPzOQS+MFp1dBSz3l3ynOeviwhUSpeQvZfaTzdd3MHKU0uiEUV OnD3RDKHBAKA4KV6/YGGXO13Uh/dUVep4M4RPnutRu+aXJ4OkVP0xSrsy jrimARPbe0/HQhz+80YiDhNQ5hx0IW42NQhntKQJVD+d7ogUtFZdq1cGf RbTtA18p+Vu7CAzegA2o+40UM/bfD+UqT7I2x7exnnlmS/nOS4tTPXNGA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532010" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532010" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730040" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730040" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 20/41] hw/cpu/cluster: Descript cluster is not only used for TCG in comment Date: Thu, 30 Nov 2023 22:41:42 +0800 Message-Id: <20231130144203.2307629-21-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354981181000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Update the comment to make the cpu-cluster description more general for both TCG and accel cases. Signed-off-by: Zhao Liu --- hw/cpu/cluster.c | 2 +- include/hw/cpu/cluster.h | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index 340cfad9f8f1..27ab9e25a265 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -1,5 +1,5 @@ /* - * QEMU CPU cluster + * CPU cluster abstract device * * Copyright (c) 2018 GreenSocs SAS * diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h index c038f05ddc9f..b3185e2f2566 100644 --- a/include/hw/cpu/cluster.h +++ b/include/hw/cpu/cluster.h @@ -1,5 +1,5 @@ /* - * QEMU CPU cluster + * CPU cluster abstract device * * Copyright (c) 2018 GreenSocs SAS * @@ -24,17 +24,27 @@ #include "qom/object.h" =20 /* - * CPU Cluster type + * # CPU Cluster * - * A cluster is a group of CPUs which are all identical and have the same = view - * of the rest of the system. It is mainly an internal QEMU representation= and - * does not necessarily match with the notion of clusters on the real hard= ware. + * A cluster is a group of CPUs, that is, a level above the CPU (or Core). + * + * - For accel case, it's a CPU topology level concept above cores, in whi= ch + * the cores may share some resources (L2 cache or some others like L3 + * cache tags, depending on the Archs). It is used to emulate the physical + * CPU cluster/module. + * + * - For TCG, cluster is used to organize CPUs directly without core. In o= ne + * cluster, CPUs are all identical and have the same view of the rest of t= he + * system. It is mainly an internal QEMU representation and may not necess= arily + * match with the notion of clusters on the real hardware. * * If CPUs are not identical (for example, Cortex-A53 and Cortex-A57 CPUs = in an * Arm big.LITTLE system) they should be in different clusters. If the CPU= s do * not have the same view of memory (for example the main CPU and a manage= ment * controller processor) they should be in different clusters. * + * # Use case for cluster in TCG + * * A cluster is created by creating an object of TYPE_CPU_CLUSTER, and then * adding the CPUs to it as QOM child objects (e.g. using the * object_initialize_child() or object_property_add_child() functions). --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354908; cv=none; d=zohomail.com; s=zohoarc; b=gCd00R1BwuatiOezkogKyoFlPkwI++1K1VXrO7xGH743GEc0rqeGZKB71CQlwvHkBW8AEIKaBQgokbrgR011pWYdcc063OWX86uDpFAIKZHWmNyeDlCrn3zCy++kWThUZszKFvqH5bWVij+xFzGkxHyU/3ORp7Jgd4xsFBAadgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354908; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yK1DTcZIT0smB57A3nagVnG+VCzq4+olInu+M+g13pA=; b=R4pRsIST8j4diSEjlRHA7/VorEHFRKejcWtTnvhrVGrMVOpt0RGGAlwJFss2tkQ7FLqh35zY0gXFb1vgkjRDUP0AU7K6T2Ht3Pf4aX0BbX0fJAKGO7F56dpGATF8dwJbAxOuNyVwX75Wg/LP66nWDCOz039Pz1nZRlZDF3vW568= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354908241921.5423975564572; Thu, 30 Nov 2023 06:35:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7N-0006WI-9j; Thu, 30 Nov 2023 09:34:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i72-000632-Ss; Thu, 30 Nov 2023 09:34:01 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i70-0001RT-97; Thu, 30 Nov 2023 09:33:56 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:33:50 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354834; x=1732890834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TLbpY7EX///aEBUshQ9nHMg5QAVw4jJxDP0uMhZZdFI=; b=c0bwLVp+7JpS2l2uUEo0otrQ1ixwvm73HHlaA+gdqKfWaCS+kU0MRmTW 7sN57ktK2ubSlW93qlAUkLtD8tNKj6zGeUzckN0j1GVa21IcUIrEhWRu+ 3gsTVPGchALYxGkJp/2wIq9dyYE6B2dQG5aAYma0gFNjy+AFvmyIWm+yg kUJfmmpBFEBiA69Y9MpoKUp7LKEZtzGzybrYUaxfph6PdoWpRemgl6rMn +7i35xhMDoocSclIe9gaZ65Ent+7U63Ulu4+FhJxevTi1afLEcd+zJGjr m4kpUr4jrLkJCqSy5+ozxXraXT7DH5KsqcTfllC/MP8UrET+f//zAZr05 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532052" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532052" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730047" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730047" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 21/41] hw/cpu/cluster: Allow cpu-cluster to be created by -device Date: Thu, 30 Nov 2023 22:41:43 +0800 Message-Id: <20231130144203.2307629-22-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354908939000009 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Since we will extend cpu-cluster to build CPU topology in virtualization case via -device, remove the original limitition. Signed-off-by: Zhao Liu --- hw/cpu/cluster.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index 27ab9e25a265..8a666c27d151 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -96,9 +96,6 @@ static void cpu_cluster_class_init(ObjectClass *klass, vo= id *data) device_class_set_props(dc, cpu_cluster_properties); dc->realize =3D cpu_cluster_realize; =20 - /* This is not directly for users, CPU children must be attached by co= de */ - dc->user_creatable =3D false; - #ifdef CONFIG_TCG cc->tcg_clu_ops =3D &common_cluster_tcg_ops; #endif --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354981; cv=none; d=zohomail.com; s=zohoarc; b=B+4PEXvmkDtW51xpbVVcW5YfF9vnoiKAMCSw5WQgC4j4fztalo2OjoFU45ffYGUZXBCF6Zx6P/QuoEfZ0ENXg51a9ky5f0U5u9KOqp7xo8y1VzzzNzzwC8ZGKh4H/g3PPBTL0SZwDkjZYcky2cM8idUnAk37Nk8mvs9BJyBCXz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354981; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=isIZewBlWhHlPIRd4AOCKWvDW7hj+Xa7GjguZrlH764=; b=dllhMrou2tkXkFP/poPPkj2/wImpn6TCMuh7L90yTxW0u60TE+ogjwJGvfTf2Enzy2MgFO3RVlL/AzJDjZAqwitjdLAIZpDeGNk35pUG64CibwgCgfGoqpLRzY6hDiMuNx+S/L0EBJlqr2lw0+omDvDopE0CCRUfVw0l4Sannb4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354981272453.81869373386894; Thu, 30 Nov 2023 06:36:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7S-0006uD-GO; Thu, 30 Nov 2023 09:34:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7G-00068Z-6I; Thu, 30 Nov 2023 09:34:10 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7A-0001Un-Ub; Thu, 30 Nov 2023 09:34:07 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:00 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:33:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354844; x=1732890844; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ojKaeiijveA4rQSsZpp2eyLul8UTXwtywNBoYac3pw0=; b=KffefMi63af5nmZYTDhlpSDBuIGsay1Zvuzoft0mO3rkUpO+P2Ys70Cr kyXYZ6+zISYNsrdxGsGuHIginbLoa8u/9/mbbckVZ7Ccd/ZeO8uEBHmBI RBYchHff4EpAUQn3v8v70ypfXtNy3OVEst+BgPM2SguywgzTYEGsAolIi S1FJBRRXXPNdp+zVrI0mI+c41sC1RjHg/ll8a6/EnRvWDwEY/BgLFLxSG ng33F7gTc79udonbrZ/mNJKXA1c3+V+rKYB8iUZ5G3nyCcePC1QrdeN2v oEKlTd0Ak3MQ5USTLxvhy8m+qfM5Rnd6h9HUDnwP99gKvObk5Gy/oTrGl Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532120" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532120" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730060" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730060" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 22/41] hw/cpu/cluster: Convert cpu-cluster from general device to topology device Date: Thu, 30 Nov 2023 22:41:44 +0800 Message-Id: <20231130144203.2307629-23-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354983215000014 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Convert cpu-cluster to topology device then user could create cluster level topology from cli and later the cpu-clusters could be added into topology tree. In addition, mark the cpu-cluster as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. Signed-off-by: Zhao Liu --- hw/cpu/cluster.c | 11 +++++++++-- include/hw/cpu/cluster.h | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index 8a666c27d151..adf0ef23e8d4 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -86,15 +86,21 @@ static void cpu_cluster_realize(DeviceState *dev, Error= **errp) if (cc->tcg_clu_ops->collect_cpus) { cc->tcg_clu_ops->collect_cpus(cluster, errp); } + + cc->parent_realize(dev, errp); } =20 static void cpu_cluster_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(klass); CPUClusterClass *cc =3D CPU_CLUSTER_CLASS(klass); =20 + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); device_class_set_props(dc, cpu_cluster_properties); - dc->realize =3D cpu_cluster_realize; + device_class_set_parent_realize(dc, cpu_cluster_realize, + &cc->parent_realize); + tc->level =3D CPU_TOPO_CLUSTER; =20 #ifdef CONFIG_TCG cc->tcg_clu_ops =3D &common_cluster_tcg_ops; @@ -103,8 +109,9 @@ static void cpu_cluster_class_init(ObjectClass *klass, = void *data) =20 static const TypeInfo cpu_cluster_type_info =3D { .name =3D TYPE_CPU_CLUSTER, - .parent =3D TYPE_DEVICE, + .parent =3D TYPE_CPU_TOPO, .instance_size =3D sizeof(CPUCluster), + .class_size =3D sizeof(CPUClusterClass), .class_init =3D cpu_cluster_class_init, }; =20 diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h index b3185e2f2566..888993c36da4 100644 --- a/include/hw/cpu/cluster.h +++ b/include/hw/cpu/cluster.h @@ -20,6 +20,7 @@ #ifndef HW_CPU_CLUSTER_H #define HW_CPU_CLUSTER_H =20 +#include "hw/core/cpu-topo.h" #include "hw/qdev-core.h" #include "qom/object.h" =20 @@ -84,11 +85,13 @@ struct TCGClusterOps { =20 struct CPUClusterClass { /*< private >*/ - DeviceClass parent_class; + CPUTopoClass parent_class; =20 /*< public >*/ /* when TCG is not available, this pointer is NULL */ const struct TCGClusterOps *tcg_clu_ops; + + DeviceRealize parent_realize; }; =20 /** @@ -100,7 +103,7 @@ struct CPUClusterClass { */ struct CPUCluster { /*< private >*/ - DeviceState parent_obj; + CPUTopoState parent_obj; =20 /*< public >*/ uint32_t cluster_id; --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355101; cv=none; d=zohomail.com; s=zohoarc; b=BkKBx7yx0zyfj6WPTVMGaHA/vwZCcHYJArVPV8tz7ZBTrB7oPRiXPAb9bE5W3JuWtyj8r2x6npILpJsQSob5Gi2Z2t8Q2FQ0uPMM0ONkmOMoyx2EKTyt2eq/vfBnoCjDjbYOaBiBZ98524PkP4rGsZ6E0YXjpRrvN4Zn++ZyCPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355101; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nFABTT5Yh+aPai95tE3eMLRSQEusNuwuwX2PUaKd0/Q=; b=lI/29zXnIHaMnVT6g4tyuN1sWYMSil9EWNzjGQZV22mLi5bFh4INyFwBCQTFqqkrih6APNG1MASSTs4uiFiGpxGsNyxnEHnOjo01PzTuyrNkNba4d5VOQKTf6/Sqcc1LMRO/hxxuQ0yXMSVW/T2K0ZN7AkkMKqhHKRYhAGPspRQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355101126725.3788066627675; Thu, 30 Nov 2023 06:38:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7a-00072z-81; Thu, 30 Nov 2023 09:34:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7L-0006NL-WD; Thu, 30 Nov 2023 09:34:16 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7I-0001Un-OM; Thu, 30 Nov 2023 09:34:15 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:09 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354852; x=1732890852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IhpodbfJau6szIdQazmb+IK5Vtn7KUNNpXNSlzloW+Q=; b=FhMQfiO9KA0KRRQSAbFS7bQ58jqH95th0hZs4wonD0peIknsmWm2yy+t 1pA/xGSpm3snEqq2eB1EeuLYkzg68R0/oC2kZ8EslPquklCGzzV9IfcWc O5engfx66L0brqasSe92mOlYLaS2lxOuCh0Lj+NQhe58U/N5FcKzyWpsp enYokScWmi5kFQ4WOb/ypyHAX/fe0eMQMB2Bq0YsPAE8S6pv9ozY3OTlo l2OoHKoqxfhMIPtnpIYF1OmkBHqmonbYhyk4V5BGne8VoQNUfdL92mJR1 jVE6a5Y/jxsdGSTg/fAb6Cz2/P/lV5VMdhO+ixVluNMVf3zVfVenOhl7N A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532154" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532154" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730068" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730068" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 23/41] hw/cpu/die: Abstract cpu-die level as topology device Date: Thu, 30 Nov 2023 22:41:45 +0800 Message-Id: <20231130144203.2307629-24-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355101641000008 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Abstract die level as a topology device "cpu-die" to allow user to create die level topology from cli and later the cpu-dies could be added into topology tree. In addition, mark the cpu-die as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/cpu/die.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 2 +- include/hw/cpu/die.h | 38 ++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 hw/cpu/die.c create mode 100644 include/hw/cpu/die.h diff --git a/MAINTAINERS b/MAINTAINERS index 89e350866d6a..91d0936edb32 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1863,6 +1863,7 @@ F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c +F: hw/cpu/die.c F: qapi/machine.json F: qapi/machine-common.json F: qapi/machine-target.json @@ -1870,6 +1871,7 @@ F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/core/cpu-topo.h F: include/hw/cpu/cluster.h +F: include/hw/cpu/die.h F: include/sysemu/numa.h F: tests/unit/test-smp-parse.c T: git https://gitlab.com/ehabkost/qemu.git machine-next diff --git a/hw/cpu/die.c b/hw/cpu/die.c new file mode 100644 index 000000000000..06c4f7cc8fa2 --- /dev/null +++ b/hw/cpu/die.c @@ -0,0 +1,46 @@ +/* + * CPU die abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/cpu/die.h" + +static void cpu_die_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); + + tc->level =3D CPU_TOPO_DIE; +} + +static const TypeInfo cpu_die_type_info =3D { + .name =3D TYPE_CPU_DIE, + .parent =3D TYPE_CPU_TOPO, + .class_init =3D cpu_die_class_init, + .instance_size =3D sizeof(CPUDie), +}; + +static void cpu_die_register_types(void) +{ + type_register_static(&cpu_die_type_info); +} + +type_init(cpu_die_register_types) diff --git a/hw/cpu/meson.build b/hw/cpu/meson.build index 6d319947ca0b..e685fe1c7d8a 100644 --- a/hw/cpu/meson.build +++ b/hw/cpu/meson.build @@ -1,4 +1,4 @@ -system_ss.add(files('core.c', 'cluster.c')) +system_ss.add(files('core.c', 'cluster.c', 'die.c')) =20 system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c')) system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview_mpcore.c')) diff --git a/include/hw/cpu/die.h b/include/hw/cpu/die.h new file mode 100644 index 000000000000..4c68786b5f2f --- /dev/null +++ b/include/hw/cpu/die.h @@ -0,0 +1,38 @@ +/* + * CPU die abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_CPU_DIE_H +#define HW_CPU_DIE_H + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_DIE "cpu-die" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUDie, CPU_DIE) + +struct CPUDie { + /*< private >*/ + CPUTopoState obj; + + /*< public >*/ +}; + +#endif /* HW_CPU_DIE_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355068; cv=none; d=zohomail.com; s=zohoarc; b=AtYNVXkzNJCQmhaICEDPiDc6V1NLxoMwQQ2tKg6N5fiz8ohyKNo3+tFcnL8uypW+tbHiOsxMK0dfBqb10Vm/L8I6UjxDtEW+zrqEZvz8tBVSehhSoMIdwmVtvXZqZ2cAutqyJ1eMaqt5S5fD4LBYPIxmTseVGULpS+8WVmIFMRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355068; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X0EDjMjAtaYH5ejzoFVHqmRC7ieoXrfQPsYJIPteaUU=; b=S+RvyMtYNunBt31aLvluE+y3PdY/DUVh43c53ZZcvxVUc5xX9/YKiN8uhpUeMBvjnqIERenI/+m3h7cKY0eCMtgCXP3Pbppy0x8QFUomJpRC6UdrxnMebkH512VJfBAjy0BW8cbkvlGqNBBKDHx2sAst2EK97c7ie+a830ngRS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355068535202.41862248369603; Thu, 30 Nov 2023 06:37:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7k-0007T8-Dx; Thu, 30 Nov 2023 09:34:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7V-0006xN-Ot; Thu, 30 Nov 2023 09:34:26 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7S-0001Un-Ct; Thu, 30 Nov 2023 09:34:24 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:19 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354862; x=1732890862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KYdyPQbbzxDFAf7dgOGDTufkcJTYeF0L4udr4i03f58=; b=nVrvZOQ2zLkvLt5zc8ZVitp4F2lAJYYQ8h/3qzfWoW1DVQSHCf2z1Rc2 ZY7lB/2RolYIauH4MmK8UoWWPCjFSoKkUIg5M8axmfXQzKOs4kO5dB6X5 b4L5K6vhIdabnxupL4uSx5jQ2w7/L+LcqjRwCUwHKBlZbps+Z7B+uEiik 4mLGQTaQ8IKKS9re6pSsoAVjqxkLby+cvtwle1w16lrA0u97jSkZUPloM BDYav9fCPYUT5CCLJCMFNsItvuJ7+qEuwhvmvXla5GqDYu8E9ivjxtZjt /lPdP8dPID0SVeJvSPDrzMcqeEdURJL0KdwWjAt04UuFu8LqsnjbJmJm7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532180" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532180" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730082" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730082" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 24/41] hw/cpu/socket: Abstract cpu-socket level as topology device Date: Thu, 30 Nov 2023 22:41:46 +0800 Message-Id: <20231130144203.2307629-25-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355069564000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Abstract socket level as a topology device "cpu-socket" to allow user to create socket level topology from cli and later the cpu-sockets could be added into topology tree. In addition, mark the cpu-socket as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/cpu/meson.build | 2 +- hw/cpu/socket.c | 46 +++++++++++++++++++++++++++++++++++++++++ include/hw/cpu/socket.h | 38 ++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 hw/cpu/socket.c create mode 100644 include/hw/cpu/socket.h diff --git a/MAINTAINERS b/MAINTAINERS index 91d0936edb32..6a9fa0aeed0c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1864,6 +1864,7 @@ F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c F: hw/cpu/die.c +F: hw/cpu/socket.c F: qapi/machine.json F: qapi/machine-common.json F: qapi/machine-target.json @@ -1872,6 +1873,7 @@ F: include/hw/core/cpu.h F: include/hw/core/cpu-topo.h F: include/hw/cpu/cluster.h F: include/hw/cpu/die.h +F: include/hw/cpu/socket.h F: include/sysemu/numa.h F: tests/unit/test-smp-parse.c T: git https://gitlab.com/ehabkost/qemu.git machine-next diff --git a/hw/cpu/meson.build b/hw/cpu/meson.build index e685fe1c7d8a..251724fea86c 100644 --- a/hw/cpu/meson.build +++ b/hw/cpu/meson.build @@ -1,4 +1,4 @@ -system_ss.add(files('core.c', 'cluster.c', 'die.c')) +system_ss.add(files('core.c', 'cluster.c', 'die.c', 'socket.c')) =20 system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c')) system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview_mpcore.c')) diff --git a/hw/cpu/socket.c b/hw/cpu/socket.c new file mode 100644 index 000000000000..afd29f8a91c1 --- /dev/null +++ b/hw/cpu/socket.c @@ -0,0 +1,46 @@ +/* + * CPU socket abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/cpu/socket.h" + +static void cpu_socket_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); + + tc->level =3D CPU_TOPO_SOCKET; +} + +static const TypeInfo cpu_socket_type_info =3D { + .name =3D TYPE_CPU_SOCKET, + .parent =3D TYPE_CPU_TOPO, + .class_init =3D cpu_socket_class_init, + .instance_size =3D sizeof(CPUSocket), +}; + +static void cpu_socket_register_types(void) +{ + type_register_static(&cpu_socket_type_info); +} + +type_init(cpu_socket_register_types) diff --git a/include/hw/cpu/socket.h b/include/hw/cpu/socket.h new file mode 100644 index 000000000000..897852903cd2 --- /dev/null +++ b/include/hw/cpu/socket.h @@ -0,0 +1,38 @@ +/* + * CPU socket abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_CPU_SOCKET_H +#define HW_CPU_SOCKET_H + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_SOCKET "cpu-socket" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUSocket, CPU_SOCKET) + +struct CPUSocket { + /*< private >*/ + CPUTopoState parent_obj; + + /*< public >*/ +}; + +#endif /* HW_CPU_SOCKET_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355100; cv=none; d=zohomail.com; s=zohoarc; b=gvq+bDIZHAPvUw4ovt45m4EprURZDkdxmQlTSsyPiBLaNDC3Fw5qtAHBd4BsWUSvUWuS8Qks7NHdRmvU1rGxpXwekU3NaC1F6Fz2SIPbq8vUAiZe6obgV95xr52BjSEmX+pUPA6VW5yH9B3K0CJA/EDDPhAiSxeG6vNUdeIbHZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355100; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NhGSjSM8zvmYtF9htWUN1IC/xVQTqQTxXNmapm/ov9g=; b=fJ66d2VFDB7Q8qBae7afUJ5Wutlh1m+LQNTgld+QEvUVN19u0dvyUK709+LZ6oAnjFA/0G+C5Sa4aYzFW1OMRU03NQRfbL63EbenZpcwGY6bP7bYzu6mw74GS5kQDfeMlJ9SXccyjk9jffl8d5MllFvjNdCiW6AqQOV4aZ8GlWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355100770485.36545839365806; Thu, 30 Nov 2023 06:38:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i7l-0007hI-NU; Thu, 30 Nov 2023 09:34:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7d-0007Db-WF; Thu, 30 Nov 2023 09:34:35 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7a-0001Un-R7; Thu, 30 Nov 2023 09:34:33 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:28 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354870; x=1732890870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R67m9mW34W7uiETtegm4359TeHvWglaSP7oCtBRRyHM=; b=A7LjNdy2Cl1idzU5WEFIh+IWk8Jzgx+oZMnkcWWtXEiBUFFkT/qfZgE5 hxToLcxpj6GyFJdUmYrR3xl6iTpyXjCHVXryCJivk9IVEXMynH3qD/F93 eZnF3oI3uoB9wTsOYbYzwVhR7rujApL7YoQncNreDK3s+PWogwgDKYscv fHDjpsvLXafe7ptI6j94QyqN6O6c7lNS5pSNyI0uu2LE+70jBQgd3MemS 3iUMkv9SeFyfAk2dsH0xS2vL1De5JV3jYMzlr9VFS03gM1krd3pUFUXvZ rlBt+VgCxFCc1s4joYsmk5zTtuxFaA0iw00Mg+BNptKoBPWRsXqqVMfY7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532214" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532214" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730090" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730090" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 25/41] hw/cpu/book: Abstract cpu-book level as topology device Date: Thu, 30 Nov 2023 22:41:47 +0800 Message-Id: <20231130144203.2307629-26-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355101654000009 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Abstract book level as a topology device "cpu-book" to allow user to create book level topology from cli and later the cpu-books could be added into topology tree. In addition, mark the cpu-book as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/cpu/book.c | 46 +++++++++++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 2 +- include/hw/cpu/book.h | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 hw/cpu/book.c create mode 100644 include/hw/cpu/book.h diff --git a/MAINTAINERS b/MAINTAINERS index 6a9fa0aeed0c..dd5adfda64cc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1862,6 +1862,7 @@ F: hw/core/machine.c F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c +F: hw/cpu/book.c F: hw/cpu/cluster.c F: hw/cpu/die.c F: hw/cpu/socket.c @@ -1871,6 +1872,7 @@ F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/core/cpu-topo.h +F: include/hw/cpu/book.h F: include/hw/cpu/cluster.h F: include/hw/cpu/die.h F: include/hw/cpu/socket.h diff --git a/hw/cpu/book.c b/hw/cpu/book.c new file mode 100644 index 000000000000..4b16267b10eb --- /dev/null +++ b/hw/cpu/book.c @@ -0,0 +1,46 @@ +/* + * CPU book abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/cpu/book.h" + +static void cpu_book_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); + + tc->level =3D CPU_TOPO_BOOK; +} + +static const TypeInfo cpu_book_type_info =3D { + .name =3D TYPE_CPU_BOOK, + .parent =3D TYPE_CPU_TOPO, + .class_init =3D cpu_book_class_init, + .instance_size =3D sizeof(CPUBook), +}; + +static void cpu_book_register_types(void) +{ + type_register_static(&cpu_book_type_info); +} + +type_init(cpu_book_register_types) diff --git a/hw/cpu/meson.build b/hw/cpu/meson.build index 251724fea86c..c44b54c5abb0 100644 --- a/hw/cpu/meson.build +++ b/hw/cpu/meson.build @@ -1,4 +1,4 @@ -system_ss.add(files('core.c', 'cluster.c', 'die.c', 'socket.c')) +system_ss.add(files('core.c', 'cluster.c', 'die.c', 'socket.c', 'book.c')) =20 system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c')) system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview_mpcore.c')) diff --git a/include/hw/cpu/book.h b/include/hw/cpu/book.h new file mode 100644 index 000000000000..b91bd553bea6 --- /dev/null +++ b/include/hw/cpu/book.h @@ -0,0 +1,38 @@ +/* + * CPU book abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_CPU_BOOK_H +#define HW_CPU_BOOK_H + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_BOOK "cpu-book" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUBook, CPU_BOOK) + +struct CPUBook { + /*< private >*/ + CPUTopoState obj; + + /*< public >*/ +}; + +#endif /* HW_CPU_BOOK_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355198; cv=none; d=zohomail.com; s=zohoarc; b=Z9JqJ/NwhsDN3zp0mQ9J+qLCXaUmqRsSzs3hRuZJ/XraW0QN8tGHJtuxXpAqTdgGCDSCKbU8ihUHo1EYxzPA0s3rKz0ZYPiflGvmrOuQTknwsEkm0J7E2kI2O7f39LGTOGbxvA/0KuggeL9UG9gewT0xtzLHKAjhDdrGg4T81Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355198; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a3PfrP6grf+wCb8xF9RWuJQLRUklMSdVW4gKqQZduOU=; b=gYRB9niOk5BfmjlwTmtVmPGtOWqEavw5yOeJEJHAorbVqtgwAFf4TBzlAa9GXuvA32kUchMvPASUEqMH/rHDb3jlZM45htIyn11/IkUzEEm1BE1jwdUZY/yUpKon0fxPMO1LV390TMuIUy+HzmmPdkl4mRMBocIk0ffppmAsWHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1701355198252442.5307690222843; Thu, 30 Nov 2023 06:39:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.644797.1006408 (Exim 4.92) (envelope-from ) id 1r8iCP-0007le-EH; Thu, 30 Nov 2023 14:39:29 +0000 Received: by outflank-mailman (output) from mailman id 644797.1006408; Thu, 30 Nov 2023 14:39:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8iCO-0007es-7v; Thu, 30 Nov 2023 14:39:28 +0000 Received: by outflank-mailman (input) for mailman id 644797; Thu, 30 Nov 2023 14:34:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8i7k-0008E0-U9 for xen-devel@lists.xenproject.org; Thu, 30 Nov 2023 14:34:40 +0000 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9743db74-8f8d-11ee-98e4-6d05b1d4d9a1; Thu, 30 Nov 2023 15:34:40 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:37 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:28 -0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9743db74-8f8d-11ee-98e4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354880; x=1732890880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RiCVpo1qnLcoDF3gFOkmvt/7Et6vXhRGVnHUCJw060w=; b=Gd0+I34fYrJQ8fW9UAgUvSatB8+xB0MkdBgr5hj/PJsdyid6PM/TqC4o PLtaQW9x0LMIquokBemNzOSpxeNd/eKQ4lDjGBBJGsiDY1NUHdkBHsuQD XKpfpyQKaEq6bY73dqmqIrkVZkiZtFLcqWS7lyIGSq6qCfzkDmCfLHqbM XsyUw3AGSWbrX/HVuKVQJCxekULHAmdm4hLSBLAF9DjXcy53g1TASuIkg 94rcDQXsErSqGkQRN8y1h1U1COQKFR2CtJgt6X4volbT8Up0K70W9aIRu FJXnU0GufBC6AErDc3eWEB4QKiZzrI5OdLw0OXC4FgYSttED016rJdkLb w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532241" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532241" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730101" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730101" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 26/41] hw/cpu/drawer: Abstract cpu-drawer level as topology device Date: Thu, 30 Nov 2023 22:41:48 +0800 Message-Id: <20231130144203.2307629-27-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355199961000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Abstract drawer level as a topology device "cpu-drawer" to allow user to create drawer level topology from cli and later the cpu-drawers could be added into topology tree. In addition, mark the cpu-drawer as DEVICE_CATEGORY_CPU_DEF category to indicate it belongs to the basic CPU definition and should be created from cli before board initialization. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/cpu/drawer.c | 46 +++++++++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 2 +- include/hw/cpu/drawer.h | 38 ++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 hw/cpu/drawer.c create mode 100644 include/hw/cpu/drawer.h diff --git a/MAINTAINERS b/MAINTAINERS index dd5adfda64cc..4b373ff46ce3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1865,6 +1865,7 @@ F: hw/core/numa.c F: hw/cpu/book.c F: hw/cpu/cluster.c F: hw/cpu/die.c +F: hw/cpu/drawer.c F: hw/cpu/socket.c F: qapi/machine.json F: qapi/machine-common.json @@ -1875,6 +1876,7 @@ F: include/hw/core/cpu-topo.h F: include/hw/cpu/book.h F: include/hw/cpu/cluster.h F: include/hw/cpu/die.h +F: include/hw/cpu/drawer.h F: include/hw/cpu/socket.h F: include/sysemu/numa.h F: tests/unit/test-smp-parse.c diff --git a/hw/cpu/drawer.c b/hw/cpu/drawer.c new file mode 100644 index 000000000000..f1ccfd153284 --- /dev/null +++ b/hw/cpu/drawer.c @@ -0,0 +1,46 @@ +/* + * CPU drawer abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/cpu/drawer.h" + +static void cpu_drawer_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); + + tc->level =3D CPU_TOPO_DRAWER; +} + +static const TypeInfo cpu_drawer_type_info =3D { + .name =3D TYPE_CPU_DRAWER, + .parent =3D TYPE_CPU_TOPO, + .class_init =3D cpu_drawer_class_init, + .instance_size =3D sizeof(CPUDrawer), +}; + +static void cpu_drawer_register_types(void) +{ + type_register_static(&cpu_drawer_type_info); +} + +type_init(cpu_drawer_register_types) diff --git a/hw/cpu/meson.build b/hw/cpu/meson.build index c44b54c5abb0..0dea39364b98 100644 --- a/hw/cpu/meson.build +++ b/hw/cpu/meson.build @@ -1,4 +1,4 @@ -system_ss.add(files('core.c', 'cluster.c', 'die.c', 'socket.c', 'book.c')) +system_ss.add(files('core.c', 'cluster.c', 'die.c', 'socket.c', 'book.c', = 'drawer.c')) =20 system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c')) system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview_mpcore.c')) diff --git a/include/hw/cpu/drawer.h b/include/hw/cpu/drawer.h new file mode 100644 index 000000000000..34ae089d33bf --- /dev/null +++ b/include/hw/cpu/drawer.h @@ -0,0 +1,38 @@ +/* + * CPU drawer abstract device + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_CPU_DRAWER_H +#define HW_CPU_DRAWER_H + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_DRAWER "cpu-drawer" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUDrawer, CPU_DRAWER) + +struct CPUDrawer { + /*< private >*/ + CPUTopoState obj; + + /*< public >*/ +}; + +#endif /* HW_CPU_DRAWER_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354987; cv=none; d=zohomail.com; s=zohoarc; b=HIFYWMjfPK7iYAmmOnTZx2xY8WbSe3GLw4DWthLj7Y886INSLRsm/jbWRyD3J+07N6xuc5Y9jlH1CmOLnjRAUKBUxvSwwNNufkBg6RoLyGdscD0xDadlq+NI6Qo2wISHWYChTs4JncPksK9I3h8ETlUBNcqGJJ2Zgj5aebQpUwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354987; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hX8MTd+RhIF3J7qaJiG28gdCnUnyZmf+y1qQCDMVFpQ=; b=CdJN6fClyuAZto4xIjcxrYaLDlnunhlIDLgorLkWCaO1FV/KS5N8ifu9SnPc3mTP5eeqbVStDe+F66bz7GcGvsDR7e89+oBZmAEl6oWrWIzjmGlwfjWywiDPLIqxRA6Ga2l3WaEqfz3TkDVFjnD62sc1vhunnKK6HFERnbSmB6Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354987073715.048788140689; Thu, 30 Nov 2023 06:36:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i87-0000EN-VS; Thu, 30 Nov 2023 09:35:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i85-0008Tr-2S; Thu, 30 Nov 2023 09:35:01 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i7u-0001Un-SP; Thu, 30 Nov 2023 09:35:00 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:47 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354890; x=1732890890; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dK+ilj3Q1LqgiJ2/EiJWYjQp1qXfjG6+/g3hE8BTtcM=; b=CBoT00iUZavpZrRiU+b75R3pv+ggnBmPYkA3OVVGpHXlZXP8BkmReFDL nzeSWUyj86Om8LG3Oo1r9VMeI65OwpvuxWrFhU3VZceg2WWm7mprZPB8H /hEHgeFxedIEmnF1fz7PgisTHufE7jUa1IA57P/voCJv+8Q+JGgXzb5m7 oPFy5gQUszeQtZMhjsq/A23VTZsykpJePbeOkHGAR2T1e2diCfKkTTvDt 9gzJVjwnfi5vDparYIc7r+I74W4s8n8iRHof2pRhee2Img3sjbO/0g7wu uxg7XTPHEF1d5qGpP/m4t+cAiuWyGXXTtrnryn0gauXUGocEcnvUfdY2M g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532284" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532284" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730118" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730118" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 27/41] hw/core/slot: Introduce CPU slot as the root of CPU topology Date: Thu, 30 Nov 2023 22:41:49 +0800 Message-Id: <20231130144203.2307629-28-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354987217000004 From: Zhao Liu Abstract the root of topology tree as a special topology device "cpu-slot". Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/core/cpu-slot.c | 48 ++++++++++++++++++++++++++++++++++++++ hw/core/meson.build | 1 + include/hw/core/cpu-slot.h | 38 ++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 hw/core/cpu-slot.c create mode 100644 include/hw/core/cpu-slot.h diff --git a/MAINTAINERS b/MAINTAINERS index 4b373ff46ce3..ac08b5a8c4e0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1856,6 +1856,7 @@ R: Philippe Mathieu-Daud=C3=A9 R: Yanan Wang S: Supported F: hw/core/cpu.c +F: hw/core/cpu-slot.c F: hw/core/cpu-topo.c F: hw/core/machine-qmp-cmds.c F: hw/core/machine.c @@ -1872,6 +1873,7 @@ F: qapi/machine-common.json F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h +F: include/hw/core/cpu-slot.h F: include/hw/core/cpu-topo.h F: include/hw/cpu/book.h F: include/hw/cpu/cluster.h diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c new file mode 100644 index 000000000000..5aef5b0189c2 --- /dev/null +++ b/hw/core/cpu-slot.c @@ -0,0 +1,48 @@ +/* + * CPU slot device abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "hw/core/cpu-slot.h" + +static void cpu_slot_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + + set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories); + dc->user_creatable =3D false; + + tc->level =3D CPU_TOPO_ROOT; +} + +static const TypeInfo cpu_slot_type_info =3D { + .name =3D TYPE_CPU_SLOT, + .parent =3D TYPE_CPU_TOPO, + .class_init =3D cpu_slot_class_init, + .instance_size =3D sizeof(CPUSlot), +}; + +static void cpu_slot_register_types(void) +{ + type_register_static(&cpu_slot_type_info); +} + +type_init(cpu_slot_register_types) diff --git a/hw/core/meson.build b/hw/core/meson.build index 501d2529697e..3347c054e162 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -23,6 +23,7 @@ else endif =20 common_ss.add(files('cpu-common.c')) +common_ss.add(files('cpu-slot.c')) common_ss.add(files('cpu-topo.c')) common_ss.add(files('machine-smp.c')) system_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h new file mode 100644 index 000000000000..718c8ecaa751 --- /dev/null +++ b/include/hw/core/cpu-slot.h @@ -0,0 +1,38 @@ +/* + * CPU slot device abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef CPU_SLOT_H +#define CPU_SLOT_H + +#include "hw/core/cpu-topo.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_SLOT "cpu-slot" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) + +struct CPUSlot { + /*< private >*/ + CPUTopoState parent_obj; + + /*< public >*/ +}; + +#endif /* CPU_SLOT_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354936; cv=none; d=zohomail.com; s=zohoarc; b=SFf/EiozqnPMg6nkCf1Wswbxy0kqyDFY2BQBfEcbVM5t1CYPCXfKWeuXOcB+OqKkBMYeITroxVqj9/oSStXVJ/M23iplHUTFLGUuFbsuutkgcm58NLzlhYNmwXeigwvee8s7emRpFKKgdnLLCSN+akChgTTA5yTObuwVDB/r6yU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354936; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d0Ga5ikdsdqlhyMzLOc2LbcPBfD9RM1dLJtf4FVVs78=; b=a50cUFpPKRKEb6V/P9ecJyvD1eYUiZEO8s8YIP51nZtKdtqTiVZO956jkkYLyMqts3FXt5/1SUruEKLrNMbGttWLCHVpcqH4uK4rN9WO6G4xkk4SrwxxNuxyMWwgmFgW2w/a/H+Lbs5h5EWts5LFUF8s58aDXNMe8wCtQcXCmCU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701354936080340.88316332545025; Thu, 30 Nov 2023 06:35:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i89-0000Lu-O3; Thu, 30 Nov 2023 09:35:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i86-0000BJ-WE; Thu, 30 Nov 2023 09:35:03 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i85-0001d0-3b; Thu, 30 Nov 2023 09:35:02 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:34:56 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354901; x=1732890901; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FbB6vbX6bR4dqU1fCV07ghJ+c5nYYHlqh35CAqrTsmY=; b=B/nP++8jsG+K2z9pnGPDpayNbQ2YXtdACARmebKqiqXEGl2dBrcX2657 +x9QBSlx/lW+m7eC7n0j/cto7yJ0HGWtogRPlwzdRUdDyRWm4b3hlV7kr RR2jmSPoh1YtS63KNKdQdrkKb9he9RXVOLzBDQXY3R3uSeGfmGDpzzkhR IxUoGFo4l/wJXoEJidYaie/2IxKy3KIlm/oH4TJkNgHQKiNVQpAzmmrUJ 5cSP0OwXrF9xa9lMRLbozr+t7EBVzuFm/yyotH5eWr5aE/ZfZae/7cEjc vAy1XwoG/5jPlErXBfKWblmwi2Xffi4lpVjcQ/ChqzxP/u9adri9ir9iF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532317" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532317" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730130" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730130" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot Date: Thu, 30 Nov 2023 22:41:50 +0800 Message-Id: <20231130144203.2307629-29-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354939028000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Maintain the cores queue at cpu-slot to facilitate direct traversal of all cores. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 43 ++++++++++++++++++++++++++++++++++++++ include/hw/core/cpu-slot.h | 9 ++++++++ include/hw/cpu/core.h | 2 ++ 3 files changed, 54 insertions(+) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index 5aef5b0189c2..a6b7d98dea18 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -22,6 +22,40 @@ =20 #include "hw/core/cpu-slot.h" =20 +static void cpu_slot_add_topo_info(CPUTopoState *root, CPUTopoState *child) +{ + CPUSlot *slot =3D CPU_SLOT(root); + CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + + if (level =3D=3D CPU_TOPO_CORE) { + QTAILQ_INSERT_TAIL(&slot->cores, CPU_CORE(child), node); + } + return; +} + +static void cpu_slot_del_topo_info(CPUTopoState *root, CPUTopoState *child) +{ + CPUSlot *slot =3D CPU_SLOT(root); + CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + + if (level =3D=3D CPU_TOPO_CORE) { + QTAILQ_REMOVE(&slot->cores, CPU_CORE(child), node); + } + return; +} + +static void cpu_slot_update_topo_info(CPUTopoState *root, CPUTopoState *ch= ild, + bool is_realize) +{ + g_assert(child->parent); + + if (is_realize) { + cpu_slot_add_topo_info(root, child); + } else { + cpu_slot_del_topo_info(root, child); + } +} + static void cpu_slot_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); @@ -31,12 +65,21 @@ static void cpu_slot_class_init(ObjectClass *oc, void *= data) dc->user_creatable =3D false; =20 tc->level =3D CPU_TOPO_ROOT; + tc->update_topo_info =3D cpu_slot_update_topo_info; +} + +static void cpu_slot_instance_init(Object *obj) +{ + CPUSlot *slot =3D CPU_SLOT(obj); + + QTAILQ_INIT(&slot->cores); } =20 static const TypeInfo cpu_slot_type_info =3D { .name =3D TYPE_CPU_SLOT, .parent =3D TYPE_CPU_TOPO, .class_init =3D cpu_slot_class_init, + .instance_init =3D cpu_slot_instance_init, .instance_size =3D sizeof(CPUSlot), }; =20 diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index 718c8ecaa751..d2a1160562be 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -22,17 +22,26 @@ #define CPU_SLOT_H =20 #include "hw/core/cpu-topo.h" +#include "hw/cpu/core.h" #include "hw/qdev-core.h" =20 #define TYPE_CPU_SLOT "cpu-slot" =20 OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) =20 +/** + * CPUSlot: + * @cores: Queue consisting of all the cores in the topology tree + * where the cpu-slot is the root. cpu-slot can maintain similar + * queues for other topology levels to facilitate traversal + * when necessary. + */ struct CPUSlot { /*< private >*/ CPUTopoState parent_obj; =20 /*< public >*/ + QTAILQ_HEAD(, CPUCore) cores; }; =20 #endif /* CPU_SLOT_H */ diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h index 591240861efb..65dc10931190 100644 --- a/include/hw/cpu/core.h +++ b/include/hw/cpu/core.h @@ -40,6 +40,8 @@ struct CPUCore { * "-device"/"device_add"? */ int plugged_threads; + + QTAILQ_ENTRY(CPUCore) node; }; =20 #endif --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355057; cv=none; d=zohomail.com; s=zohoarc; b=Xl2HFm58N6YLUpDaAXrv6kQvga61YAyMo4Ix90JA5koM+IhrLVqLwuQQOtRG9N2ts2HyD6FKFanZ0Qp+F3XS/QfTxKBeAa8/bm7z4GgV/V4VZnBM2iq7PXSkdGMIR/07ov+UY5poa71MEFLR5V/LdbSKe8Yg4VTA6FhH3XCJyHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355057; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Nifg9vBUOfnBo+UdWWuT66+sHZgL97f+w4zZVOX+mus=; b=EUrMMfUyOWS8Pu68eW9PDNz1vOGCG9w1HT161Fk6TCJe9bG9N4nRwbjK/ma4LR93QpIyTpQHnOzClKJQhMBS/yJuU5kgzCa17M8vSep80/xvnsQkAPfRzQbnQwNR2GBXifyl7usCIf/BqwxssqrFA3H/et1B/pf3TlC2fwMhveA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355057271427.25974258057056; Thu, 30 Nov 2023 06:37:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9E-0001xz-P4; Thu, 30 Nov 2023 09:36:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8O-00015j-Vz; Thu, 30 Nov 2023 09:35:21 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8H-0001pX-9K; Thu, 30 Nov 2023 09:35:20 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:05 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:34:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354913; x=1732890913; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3aKtyhn4HEa/g5VVCwXVJ9czPMzUH1bTJvhs1x/p4jk=; b=XJtwbaKvtZzA19SeU6jvNVCAJTv4RvPC8IPNAlv2vuL6dJmXhaq42p0O /znPg6S/rXNUgIM9y4TP2bOnf6LLS0yPcUN8Jz+d7McxoxlZfWtBBX2ET DQdbxQg3LwX1t9L3W38Kv3qLdcSAt1Lw40JAA3AKK8WoxcusyMXdFEFLQ z808TcQ763jHNxFpwpDnfKJ2VlSjKqZkwXCJX0rQveGMlWhdDjdtDAG1R HQu6gEJCC82IW7JloKqS6IDr46yC8lmfNpBelg6hXdl4KJP/2vDARGum2 8B+V8LObvzl86uKI/19FE5B/6koOhNcvsyHsV6lGKYD8X6MqKtVqxLyIU A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532333" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532333" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730181" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730181" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 29/41] hw/core/slot: Statistics topology information in CPU slot Date: Thu, 30 Nov 2023 22:41:51 +0800 Message-Id: <20231130144203.2307629-30-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355057494000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The CPU slot, as the root of the topology tree, is responsible for global topology information collection and updates. When a new topology device is added to/deleted from the topology tree, update the corresponding information in the slot. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 41 +++++++++++++++++++++++++++++++++++- include/hw/core/cpu-slot.h | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index a6b7d98dea18..e8e6f4d25532 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -22,14 +22,44 @@ =20 #include "hw/core/cpu-slot.h" =20 +static inline +CPUTopoStatEntry *get_topo_stat_entry(CPUTopoStat *stat, + CPUTopoLevel level) +{ + assert(level !=3D CPU_TOPO_UNKNOWN); + + return &stat->entries[TOPO_STAT_ENTRY_IDX(level)]; +} + static void cpu_slot_add_topo_info(CPUTopoState *root, CPUTopoState *child) { CPUSlot *slot =3D CPU_SLOT(root); CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + CPUTopoStatEntry *entry; =20 if (level =3D=3D CPU_TOPO_CORE) { - QTAILQ_INSERT_TAIL(&slot->cores, CPU_CORE(child), node); + CPUCore *core =3D CPU_CORE(child); + CPUTopoStatEntry *thread_entry; + + QTAILQ_INSERT_TAIL(&slot->cores, core, node); + + /* Max CPUs per core is pre-configured by "nr-threads". */ + slot->stat.max_cpus +=3D core->nr_threads; + slot->stat.pre_plugged_cpus +=3D core->plugged_threads; + + thread_entry =3D get_topo_stat_entry(&slot->stat, CPU_TOPO_THREAD); + if (child->max_children > thread_entry->max_units) { + thread_entry->max_units =3D child->max_children; + } } + + entry =3D get_topo_stat_entry(&slot->stat, level); + entry->total_units++; + if (child->parent->num_children > entry->max_units) { + entry->max_units =3D child->parent->num_children; + } + + set_bit(level, slot->stat.curr_levels); return; } =20 @@ -37,10 +67,18 @@ static void cpu_slot_del_topo_info(CPUTopoState *root, = CPUTopoState *child) { CPUSlot *slot =3D CPU_SLOT(root); CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + CPUTopoStatEntry *entry; + + assert(level !=3D CPU_TOPO_UNKNOWN); =20 if (level =3D=3D CPU_TOPO_CORE) { QTAILQ_REMOVE(&slot->cores, CPU_CORE(child), node); } + + entry =3D get_topo_stat_entry(&slot->stat, level); + entry->total_units--; + + /* No need to update entries[*].max_units and curr_levels. */ return; } =20 @@ -73,6 +111,7 @@ static void cpu_slot_instance_init(Object *obj) CPUSlot *slot =3D CPU_SLOT(obj); =20 QTAILQ_INIT(&slot->cores); + set_bit(CPU_TOPO_ROOT, slot->stat.curr_levels); } =20 static const TypeInfo cpu_slot_type_info =3D { diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index d2a1160562be..fa2bd4af247d 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -25,6 +25,47 @@ #include "hw/cpu/core.h" #include "hw/qdev-core.h" =20 +/** + * @USER_AVAIL_LEVEL_NUM: the number of total topology levels in topology + * bitmap, which includes CPU_TOPO_UNKNOWN. + */ +#define USER_AVAIL_LEVEL_NUM (CPU_TOPO_ROOT + 1) + +/** + * @VALID_LEVEL_NUM: the number of valid topology levels, which excludes + * CPU_TOPO_UNKNOWN and CPU_TOPO_ROOT. + */ +#define VALID_LEVEL_NUM (CPU_TOPO_ROOT - 1) + +#define TOPO_STAT_ENTRY_IDX(level) ((level) - 1) + +/** + * CPUTopoStatEntry: + * @total: Total number of topological units at the same level that are + * currently inserted in CPU slot + * @max: Maximum number of topological units at the same level under the + * parent topolofical container + */ +typedef struct CPUTopoStatEntry { + unsigned int total_units; + unsigned int max_units; +} CPUTopoStatEntry; + +/** + * CPUTopoStat: + * @max_cpus: Maximum number of CPUs in CPU slot. + * @pre_plugged_cpus: Number of pre-plugged CPUs in CPU slot. + * @entries: Detail count information for valid topology levels under + * CPU slot + * @curr_levels: Current CPU topology levels inserted in CPU slot + */ +typedef struct CPUTopoStat { + unsigned int max_cpus; + unsigned int pre_plugged_cpus; + CPUTopoStatEntry entries[VALID_LEVEL_NUM]; + DECLARE_BITMAP(curr_levels, USER_AVAIL_LEVEL_NUM); +} CPUTopoStat; + #define TYPE_CPU_SLOT "cpu-slot" =20 OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) @@ -35,6 +76,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) * where the cpu-slot is the root. cpu-slot can maintain similar * queues for other topology levels to facilitate traversal * when necessary. + * @stat: Statistical topology information for topology tree. */ struct CPUSlot { /*< private >*/ @@ -42,6 +84,7 @@ struct CPUSlot { =20 /*< public >*/ QTAILQ_HEAD(, CPUCore) cores; + CPUTopoStat stat; }; =20 #endif /* CPU_SLOT_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355162; cv=none; d=zohomail.com; s=zohoarc; b=fZglFXQZsilQN7oNgAO7bx7uN+i1bJzDW6z6WCbb0g+WapjrRswERZ6gt657BxSht40m7Ozg/RwobBV/he1JQd4E9D8mt3798kut770EfUP8t5TwwY8A0WBA6PyS7L8D3KXGm40RkFk1vU9GJy2k3glfHPAA99RRbSDMYD1jvgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355162; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OmYa/5gkNTA0z+R1wsqm4BWqfL45cJ4MgBQ2Q5U3oKw=; b=j7WozlRox4S2FrnMxkpfRn8um50mE3FUNImaNkxv43aIrXH9OzfdeAgi+iaGP19sj2fiAjLs6qv8gMYdj6sXXFSI7/Z35DnbEHTQCkWzXE8hx8RuSmbx3Yh/cHZd+b3Ic0XIAsMxGl1Wh69PMHFi28LzsDOfFNKXfCPQrDI2K1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355162694648.5871460038877; Thu, 30 Nov 2023 06:39:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9C-0001ov-Ti; Thu, 30 Nov 2023 09:36:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8P-000160-5z; Thu, 30 Nov 2023 09:35:21 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8N-0001qi-0i; Thu, 30 Nov 2023 09:35:20 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:15 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354919; x=1732890919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HnOAO3NMx1dRMWQIeSpDRtg/0be+6N1pOpK/5nWbTXE=; b=DU//5S62izPMvrZxFxAZ+lXRnPSNs+WPPZo3blL01HjQnSB+k0fbnken SPWJSMf6BdFDdQVGIkQ/Nkf2AM8r474YR8K3mti69JfmDfMomfR2DL1iE eZ1NYFdDxgipBwVhx6s12tyUvhRoj5W07EEFmHToWCjEiv+xCpUETKPCc JUJyMUQigyrZ5UXyFR+zuMe1z9xxWtV9xNPHz18YKczbHY6FmqCimC+AE tvczfUfokmf0/ACnITmMTIHHebLoB7FF/d90TA7mjrnwXyM45GRirpTn5 uxz1x3amwbukUmGBQBCeohOb+ZdkqfSCyvIfWacvMPaedJ2zucc7F3RHW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532380" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532380" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730225" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730225" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 30/41] hw/core/slot: Check topology child to be added under CPU slot Date: Thu, 30 Nov 2023 22:41:52 +0800 Message-Id: <20231130144203.2307629-31-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355163831000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Implement CPUTopoClass.check_topo_child() in cpu-slot to be compatible with the limitations of the current smp topology. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 37 +++++++++++++++++++++++++++++++++++++ hw/core/cpu-topo.c | 2 +- include/hw/core/cpu-slot.h | 2 ++ include/hw/core/cpu-topo.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index e8e6f4d25532..2a796ad5b6e7 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" =20 #include "hw/core/cpu-slot.h" +#include "qapi/error.h" =20 static inline CPUTopoStatEntry *get_topo_stat_entry(CPUTopoStat *stat, @@ -94,6 +95,37 @@ static void cpu_slot_update_topo_info(CPUTopoState *root= , CPUTopoState *child, } } =20 +static void cpu_slot_check_topo_support(CPUTopoState *root, CPUTopoState *= child, + Error **errp) +{ + CPUSlot *slot =3D CPU_SLOT(root); + CPUTopoLevel child_level =3D CPU_TOPO_LEVEL(child); + + if (!test_bit(child_level, slot->supported_levels)) { + error_setg(errp, "cpu topo: the level %s is not supported", + cpu_topo_level_to_string(child_level)); + return; + } + + /* + * Currently we doesn't support hybrid topology. For SMP topology, + * each child under the same parent are same type. + */ + if (child->parent->num_children) { + CPUTopoState *sibling =3D QTAILQ_FIRST(&child->parent->children); + const char *sibling_type =3D object_get_typename(OBJECT(sibling)); + const char *child_type =3D object_get_typename(OBJECT(child)); + + if (strcmp(sibling_type, child_type)) { + error_setg(errp, "Invalid smp topology: different CPU " + "topology types (%s child vs %s sibling) " + "under the same parent (%s).", + child_type, sibling_type, + object_get_typename(OBJECT(child->parent))); + } + } +} + static void cpu_slot_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); @@ -104,6 +136,7 @@ static void cpu_slot_class_init(ObjectClass *oc, void *= data) =20 tc->level =3D CPU_TOPO_ROOT; tc->update_topo_info =3D cpu_slot_update_topo_info; + tc->check_topo_child =3D cpu_slot_check_topo_support; } =20 static void cpu_slot_instance_init(Object *obj) @@ -112,6 +145,10 @@ static void cpu_slot_instance_init(Object *obj) =20 QTAILQ_INIT(&slot->cores); set_bit(CPU_TOPO_ROOT, slot->stat.curr_levels); + + /* Set all levels by default. */ + bitmap_fill(slot->supported_levels, USER_AVAIL_LEVEL_NUM); + clear_bit(CPU_TOPO_UNKNOWN, slot->supported_levels); } =20 static const TypeInfo cpu_slot_type_info =3D { diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index 687a4cc566ec..351112ca7a73 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -24,7 +24,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" =20 -static const char *cpu_topo_level_to_string(CPUTopoLevel level) +const char *cpu_topo_level_to_string(CPUTopoLevel level) { switch (level) { case CPU_TOPO_UNKNOWN: diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index fa2bd4af247d..7bf51988afb3 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -77,6 +77,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) * queues for other topology levels to facilitate traversal * when necessary. * @stat: Statistical topology information for topology tree. + * @supported_levels: Supported topology levels for topology tree. */ struct CPUSlot { /*< private >*/ @@ -85,6 +86,7 @@ struct CPUSlot { /*< public >*/ QTAILQ_HEAD(, CPUCore) cores; CPUTopoStat stat; + DECLARE_BITMAP(supported_levels, USER_AVAIL_LEVEL_NUM); }; =20 #endif /* CPU_SLOT_H */ diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index 453bacbb558b..d27da0335c42 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -102,5 +102,6 @@ int cpu_topo_child_foreach(CPUTopoState *topo, unsigned= long *levels, int cpu_topo_child_foreach_recursive(CPUTopoState *topo, unsigned long *levels, topo_fn fn, void *opaque); +const char *cpu_topo_level_to_string(CPUTopoLevel level); =20 #endif /* CPU_TOPO_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355013; cv=none; d=zohomail.com; s=zohoarc; b=ngmjK627zl/nQGGhnQDVwqR0kAhQIdPk97C5un0R582HYeFkrtt4+vdXhRMLmKzn64GfdT7Oh/aHcwYS2tni48SKhd7k0AxpwpmSdhf5B34lTgJyCy2Hr0QImCj1v4j5HpfGgExrXWKbNeIj12n1wz8p5JwNsRea5OrbQA4shro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355013; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Sn66a9bPrp4KNlWbcDoa9kt45YGbbvfHbM1x5RGU4U0=; b=CVIsFgJKItOJRLivlNlPfrF7wJY8rRg6TbKlZqEDWzh+pbW6VZcQX0Re+F19JsSdaupbUDOx7f+GW1rVKsxJlMMh0oo07HrXaGG5OfErRfgHY3lYiAdhYO6YtH4Fc6XjDtb9+IqoBk/obiNmpnVWQigH/q7Z0mMBBbDjrQvRRO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355013985735.3822394645864; Thu, 30 Nov 2023 06:36:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9G-0002PU-J6; Thu, 30 Nov 2023 09:36:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8d-0001Mn-MP; Thu, 30 Nov 2023 09:35:37 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8Z-0001tW-Iw; Thu, 30 Nov 2023 09:35:34 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:24 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354931; x=1732890931; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f8dzVIiaV15FUJhTAcShJBTihquI/MGo+GvFSgqbGOs=; b=CGADjJyleEKvWjqLrSJqVu4kQIgphAR6wQBD/Ifbpfz6FaifT2b2RMtv 6RRLZSPtCxGEWieNH3cKDepxb7AIX+Tjv5VkxMn6wovUb+Ac6gfYpCLgr b/d+zRibQg31wk6uOJ685WQbiyMv/Loxx9gskj5FQamRVp3rY5c8oH8Ae +sqzovCYUgjtyVrDM2f9b2rdaMhNnkEXHj5TvkYetiiuIj6bsP0stUYIa xBuasb+QK9N60wOvYZjpcT7wJTUwoYXIyv7/Bf9OWH0cWJ/YwIjXj2LS4 5o85lIY5LDZT/Xe7gf0b3aOZKf8R4meZ4v+lhIkDDZV8RdFVoBvGr4a2C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532412" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532412" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730271" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730271" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 31/41] hw/machine: Plug cpu-slot into machine to maintain topology tree Date: Thu, 30 Nov 2023 22:41:53 +0800 Message-Id: <20231130144203.2307629-32-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355015368000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Add a cpu-slot in machine as the root of topology tree to maintain the QOM topology. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 31 +++++++++++++++++++++++++++++++ include/hw/boards.h | 2 ++ include/hw/core/cpu-slot.h | 7 +++++++ system/vl.c | 2 ++ 4 files changed, 42 insertions(+) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index 2a796ad5b6e7..4b148440ed3d 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" =20 +#include "hw/boards.h" #include "hw/core/cpu-slot.h" #include "qapi/error.h" =20 @@ -165,3 +166,33 @@ static void cpu_slot_register_types(void) } =20 type_init(cpu_slot_register_types) + +void machine_plug_cpu_slot(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + ms->topo =3D CPU_SLOT(qdev_new(TYPE_CPU_SLOT)); + + object_property_add_child(container_get(OBJECT(ms), "/peripheral"), + "cpu-slot", OBJECT(ms->topo)); + DEVICE(ms->topo)->id =3D g_strdup_printf("%s", "cpu-slot"); + + qdev_realize_and_unref(DEVICE(ms->topo), NULL, &error_abort); + ms->topo->ms =3D ms; + + if (!mc->smp_props.clusters_supported) { + clear_bit(CPU_TOPO_CLUSTER, ms->topo->supported_levels); + } + + if (!mc->smp_props.dies_supported) { + clear_bit(CPU_TOPO_DIE, ms->topo->supported_levels); + } + + if (!mc->smp_props.books_supported) { + clear_bit(CPU_TOPO_BOOK, ms->topo->supported_levels); + } + + if (!mc->smp_props.drawers_supported) { + clear_bit(CPU_TOPO_DRAWER, ms->topo->supported_levels); + } +} diff --git a/include/hw/boards.h b/include/hw/boards.h index da85f86efb91..81a7b04ece86 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -10,6 +10,7 @@ #include "qemu/module.h" #include "qom/object.h" #include "hw/core/cpu.h" +#include "hw/core/cpu-slot.h" =20 #define TYPE_MACHINE_SUFFIX "-machine" =20 @@ -398,6 +399,7 @@ struct MachineState { AccelState *accelerator; CPUArchIdList *possible_cpus; CpuTopology smp; + CPUSlot *topo; struct NVDIMMState *nvdimms_state; struct NumaState *numa_state; }; diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index 7bf51988afb3..1361af4ccfc0 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -78,6 +78,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) * when necessary. * @stat: Statistical topology information for topology tree. * @supported_levels: Supported topology levels for topology tree. + * @ms: Machine in which this cpu-slot is plugged. */ struct CPUSlot { /*< private >*/ @@ -87,6 +88,12 @@ struct CPUSlot { QTAILQ_HEAD(, CPUCore) cores; CPUTopoStat stat; DECLARE_BITMAP(supported_levels, USER_AVAIL_LEVEL_NUM); + MachineState *ms; }; =20 +#define MACHINE_CORE_FOREACH(ms, core) \ + QTAILQ_FOREACH((core), &(ms)->topo->cores, node) + +void machine_plug_cpu_slot(MachineState *ms); + #endif /* CPU_SLOT_H */ diff --git a/system/vl.c b/system/vl.c index 65add2fb2460..637f708d2265 100644 --- a/system/vl.c +++ b/system/vl.c @@ -2128,6 +2128,8 @@ static void qemu_create_machine(QDict *qdict) false, &error_abort); qobject_unref(default_opts); } + + machine_plug_cpu_slot(current_machine); } =20 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355128; cv=none; d=zohomail.com; s=zohoarc; b=SgDFcO5JfIXEp7P/v6UZQV8/WRJgCzMvn5+loSePMC0HEdBpfEre6DgxmPtF7HtqmOM1tay+NGUhsYj2hGAuC/+5vijfvD0PmXN6eqfBaE17HLpF+bTW4XaTODpplWpLvSH7RSEEjnkRucKhT0OtjfTQ04LAlunKPwhoK6jjABI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355128; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zgwp8hwjF1Y58oR9f9s9fCaJ73u4CMErmdT7kw9UUZw=; b=XlcolhsHoGf/Cr3VkhzU0dBCc9oSjij/W7VJqcaY6+q/AXf/B6S9zTseIznmLPLrhHk2BHeYQbMYlI/3HofechyngFfPGrc3FnGrv3CKFbVSI6cnKMoPWC5m/czP1+++IFKuGxRbtovFAkYzUMGOO527j5L8UJ237z2lanO+v54= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17013551281817.242003536516904; Thu, 30 Nov 2023 06:38:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9H-0002SC-86; Thu, 30 Nov 2023 09:36:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8j-0001Y2-JU; Thu, 30 Nov 2023 09:35:47 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8g-0001tW-W8; Thu, 30 Nov 2023 09:35:41 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:35 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354939; x=1732890939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ONngA8TQ7iwdQG2PpHP3CY/JQBJI2+erv4AqH9RU4Wo=; b=EnRRJHYUhV5KvPNMKNI/m+HDzyPEXOwTQPKjau7BhYvlt0acJDaW2YT5 Z7DySdGiWN4Wd65B3zMjby6M1QGa9AXMi+WdsaHC1QFKhlGqy688pecFd BqQoWGd7zQ02CO0ohn/zFD0JBGloNwp8h/pHFjuHOVzPYmSSrg64lKeoa y2DNV4SmRmcmmFlzPnEhDppnCK8y3BzYekbdnEnbVVdkFTuXj9LknZ4Bf f+w29uIvP2E0MOanUkdvP1I91GWW862ZZ/aqyspOS89bQ/7bq5w3RMZy5 lghVH2xpceODdHrE4CusHY0WtbaT/pFDPhMcG5C1nFmxaL6agUIeQ5719 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532444" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532444" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730298" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730298" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 32/41] hw/machine: Build smp topology tree from -smp Date: Thu, 30 Nov 2023 22:41:54 +0800 Message-Id: <20231130144203.2307629-33-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355129705000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For the architecture supports QOM topology (the field MachineClass.possible_cpus_qom_granu is set), implement smp QOM topology tree from MachineState.smp. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 217 +++++++++++++++++++++++++++++++++++++ hw/core/machine-smp.c | 9 ++ hw/cpu/core.c | 1 - include/hw/boards.h | 11 ++ include/hw/core/cpu-slot.h | 5 + tests/unit/meson.build | 5 +- 6 files changed, 246 insertions(+), 2 deletions(-) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index 4b148440ed3d..ade155baf60b 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -22,6 +22,11 @@ =20 #include "hw/boards.h" #include "hw/core/cpu-slot.h" +#include "hw/cpu/book.h" +#include "hw/cpu/cluster.h" +#include "hw/cpu/die.h" +#include "hw/cpu/drawer.h" +#include "hw/cpu/socket.h" #include "qapi/error.h" =20 static inline @@ -196,3 +201,215 @@ void machine_plug_cpu_slot(MachineState *ms) clear_bit(CPU_TOPO_DRAWER, ms->topo->supported_levels); } } + +static unsigned int *get_smp_info_by_level(CpuTopology *smp_info, + CPUTopoLevel child_level) +{ + switch (child_level) { + case CPU_TOPO_THREAD: + return &smp_info->threads; + case CPU_TOPO_CORE: + return &smp_info->cores; + case CPU_TOPO_CLUSTER: + return &smp_info->clusters; + case CPU_TOPO_DIE: + return &smp_info->dies; + case CPU_TOPO_SOCKET: + return &smp_info->sockets; + case CPU_TOPO_BOOK: + return &smp_info->books; + case CPU_TOPO_DRAWER: + return &smp_info->drawers; + default: + /* No need to consider CPU_TOPO_UNKNOWN, and CPU_TOPO_ROOT. */ + g_assert_not_reached(); + } + + return NULL; +} + +static const char *get_topo_typename_by_level(CPUTopoLevel level) +{ + switch (level) { + case CPU_TOPO_CORE: + return TYPE_CPU_CORE; + case CPU_TOPO_CLUSTER: + return TYPE_CPU_CLUSTER; + case CPU_TOPO_DIE: + return TYPE_CPU_DIE; + case CPU_TOPO_SOCKET: + return TYPE_CPU_SOCKET; + case CPU_TOPO_BOOK: + return TYPE_CPU_BOOK; + case CPU_TOPO_DRAWER: + return TYPE_CPU_DRAWER; + default: + /* + * No need to consider CPU_TOPO_UNKNOWN, CPU_TOPO_THREAD + * and CPU_TOPO_ROOT. + */ + g_assert_not_reached(); + } + + return NULL; +} + +static char *get_topo_global_name(CPUTopoStat *stat, + CPUTopoLevel level) +{ + const char *type =3D NULL; + CPUTopoStatEntry *entry; + + type =3D cpu_topo_level_to_string(level); + entry =3D get_topo_stat_entry(stat, level); + return g_strdup_printf("%s[%d]", type, entry->total_units); +} + +typedef struct SMPBuildCbData { + unsigned long *supported_levels; + unsigned int plugged_cpus; + CpuTopology *smp_info; + CPUTopoStat *stat; + Error **errp; +} SMPBuildCbData; + +static int smp_core_set_threads(Object *core, unsigned int max_threads, + unsigned int *plugged_cpus, Error **errp) +{ + if (!object_property_set_int(core, "nr-threads", max_threads, errp)) { + object_unref(core); + return TOPO_FOREACH_ERR; + } + + if (*plugged_cpus > max_threads) { + if (!object_property_set_int(core, "plugged-threads", + max_threads, errp)) { + object_unref(core); + return TOPO_FOREACH_ERR; + } + *plugged_cpus -=3D max_threads; + } else{ + if (!object_property_set_int(core, "plugged-threads", + *plugged_cpus, errp)) { + object_unref(core); + return TOPO_FOREACH_ERR; + } + *plugged_cpus =3D 0; + } + + return TOPO_FOREACH_CONTINUE; +} + +static int add_smp_topo_child(CPUTopoState *topo, void *opaque) +{ + CPUTopoLevel level, child_level; + Object *parent =3D OBJECT(topo); + SMPBuildCbData *cb =3D opaque; + unsigned int *nr_children; + Error **errp =3D cb->errp; + + level =3D CPU_TOPO_LEVEL(topo); + child_level =3D find_last_bit(cb->supported_levels, level); + + /* + * child_level equals to level, that means no child needs to create. + * This shouldn't happen. + */ + g_assert(child_level !=3D level); + + nr_children =3D get_smp_info_by_level(cb->smp_info, child_level); + topo->max_children =3D *nr_children; + + for (int i =3D 0; i < topo->max_children; i++) { + ObjectProperty *prop; + Object *child; + gchar *name; + + child =3D object_new(get_topo_typename_by_level(child_level)); + name =3D get_topo_global_name(cb->stat, child_level); + + prop =3D object_property_try_add_child(parent, name, child, errp); + g_free(name); + if (!prop) { + return TOPO_FOREACH_ERR; + } + + if (child_level =3D=3D CPU_TOPO_CORE) { + int ret =3D smp_core_set_threads(child, cb->smp_info->threads, + &cb->plugged_cpus, errp); + + if (ret =3D=3D TOPO_FOREACH_ERR) { + return ret; + } + } + + qdev_realize(DEVICE(child), NULL, errp); + if (*errp) { + return TOPO_FOREACH_ERR; + } + } + + return TOPO_FOREACH_CONTINUE; +} + +void machine_create_smp_topo_tree(MachineState *ms, Error **errp) +{ + DECLARE_BITMAP(foreach_bitmap, USER_AVAIL_LEVEL_NUM); + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + CPUSlot *slot =3D ms->topo; + SMPBuildCbData cb; + + if (!slot) { + error_setg(errp, "Invalid machine: " + "the cpu-slot of machine is not initialized."); + return; + } + + if (mc->smp_props.possible_cpus_qom_granu !=3D CPU_TOPO_CORE && + mc->smp_props.possible_cpus_qom_granu !=3D CPU_TOPO_THREAD) { + error_setg(errp, "Invalid machine: Only support building " + "qom smp topology with core/thread granularity. " + "Not support %s granularity.", + cpu_topo_level_to_string( + mc->smp_props.possible_cpus_qom_granu)); + return; + } + + cb.supported_levels =3D slot->supported_levels; + cb.plugged_cpus =3D ms->smp.cpus; + cb.smp_info =3D &ms->smp; + cb.stat =3D &slot->stat; + cb.errp =3D errp; + + if (add_smp_topo_child(CPU_TOPO(slot), &cb) < 0) { + return; + } + + bitmap_copy(foreach_bitmap, slot->supported_levels, USER_AVAIL_LEVEL_N= UM); + + /* + * Don't create threads from -smp, and just record threads + * number in core. + */ + clear_bit(CPU_TOPO_CORE, foreach_bitmap); + clear_bit(CPU_TOPO_THREAD, foreach_bitmap); + + /* + * If the core level is inserted by hotplug way, don't create cores + * from -smp ethier. + */ + if (mc->smp_props.possible_cpus_qom_granu =3D=3D CPU_TOPO_CORE) { + CPUTopoLevel next_level; + + next_level =3D find_next_bit(foreach_bitmap, USER_AVAIL_LEVEL_NUM, + CPU_TOPO_CORE + 1); + clear_bit(next_level, foreach_bitmap); + } + + cpu_topo_child_foreach_recursive(CPU_TOPO(slot), foreach_bitmap, + add_smp_topo_child, &cb); + if (*errp) { + return; + } + slot->smp_parsed =3D true; +} diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 25019c91ee36..a0d091b23b97 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -19,6 +19,7 @@ =20 #include "qemu/osdep.h" #include "hw/boards.h" +#include "hw/core/cpu-slot.h" #include "qapi/error.h" #include "qemu/error-report.h" =20 @@ -230,6 +231,14 @@ void machine_parse_smp_config(MachineState *ms, mc->name, mc->max_cpus); return; } + + /* + * TODO: drop this check and convert "smp" to QOM topology tree by + * default when all arches support QOM topology. + */ + if (mc->smp_props.possible_cpus_qom_granu) { + machine_create_smp_topo_tree(ms, errp); + } } =20 unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 261b15fa8171..07100754e9d1 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -107,7 +107,6 @@ static void cpu_core_class_init(ObjectClass *oc, void *= data) static const TypeInfo cpu_core_type_info =3D { .name =3D TYPE_CPU_CORE, .parent =3D TYPE_CPU_TOPO, - .abstract =3D true, .class_init =3D cpu_core_class_init, .class_size =3D sizeof(CPUCoreClass), .instance_size =3D sizeof(CPUCore), diff --git a/include/hw/boards.h b/include/hw/boards.h index 81a7b04ece86..88de08d98f9f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -138,6 +138,11 @@ typedef struct { * provided SMP configuration * @books_supported - whether books are supported by the machine * @drawers_supported - whether drawers are supported by the machine + * @possible_cpus_qom_granu - the topology granularity for possible_cpus[] + * based on QOM CPU topology to plug CPUs. + * Note this flag indicates the support for QOM= CPU + * topology. If QOM CPU topology is not support= ed, + * must set this field as CPU_TOPO_UNKNOWN. */ typedef struct { bool prefer_sockets; @@ -146,6 +151,7 @@ typedef struct { bool has_clusters; bool books_supported; bool drawers_supported; + CPUTopoLevel possible_cpus_qom_granu; } SMPCompatProps; =20 /** @@ -187,6 +193,9 @@ typedef struct { * specifies default CPU_TYPE, which will be used for parsing target * specific features and for creating CPUs if CPU name wasn't provided * explicitly at CLI + * @default_core_tyep: + * specifies default CORE_TYPE, which will be used to create default co= re + * topology device for smp topology tree from -smp * @minimum_page_bits: * If non-zero, the board promises never to create a CPU with a page si= ze * smaller than this, so QEMU can use a more efficient larger page @@ -267,6 +276,7 @@ struct MachineClass { const char *hw_version; ram_addr_t default_ram_size; const char *default_cpu_type; + const char *default_core_type; bool default_kernel_irqchip_split; bool option_rom_has_mr; bool rom_file_has_mr; @@ -398,6 +408,7 @@ struct MachineState { const char *cpu_type; AccelState *accelerator; CPUArchIdList *possible_cpus; + /* TODO: get rid of "smp" when all arches support QOM topology. */ CpuTopology smp; CPUSlot *topo; struct NVDIMMState *nvdimms_state; diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index 1361af4ccfc0..de3d08fcb2ac 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -79,6 +79,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT) * @stat: Statistical topology information for topology tree. * @supported_levels: Supported topology levels for topology tree. * @ms: Machine in which this cpu-slot is plugged. + * @smp_parsed: Flag indicates if topology tree is derived from "-smp". + * If not, MachineState.smp needs to be initialized based on + * topology tree. */ struct CPUSlot { /*< private >*/ @@ -89,11 +92,13 @@ struct CPUSlot { CPUTopoStat stat; DECLARE_BITMAP(supported_levels, USER_AVAIL_LEVEL_NUM); MachineState *ms; + bool smp_parsed; }; =20 #define MACHINE_CORE_FOREACH(ms, core) \ QTAILQ_FOREACH((core), &(ms)->topo->cores, node) =20 void machine_plug_cpu_slot(MachineState *ms); +void machine_create_smp_topo_tree(MachineState *ms, Error **errp); =20 #endif /* CPU_SLOT_H */ diff --git a/tests/unit/meson.build b/tests/unit/meson.build index a05d47109040..5806dc5d813c 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -138,7 +138,10 @@ if have_system 'test-util-sockets': ['socket-helpers.c'], 'test-base64': [], 'test-bufferiszero': [], - 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine= -smp.c'], + 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine= -smp.c', + meson.project_source_root() / 'hw/core/cpu-slot.c', + meson.project_source_root() / 'hw/core/cpu-topo.c', + hwcore], 'test-vmstate': [migration, io], 'test-yank': ['socket-helpers.c', qom, io, chardev] } --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355073; cv=none; d=zohomail.com; s=zohoarc; b=RS9E8KFvaP7HfMnkDpTYswda8cMt0tteCF1IkpDMUHWI7PWcURNIYTcfQi+5lg1zdFpdGI+oFHqyUrNX687N8t6HDvo/zIypC0Fz3Z19C6tgqrNM5FDKlI0LB6vnsu8osuLpA9Y9d12pM41Tl7hdOIEEmgldBXNspM3hmS/FtnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355073; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UqEymSnO2UJ/jOwqPdfEx0Diu6WiaJcggjFVME9na9o=; b=mF0r4HirXMxEQ3n5nhcW9zO0J8a6ujKPXdhy5rqdy5o6fWSyk9VZjivcDwE6tAD/Xfj60leQw1Ao4EeiYI5gNhoKeAVKJmMl+JDqxoTqgwLVVW9hg/G9BdQM9riw0HQoAoJAmy1sPpDiMUtU+UZ6CNvhyoxybanHAsCyer+/vAc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355073216251.5429795019412; Thu, 30 Nov 2023 06:37:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9K-0002pz-J1; Thu, 30 Nov 2023 09:36:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8t-0001gQ-0c; Thu, 30 Nov 2023 09:35:54 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i8q-0001tW-SM; Thu, 30 Nov 2023 09:35:50 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:45 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354948; x=1732890948; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zMs3wimSwFi3OS/xT8fCJCLyivsPCu0OTNgeR6TOgP0=; b=UNDKxkCO8wZu9qJumGgCM6x621nMt5fUsWIH9bYZypa+i9jJ6+U+Jk76 PlrgEIgxpDjr/VAC4ORzqlMdmxEw9tVNlcSfirr9Nze0TvRnj+cPS2zkk BGDzQeZJmbmC/K8x8OYqHNIWerHNNosWoz8Yn4mPWC+6J3Cou5aiRe5UM n9ELpAx+UD4JPc08Hy5vmAHXYBa4p5ohszmw2jZmo3ghSpM96nluCnraI oRaHOsK+7ZfPUbG3tSkRSI4N+St/T97S8/Kgz0xdrTZfL94R8shG+NyuS pPAoJJx1qUjxI1sK1VE0/bJpQz+mPJ4QS2jLL+BTZaF04JnQCMo7bMFMq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532481" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532481" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730310" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730310" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 33/41] hw/machine: Validate smp topology tree without -smp Date: Thu, 30 Nov 2023 22:41:55 +0800 Message-Id: <20231130144203.2307629-34-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355073697000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu QOM topology allows user to create topology tree from cli without -smp, in this case, validate the topology tree to meet the smp requirement. Currently, for compatibility with MachineState.smp, initialize MachineState.smp from topology tree in this case. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 146 +++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 10 +++ include/hw/core/cpu-slot.h | 1 + 3 files changed, 157 insertions(+) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index ade155baf60b..45b6aef0750a 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -413,3 +413,149 @@ void machine_create_smp_topo_tree(MachineState *ms, E= rror **errp) } slot->smp_parsed =3D true; } + +static void set_smp_child_topo_info(CpuTopology *smp_info, + CPUTopoStat *stat, + CPUTopoLevel child_level) +{ + unsigned int *smp_count; + CPUTopoStatEntry *entry; + + smp_count =3D get_smp_info_by_level(smp_info, child_level); + entry =3D get_topo_stat_entry(stat, child_level); + *smp_count =3D entry->max_units ? entry->max_units : 1; + + return; +} + +typedef struct ValidateCbData { + CPUTopoStat *stat; + CpuTopology *smp_info; + Error **errp; +} ValidateCbData; + +static int validate_topo_children(CPUTopoState *topo, void *opaque) +{ + CPUTopoLevel level =3D CPU_TOPO_LEVEL(topo), next_level; + ValidateCbData *cb =3D opaque; + unsigned int max_children; + CPUTopoStatEntry *entry; + Error **errp =3D cb->errp; + + if (level !=3D CPU_TOPO_THREAD && !topo->num_children && + !topo->max_children) { + error_setg(errp, "Invalid topology: the CPU topology " + "(level: %s, index: %d) isn't completed.", + cpu_topo_level_to_string(level), topo->index); + return TOPO_FOREACH_ERR; + } + + if (level =3D=3D CPU_TOPO_UNKNOWN) { + error_setg(errp, "Invalid CPU topology: unknown topology level."); + return TOPO_FOREACH_ERR; + } + + /* + * Only CPU_TOPO_THREAD level's child_level could be CPU_TOPO_UNKNOWN, + * but machine_validate_cpu_topology() is before CPU creation. + */ + if (topo->child_level =3D=3D CPU_TOPO_UNKNOWN) { + error_setg(errp, "Invalid CPU topology: incomplete topology " + "(level: %s, index: %d), no child?.", + cpu_topo_level_to_string(level), topo->index); + return TOPO_FOREACH_ERR; + } + + /* + * Currently hybrid topology isn't supported, so only SMP topology + * is allowed. + */ + + entry =3D get_topo_stat_entry(cb->stat, topo->child_level); + + /* Max threads per core is pre-configured by "nr-threads". */ + max_children =3D topo->child_level !=3D CPU_TOPO_THREAD ? + topo->num_children : topo->max_children; + + if (entry->max_units !=3D max_children) { + error_setg(errp, "Invalid SMP topology: " + "The %s topology is asymmetric.", + cpu_topo_level_to_string(level)); + return TOPO_FOREACH_ERR; + } + + next_level =3D find_next_bit(cb->stat->curr_levels, USER_AVAIL_LEVEL_N= UM, + topo->child_level + 1); + + if (next_level !=3D level) { + error_setg(errp, "Invalid smp topology: " + "asymmetric CPU topology depth."); + return TOPO_FOREACH_ERR; + } + + set_smp_child_topo_info(cb->smp_info, cb->stat, topo->child_level); + + return TOPO_FOREACH_CONTINUE; +} + +/* + * Only check the case user configures CPU topology via -device + * without -smp. In this case, MachineState.smp also needs to be + * initialized based on topology tree. + */ +bool machine_validate_cpu_topology(MachineState *ms, Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + CPUTopoState *slot_topo =3D CPU_TOPO(ms->topo); + CPUTopoStat *stat =3D &ms->topo->stat; + CpuTopology *smp_info =3D &ms->smp; + unsigned int total_cpus; + ValidateCbData cb; + + if (ms->topo->smp_parsed) { + return true; + } else if (!slot_topo->num_children) { + /* + * If there's no -smp nor -device to add topology children, + * then create the default topology. + */ + machine_create_smp_topo_tree(ms, errp); + if (*errp) { + return false; + } + return true; + } + + if (test_bit(CPU_TOPO_CLUSTER, stat->curr_levels)) { + mc->smp_props.has_clusters =3D true; + } + + /* + * The next cpu_topo_child_foreach_recursive() doesn't cover the + * parent topology unit. Update information for root here. + */ + set_smp_child_topo_info(smp_info, stat, slot_topo->child_level); + + cb.stat =3D stat; + cb.smp_info =3D smp_info; + cb.errp =3D errp; + + cpu_topo_child_foreach_recursive(slot_topo, NULL, + validate_topo_children, &cb); + if (*errp) { + return false; + } + + ms->smp.cpus =3D stat->pre_plugged_cpus ? + stat->pre_plugged_cpus : 1; + ms->smp.max_cpus =3D stat->max_cpus ? + stat->max_cpus : 1; + + total_cpus =3D ms->smp.drawers * ms->smp.books * + ms->smp.sockets * ms->smp.dies * + ms->smp.clusters * ms->smp.cores * + ms->smp.threads; + g_assert(total_cpus =3D=3D ms->smp.max_cpus); + + return true; +} diff --git a/hw/core/machine.c b/hw/core/machine.c index 0c1739814124..5fa0c826f35e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1505,6 +1505,16 @@ void machine_run_board_init(MachineState *machine, c= onst char *mem_path, Error * "on", false); } =20 + /* + * TODO: drop this check and validate topology tree by default + * when all arches support QOM topology. + */ + if (machine_class->smp_props.possible_cpus_qom_granu) { + if (!machine_validate_cpu_topology(machine, errp)) { + return; + } + } + accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator)); machine_class->init(machine); phase_advance(PHASE_MACHINE_INITIALIZED); diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index de3d08fcb2ac..9e1c6d6b7ff2 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -100,5 +100,6 @@ struct CPUSlot { =20 void machine_plug_cpu_slot(MachineState *ms); void machine_create_smp_topo_tree(MachineState *ms, Error **errp); +bool machine_validate_cpu_topology(MachineState *ms, Error **errp); =20 #endif /* CPU_SLOT_H */ --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355043; cv=none; d=zohomail.com; s=zohoarc; b=bl4vRT88Ax/A4l1rzMCu3S2kHRoF29SLgLpX9VixvmRvj3cmjaDTVU8fV2Zv5nj7SzLh27cSI5O7PaYfBfwyqapwmY3tIPp3zJtHXyGGr93d/OCigx2ixhxTJReeUmBaeMWXhnkBGKJWAW5Yg2j3p2DD5i18ZMUhSVflvdazZAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355043; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Eu6idYEam8+HyrNZPh3b4H+LK4Wbsj6ztuwJv9PdeAU=; b=G2kxwVoJkWrb2tG5R1SF79wBP/Id51uEGyVHw2iYB69gBGfC7BeNAyVho6KVITlalNxTXB/IYIuBZcvxuthig5spblZSh+upGfnqrIXxLEfIHEmZMrj/AcdCU/p6drEvHxlBjGBuV5GML3TlSvwmKYDlvSnMxvd5N2qeucCa1nc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355043276225.89283575591014; Thu, 30 Nov 2023 06:37:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9K-0002qN-Qc; Thu, 30 Nov 2023 09:36:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i98-0001jV-MO; Thu, 30 Nov 2023 09:36:07 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i90-0001tW-E1; Thu, 30 Nov 2023 09:36:06 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:35:54 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354958; x=1732890958; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/v8heKKPYeoDkQz9adBaYazg44MH5EQbkce1fx19vRE=; b=ho2+FRa+OIviTDwySshVXwSE5mx0tXUzClJ9qIoZpSBjd8ZOTWghvEOC Z//8cLpwlI85ZzaE0OEJY8XiPSsr2WbbGSvxziaFMQWTqXDfbXfzubxP9 EUZv6v9DsxQ8HNOjBQmyt3rzYiTNPfb5vk38X3irH0FJz2AAXaz0phAaR Zteq8PU9ytCe7C+/QNMq7cteAglCWKH7pZBmyiJevJvkqru8RcmPpZ3UF fuQtj0sOhLXF9J44Z+nEtaMXRn/t5ccYHWa/KITLeWi+/opmECySnXII0 fMs+0rvN/3kVnjfTnu8+eSRbxHdVVFX+dOrhp1lkoj8QtZvzyJ4Z8xi2x Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532517" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532517" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730319" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730319" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 34/41] hw/core/topo: Implement user-child to collect topology device from cli Date: Thu, 30 Nov 2023 22:41:56 +0800 Message-Id: <20231130144203.2307629-35-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355043486000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Support user-child for topology devices. This will affect these 2 aspects: 1. For the basic topology device (with DEVICE_CATEGORY_CPU_DEF category), user could specify "parent" to build the topology relationship from cli. And cpu-slot will collect all topology devices. 2. For the hotplug topology devices (ppc-core or CPUs of other arches), user-child could help to search the correct topology parent in topology tree with the index properties. This is compatible with the original behavior of inserting CPU/core from cli. And this requires arch to support QOM topology with a few arch-specific modifications, before this support, hotplugged CPUs/cores are inserted into cpu-slot by default. Signed-off-by: Zhao Liu --- hw/core/cpu-slot.c | 44 ++++++++++++++++++++++++++++++++++++++ hw/core/cpu-topo.c | 38 ++++++++++++++++++++++++++++++++ include/hw/core/cpu-slot.h | 3 +++ include/hw/core/cpu-topo.h | 4 ++++ 4 files changed, 89 insertions(+) diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c index 45b6aef0750a..413daa66aaad 100644 --- a/hw/core/cpu-slot.c +++ b/hw/core/cpu-slot.c @@ -559,3 +559,47 @@ bool machine_validate_cpu_topology(MachineState *ms, E= rror **errp) =20 return true; } + +Object *cpu_slot_get_free_parent(CPUTopoState *child, Error **errp) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + CPUSlot *slot =3D ms->topo; + + if (!slot) { + return NULL; + } + + /* + * For CPUs and cores that support hotplug, the behavior is to specify + * some topology sub ids. This requires special handling. + */ + if (level =3D=3D mc->smp_props.possible_cpus_qom_granu) { + CPUTopoClass *child_tc =3D CPU_TOPO_GET_CLASS(child); + + if (child_tc->search_parent_pre_plug) { + return child_tc->search_parent_pre_plug(child, + CPU_TOPO(slot), errp); + } + } + + /* + * For other topology devices, just collect them into CPU slot. + * The realize() of CPUTopoClass will check no "parent" option case. + */ + return OBJECT(slot); +} + +char *cpu_slot_name_future_child(CPUTopoState *child) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + CPUTopoLevel level =3D CPU_TOPO_LEVEL(child); + CPUSlot *slot =3D ms->topo; + + if (!slot) { + return NULL; + } + + return get_topo_global_name(&slot->stat, level); +} diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c index 351112ca7a73..143b0a148b17 100644 --- a/hw/core/cpu-topo.c +++ b/hw/core/cpu-topo.c @@ -20,8 +20,10 @@ =20 #include "qemu/osdep.h" =20 +#include "hw/core/cpu-slot.h" #include "hw/core/cpu-topo.h" #include "hw/qdev-properties.h" +#include "monitor/user-child.h" #include "qapi/error.h" =20 const char *cpu_topo_level_to_string(CPUTopoLevel level) @@ -272,10 +274,38 @@ static void cpu_topo_unrealize(DeviceState *dev) } } =20 +/* + * Prefer to insert topology device into topology tree where the CPU + * slot is the root. + */ +static Object *cpu_topo_get_parent(UserChild *uc, Error **errp) +{ + return cpu_slot_get_free_parent(CPU_TOPO(uc), errp); +} + +static char *cpu_topo_get_child_name(UserChild *uc, Object *parent) +{ + return cpu_slot_name_future_child(CPU_TOPO(uc)); +} + +/* Only check type. Other topology details with be checked at realize(). */ +static bool cpu_topo_check_user_parent(UserChild *uc, Object *parent) +{ + CPUTopoState *topo; + + topo =3D (CPUTopoState *)object_dynamic_cast(parent, TYPE_CPU_TOPO); + if (!topo) { + return false; + } + + return true; +} + static void cpu_topo_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); CPUTopoClass *tc =3D CPU_TOPO_CLASS(oc); + UserChildClass *ucc =3D USER_CHILD_CLASS(oc); =20 /* All topology devices belong to CPU property. */ set_bit(DEVICE_CATEGORY_CPU, dc->categories); @@ -290,6 +320,10 @@ static void cpu_topo_class_init(ObjectClass *oc, void = *data) dc->hotpluggable =3D false; =20 tc->level =3D CPU_TOPO_UNKNOWN; + + ucc->get_parent =3D cpu_topo_get_parent; + ucc->get_child_name =3D cpu_topo_get_child_name; + ucc->check_parent =3D cpu_topo_check_user_parent; } =20 static void cpu_topo_instance_init(Object *obj) @@ -310,6 +344,10 @@ static const TypeInfo cpu_topo_type_info =3D { .class_init =3D cpu_topo_class_init, .instance_size =3D sizeof(CPUTopoState), .instance_init =3D cpu_topo_instance_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CHILD }, + { } + } }; =20 static void cpu_topo_register_types(void) diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h index 9e1c6d6b7ff2..1a63f55f52c3 100644 --- a/include/hw/core/cpu-slot.h +++ b/include/hw/core/cpu-slot.h @@ -102,4 +102,7 @@ void machine_plug_cpu_slot(MachineState *ms); void machine_create_smp_topo_tree(MachineState *ms, Error **errp); bool machine_validate_cpu_topology(MachineState *ms, Error **errp); =20 +Object *cpu_slot_get_free_parent(CPUTopoState *child, Error **errp); +char *cpu_slot_name_future_child(CPUTopoState *child); + #endif /* CPU_SLOT_H */ diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h index d27da0335c42..6cef26cce0b7 100644 --- a/include/hw/core/cpu-topo.h +++ b/include/hw/core/cpu-topo.h @@ -48,6 +48,8 @@ OBJECT_DECLARE_TYPE(CPUTopoState, CPUTopoClass, CPU_TOPO) * new child (including direct child and non-direct child) is added. * @check_topo_child: Method to check the support for new child (including * direct child and non-direct child) to be added. + * @search_parent_pre_plug: Method to search proper topology parent of @ch= ild + * from @root. */ struct CPUTopoClass { /*< private >*/ @@ -59,6 +61,8 @@ struct CPUTopoClass { bool is_realize); void (*check_topo_child)(CPUTopoState *parent, CPUTopoState *child, Error **errp); + Object *(*search_parent_pre_plug)(CPUTopoState *child, CPUTopoState *r= oot, + Error **errp); }; =20 /** --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355149; cv=none; d=zohomail.com; s=zohoarc; b=KTVXwYdKunZ2IYSjnJwhRBTRsF+5LkD2LGRdLopE2XHIARdwwvrG8L/IX1GSD84d9Gn+ZEfJ5fNgYkLaEBksOg2tiT52fqlyv65qLKGqdxx5TJJBUuf3pYFKuhTGKGHU8QdHGSZnnXSe51efp8SY6u9NQ5XsXntreQwAVRk8TWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355149; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8Fp5BZWPN/UpF5qDGDE77iO5ixRV0vutuGnOYigIF1Y=; b=TvRRxD5/VL+0MBJ0UA7oibWrU0+6oceigdkAlikPSLP1if0o/NDWMjw6J813wncX8+vGh2knpNnIJAjDIOIr9MhybSBgooCwoPI3w4Z+Y/pbKHszLBmUM+4OwGe9j9lb+d/NgsKRFSetVLPTas7Ss97ohCOwAmVq6Qt6xuerXf8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355149090880.0174370404758; Thu, 30 Nov 2023 06:39:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i9J-0002jS-7f; Thu, 30 Nov 2023 09:36:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9B-0001mS-4Q; Thu, 30 Nov 2023 09:36:09 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i99-00022Z-Fy; Thu, 30 Nov 2023 09:36:08 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:03 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:35:54 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354967; x=1732890967; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1ATU854G1+lM0AKtC/FFv0wTbLk1yiIDIW9pRjL09lQ=; b=GPlEhgiY3i9sjUG7S8ZmIFWz/B1aoktFs2dOxSZrHBE3FzooXzq7mwNr Dpbi6GNZimcoC70E2vPpgSqXApNM5pkAJRaN/jNXYqu2c3aYBIL826RK9 yhMluUILWBfeDPQhOGgJNvcOhRcqfrdziZ/iSZrt4m67cNx+cZ2Hs36OW XSVVIkRN9JfaowZenWSupPb8hfHe2dUY6rmZVcC1U0GmgdFE0B8Apw5p0 1j2vT1MCoSSi6WgOevC4yW3Gw2XB61DRc+/nCtNNcG/V3n/1OSwU8TFOr tHGdeHt3A8eL69ClhXjJrSKIm8DzIiVXCZvbPQmAS0pEyASx0TVNwJFeG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532581" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532581" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730346" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730346" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 35/41] hw/i386: Make x86_cpu_new() private in x86.c Date: Thu, 30 Nov 2023 22:41:57 +0800 Message-Id: <20231130144203.2307629-36-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355149767000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu x86_cpu_new() is only invoked in x86.c. Declear it as static in x86.c. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 3 ++- include/hw/i386/x86.h | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index b3d054889bba..d9293846db64 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -95,7 +95,8 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86m= s, } =20 =20 -void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp) +static void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, + Error **errp) { Object *cpu =3D object_new(MACHINE(x86ms)->cpu_type); =20 diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index da19ae15463a..19e9f93fe286 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -97,8 +97,6 @@ OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86= _MACHINE) =20 uint32_t x86_cpu_apic_id_from_index(X86MachineState *pcms, unsigned int cpu_index); - -void x86_cpu_new(X86MachineState *pcms, int64_t apic_id, Error **errp); void x86_cpus_init(X86MachineState *pcms, int default_cpu_version); CpuInstanceProperties x86_cpu_index_to_props(MachineState *ms, unsigned cpu_index); --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355102; cv=none; d=zohomail.com; s=zohoarc; b=L9PK5TjDvXpGuSidT9wersXaGgDPSbagY7FS6Dkc5UeoREPohCkhw0Bl/Ig+A3n2ROdg/j6XIDWb5Fg/uo9WKdm3lDkYznOddbRulIufqs4py2hAARUNkgJkY8Kp9GqyxynCrSP9lFaVZW1Jlyeau+EoCM6VceEtryJ9Zb8at1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hOnyms6Xj8MOjTu0mLFaVeWY9Z44zv8sVi+MLJlL2D8=; b=Qh7JeTpIRfY03gHzfy9vICD9Ya9qztq8lj+mVdAf236zsUQfBHVmjNvkRqWpgBEUksPIIv63kE2rrIHCsXcLcnJ3OKAtMytS+mhkoVeMIYD/I4rNu5tcUse4hrZawmCk7jq4tmBWHa5y9ROS5TClowmZvgoUYkT7Fz+1QTQgDUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355102054908.0081429774245; Thu, 30 Nov 2023 06:38:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8iA4-0005dF-AN; Thu, 30 Nov 2023 09:37:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9n-00053f-Hy; Thu, 30 Nov 2023 09:36:50 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9i-00027I-8L; Thu, 30 Nov 2023 09:36:46 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:16 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:03 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355002; x=1732891002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xvYlraOGB3zayUrWIK0PscKH2Ic2SrgqXJLGzTM1XXI=; b=N/stiCaqgm8IXLQOCE6sjhMe4Dp64ZmY23FzgkH/mSHpxPi2IBEmz5s1 ur/KTSsNAk+iMfYvsO/kvVuZLrNpgNLKY0IEccc+MzAzCDfpQj/HSYlgp xX2wtNUPzVxxiK2AVvadhOb8BBlsEqyzDxQAnM2Gt0ec7LuQ8F0c50+Dy ps/00ylljGJJN28l36tCDPNm+83TpBm23XqtCoGoYI4x/fLXJjamrjR8j GSSXTCWUR3uap8rS1kCT1rQ2o7NRe2xAQTNGFqvWgwFoXs1pQ6mXixhCm Ib3MUM3T3vh12H5uwd8k37BDcTuZdpNtQWZTOHpCrg5vndTsEcr6C0r+V Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532650" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532650" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730473" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730473" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 36/41] hw/i386: Allow x86_cpu_new() to specify parent for new CPU Date: Thu, 30 Nov 2023 22:41:58 +0800 Message-Id: <20231130144203.2307629-37-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355103606000017 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For QOM topology, CPU should be inserted under its parent core. Extend x86_cpu_new() to allow caller to specify topology parent. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index d9293846db64..3c99f4c3ab51 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -94,15 +94,22 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x8= 6ms, return x86_apicid_from_cpu_idx(&topo_info, cpu_index); } =20 - static void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, - Error **errp) + Object *parent, int index, Error **errp) { - Object *cpu =3D object_new(MACHINE(x86ms)->cpu_type); + const char *cpu_type =3D MACHINE(x86ms)->cpu_type; + Object *cpu =3D object_new(cpu_type); =20 if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) { goto out; } + + if (parent) { + char *name =3D g_strdup_printf("%s[%d]", cpu_type, index); + object_property_add_child(parent, name, cpu); + g_free(name); + } + qdev_realize(DEVICE(cpu), NULL, errp); =20 out: @@ -146,7 +153,8 @@ void x86_cpus_init(X86MachineState *x86ms, int default_= cpu_version) =20 possible_cpus =3D mc->possible_cpu_arch_ids(ms); for (i =3D 0; i < ms->smp.cpus; i++) { - x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); + x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, + NULL, i, &error_fatal); } } =20 --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355221; cv=none; d=zohomail.com; s=zohoarc; b=XarCjfLFJ34SHp4DlYJ4FlbrYPp9FcDGulHE+hG/+p7/qkVy9bsi3fWXt8eMTQEeCEcHKSmZDNH1burjqlFzFZp+t5x5RFWTRxnrs2o1M+PRe/3+vSC0pqke8NKnfsX75wbqesKiwjJLH/o5qQgGb53H1qIhEVrPe97TQOaMXco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355221; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p12BeQhcmKSgnkJJJQ3ZDkbTcZ5sKuxF+tV1dPV93lU=; b=iTSSBqnVZPzqLnUYs82DK15o0oeaGp105ohjH2LIQpN4Plclsg2wFOUnHtufzmXjJbKWcihuRCQnvBL4NkIIitLvPEQBWI1NP+rBJiG8XcULf+nnDMzHrfkSQCNx7wKa+wgQDO/1IG++BTtz9V9a3mwUoycegXSKK+kcRt1D124= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1701355221036153.00211656150566; Thu, 30 Nov 2023 06:40:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.644820.1006494 (Exim 4.92) (envelope-from ) id 1r8iCh-0003WV-KY; Thu, 30 Nov 2023 14:39:47 +0000 Received: by outflank-mailman (output) from mailman id 644820.1006494; Thu, 30 Nov 2023 14:39:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8iCg-0003P8-N4; Thu, 30 Nov 2023 14:39:46 +0000 Received: by outflank-mailman (input) for mailman id 644820; Thu, 30 Nov 2023 14:36:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8i9k-0000pO-AZ for xen-devel@lists.xenproject.org; Thu, 30 Nov 2023 14:36:44 +0000 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dfa734af-8f8d-11ee-9b0f-b553b5be7939; Thu, 30 Nov 2023 15:36:42 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:24 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:14 -0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dfa734af-8f8d-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355002; x=1732891002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lndGadsp6lchipVix45sBuugJYcXf54DoIQPmPepLjo=; b=A6azXLPohjn3O2rubFp/PwjM2P0N7a1vzt+L4NzbeQoNeofkrrtPBG/V cVz5L2SGMPrFA1l5NUmqhJ253NbxyUg/ZIFrmkgprX0Y8f2Fr9fdnAlqk jhRJTq8FKmnPjdFXWtbJdgoBhKs59YptmVLm6FE87Eov8rGRgGDqmY60A 47/SdNx8iMnGlK22IMQXNESB57X0UU2jq6G6H4Re4/olwPJnBnKGMi/LK RRRiQhDOzjiVF2XoVMinXQ9RiQOjHw3dDbVdN6DkX0uE8+UVlbynjGWRI 0K2ezNsW1+f4+CqnyuJlZN36itjZChq9OgKlmqESyCCgk6nU+9FAdkEhp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532685" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532685" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730506" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730506" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 37/41] hw/i386: Allow i386 to create new CPUs from QOM topology Date: Thu, 30 Nov 2023 22:41:59 +0800 Message-Id: <20231130144203.2307629-38-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355224000000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For QOM topology, maximum number of CPUs and the number of plugged CPUs are configured in core level. Iterate through all the cpu-cores to determine how many CPUs should be created in each cpu-core. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 3c99f4c3ab51..febffed92a83 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -152,9 +152,35 @@ void x86_cpus_init(X86MachineState *x86ms, int default= _cpu_version) } =20 possible_cpus =3D mc->possible_cpu_arch_ids(ms); - for (i =3D 0; i < ms->smp.cpus; i++) { - x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, - NULL, i, &error_fatal); + + /* + * possible_cpus_qom_granu means the QOM topology support. + * + * TODO: Drop the "!mc->smp_props.possible_cpus_qom_granu" case when + * i386 completes QOM topology support. + */ + if (mc->smp_props.possible_cpus_qom_granu) { + CPUCore *core; + int cpu_index =3D 0; + int core_idx =3D 0; + + MACHINE_CORE_FOREACH(ms, core) { + for (i =3D 0; i < core->plugged_threads; i++) { + x86_cpu_new(x86ms, possible_cpus->cpus[cpu_index].arch_id, + OBJECT(core), cpu_index, &error_fatal); + cpu_index++; + } + + if (core->plugged_threads < core->nr_threads) { + cpu_index +=3D core->nr_threads - core->plugged_threads; + } + core_idx++; + } + } else { + for (i =3D 0; i < ms->smp.cpus; i++) { + x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, + NULL, i, &error_fatal); + } } } =20 --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355065; cv=none; d=zohomail.com; s=zohoarc; b=NqTaaf9KJCSHMTpryozykgvpQi7svLCon1aky4KFkmSjI2fPghP2OwgeoWvmXGAEL6wfxvUKWwt82vNh7PwSQCcIG4hlLfWih6538+7UugqrQ5cSxzo6WlF9Wb6iCYnNdKNxUgfR4t/ZrRfh7k+WjKPwoUI4YhbTOF96rOSZC/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355065; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cnGSAwofHH4yKER93kwGtV9lmYaeZyjZriv6vXVyWyo=; b=ef+APDHsnDy1gTISIF9xdhInHIpcxfIl77lMsXZbhW0Poc+o3bowsYD7z8n1steJsnQyq3GBBMt5myYnks8nrWPut1R4eLPUUuPwxQx+lCFjl7kpe6USOM7YlL7TlgUxU3FUwHQXzJ+ilmiHmN4WrjRZOHwyKU9CztpKTFzjCPk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355065080718.5169722356578; Thu, 30 Nov 2023 06:37:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8iA4-0005gF-HA; Thu, 30 Nov 2023 09:37:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9p-00053v-FZ; Thu, 30 Nov 2023 09:36:50 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9n-000284-58; Thu, 30 Nov 2023 09:36:48 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:34 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355007; x=1732891007; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RjfOv7ECY6GXSAStu2RlCVg7nYnpovILbpK6PYk0aaQ=; b=nahkhQ8mea5zDyozUIS/jQIiCL4If89OBmyf/IuYv5o1v2s/In4uyhcp 7L8ZE0U2P04sc3L816WtC+/CuVUThC2Xf1WjNdy5/fP9XGWymrLeyRbZs qwx/+XlRwLNu0dpIetKnQjUtiT5hpuLFgP1r2H3imIQvnIsUOBnx86Kpm NOqKkxuYVT5ZRXqPeuYEWsTG+Az57V2o6G8peBhfg1P+emGbMFAXQlMQU 9dMtqe8gxRFRo0eBJfFv8nUcdxwqSKNeRDmIZOopjMRNhPowlvoHz/xNg kvRzR4mnbsSMWAz+2eGOvXnLOExBIy0utGBOEZhy/jpsYnHV+9vpuKk7c w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532725" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532725" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730519" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730519" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 38/41] hw/i386: Wrap apic id and topology sub ids assigning as helpers Date: Thu, 30 Nov 2023 22:42:00 +0800 Message-Id: <20231130144203.2307629-39-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355065597000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu For QOM topology, these 2 helpers are needed for hotplugged CPU to verify its topology sub indexes and then search its parent core. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 173 ++++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 77 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index febffed92a83..04edd6de6aeb 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -306,6 +306,98 @@ void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev, error_propagate(errp, local_err); } =20 +static void x86_cpu_assign_apic_id(MachineState *ms, X86CPU *cpu, + X86CPUTopoIDs *topo_ids, + X86CPUTopoInfo *topo_info, + Error **errp) +{ + int max_socket =3D (ms->smp.max_cpus - 1) / + ms->smp.threads / ms->smp.cores / ms->smp.dies; + + /* + * die-id was optional in QEMU 4.0 and older, so keep it optional + * if there's only one die per socket. + */ + if (cpu->die_id < 0 && ms->smp.dies =3D=3D 1) { + cpu->die_id =3D 0; + } + + if (cpu->socket_id < 0) { + error_setg(errp, "CPU socket-id is not set"); + return; + } else if (cpu->socket_id > max_socket) { + error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u", + cpu->socket_id, max_socket); + return; + } + if (cpu->die_id < 0) { + error_setg(errp, "CPU die-id is not set"); + return; + } else if (cpu->die_id > ms->smp.dies - 1) { + error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u", + cpu->die_id, ms->smp.dies - 1); + return; + } + if (cpu->core_id < 0) { + error_setg(errp, "CPU core-id is not set"); + return; + } else if (cpu->core_id > (ms->smp.cores - 1)) { + error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u", + cpu->core_id, ms->smp.cores - 1); + return; + } + if (cpu->thread_id < 0) { + error_setg(errp, "CPU thread-id is not set"); + return; + } else if (cpu->thread_id > (ms->smp.threads - 1)) { + error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u", + cpu->thread_id, ms->smp.threads - 1); + return; + } + + topo_ids->pkg_id =3D cpu->socket_id; + topo_ids->die_id =3D cpu->die_id; + topo_ids->core_id =3D cpu->core_id; + topo_ids->smt_id =3D cpu->thread_id; + cpu->apic_id =3D x86_apicid_from_topo_ids(topo_info, topo_ids); +} + +static void x86_cpu_assign_topo_id(X86CPU *cpu, + X86CPUTopoIDs *topo_ids, + Error **errp) +{ + if (cpu->socket_id !=3D -1 && cpu->socket_id !=3D topo_ids->pkg_id) { + error_setg(errp, "property socket-id: %u doesn't match set apic-id= :" + " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, + topo_ids->pkg_id); + return; + } + cpu->socket_id =3D topo_ids->pkg_id; + + if (cpu->die_id !=3D -1 && cpu->die_id !=3D topo_ids->die_id) { + error_setg(errp, "property die-id: %u doesn't match set apic-id:" + " 0x%x (die-id: %u)", cpu->die_id, cpu->apic_id, topo_ids->die= _id); + return; + } + cpu->die_id =3D topo_ids->die_id; + + if (cpu->core_id !=3D -1 && cpu->core_id !=3D topo_ids->core_id) { + error_setg(errp, "property core-id: %u doesn't match set apic-id:" + " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, + topo_ids->core_id); + return; + } + cpu->core_id =3D topo_ids->core_id; + + if (cpu->thread_id !=3D -1 && cpu->thread_id !=3D topo_ids->smt_id) { + error_setg(errp, "property thread-id: %u doesn't match set apic-id= :" + " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, + topo_ids->smt_id); + return; + } + cpu->thread_id =3D topo_ids->smt_id; +} + void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -317,8 +409,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, CPUX86State *env =3D &cpu->env; MachineState *ms =3D MACHINE(hotplug_dev); X86MachineState *x86ms =3D X86_MACHINE(hotplug_dev); - unsigned int smp_cores =3D ms->smp.cores; - unsigned int smp_threads =3D ms->smp.threads; X86CPUTopoInfo topo_info; =20 if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { @@ -347,55 +437,10 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, * set it based on socket/die/core/thread properties. */ if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { - int max_socket =3D (ms->smp.max_cpus - 1) / - smp_threads / smp_cores / ms->smp.dies; - - /* - * die-id was optional in QEMU 4.0 and older, so keep it optional - * if there's only one die per socket. - */ - if (cpu->die_id < 0 && ms->smp.dies =3D=3D 1) { - cpu->die_id =3D 0; - } - - if (cpu->socket_id < 0) { - error_setg(errp, "CPU socket-id is not set"); - return; - } else if (cpu->socket_id > max_socket) { - error_setg(errp, "Invalid CPU socket-id: %u must be in range 0= :%u", - cpu->socket_id, max_socket); + x86_cpu_assign_apic_id(ms, cpu, &topo_ids, &topo_info, errp); + if (*errp) { return; } - if (cpu->die_id < 0) { - error_setg(errp, "CPU die-id is not set"); - return; - } else if (cpu->die_id > ms->smp.dies - 1) { - error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u= ", - cpu->die_id, ms->smp.dies - 1); - return; - } - if (cpu->core_id < 0) { - error_setg(errp, "CPU core-id is not set"); - return; - } else if (cpu->core_id > (smp_cores - 1)) { - error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%= u", - cpu->core_id, smp_cores - 1); - return; - } - if (cpu->thread_id < 0) { - error_setg(errp, "CPU thread-id is not set"); - return; - } else if (cpu->thread_id > (smp_threads - 1)) { - error_setg(errp, "Invalid CPU thread-id: %u must be in range 0= :%u", - cpu->thread_id, smp_threads - 1); - return; - } - - topo_ids.pkg_id =3D cpu->socket_id; - topo_ids.die_id =3D cpu->die_id; - topo_ids.core_id =3D cpu->core_id; - topo_ids.smt_id =3D cpu->thread_id; - cpu->apic_id =3D x86_apicid_from_topo_ids(&topo_info, &topo_ids); } =20 cpu_slot =3D x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx); @@ -422,36 +467,10 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, * once -smp refactoring is complete and there will be CPU private * CPUState::nr_cores and CPUState::nr_threads fields instead of globa= ls */ x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); - if (cpu->socket_id !=3D -1 && cpu->socket_id !=3D topo_ids.pkg_id) { - error_setg(errp, "property socket-id: %u doesn't match set apic-id= :" - " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, - topo_ids.pkg_id); - return; - } - cpu->socket_id =3D topo_ids.pkg_id; - - if (cpu->die_id !=3D -1 && cpu->die_id !=3D topo_ids.die_id) { - error_setg(errp, "property die-id: %u doesn't match set apic-id:" - " 0x%x (die-id: %u)", cpu->die_id, cpu->apic_id, topo_ids.die_= id); - return; - } - cpu->die_id =3D topo_ids.die_id; - - if (cpu->core_id !=3D -1 && cpu->core_id !=3D topo_ids.core_id) { - error_setg(errp, "property core-id: %u doesn't match set apic-id:" - " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, - topo_ids.core_id); - return; - } - cpu->core_id =3D topo_ids.core_id; - - if (cpu->thread_id !=3D -1 && cpu->thread_id !=3D topo_ids.smt_id) { - error_setg(errp, "property thread-id: %u doesn't match set apic-id= :" - " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, - topo_ids.smt_id); + x86_cpu_assign_topo_id(cpu, &topo_ids, errp); + if (*errp) { return; } - cpu->thread_id =3D topo_ids.smt_id; =20 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && kvm_enabled() && !kvm_hv_vpindex_settable()) { --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355228; cv=none; d=zohomail.com; s=zohoarc; b=CBU5arKl2ykQdGFGJVqAGwqprfJxvjCBP5SrlJCqDMK+HdOl8mKKe+npVUzYQak4262dVtyRAt9cEkB+24x3GbN0dJ9n/N6bcu2RbpjjJY7Rja/wtvP4UFHD3YN5oyOWSDmxDbPTtfixaFlxHYw9bt3c/PtpfC0b/tsrz7nqbW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z4L3nI7wR/SVhNHr/XVqJtZAzytK6Ic2h7XDN6tz6YM=; b=Wh4LRbx2+EAMpzZr8kxjn9/SGbr6IW0vEiHSDQaNEp5C5HaoFvHpONZxRaJycA7WTbV0YR1R/dLSiH6KL9LNL8XPpimUuCbtPQHeCWmlTcnI2YqyIqA6cnKr0hZw86Sj2xYGPdgbDY0lQ05YNtOIVyVe+1FZdsE/X9SzX3yP5Hc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1701355228926458.01951154788867; Thu, 30 Nov 2023 06:40:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.644824.1006518 (Exim 4.92) (envelope-from ) id 1r8iCm-0004lm-LY; Thu, 30 Nov 2023 14:39:52 +0000 Received: by outflank-mailman (output) from mailman id 644824.1006518; Thu, 30 Nov 2023 14:39:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8iCl-0004Wc-Ek; Thu, 30 Nov 2023 14:39:51 +0000 Received: by outflank-mailman (input) for mailman id 644824; Thu, 30 Nov 2023 14:36:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r8i9n-0000pO-Uk for xen-devel@lists.xenproject.org; Thu, 30 Nov 2023 14:36:47 +0000 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e3151d4e-8f8d-11ee-9b0f-b553b5be7939; Thu, 30 Nov 2023 15:36:46 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:42 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:33 -0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e3151d4e-8f8d-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355006; x=1732891006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q0lEBoFOr9b0x5amAD6sBLj9mxt45Se06XmWgm72SHY=; b=aCv8TiwjThHi9DnlHxz3vJ6b31n05Kofu3wuWgXE+6wb9hgy0Ph2xAPj u/w/zHbvjh5AAhDM3ImFz7XunalIXo/RoUc9F6tfGPSNV/+Eb3o/jLzU+ CjwlRnyPQoKXa1Fs1cZ6QVzhDPEI4ZQsANedF0CpRnMDqYNXjlRTVnJ2Y f7cmY4UtQlSBzNJBq/qN7C4Offqwpi24SZxaWOxP0Yhu4SErFyva6ODlH /DKXRQzAqALUzB2co7zqh/SpYuk0QY74Tt41+hwgpKHMdM1U1Yb0o+hxC zZgNIcn1pJkTQwO2s+6Ngdj9hlYeuUHKOp5EMFQcmxogs/EvWDQleartj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532773" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532773" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730530" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730530" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 39/41] hw/i386: Add the interface to search parent for QOM topology Date: Thu, 30 Nov 2023 22:42:01 +0800 Message-Id: <20231130144203.2307629-40-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355230054000002 Content-Type: text/plain; charset="utf-8" From: Zhao Liu QOM topology needs to search parent cpu-core for hotplugged CPU to create topology child<> property in qdev_set_id(). This process is before x86_cpu_pre_plug(), thus place 2 helpers x86_cpu_assign_apic_id() and x86_cpu_assign_topo_id() in x86_cpu_search_parent_pre_plug() to help get the correct topology sub indexes. Then x86_cpu_search_parent_pre_plug() searches the parent cpu-core with these sub indexes. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 128 +++++++++++++++++++++++++++++++++++++++--- include/hw/i386/x86.h | 3 + 2 files changed, 122 insertions(+), 9 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 04edd6de6aeb..595d4365fdd1 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -460,16 +460,18 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, return; } =20 - /* if 'address' properties socket-id/core-id/thread-id are not set, se= t them - * so that machine_query_hotpluggable_cpus would show correct values + /* + * possible_cpus_qom_granu means the QOM topology support. + * + * TODO: Drop the "!mc->smp_props.possible_cpus_qom_granu" case when + * i386 completes QOM topology support. */ - /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizef= n() - * once -smp refactoring is complete and there will be CPU private - * CPUState::nr_cores and CPUState::nr_threads fields instead of globa= ls */ - x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); - x86_cpu_assign_topo_id(cpu, &topo_ids, errp); - if (*errp) { - return; + if (!mc->smp_props.possible_cpus_qom_granu) { + x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); + x86_cpu_assign_topo_id(cpu, &topo_ids, errp); + if (*errp) { + return; + } } =20 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && @@ -484,6 +486,114 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, numa_cpu_pre_plug(cpu_slot, dev, errp); } =20 +static int x86_cpu_get_topo_id_by_level(X86CPU *cpu, + CPUTopoLevel level) +{ + switch (level) { + case CPU_TOPO_THREAD: + return cpu->thread_id; + case CPU_TOPO_CORE: + return cpu->core_id; + case CPU_TOPO_DIE: + return cpu->die_id; + case CPU_TOPO_SOCKET: + return cpu->socket_id; + default: + g_assert_not_reached(); + } + + return -1; +} + +typedef struct SearchCoreCb { + X86CPU *cpu; + CPUTopoState *parent; + int id; +} SearchCoreCb; + +static int x86_cpu_search_parent_core(CPUTopoState *topo, + void *opaque) +{ + SearchCoreCb *cb =3D opaque; + CPUTopoLevel level =3D CPU_TOPO_LEVEL(topo); + + cb->parent =3D topo; + cb->id =3D x86_cpu_get_topo_id_by_level(cb->cpu, level); + + if (cb->id =3D=3D topo->index) { + if (level =3D=3D CPU_TOPO_CORE) { + return TOPO_FOREACH_END; + } + return TOPO_FOREACH_CONTINUE; + } + return TOPO_FOREACH_SIBLING; +} + +Object *x86_cpu_search_parent_pre_plug(CPUTopoState *topo, + CPUTopoState *root, + Error **errp) +{ + int ret; + SearchCoreCb cb; + X86CPUTopoIDs topo_ids; + X86CPUTopoInfo topo_info; + X86CPU *cpu =3D X86_CPU(topo); + CPUSlot *slot =3D CPU_SLOT(root); + MachineState *ms =3D slot->ms; + DECLARE_BITMAP(foreach_bitmap, USER_AVAIL_LEVEL_NUM); + + topo_info.dies_per_pkg =3D ms->smp.dies; + topo_info.cores_per_die =3D ms->smp.cores; + topo_info.threads_per_core =3D ms->smp.threads; + + if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { + x86_cpu_assign_apic_id(ms, cpu, &topo_ids, &topo_info, errp); + if (*errp) { + return NULL; + } + } else { + /* + * if 'address' properties socket-id/core-id/thread-id are not set, + * set them so that machine_query_hotpluggable_cpus would show + * correct values. + * + * TODO: move socket_id/core_id/thread_id checks into + * x86_cpu_realizefn() once -smp refactoring is complete and there + * will be CPU private CPUState::nr_cores and CPUState::nr_threads + * fields instead of globals. + */ + x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); + } + + x86_cpu_assign_topo_id(cpu, &topo_ids, errp); + if (*errp) { + return NULL; + } + + cb.cpu =3D cpu; + cb.parent =3D NULL; + cb.id =3D -1; + bitmap_fill(foreach_bitmap, USER_AVAIL_LEVEL_NUM); + clear_bit(CPU_TOPO_UNKNOWN, foreach_bitmap); + clear_bit(CPU_TOPO_THREAD, foreach_bitmap); + + ret =3D cpu_topo_child_foreach_recursive(root, foreach_bitmap, + x86_cpu_search_parent_core, &cb= ); + if (ret !=3D TOPO_FOREACH_END) { + g_autofree char *search_info =3D NULL; + + search_info =3D !cb.parent ? g_strdup("") : + g_strdup_printf(" for %s level with id: %d", + cpu_topo_level_to_string(CPU_TOPO_LEVEL(cb.parent)), cb.id); + error_setg(errp, "Can't find parent%s", search_info); + return NULL; + } + + /* Keep the index of CPU topology device the same as the thread_id. */ + topo->index =3D cpu->thread_id; + return OBJECT(cb.parent); +} + CpuInstanceProperties x86_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 19e9f93fe286..e8c9ddc36359 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -104,6 +104,9 @@ int64_t x86_get_default_cpu_node_id(const MachineState = *ms, int idx); const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms); CPUArchId *x86_find_cpu_slot(MachineState *ms, uint32_t id, int *idx); void x86_rtc_set_cpus_count(ISADevice *rtc, uint16_t cpus_count); +Object *x86_cpu_search_parent_pre_plug(CPUTopoState *topo, + CPUTopoState *root, + Error **errp); void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void x86_cpu_plug(HotplugHandler *hotplug_dev, --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355287; cv=none; d=zohomail.com; s=zohoarc; b=jxmKi7NKN2RIFPl5PyV43w2nn5Tg9vZz29edy6XR0X09dVMgznCazO4V4DTqBSMc+g6HW2YHKsoQM78yvK7zeXCCJQcFN7RSDvk56phSIN72Hky/mRENhmHr8h9iw8JUhl7z8TwS1U13zzam3GdMdWE1g/Q3Qr0dUoU7n2hPEtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355287; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=up7w2lhgluFde6n2xVBvlMKLFccOF26if/81dpq3obI=; b=E6j7g7Y2jThULDsdjWFsROwbSHQFFjexacdv7yZvENjVeSGIrBepdVoStZ/blRrmIjaLEyWtYBaB8ylq8mO0JugCU7Cga35qOE9NjAJvfEByFXwJvrHXESn/RyQX5jT0C44ioBO4XswiMFzlxPJbe6wMQkRpXr5C4YK8uW1GSDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355287436875.5439391107084; Thu, 30 Nov 2023 06:41:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8iAA-0006H2-1Y; Thu, 30 Nov 2023 09:37:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9x-0005EA-5L; Thu, 30 Nov 2023 09:36:58 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i9v-00027I-Hf; Thu, 30 Nov 2023 09:36:56 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:52 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355015; x=1732891015; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n1bOTd1De6zljXfwth5hOf8VQYb/0aDsDjxTGUGzfGQ=; b=Yu4EGhg6yNshxMTJYvtudEMoU2SJagl/F8MQClr47J9bZmuFtKpBNODl IzLhhYEJmu0ZWUDF//G9NUKcDiKgAYp5jWm5QnSAIdKAGkwUFZCuoCAVT FWOoQVnpeU18pt3dVgu8iQ+8IdlFCdSeBqB37k7BPCiuL7/jRyTRKwuWv KhnqpF9u6J29gyKGWGLyX5DWNRGeDY9CR0qUV6qaoZp1C2/TGd14AYzwy BgOw+PtOS1DxwiRHNEMs68QZZCuu82pf+FJcYrMgAws4unI4fZ59uwcY0 uAWHoliihs5DORIasvSOtlQHA0+rVVTzM54zxedlVngX13BodedG7K00Q w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532839" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532839" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730582" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730582" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 40/41] hw/i386: Support QOM topology Date: Thu, 30 Nov 2023 22:42:02 +0800 Message-Id: <20231130144203.2307629-41-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355288386000003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Set MachineClass.smp_props.possible_cpus_qom_granu and TopoClass.search_parent_pre_plug for i386. So far, the i386 topology is based on the QOM topology. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 1 + target/i386/cpu.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 595d4365fdd1..99f6c502de43 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1565,6 +1565,7 @@ static void x86_machine_class_init(ObjectClass *oc, v= oid *data) mc->cpu_index_to_instance_props =3D x86_cpu_index_to_props; mc->get_default_cpu_node_id =3D x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids =3D x86_possible_cpu_arch_ids; + mc->smp_props.possible_cpus_qom_granu =3D CPU_TOPO_THREAD; x86mc->save_tsc_khz =3D true; x86mc->fwcfg_dma_enabled =3D true; nc->nmi_monitor_handler =3D x86_nmi; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index cd16cb893daf..1de5726691e1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -41,6 +41,7 @@ #include "exec/address-spaces.h" #include "hw/boards.h" #include "hw/i386/sgx-epc.h" +#include "hw/i386/x86.h" #endif =20 #include "disas/capstone.h" @@ -8009,6 +8010,9 @@ static void x86_cpu_common_class_init(ObjectClass *oc= , void *data) #if !defined(CONFIG_USER_ONLY) object_class_property_add(oc, "crash-information", "GuestPanicInformat= ion", x86_cpu_get_crash_info_qom, NULL, NULL, NULL= ); + + CPU_TOPO_CLASS(oc)->search_parent_pre_plug =3D + x86_cpu_search_parent_pre_plug; #endif =20 for (w =3D 0; w < FEATURE_WORDS; w++) { --=20 2.34.1 From nobody Wed Nov 27 02:22:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701355114; cv=none; d=zohomail.com; s=zohoarc; b=SbpEKoiHkbSHsomMMUs2O6gQNZ5RGUQmO6H8fJcy1wrRw3agtLQ31cwXtvvxq6cUp5SgBMxoA5w7Y8zD0dsNuWHbdM7tD/c5lhoPsHo5R63OV1vf9cqPT96DjQ0ZhYTvi/fzg9/KIewOdp5Nt+6RoW3+MhSWelg2SRdsGCsWM3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701355114; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g6G1a8dTSfFyn165wf6V29FA7Uk+L81d2NzpIDerB8A=; b=HuBSn2+6bVdUmhNAsUO8YQ4IPfyvuDreQjouo3YlZop9MH/8j+mjkRawoCjxhuXT27ubDyOolanZZqAF1BQO9aFk+ejT9i4FLvGSl/lLr/WMnMN4/N+C4W/Izo6evFTwlXwhRcH9V3gpBY/QAa9qt70o6gjjJp6IwMvKlb69QFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701355114908761.8095689649326; Thu, 30 Nov 2023 06:38:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8iAC-0006XZ-Pi; Thu, 30 Nov 2023 09:37:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8iA8-0006Aa-3K; Thu, 30 Nov 2023 09:37:08 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8iA6-0002CQ-3H; Thu, 30 Nov 2023 09:37:07 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:37:01 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701355026; x=1732891026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1TBuBuayUq5ep3LedB2XG6MRM6nllhfykxLgfM/A+kw=; b=myqWtp1P9nIxX3zGWkd+pg+VMXUsWniH8dQHsxW3R+KbkCEABxG17x8c ONKvlYZuYK5ox8SUFymjCAw00e/2uGgACySYv8IIggSRUloxftjDec4Ab c13nCqcDVwEce5HAdPunFvQaGAym4zsz/zGvsTs/Vx7JIekY5HDndp5KT DehAIe5ltwf+oi7OWyhQQNHcLDr/Sbkxe0GPRoYDcsnceuuHT/qci34hG QTXJqWQgYr2WnjLAxgjy6R3m63RnwXwzlM2T/cQ5Tk/iT1Bdim/V3f2vH uIsEq3C29nWVxklROcJCr+lF+KqcjbkNtctvz7gE73VaK77TvgaW6eIuL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532878" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532878" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730622" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730622" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 41/41] hw/i386: Cleanup non-QOM topology support Date: Thu, 30 Nov 2023 22:42:03 +0800 Message-Id: <20231130144203.2307629-42-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701355115651000001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu After i386 supports QOM topology, drop original topology logic. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 52 +++++++++++---------------------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 99f6c502de43..cba8b806cdb6 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -118,7 +118,8 @@ out: =20 void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) { - int i; + CPUCore *core; + int i, cpu_index =3D 0, core_idx =3D 0; const CPUArchIdList *possible_cpus; MachineState *ms =3D MACHINE(x86ms); MachineClass *mc =3D MACHINE_GET_CLASS(x86ms); @@ -153,34 +154,17 @@ void x86_cpus_init(X86MachineState *x86ms, int defaul= t_cpu_version) =20 possible_cpus =3D mc->possible_cpu_arch_ids(ms); =20 - /* - * possible_cpus_qom_granu means the QOM topology support. - * - * TODO: Drop the "!mc->smp_props.possible_cpus_qom_granu" case when - * i386 completes QOM topology support. - */ - if (mc->smp_props.possible_cpus_qom_granu) { - CPUCore *core; - int cpu_index =3D 0; - int core_idx =3D 0; - - MACHINE_CORE_FOREACH(ms, core) { - for (i =3D 0; i < core->plugged_threads; i++) { - x86_cpu_new(x86ms, possible_cpus->cpus[cpu_index].arch_id, - OBJECT(core), cpu_index, &error_fatal); - cpu_index++; - } - - if (core->plugged_threads < core->nr_threads) { - cpu_index +=3D core->nr_threads - core->plugged_threads; - } - core_idx++; + MACHINE_CORE_FOREACH(ms, core) { + for (i =3D 0; i < core->plugged_threads; i++) { + x86_cpu_new(x86ms, possible_cpus->cpus[cpu_index].arch_id, + OBJECT(core), cpu_index, &error_fatal); + cpu_index++; } - } else { - for (i =3D 0; i < ms->smp.cpus; i++) { - x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, - NULL, i, &error_fatal); + + if (core->plugged_threads < core->nr_threads) { + cpu_index +=3D core->nr_threads - core->plugged_threads; } + core_idx++; } } =20 @@ -460,20 +444,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, return; } =20 - /* - * possible_cpus_qom_granu means the QOM topology support. - * - * TODO: Drop the "!mc->smp_props.possible_cpus_qom_granu" case when - * i386 completes QOM topology support. - */ - if (!mc->smp_props.possible_cpus_qom_granu) { - x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); - x86_cpu_assign_topo_id(cpu, &topo_ids, errp); - if (*errp) { - return; - } - } - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && kvm_enabled() && !kvm_hv_vpindex_settable()) { error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX"); --=20 2.34.1