From nobody Mon Feb 9 23:01:00 2026 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 1529373466292291.16757289715736; Mon, 18 Jun 2018 18:57:46 -0700 (PDT) Received: from localhost ([::1]:38429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5tt-0001v3-U9 for importer@patchew.org; Mon, 18 Jun 2018 21:57:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5gv-0000NM-7K for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:44:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5gt-0007nL-MI for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:44:17 -0400 Received: from mail-oi0-x242.google.com ([2607:f8b0:4003:c06::242]:40995) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5gt-0007mz-GZ; Mon, 18 Jun 2018 21:44:15 -0400 Received: by mail-oi0-x242.google.com with SMTP id a141-v6so16691792oii.8; Mon, 18 Jun 2018 18:44:15 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id q7-v6sm15879766otq.39.2018.06.18.18.44.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=1nyoRAdVyiFmu0+FgWK7Qu9UPHmyHAM39c9AxhYp7qE=; b=ZKpDYJ7gJFXw/tVQwCCefPQ+4j4Ys+6PnuEtpehkDQehlgskmDgM+72tHRMfCorGsM Rayrx2xAqXbLOWCdylX79rRjc0QlHTzNXJv/axaFNCVQCxf3O8dzKNiPkMUhBsWGFTpi 7sSvGZQkkbefJe3C+oEVzphBzIHn6z9sEbpIam39Ysq1O5n8nuEqoW/ecmRZ9WU6qZug dhOc3sscUPxV88hROVmMniGtecAi78hPyHmTEoJUvUSbsRbxXhBg4TbnGy97S2QJrxU1 I2aySAhmnNMEmjGgtdCOOCz2HYdWexa8+OWVg4mJs9BX3lBCfWfbnUi8FbSOSePacayE WhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=1nyoRAdVyiFmu0+FgWK7Qu9UPHmyHAM39c9AxhYp7qE=; b=tGNWHIqzP11crj1OFK8QCzXTVmigogoG+uS8T7MUAxwy+y3VzaZD0rZaW6gg8bOV9S H8dMU/l0YFcBMlu2qMy3VESjUhRXNQWftlwq3oCptfMkwc1BZjgXiN5uPLzO0/X7nFej zspxHNRBESaBPEBm0Mn7ZQZZOJ9UZL6R2fnNHBVttgp6V78hC5kMLORsXH3L6bXSpw9+ FrtbEUrmvH6akx7GypsPVgH11CRiTwEjmG0xLxp6lvGBp9niOgH7fel+WSSueAPpDj+p d/knoHC0gpz8JNtlll9ZUUlFavMuRVaTCx4aY2uiY0M6QzX26AZO7/k0n5ASA9/74gm8 oTNw== X-Gm-Message-State: APt69E31+sZSE+pcoWnZuB+tZmSrTgCKXFOzUpKGzDq9Rs2QKNK5sbpU ta/v9EWN9HxvgBWLpFDjI4buYaJw X-Google-Smtp-Source: ADUXVKISkUdOFWW9RYggccV6qlHUVkx5X92RJWzwpiqEi7sPwJcOFx2lH3zc8UPVCb69Bdvx688DzA== X-Received: by 2002:aca:480d:: with SMTP id v13-v6mr8713605oia.244.1529372654280; Mon, 18 Jun 2018 18:44:14 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:41:36 -0500 Message-Id: <20180619014319.28272-11-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::242 Subject: [Qemu-devel] [PATCH 010/113] 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: David Gibson , qemu-stable@nongnu.org, Greg Kurz 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 (cherry picked from commit 648edb64751ea0e550f36302fa66f9f11e480824) Signed-off-by: Greg Kurz --- 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 094e75f97d..f9505d926d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3647,6 +3647,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 e8b0ffb1b1..1c508022aa 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -176,13 +176,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, E= rror **errp) cs =3D CPU(obj); cpu =3D POWERPC_CPU(cs); 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 363ffd71c4..38a657426a 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -757,6 +757,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_caps_pre_load(void *opaque); --=20 2.11.0