From patchwork Wed Jul 6 12:14:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9216295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 74F1D60752 for ; Wed, 6 Jul 2016 12:25:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C4C28832 for ; Wed, 6 Jul 2016 12:25:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5963A2888D; Wed, 6 Jul 2016 12:25:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A742328832 for ; Wed, 6 Jul 2016 12:25:37 +0000 (UTC) Received: from localhost ([::1]:33299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKltZ-0001LM-09 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 08:25:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKljh-0007aa-63 for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:15:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKljb-0002yT-WF for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:15:24 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKljb-0002yJ-OO for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:15:19 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u66CEBiw101681 for ; Wed, 6 Jul 2016 08:15:19 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 240ndx5gb1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 06 Jul 2016 08:15:19 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jul 2016 06:15:18 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Jul 2016 06:15:03 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id BE8AC3E4003F; Wed, 6 Jul 2016 06:15:02 -0600 (MDT) Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u66CF22M61669554; Wed, 6 Jul 2016 05:15:02 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 74FF4C6037; Wed, 6 Jul 2016 06:15:02 -0600 (MDT) Received: from bahia.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.41]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id C6C7DC6042; Wed, 6 Jul 2016 06:15:00 -0600 (MDT) From: Greg Kurz To: David Gibson Date: Wed, 06 Jul 2016 14:14:59 +0200 In-Reply-To: <146780713904.26232.12351310667258006783.stgit@bahia.lab.toulouse-stg.fr.ibm.com> References: <146780713904.26232.12351310667258006783.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16070612-0008-0000-0000-000004FD5007 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16070612-0009-0000-0000-0000390F2BEA Message-Id: <146780729482.26232.15157160444569956720.stgit@bahia.lab.toulouse-stg.fr.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-07-06_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607060109 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v3 7/7] spapr: consolidate the logic of core cpu_dt_id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Alexander Graf , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Cedric Le Goater , Bharata B Rao , Scott Wood , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP POWER5 and newer cpus from IBM have a specific numbering scheme for DT ids. This is currently open coded in several places. This patch consolidates the logic in helpers. Suggested-by: Bharata B Rao Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 11 ++++------- hw/ppc/spapr_cpu_core.c | 26 +++++++++++++++++++------- include/hw/ppc/spapr_cpu_core.h | 9 +++++++++ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index baefc7bd279c..89e61b976c60 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -199,7 +199,6 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *spapr) int ret = 0, offset, cpus_offset; CPUState *cs; char cpu_model[32]; - int smt = kvmppc_smt_threads(); uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)}; CPU_FOREACH(cs) { @@ -207,7 +206,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *spapr) DeviceClass *dc = DEVICE_GET_CLASS(cs); int index = ppc_get_vcpu_dt_id(cpu); - if ((index % smt) != 0) { + if (!spapr_core_dt_id_is_valid(index)) { continue; } @@ -735,7 +734,6 @@ static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spapr) CPUState *cs; int cpus_offset; char *nodename; - int smt = kvmppc_smt_threads(); cpus_offset = fdt_add_subnode(fdt, 0, "cpus"); _FDT(cpus_offset); @@ -753,7 +751,7 @@ static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spapr) DeviceClass *dc = DEVICE_GET_CLASS(cs); int offset; - if ((index % smt) != 0) { + if (!spapr_core_dt_id_is_valid(index)) { continue; } @@ -1822,7 +1820,7 @@ static void ppc_spapr_init(MachineState *machine) spapr->cores = g_new0(Object *, spapr_max_cores); for (i = 0; i < spapr_max_cores; i++) { - int core_dt_id = i * smt; + int core_dt_id = spapr_core_index_to_dt_id(i); sPAPRDRConnector *drc = spapr_dr_connector_new(OBJECT(spapr), SPAPR_DR_CONNECTOR_TYPE_CPU, core_dt_id); @@ -2386,7 +2384,6 @@ static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine) HotpluggableCPUList *head = NULL; sPAPRMachineState *spapr = SPAPR_MACHINE(machine); int spapr_max_cores = max_cpus / smp_threads; - int smt = kvmppc_smt_threads(); for (i = 0; i < spapr_max_cores; i++) { HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1); @@ -2396,7 +2393,7 @@ static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine) cpu_item->type = spapr_get_cpu_core_type(machine->cpu_model); cpu_item->vcpus_count = smp_threads; cpu_props->has_core_id = true; - cpu_props->core_id = i * smt; + cpu_props->core_id = spapr_core_index_to_dt_id(i); /* TODO: add 'has_node/node' here to describe to which node core belongs */ diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index e3a3024baf32..b104778350df 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -103,7 +103,6 @@ static void spapr_core_release(DeviceState *dev, void *opaque) size_t size = object_type_get_instance_size(typename); sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); CPUCore *cc = CPU_CORE(dev); - int smt = kvmppc_smt_threads(); int i; for (i = 0; i < cc->nr_threads; i++) { @@ -117,7 +116,7 @@ static void spapr_core_release(DeviceState *dev, void *opaque) object_unparent(obj); } - spapr->cores[cc->core_id / smt] = NULL; + spapr->cores[spapr_dt_id_to_core_index(cc->core_id)] = NULL; g_free(sc->threads); object_unparent(OBJECT(dev)); @@ -160,10 +159,9 @@ void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, void *fdt = NULL; int fdt_offset = 0; int index; - int smt = kvmppc_smt_threads(); drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id); - index = cc->core_id / smt; + index = spapr_dt_id_to_core_index(cc->core_id); spapr->cores[index] = OBJECT(dev); if (!smc->dr_cpu_enabled) { @@ -217,7 +215,6 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); int spapr_max_cores = max_cpus / smp_threads; int index; - int smt = kvmppc_smt_threads(); Error *local_err = NULL; CPUCore *cc = CPU_CORE(dev); char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model); @@ -238,12 +235,12 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, goto out; } - if (cc->core_id % smt) { + if (!spapr_core_dt_id_is_valid(cc->core_id)) { error_setg(&local_err, "invalid core id %d\n", cc->core_id); goto out; } - index = cc->core_id / smt; + index = spapr_dt_id_to_core_index(cc->core_id); if (index < 0 || index >= spapr_max_cores) { error_setg(&local_err, "core id %d out of range", cc->core_id); goto out; @@ -331,6 +328,21 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void *data) dc->realize = spapr_cpu_core_realize; } +unsigned spapr_core_index_to_dt_id(unsigned index) +{ + return index * kvmppc_smt_threads(); +} + +unsigned spapr_dt_id_to_core_index(unsigned dt_id) +{ + return dt_id / kvmppc_smt_threads(); +} + +unsigned spapr_dt_id_to_thread_index(unsigned dt_id) +{ + return dt_id % kvmppc_smt_threads(); +} + /* * instance_init routines from different flavours of sPAPR CPU cores. */ diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 1c9b3195cce9..be7be91308ce 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -33,4 +33,13 @@ void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); + +unsigned spapr_core_index_to_dt_id(unsigned index); +unsigned spapr_dt_id_to_core_index(unsigned dt_id); +unsigned spapr_dt_id_to_thread_index(unsigned dt_id); + +static inline bool spapr_core_dt_id_is_valid(unsigned dt_id) +{ + return spapr_dt_id_to_thread_index(dt_id) == 0; +} #endif