From patchwork Wed Jun 29 20:51:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9206205 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 1E47560757 for ; Wed, 29 Jun 2016 20:59:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C50B28662 for ; Wed, 29 Jun 2016 20:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00A0D2866F; Wed, 29 Jun 2016 20:59:21 +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 0772B28662 for ; Wed, 29 Jun 2016 20:59:21 +0000 (UTC) Received: from localhost ([::1]:45759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMZs-000821-61 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 Jun 2016 16:59:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMSw-0000pp-F4 for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:52:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIMSr-0002L7-Bf for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:52:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:13535 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMSq-0002Ke-Vn for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:52:05 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5TKhRtr006981 for ; Wed, 29 Jun 2016 16:52:04 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 23uvaev6vj-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 29 Jun 2016 16:52:03 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Jun 2016 14:52:03 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Jun 2016 14:51:59 -0600 X-IBM-Helo: d03dlp03.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 d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 2EA9A19D8026; Wed, 29 Jun 2016 14:51:37 -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 u5TKpxK761472860; Wed, 29 Jun 2016 13:51:59 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D91EC604C; Wed, 29 Jun 2016 14:51:59 -0600 (MDT) Received: from bahia.lan (unknown [9.164.167.94]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 4436DC6042; Wed, 29 Jun 2016 14:51:51 -0600 (MDT) From: Greg Kurz To: David Gibson Date: Wed, 29 Jun 2016 22:51:50 +0200 In-Reply-To: <146723340662.9665.6413150884317978000.stgit@bahia.lan> References: <146723340662.9665.6413150884317978000.stgit@bahia.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062920-0024-0000-0000-000014014731 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062920-0025-0000-0000-0000424445F7 Message-Id: <146723351048.9665.9665959488204905423.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-29_11:, , 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-1606290192 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 8/8] hw/ppc: move DT cpu id generation to machine code 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: Peter Crosthwaite , qemu-devel@nongnu.org, Alexander Graf , qemu-ppc@nongnu.org, Cedric Le Goater , bharata@linux.vnet.ibm.com, Scott Wood , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that cpu_index is computed at cpu initialization time, we can compute cpu_dt_id in the machine code. All the logic moves from ppc_cpu_realizefn() to a generic function in the machine code, that serves as the default for all machine types. A new ppc_cpu_init() helper is also added to be used instead of the current cpu_ppc_init() from the target code. It allows each machine type to use the default numbering logic or to provide its own one, which will be called just before realizing the cpu. This has no impact on user mode since all of this is for system mode only. Signed-off-by: Greg Kurz --- hw/ppc/e500.c | 2 + hw/ppc/mac_newworld.c | 2 + hw/ppc/mac_oldworld.c | 2 + hw/ppc/ppc.c | 60 +++++++++++++++++++++++++++++++++++++++++++ hw/ppc/ppc440_bamboo.c | 2 + hw/ppc/ppc4xx_devs.c | 2 + hw/ppc/prep.c | 2 + hw/ppc/spapr.c | 2 + hw/ppc/spapr_cpu_core.c | 7 +++++ hw/ppc/virtex_ml507.c | 2 + include/hw/ppc/ppc.h | 4 +++ target-ppc/translate_init.c | 30 ---------------------- 12 files changed, 79 insertions(+), 38 deletions(-) diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 0cd534df55f8..a8153448c4d4 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -820,9 +820,9 @@ void ppce500_init(MachineState *machine, PPCE500Params *params) PowerPCCPU *cpu; CPUState *cs; qemu_irq *input; - cpu = cpu_ppc_init(machine->cpu_model); + cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to initialize CPU!\n"); exit(1); } diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 32e88b378687..5d4c28cdb5b2 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -192,9 +192,9 @@ static void ppc_core99_init(MachineState *machine) machine->cpu_model = "G4"; #endif } for (i = 0; i < smp_cpus; i++) { - cpu = cpu_ppc_init(machine->cpu_model); + cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 447948746b1a..3ebabd7f203b 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -112,9 +112,9 @@ static void ppc_heathrow_init(MachineState *machine) /* init CPUs */ if (machine->cpu_model == NULL) machine->cpu_model = "G3"; for (i = 0; i < smp_cpus; i++) { - cpu = cpu_ppc_init(machine->cpu_model); + cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index e4252528a69d..c234b7adfd43 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -36,8 +36,9 @@ #include "hw/loader.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" #include "trace.h" +#include "qapi/error.h" //#define PPC_DEBUG_IRQ //#define PPC_DEBUG_TB @@ -1349,4 +1350,63 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id) } return NULL; } + +void ppc_cpu_compute_dt_id_generic(PowerPCCPU *cpu, Error **errp) +{ + CPUState *cs = CPU(cpu); + int max_smt = kvm_enabled() ? kvmppc_smt_threads() : 1; + + if (smp_threads > max_smt) { + error_setg(errp, "Cannot support more than %d threads on PPC with %s", + max_smt, kvm_enabled() ? "KVM" : "TCG"); + return; + } + if (!is_power_of_2(smp_threads)) { + error_setg(errp, "Cannot support %d threads on PPC with %s, " + "threads count must be a power of 2.", + smp_threads, kvm_enabled() ? "KVM" : "TCG"); + return; + } + + if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->cpu_dt_id)) { + error_setg(errp, "Can't create CPU with id %d in KVM", cpu->cpu_dt_id); + error_append_hint(errp, "Adjust the number of cpus to %d " + "or try to raise the number of threads per core\n", + cpu->cpu_dt_id * smp_threads / max_smt); + return; + } + + cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * max_smt + + (cs->cpu_index % smp_threads); +} + +PowerPCCPU *ppc_cpu_init(const char *cpu_model, cpu_compute_dt_id_fn compute_fn) +{ + PowerPCCPU *cpu; + Error *err = NULL; + + cpu = POWERPC_CPU(cpu_generic_init_no_realize(TYPE_POWERPC_CPU, cpu_model)); + if (cpu == NULL) { + return NULL; + } + + if (compute_fn) { + compute_fn(cpu, &err); + } else { + ppc_cpu_compute_dt_id_generic(cpu, &err); + } + if (err != NULL) { + goto out; + } + + object_property_set_bool(OBJECT(cpu), true, "realized", &err); +out: + if (err != NULL) { + error_report_err(err); + object_unref(OBJECT(cpu)); + return NULL; + } + + return cpu; +} diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c index 5c535b18a20d..c5ea15b1f732 100644 --- a/hw/ppc/ppc440_bamboo.c +++ b/hw/ppc/ppc440_bamboo.c @@ -185,9 +185,9 @@ static void bamboo_init(MachineState *machine) /* Setup CPU. */ if (machine->cpu_model == NULL) { machine->cpu_model = "440EP"; } - cpu = cpu_ppc_init(machine->cpu_model); + cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to initialize CPU!\n"); exit(1); } diff --git a/hw/ppc/ppc4xx_devs.c b/hw/ppc/ppc4xx_devs.c index e7f413e49d08..b28bca1b797b 100644 --- a/hw/ppc/ppc4xx_devs.c +++ b/hw/ppc/ppc4xx_devs.c @@ -55,9 +55,9 @@ PowerPCCPU *ppc4xx_init(const char *cpu_model, PowerPCCPU *cpu; CPUPPCState *env; /* init CPUs */ - cpu = cpu_ppc_init(cpu_model); + cpu = ppc_cpu_init(cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC %s CPU definition\n", cpu_model); exit(1); diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index 054af1e8b481..1bd3ede62114 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -508,9 +508,9 @@ static void ppc_prep_init(MachineState *machine) /* init CPUs */ if (machine->cpu_model == NULL) machine->cpu_model = "602"; for (i = 0; i < smp_cpus; i++) { - cpu = cpu_ppc_init(machine->cpu_model); + cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0771c93f6550..040c9158cce4 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1834,9 +1834,9 @@ static void ppc_spapr_init(MachineState *machine) } g_free(type); } else { for (i = 0; i < smp_cpus; i++) { - PowerPCCPU *cpu = cpu_ppc_init(machine->cpu_model); + PowerPCCPU *cpu = ppc_cpu_init(machine->cpu_model, NULL); if (cpu == NULL) { error_report("Unable to find PowerPC CPU definition"); exit(1); } diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index a15dc010626d..56f360cb6c7f 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -12,8 +12,9 @@ #include "hw/ppc/spapr.h" #include "hw/boards.h" #include "qapi/error.h" #include +#include #include "target-ppc/kvm_ppc.h" #include "hw/ppc/ppc.h" #include "target-ppc/mmu-hash64.h" #include @@ -265,8 +266,14 @@ static int spapr_cpu_core_realize_child(Object *child, void *opaque) sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); CPUState *cs = CPU(child); PowerPCCPU *cpu = POWERPC_CPU(cs); + ppc_cpu_compute_dt_id_generic(cpu, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return 1; + } + object_property_set_bool(child, true, "realized", &local_err); if (local_err) { error_propagate(errp, local_err); return 1; diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index b97d96685cf1..cf3e71b9f2cc 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -95,9 +95,9 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size, PowerPCCPU *cpu; CPUPPCState *env; qemu_irq *irqs; - cpu = cpu_ppc_init(cpu_model); + cpu = ppc_cpu_init(cpu_model, NULL); if (cpu == NULL) { fprintf(stderr, "Unable to initialize CPU!\n"); exit(1); } diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h index 5617dc4a2c04..3e6aa7e7720f 100644 --- a/include/hw/ppc/ppc.h +++ b/include/hw/ppc/ppc.h @@ -105,5 +105,9 @@ enum { /* ppc_booke.c */ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags); +typedef void (*cpu_compute_dt_id_fn)(PowerPCCPU *cpu, Error **errp); +PowerPCCPU *ppc_cpu_init(const char *cpu_model, + cpu_compute_dt_id_fn compute_fn); +void ppc_cpu_compute_dt_id_generic(PowerPCCPU *cpu, Error **errp); #endif diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index f7571f34d6ac..f9d1ee8b12f9 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -9522,45 +9522,15 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) CPUState *cs = CPU(dev); PowerPCCPU *cpu = POWERPC_CPU(dev); PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); Error *local_err = NULL; -#if !defined(CONFIG_USER_ONLY) - int max_smt = kvm_enabled() ? kvmppc_smt_threads() : 1; -#endif - -#if !defined(CONFIG_USER_ONLY) - if (smp_threads > max_smt) { - error_setg(errp, "Cannot support more than %d threads on PPC with %s", - max_smt, kvm_enabled() ? "KVM" : "TCG"); - return; - } - if (!is_power_of_2(smp_threads)) { - error_setg(errp, "Cannot support %d threads on PPC with %s, " - "threads count must be a power of 2.", - smp_threads, kvm_enabled() ? "KVM" : "TCG"); - return; - } -#endif cpu_exec_realize(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); return; } -#if !defined(CONFIG_USER_ONLY) - cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * max_smt - + (cs->cpu_index % smp_threads); - - if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->cpu_dt_id)) { - error_setg(errp, "Can't create CPU with id %d in KVM", cpu->cpu_dt_id); - error_append_hint(errp, "Adjust the number of cpus to %d " - "or try to raise the number of threads per core\n", - cpu->cpu_dt_id * smp_threads / max_smt); - return; - } -#endif - if (tcg_enabled()) { if (ppc_fixup_cpu(cpu) != 0) { error_setg(errp, "Unable to emulate selected CPU with TCG"); return;