From nobody Fri Oct 24 20:18:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518775915624536.9857675462529; Fri, 16 Feb 2018 02:11:55 -0800 (PST) Received: from localhost ([::1]:59104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emczi-00061u-PU for importer@patchew.org; Fri, 16 Feb 2018 05:11:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emcuV-0001bi-EY for qemu-devel@nongnu.org; Fri, 16 Feb 2018 05:06:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emcuT-0005D1-0J for qemu-devel@nongnu.org; Fri, 16 Feb 2018 05:06:31 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:56761) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emcuS-00057z-Iw; Fri, 16 Feb 2018 05:06:28 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zjTLl295Rz9t73; Fri, 16 Feb 2018 21:06:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1518775583; bh=kAOkXnbC+2B3/J6FIypr6HNt2R8CI+Y5VJo0/IeR1RI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bh0+8D4QG4AvtKc0cGwyaf5AUR4Tzmnp0cA15oYHeTUqz3tL10U7huHKJPCSUoRYp Ki/6JylEA2uXmmplARYDj89B+nwY/loCV2GdKWExVCzed1A1JdzQzetSb9T59iL42l KpvxTLyO0or/VmPo6T+SsSA734IHRHhlU6RSn6wo= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 16 Feb 2018 21:06:11 +1100 Message-Id: <20180216100617.25265-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180216100617.25265-1-david@gibson.dropbear.id.au> References: <20180216100617.25265-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 08/14] spapr: move VCPU calculation to core 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: lvivier@redhat.com, surajjs@au1.ibm.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz The VCPU ids are currently computed and assigned to each individual CPU threads in spapr_cpu_core_realize(). But the numbering logic of VCPU ids is actually a machine-level concept, and many places in hw/ppc/spapr.c also have to compute VCPU ids out of CPU indexes. The current formula used in spapr_cpu_core_realize() is: vcpu_id =3D (cc->core_id * spapr->vsmt / smp_threads) + i where: cc->core_id is a multiple of smp_threads cpu_index =3D cc->core_id + i 0 <=3D i < smp_threads So we have: cpu_index % smp_threads =3D=3D i cc->core_id / smp_threads =3D=3D cpu_index / smp_threads hence: vcpu_id =3D (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads; This formula was used before VSMT at the time VCPU ids where computed at the target emulation level. It has the advantage of being useable to derive a VPCU id out of a CPU index only. It is fitted for all the places where the machine code has to compute a VCPU id. This patch introduces an accessor to set the VCPU id in a PowerPCCPU object using the above formula. It is a first step to consolidate all the VCPU id logic in a single place. Signed-off-by: Greg Kurz Signed-off-by: David Gibson --- hw/ppc/spapr.c | 19 +++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 9 ++------- include/hw/ppc/spapr.h | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ea7429c92a..30cc48fd52 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3802,6 +3802,25 @@ int spapr_vcpu_id(PowerPCCPU *cpu) } } =20 +void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp) +{ + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + int vcpu_id; + + vcpu_id =3D + (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads; + + if (kvm_enabled() && !kvm_vcpu_id_is_valid(vcpu_id)) { + error_setg(errp, "Can't create CPU with id %d in KVM", vcpu_id); + error_append_hint(errp, "Adjust the number of cpus to %d " + "or try to raise the number of threads per core\= n", + vcpu_id * smp_threads / spapr->vsmt); + return; + } + + cpu->vcpu_id =3D vcpu_id; +} + PowerPCCPU *spapr_find_cpu(int vcpu_id) { CPUState *cs; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 590d167b04..94afeb399e 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -172,13 +172,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, E= rror **errp) cs =3D CPU(obj); cpu =3D sc->threads[i] =3D POWERPC_CPU(obj); cs->cpu_index =3D cc->core_id + i; - cpu->vcpu_id =3D (cc->core_id * spapr->vsmt / smp_threads) + i; - if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->vcpu_id)) { - error_setg(&local_err, "Can't create CPU with id %d in KVM", - cpu->vcpu_id); - error_append_hint(&local_err, "Adjust the number of cpus to %d= " - "or try to raise the number of threads per c= ore\n", - cpu->vcpu_id * smp_threads / spapr->vsmt); + spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); + if (local_err) { goto err; } =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 62c077ac20..af19320d2f 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -767,6 +767,7 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_= cpu_data arg); #define HTAB_SIZE(spapr) (1ULL << ((spapr)->htab_shift)) =20 int spapr_vcpu_id(PowerPCCPU *cpu); +void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp); PowerPCCPU *spapr_find_cpu(int vcpu_id); =20 int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi, --=20 2.14.3