From patchwork Wed Mar 30 12:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 12795803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83059C433EF for ; Wed, 30 Mar 2022 13:06:31 +0000 (UTC) Received: from localhost ([::1]:59314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZY1u-000342-HB for qemu-devel@archiver.kernel.org; Wed, 30 Mar 2022 09:06:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXsb-0006mC-1G; Wed, 30 Mar 2022 08:56:53 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:40980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZXsY-0004Yk-A9; Wed, 30 Mar 2022 08:56:52 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id CE63B21C73; Wed, 30 Mar 2022 12:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1648645008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MCPBp1rxd0BRI6uj/DUHFvNtQuIDUwFbXBbxFs483vY=; b=nKJcCtPaxEONZtKtaky16eXmfZBjJCFDMEzhFmw+sBkyt89HEW5sszhygVqDI71jsnF0N2 YxfX9oolBJ6A4PgC2KXPv6zotxOAM3xZOrQ5vuTK/8bt/1UrBAeb7mCVDoNVxEUTt8iMGd g3TsB122VzbFlEAjD+Ezgc+DxC7mJH4= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH 04/18] hw/cpu/cluster: make _cpu-cluster_ a subclass of _cpus_ Date: Wed, 30 Mar 2022 14:56:25 +0200 Message-Id: <20220330125639.201937-5-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220330125639.201937-1-damien.hedde@greensocs.com> References: <20220330125639.201937-1-damien.hedde@greensocs.com> MIME-Version: 1.0 X-Spam: Yes Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: , Cc: Damien Hedde , Peter Maydell , Bin Meng , qemu-riscv@nongnu.org, Alistair Francis , mark.burton@greensocs.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-arm@nongnu.org, Palmer Dabbelt , Vijai Kumar K , "Edgar E. Iglesias" , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Drop the cluster-id property as base class defines one. cluster_id field is temporarily kept until gdbstub is updated. Signed-off-by: Damien Hedde --- include/hw/cpu/cluster.h | 17 ++++++++++-- hw/cpu/cluster.c | 58 +++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h index 09a2b86832..2125765f21 100644 --- a/include/hw/cpu/cluster.h +++ b/include/hw/cpu/cluster.h @@ -22,6 +22,7 @@ #include "hw/qdev-core.h" #include "qom/object.h" +#include "hw/cpu/cpus.h" /* * CPU Cluster type @@ -55,7 +56,7 @@ */ #define TYPE_CPU_CLUSTER "cpu-cluster" -OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER) +OBJECT_DECLARE_TYPE(CPUClusterState, CPUClusterClass, CPU_CLUSTER) /** * CPUClusterState: @@ -66,10 +67,22 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER) */ struct CPUClusterState { /*< private >*/ - DeviceState parent_obj; + CpusState parent_obj; /*< public >*/ uint32_t cluster_id; }; +/** + * CPUClusterClass: + * @parent_realize: to store base class realize method + */ +struct CPUClusterClass { + /*< private >*/ + CpusClass parent_class; + + /*< public >*/ + DeviceRealize parent_realize; +}; + #endif diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index e444b7c29d..3daf897bd9 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -20,50 +20,39 @@ #include "qemu/osdep.h" #include "hw/cpu/cluster.h" +#include "hw/cpu/cpus.h" #include "hw/qdev-properties.h" #include "hw/core/cpu.h" #include "qapi/error.h" #include "qemu/module.h" #include "qemu/cutils.h" -static Property cpu_cluster_properties[] = { - DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0), - DEFINE_PROP_END_OF_LIST() -}; - -typedef struct CallbackData { - CPUClusterState *cluster; - int cpu_count; -} CallbackData; - static int add_cpu_to_cluster(Object *obj, void *opaque) { - CallbackData *cbdata = opaque; + CpusState *base = CPUS(opaque); CPUState *cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU); if (cpu) { - cpu->cluster_index = cbdata->cluster->cluster_id; - cbdata->cpu_count++; + cpu->cluster_index = base->cluster_index; + base->topology.cpus++; } return 0; } static void cpu_cluster_realize(DeviceState *dev, Error **errp) { - /* Iterate through all our CPU children and set their cluster_index */ + CPUClusterClass *ccc = CPU_CLUSTER_GET_CLASS(dev); CPUClusterState *cluster = CPU_CLUSTER(dev); + CpusState *base = CPUS(dev); Object *cluster_obj = OBJECT(dev); - CallbackData cbdata = { - .cluster = cluster, - .cpu_count = 0, - }; - if (cluster->cluster_id >= MAX_CLUSTERS) { - error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS); - return; - } + /* This is a special legacy case */ + assert(base->topology.cpus == 0); + assert(base->cpu_type == NULL); + assert(base->is_cluster); - object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, &cbdata); + /* Iterate through all our CPU children and set their cluster_index */ + object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, base); /* * A cluster with no CPUs is a bug in the board/SoC code that created it; @@ -71,24 +60,39 @@ static void cpu_cluster_realize(DeviceState *dev, Error **errp) * created the CPUs and parented them into the cluster object before * realizing the cluster object. */ - assert(cbdata.cpu_count > 0); + assert(base->topology.cpus > 0); + + /* realize base class (will set cluster field to true) */ + ccc->parent_realize(dev, errp); + + /* + * Temporarily copy the cluster id from the base class as + * gdbstub still uses our field. + */ + cluster->cluster_id = base->cluster_index; } static void cpu_cluster_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + CPUClusterClass *ccc = CPU_CLUSTER_CLASS(klass); + CpusClass *cc = CPUS_CLASS(klass); - device_class_set_props(dc, cpu_cluster_properties); - dc->realize = cpu_cluster_realize; + device_class_set_parent_realize(dc, cpu_cluster_realize, + &ccc->parent_realize); /* This is not directly for users, CPU children must be attached by code */ dc->user_creatable = false; + + /* Cpus are created by external code */ + cc->skip_cpus_creation = true; } static const TypeInfo cpu_cluster_type_info = { .name = TYPE_CPU_CLUSTER, - .parent = TYPE_DEVICE, + .parent = TYPE_CPUS, .instance_size = sizeof(CPUClusterState), + .class_size = sizeof(CPUClusterClass), .class_init = cpu_cluster_class_init, };