From patchwork Tue Jun 19 01:41:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10472837 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 8F3AC6032A for ; Tue, 19 Jun 2018 01:57:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C243289E5 for ; Tue, 19 Jun 2018 01:57:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FD1C28B3E; Tue, 19 Jun 2018 01:57:06 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 E60D2289E5 for ; Tue, 19 Jun 2018 01:57:05 +0000 (UTC) Received: from localhost ([::1]:38429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5tJ-0001v3-1R for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jun 2018 21:57:05 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = (cc->core_id * spapr->vsmt / smp_threads) + i where: cc->core_id is a multiple of smp_threads cpu_index = cc->core_id + i 0 <= i < smp_threads So we have: cpu_index % smp_threads == i cc->core_id / smp_threads == cpu_index / smp_threads hence: vcpu_id = (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) } } +void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp) +{ + sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); + int vcpu_id; + + vcpu_id = + (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 = 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, Error **errp) cs = CPU(obj); cpu = POWERPC_CPU(cs); cs->cpu_index = cc->core_id + i; - cpu->vcpu_id = (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 core\n", - cpu->vcpu_id * smp_threads / spapr->vsmt); + spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); + if (local_err) { goto err; } 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)) 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); int spapr_caps_pre_load(void *opaque);