From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519087855716.5966579659263; Sun, 17 Oct 2021 18:04:47 -0700 (PDT) Received: from localhost ([::1]:39428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH53-0000ko-Vb for importer@patchew.org; Sun, 17 Oct 2021 21:04:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2G-0006M4-FL; Sun, 17 Oct 2021 21:01:52 -0400 Received: from mail-ua1-x92a.google.com ([2607:f8b0:4864:20::92a]:33395) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2C-00009w-74; Sun, 17 Oct 2021 21:01:52 -0400 Received: by mail-ua1-x92a.google.com with SMTP id i15so2010244uap.0; Sun, 17 Oct 2021 18:01:47 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7hEts6owz/MoxbfBw+3jz6iXo5GERS/EWgUpoLMlsqc=; b=XM+36S1hdZAvjLDiWZnBLNLzdfguszm+/BhCYWjvc0queminjbbirY1YyGg84Ua5Ti LrDmexXC2Lr28hJdiI89bklnSNbgvT7jB2rr7sDl84azpYpLiax/J+y2yg+oXG3ce4jN gmrMBAucpM6z+aMAaEa5AS9h8Q0D6aEsAjHVj+fWh6M8NpMrDXLzItGm6osPrssRrMkF AOlRf8BL4h5TQmCLq9MHhFeKW/lVkGpeufG4je1E6GEJgcU1DVl0KFNJ5mIFTM89KKo6 p7z/ByTr2RO88dKaJAR/ljzRWGRXkJ74CSrna1AkU99s4QJFnCtl75Y4nDlwmnyfBpIk NHEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7hEts6owz/MoxbfBw+3jz6iXo5GERS/EWgUpoLMlsqc=; b=np+3b7OOOlvgFT716SS1euw+nuA2MQHBndigEYaYpqq93MCn3EFmkqkKLpVW/uuPiJ cQ3CPqM+ve+LYgkRpO4Ct0uOXonB2hp8p6Bgy6EVEEeur82HHwmDuBw+f5l48Bm/FYwH XgKEcNqhvbTt6pt/SiULw1wamHCO1pxm36q7Dq2sNfVQgz24Eu4JYxkQ3nWYuhrhxbfl qgOx4aF5V+m5Am74//32b0vRSiVRxD2ybopE3hJ2lRKawdLsFjYDDqUX8nUSp3MNGIBh DANU6yHjwwcCiMVMFDieNDp0ghbxyFfoJkiCoXPWv92CvnBmSaWAYvgAcX0wTa6UWLiT Ihyg== X-Gm-Message-State: AOAM531t5xZ42a4f+9FoxBCL7bsoMgBYT/btZSEr7gu1b3nZkE8+1aj8 eGDlHJUMIW+IZDZbCVTIaYGDaskWhQ8= X-Google-Smtp-Source: ABdhPJzRtW5gnjrbBFclcvdXT/N/6HNaASn0xtqlY9FjLNW0EPqwo0oo9GZx7YG5L/SP/IVGK0Zs8g== X-Received: by 2002:ab0:58c1:: with SMTP id r1mr23059498uac.89.1634518906959; Sun, 17 Oct 2021 18:01:46 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 01/15] target/ppc: add MMCR0 PMCC bits to hflags Date: Sun, 17 Oct 2021 22:01:19 -0300 Message-Id: <20211018010133.315842-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::92a; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x92a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519089147100001 Content-Type: text/plain; charset="utf-8" We're going to add PMU support for TCG PPC64 chips, based on IBM POWER8+ emulation and following PowerISA v3.1. This requires several PMU related registers to be exposed to userspace (problem state). PowerISA v3.1 dictates that the PMCC bits of the MMCR0 register controls the level of access of the PMU registers to problem state. This patch start things off by exposing both PMCC bits to hflags, allowing us to access them via DisasContext in the read/write callbacks that we're going to add next. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 6 ++++++ target/ppc/helper_regs.c | 6 ++++++ target/ppc/translate.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index baa4e7c34d..0df1a5a970 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -342,6 +342,10 @@ typedef struct ppc_v3_pate_t { #define MSR_RI 1 /* Recoverable interrupt 1 = */ #define MSR_LE 0 /* Little-endian mode 1 hfla= gs */ =20 +/* PMU bits */ +#define MMCR0_PMCC0 PPC_BIT(44) /* PMC Control bit 0 */ +#define MMCR0_PMCC1 PPC_BIT(45) /* PMC Control bit 1 */ + /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) #define LPCR_VPM1 PPC_BIT(1) @@ -607,6 +611,8 @@ enum { HFLAGS_SE =3D 10, /* MSR_SE -- from elsewhere on embedded ppc */ HFLAGS_FP =3D 13, /* MSR_FP */ HFLAGS_PR =3D 14, /* MSR_PR */ + HFLAGS_PMCC0 =3D 15, /* MMCR0 PMCC bit 0 */ + HFLAGS_PMCC1 =3D 16, /* MMCR0 PMCC bit 1 */ HFLAGS_VSX =3D 23, /* MSR_VSX if cpu has VSX */ HFLAGS_VR =3D 25, /* MSR_VR if cpu has VRE */ =20 diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c index 1bfb480ecf..99562edd57 100644 --- a/target/ppc/helper_regs.c +++ b/target/ppc/helper_regs.c @@ -109,6 +109,12 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState = *env) if (env->spr[SPR_LPCR] & LPCR_HR) { hflags |=3D 1 << HFLAGS_HR; } + if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCC0) { + hflags |=3D 1 << HFLAGS_PMCC0; + } + if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCC1) { + hflags |=3D 1 << HFLAGS_PMCC1; + } =20 #ifndef CONFIG_USER_ONLY if (!env->has_hv_mode || (msr & (1ull << MSR_HV))) { diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 9ca78ee156..70ae4bda92 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -176,6 +176,8 @@ struct DisasContext { bool tm_enabled; bool gtse; bool hr; + bool mmcr0_pmcc0; + bool mmcr0_pmcc1; ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ int singlestep_enabled; uint32_t flags; @@ -8559,6 +8561,8 @@ static void ppc_tr_init_disas_context(DisasContextBas= e *dcbase, CPUState *cs) ctx->tm_enabled =3D (hflags >> HFLAGS_TM) & 1; ctx->gtse =3D (hflags >> HFLAGS_GTSE) & 1; ctx->hr =3D (hflags >> HFLAGS_HR) & 1; + ctx->mmcr0_pmcc0 =3D (hflags >> HFLAGS_PMCC0) & 1; + ctx->mmcr0_pmcc1 =3D (hflags >> HFLAGS_PMCC1) & 1; =20 ctx->singlestep_enabled =3D 0; if ((hflags >> HFLAGS_SE) & 1) { --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519297550583.2370944647863; Sun, 17 Oct 2021 18:08:17 -0700 (PDT) Received: from localhost ([::1]:47914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH8S-0006Tl-Bt for importer@patchew.org; Sun, 17 Oct 2021 21:08:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2K-0006S9-Sr; Sun, 17 Oct 2021 21:01:56 -0400 Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]:38554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2G-0000GP-Fq; Sun, 17 Oct 2021 21:01:55 -0400 Received: by mail-ua1-x929.google.com with SMTP id h19so3759559uax.5; Sun, 17 Oct 2021 18:01:50 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VLeaPtsf9SonR74eEhtsqiftN2+G2XqsE+fpRDQJqMo=; b=Ni3ErA0l2HO90bzXzR4ngqFT5KzGxJV6KAmHZADWxx9JfRdrnAei6f1GJFNiTkKew9 eYhJ2G5XvVnIJrtBC9D1NOJJ3rX7an1/nUTf4n7sFURc6VSon2inmPP/iLzWU5rpM6Vg X2/8PHsYlfPH89jyTQrEWeaG2EV1f+HILPyuWQJYVXtkYW8PGZG2t4L9tBEzLg2L7cmb 1LmLN52hfuECeMEyWqWHBpO0jXh8Jb8ZFurNmDsKOLOpIIY0WTdQBPJLfbOnf21l3SKz 6/PJgfh3LZWautCd0s/Nk1sHc6R/gb8hS4kFvs+P+U4E7UHAqq+qJk08bXn71BK+HjOp Hd6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VLeaPtsf9SonR74eEhtsqiftN2+G2XqsE+fpRDQJqMo=; b=GuNZVk0c4wOR4uE7AS4/36lad7qQEh25ip69dtI4Rkxis05SrFdDsKQuxdizABDb4G hNUoqmuF03DlC0+LCRh7OGFvilll46bxuf5z9cLJXJn+nlgiYEbLtSx074KTxhWQsp+a 87q/51nur3fVHGtZDFBTMQcQB+w2IBU9ojMMMRqpoOAWjYboEPB+897k/I5Y17Mv/EYT /ZzEB4QLVj9WyF1gFRgSYUopSh4Ky5OZUdzIyfOdue4y6wBOYnPATiOnG1rMqKJ5mj27 8T9XnEg4JEbuccKwYxDBDEwaR03tJRLd3coOCz5jfYe5U4+uKE9yuEZdoJF060PNZA8z uuHg== X-Gm-Message-State: AOAM531MDg5koi5ivzwyZdPYKhvhmEtYqH1pSKG/kWVNM7J4pKVJW93k SSd/zjImo6k+g4YXUNqgPsbZ0VT9JFk= X-Google-Smtp-Source: ABdhPJxh1HSux2116KFDQ5oTLyELawD9WDmpq8YV7S7fMsDFBpZzuEkwKthOyakNg97rrrVBsCRoEQ== X-Received: by 2002:a67:d393:: with SMTP id b19mr24642416vsj.33.1634518909300; Sun, 17 Oct 2021 18:01:49 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 02/15] target/ppc: add user read/write functions for MMCR0 Date: Sun, 17 Oct 2021 22:01:20 -0300 Message-Id: <20211018010133.315842-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::929; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x929.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gustavo Romero , Gustavo Romero , Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519298495100001 Content-Type: text/plain; charset="utf-8" From: Gustavo Romero Userspace need access to PMU SPRs to be able to operate the PMU. One of such SPRs is MMCR0. MMCR0, as defined by PowerISA v3.1, is classified as a 'group A' PMU register. This class of registers has common read/write rules that are governed by MMCR0 PMCC bits. MMCR0 is also not fully exposed to problem state: only MMCR0_FC, MMCR0_PMAO and MMCR0_PMAE bits are readable/writable in this case. This patch exposes MMCR0 to userspace by doing the following: - two new callbacks, spr_read_MMCR0_ureg() and spr_write_MMCR0_ureg(), are added to be used as problem state read/write callbacks of UMMCR0. Both callbacks filters the amount of bits userspace is able to read/write by using a MMCR0_UREG_MASK; - problem state access control is done by the spr_groupA_read_allowed() and spr_groupA_write_allowed() helpers. These helpers will read the current PMCC bits from DisasContext and check whether the read/write MMCR0 operation is valid or noti; - to avoid putting exclusive PMU logic into the already loaded translate.c file, let's create a new 'power8-pmu-regs.c.inc' file that will hold all the spr_read/spr_write functions of PMU registers. The 'power8' name of this new file intends to hint about the proven support of the PMU logic to be added. The code has been tested with the IBM POWER chip family, POWER8 being the oldest version tested. This doesn't mean that the PMU logic will break with any other PPC64 chip that implements Book3s, but rather that we can't assert that it works properly with any Book3s compliant chip. CC: Gustavo Romero Signed-off-by: Gustavo Romero Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 7 ++ target/ppc/cpu_init.c | 2 +- target/ppc/power8-pmu-regs.c.inc | 116 +++++++++++++++++++++++++++++++ target/ppc/spr_tcg.h | 2 + target/ppc/translate.c | 2 + 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 target/ppc/power8-pmu-regs.c.inc diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 0df1a5a970..7f80c0bb19 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -343,8 +343,15 @@ typedef struct ppc_v3_pate_t { #define MSR_LE 0 /* Little-endian mode 1 hfla= gs */ =20 /* PMU bits */ +#define MMCR0_FC PPC_BIT(32) /* Freeze Counters */ +#define MMCR0_PMAO PPC_BIT(56) /* Perf Monitor Alert Ocurred */ +#define MMCR0_PMAE PPC_BIT(37) /* Perf Monitor Alert Enable */ +#define MMCR0_EBE PPC_BIT(43) /* Perf Monitor EBB Enable */ +#define MMCR0_FCECE PPC_BIT(38) /* FC on Enabled Cond or Event */ #define MMCR0_PMCC0 PPC_BIT(44) /* PMC Control bit 0 */ #define MMCR0_PMCC1 PPC_BIT(45) /* PMC Control bit 1 */ +/* MMCR0 userspace r/w mask */ +#define MMCR0_UREG_MASK (MMCR0_FC | MMCR0_PMAO | MMCR0_PMAE) =20 /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 6aad01d1d3..375bdca1e1 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6867,7 +6867,7 @@ static void register_book3s_pmu_sup_sprs(CPUPPCState = *env) static void register_book3s_pmu_user_sprs(CPUPPCState *env) { spr_register(env, SPR_POWER_UMMCR0, "UMMCR0", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_MMCR0_ureg, &spr_write_MMCR0_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UMMCR1, "UMMCR1", diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc new file mode 100644 index 0000000000..37c812dd4d --- /dev/null +++ b/target/ppc/power8-pmu-regs.c.inc @@ -0,0 +1,116 @@ +/* + * PMU register read/write functions for TCG IBM POWER chips + * + * Copyright IBM Corp. 2021 + * + * Authors: + * Daniel Henrique Barboza + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) + +/* + * Checks whether the Group A SPR (MMCR0, MMCR2, MMCRA, and the + * PMCs) has problem state read access. + * + * Read acccess is granted for all PMCC values but 0b01, where a + * Facility Unavailable Interrupt will occur. + */ +static bool spr_groupA_read_allowed(DisasContext *ctx) +{ + if (!ctx->mmcr0_pmcc0 && ctx->mmcr0_pmcc1) { + gen_hvpriv_exception(ctx, POWERPC_EXCP_FU); + return false; + } + + return true; +} + +/* + * Checks whether the Group A SPR (MMCR0, MMCR2, MMCRA, and the + * PMCs) has problem state write access. + * + * Write acccess is granted for PMCC values 0b10 and 0b11. Userspace + * writing with PMCC 0b00 will generate a Hypervisor Emulation + * Assistance Interrupt. Userspace writing with PMCC 0b01 will + * generate a Facility Unavailable Interrupt. + */ +static bool spr_groupA_write_allowed(DisasContext *ctx) +{ + if (ctx->mmcr0_pmcc0) { + return true; + } + + if (ctx->mmcr0_pmcc1) { + /* PMCC =3D 0b01 */ + gen_hvpriv_exception(ctx, POWERPC_EXCP_FU); + } else { + /* PMCC =3D 0b00 */ + gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR); + } + + return false; +} + +void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) +{ + TCGv t0; + + if (!spr_groupA_read_allowed(ctx)) { + return; + } + + t0 =3D tcg_temp_new(); + + /* + * Filter out all bits but FC, PMAO, and PMAE, according + * to ISA v3.1, in 10.4.4 Monitor Mode Control Register 0, + * fourth paragraph. + */ + gen_load_spr(t0, SPR_POWER_MMCR0); + tcg_gen_andi_tl(t0, t0, MMCR0_UREG_MASK); + tcg_gen_mov_tl(cpu_gpr[gprn], t0); + + tcg_temp_free(t0); +} + +void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn) +{ + TCGv t0, t1; + + if (!spr_groupA_write_allowed(ctx)) { + return; + } + + t0 =3D tcg_temp_new(); + t1 =3D tcg_temp_new(); + + /* + * Filter out all bits but FC, PMAO, and PMAE, according + * to ISA v3.1, in 10.4.4 Monitor Mode Control Register 0, + * fourth paragraph. + */ + tcg_gen_andi_tl(t0, cpu_gpr[gprn], MMCR0_UREG_MASK); + gen_load_spr(t1, SPR_POWER_MMCR0); + tcg_gen_andi_tl(t1, t1, ~(MMCR0_UREG_MASK)); + /* Keep all other bits intact */ + tcg_gen_or_tl(t1, t1, t0); + gen_store_spr(SPR_POWER_MMCR0, t1); + + tcg_temp_free(t0); + tcg_temp_free(t1); +} +#else +void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) +{ + spr_read_ureg(ctx, gprn, sprn); +} + +void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn) +{ + spr_noaccess(ctx, gprn, sprn); +} +#endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index 0be5f347d5..b28b095097 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -32,6 +32,7 @@ void spr_write_lr(DisasContext *ctx, int sprn, int gprn); void spr_read_ctr(DisasContext *ctx, int gprn, int sprn); void spr_write_ctr(DisasContext *ctx, int sprn, int gprn); void spr_read_ureg(DisasContext *ctx, int gprn, int sprn); +void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_tbl(DisasContext *ctx, int gprn, int sprn); void spr_read_tbu(DisasContext *ctx, int gprn, int sprn); void spr_read_atbl(DisasContext *ctx, int gprn, int sprn); @@ -40,6 +41,7 @@ void spr_read_601_rtcl(DisasContext *ctx, int gprn, int s= prn); void spr_read_601_rtcu(DisasContext *ctx, int gprn, int sprn); void spr_read_spefscr(DisasContext *ctx, int gprn, int sprn); void spr_write_spefscr(DisasContext *ctx, int sprn, int gprn); +void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn); =20 #ifndef CONFIG_USER_ONLY void spr_write_generic32(DisasContext *ctx, int sprn, int gprn); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 70ae4bda92..96e8703dd1 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7491,6 +7491,8 @@ static int times_4(DisasContext *ctx, int x) =20 #include "decode-insn32.c.inc" #include "decode-insn64.c.inc" +#include "power8-pmu-regs.c.inc" + #include "translate/fixedpoint-impl.c.inc" =20 #include "translate/fp-impl.c.inc" --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519145160224.06184875086728; Sun, 17 Oct 2021 18:05:45 -0700 (PDT) Received: from localhost ([::1]:40808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH5z-0001fZ-UU for importer@patchew.org; Sun, 17 Oct 2021 21:05:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2I-0006Q3-Vm; Sun, 17 Oct 2021 21:01:55 -0400 Received: from mail-ua1-x930.google.com ([2607:f8b0:4864:20::930]:39675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2G-0000OS-O0; Sun, 17 Oct 2021 21:01:54 -0400 Received: by mail-ua1-x930.google.com with SMTP id f3so4747022uap.6; Sun, 17 Oct 2021 18:01:51 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AIvWPIZ2Fn+i8wFGE6eCUtLiYegQxGyN5/d03AXIMds=; b=HtVqpVV3ZbyECn7iQ2vhFi4/8SmP94KBgUpLpHy+vcnuaoi/W1L2GRxaF2xm/kfm2m 9c4MFKKXKYaThr80t4dHU4ymUSnCkKr3b8xHOVV/8molvou/U2cEExp27E8PpNTETd65 DMXF+G/wr1T/oWQdHhYSHzoOpTHTinH8bR0c7kq2sEBkeysxN79zjn73Hp1skPDWh4/v h9vbDIYwO5owum/W/vB28Ns9WY89K9n2LzHQOoMS/P5hGs2zTATkkFmhRVNHkFnY+gUt krPFafSHKjqlhJySta+oNv/fUXn1QbuYVr81RkXq2yZ8gYT4Y1bKmqqyrnHKBEruj/O0 ccbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AIvWPIZ2Fn+i8wFGE6eCUtLiYegQxGyN5/d03AXIMds=; b=YcFL6r7cgpvXQqa/F98XVNUr4t9Z+Us+mlZpFDvo7GwfFajO1qkIHDj2ck318VgJ7u IcfDjhuskooZxVThFioRv6hPQ6AYMDyA5E8kF1zag7l38+dF5PO+4RtFoZroph26rUej lGMbn7mwEkdeC+Lrbkwj7RJAx9m2RrjJWI8ou6wzVbo90r1SuDYoV8iic3ljDg4LWBMr +sIoquyYzQnzmRoROC3/G8vVhTXHfbnRlRemlq2qMmDSr/RV53hergdiaypQ2xY2j78A sx6Le4XNieLByktn6qc6bg+RQf5W6xPqNEh25otWsCiNzsWmrdgKhFlLwWZ1RRpRW+sO MYmA== X-Gm-Message-State: AOAM532mBKzHtlW8O9wYzj7pJvpLpYidGBtBUs+jr+FQqB+g5aCx55q+ jEuHBXK/K0K69cxSnNQUQllUeFNw6N0= X-Google-Smtp-Source: ABdhPJzmnjueWfriN0oCXQ9F/NKFQiw/PuApJASTfFETLv4C6NeReQy9MHeJEcjyASG4JVvFP/7fKg== X-Received: by 2002:a67:741:: with SMTP id 62mr25602396vsh.52.1634518911389; Sun, 17 Oct 2021 18:01:51 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 03/15] target/ppc: add user read/write functions for MMCR2 Date: Sun, 17 Oct 2021 22:01:21 -0300 Message-Id: <20211018010133.315842-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::930; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x930.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519147529100001 Content-Type: text/plain; charset="utf-8" Similar to the previous patch, let's add problem state read/write access to the MMCR2 SPR, which is also a group A PMU SPR that needs to be filtered to be read/written by userspace. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 9 +++ target/ppc/cpu_init.c | 2 +- target/ppc/power8-pmu-regs.c.inc | 98 ++++++++++++++++++++++++++++---- target/ppc/spr_tcg.h | 2 + 4 files changed, 99 insertions(+), 12 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 7f80c0bb19..33e3a91f6f 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -352,6 +352,15 @@ typedef struct ppc_v3_pate_t { #define MMCR0_PMCC1 PPC_BIT(45) /* PMC Control bit 1 */ /* MMCR0 userspace r/w mask */ #define MMCR0_UREG_MASK (MMCR0_FC | MMCR0_PMAO | MMCR0_PMAE) +/* MMCR2 userspace r/w mask */ +#define MMCR2_FC1P0 PPC_BIT(1) /* MMCR2 FCnP0 for PMC1 */ +#define MMCR2_FC2P0 PPC_BIT(10) /* MMCR2 FCnP0 for PMC2 */ +#define MMCR2_FC3P0 PPC_BIT(19) /* MMCR2 FCnP0 for PMC3 */ +#define MMCR2_FC4P0 PPC_BIT(28) /* MMCR2 FCnP0 for PMC4 */ +#define MMCR2_FC5P0 PPC_BIT(37) /* MMCR2 FCnP0 for PMC5 */ +#define MMCR2_FC6P0 PPC_BIT(46) /* MMCR2 FCnP0 for PMC6 */ +#define MMCR2_UREG_MASK (MMCR2_FC1P0 | MMCR2_FC2P0 | MMCR2_FC3P0 | \ + MMCR2_FC4P0 | MMCR2_FC5P0 | MMCR2_FC6P0) =20 /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 375bdca1e1..ad88e54950 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6975,7 +6975,7 @@ static void register_power8_pmu_sup_sprs(CPUPPCState = *env) static void register_power8_pmu_user_sprs(CPUPPCState *env) { spr_register(env, SPR_POWER_UMMCR2, "UMMCR2", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_MMCR2_ureg, &spr_write_MMCR2_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_USIER, "USIER", diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index 37c812dd4d..fb95175183 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -55,6 +55,33 @@ static bool spr_groupA_write_allowed(DisasContext *ctx) return false; } =20 +/* + * Helper function to avoid code repetition between MMCR0 and + * MMCR2 problem state write functions. + * + * 'ret' must be tcg_temp_freed() by the caller. + */ +static TCGv masked_gprn_for_spr_write(int gprn, int sprn, + uint64_t spr_mask) +{ + TCGv ret =3D tcg_temp_new(); + TCGv t0 =3D tcg_temp_new(); + + /* 'ret' starts with all mask bits cleared */ + gen_load_spr(ret, sprn); + tcg_gen_andi_tl(ret, ret, ~(spr_mask)); + + /* Apply the mask into 'gprn' in a temp var */ + tcg_gen_andi_tl(t0, cpu_gpr[gprn], spr_mask); + + /* Add the masked gprn bits into 'ret' */ + tcg_gen_or_tl(ret, ret, t0); + + tcg_temp_free(t0); + + return ret; +} + void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) { TCGv t0; @@ -79,29 +106,68 @@ void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, = int sprn) =20 void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn) { - TCGv t0, t1; + TCGv masked_gprn; =20 if (!spr_groupA_write_allowed(ctx)) { return; } =20 - t0 =3D tcg_temp_new(); - t1 =3D tcg_temp_new(); - /* * Filter out all bits but FC, PMAO, and PMAE, according * to ISA v3.1, in 10.4.4 Monitor Mode Control Register 0, * fourth paragraph. */ - tcg_gen_andi_tl(t0, cpu_gpr[gprn], MMCR0_UREG_MASK); - gen_load_spr(t1, SPR_POWER_MMCR0); - tcg_gen_andi_tl(t1, t1, ~(MMCR0_UREG_MASK)); - /* Keep all other bits intact */ - tcg_gen_or_tl(t1, t1, t0); - gen_store_spr(SPR_POWER_MMCR0, t1); + masked_gprn =3D masked_gprn_for_spr_write(gprn, SPR_POWER_MMCR0, + MMCR0_UREG_MASK); + gen_store_spr(SPR_POWER_MMCR0, masked_gprn); + + tcg_temp_free(masked_gprn); +} + +void spr_read_MMCR2_ureg(DisasContext *ctx, int gprn, int sprn) +{ + TCGv t0; + + if (!spr_groupA_read_allowed(ctx)) { + return; + } + + t0 =3D tcg_temp_new(); + + /* + * On read, filter out all bits that are not FCnP0 bits. + * When MMCR0[PMCC] is set to 0b10 or 0b11, providing + * problem state programs read/write access to MMCR2, + * only the FCnP0 bits can be accessed. All other bits are + * not changed when mtspr is executed in problem state, and + * all other bits return 0s when mfspr is executed in problem + * state, according to ISA v3.1, section 10.4.6 Monitor Mode + * Control Register 2, p. 1316, third paragraph. + */ + gen_load_spr(t0, SPR_POWER_MMCR2); + tcg_gen_andi_tl(t0, t0, MMCR2_UREG_MASK); + tcg_gen_mov_tl(cpu_gpr[gprn], t0); =20 tcg_temp_free(t0); - tcg_temp_free(t1); +} + +void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn, int gprn) +{ + TCGv masked_gprn; + + if (!spr_groupA_write_allowed(ctx)) { + return; + } + + /* + * Filter the bits that can be written using MMCR2_UREG_MASK, + * similar to what is done in spr_write_MMCR0_ureg(). + */ + masked_gprn =3D masked_gprn_for_spr_write(gprn, SPR_POWER_MMCR2, + MMCR2_UREG_MASK); + gen_store_spr(SPR_POWER_MMCR2, masked_gprn); + + tcg_temp_free(masked_gprn); } #else void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) @@ -113,4 +179,14 @@ void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn,= int gprn) { spr_noaccess(ctx, gprn, sprn); } + +void spr_read_MMCR2_ureg(DisasContext *ctx, int gprn, int sprn) +{ + spr_read_ureg(ctx, gprn, sprn); +} + +void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn, int gprn) +{ + spr_noaccess(ctx, gprn, sprn); +} #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index b28b095097..cb7f40eedf 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -33,6 +33,7 @@ void spr_read_ctr(DisasContext *ctx, int gprn, int sprn); void spr_write_ctr(DisasContext *ctx, int sprn, int gprn); void spr_read_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn); +void spr_read_MMCR2_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_tbl(DisasContext *ctx, int gprn, int sprn); void spr_read_tbu(DisasContext *ctx, int gprn, int sprn); void spr_read_atbl(DisasContext *ctx, int gprn, int sprn); @@ -42,6 +43,7 @@ void spr_read_601_rtcu(DisasContext *ctx, int gprn, int s= prn); void spr_read_spefscr(DisasContext *ctx, int gprn, int sprn); void spr_write_spefscr(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn); +void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn, int gprn); =20 #ifndef CONFIG_USER_ONLY void spr_write_generic32(DisasContext *ctx, int sprn, int gprn); --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519176548205.4680223242941; Sun, 17 Oct 2021 18:06:16 -0700 (PDT) Received: from localhost ([::1]:42160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH6V-0002Zr-Jt for importer@patchew.org; Sun, 17 Oct 2021 21:06:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2M-0006Ve-7n; Sun, 17 Oct 2021 21:01:58 -0400 Received: from mail-vk1-xa2f.google.com ([2607:f8b0:4864:20::a2f]:36650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2J-0000Us-1m; Sun, 17 Oct 2021 21:01:57 -0400 Received: by mail-vk1-xa2f.google.com with SMTP id f126so7815597vke.3; Sun, 17 Oct 2021 18:01:54 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EF+vYu9507vNTQv+mb4YfpI1DTMxFETRqNBOhHFolrI=; b=FT3DEoN3Fg6LLF9SpnSmTNNa01upWU2umr2KewvnSa86435rLN4uItg04z/Ge2DFrV h8BHBQJHmpLu+pGmSD50cSKEZBQuCOW0wQFGvOO14zdSWHUYUnTtpkKbRmRMa1JUG83Q 96fmfSFMET5SxfS/rX6Wb1iVPjqOcVGUZfCBJiO5QplAUHUG7N4VqVqn+9oUTyvYxCBI 0kUeoxbSQZt105xubZuOiElMZlNUYnqQL96Dvu+mGjqLTfQr1NucbbFYxzZ4BZHD6jFj hj0BvkC/TAL8Yxe8UIT79HHosBRGzVtGeZtHfeqd/4KJuHSJhJ93p9M2gFoZGeg2vfK5 tnAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EF+vYu9507vNTQv+mb4YfpI1DTMxFETRqNBOhHFolrI=; b=VQitrQXej4bL9Sapuv6MRf9x+jqinjye3noIDJHcNxQV7GZEEuK2+fAathrB68p9Qa N2d72Tt9agpY/cSGYe7fgcrIBX74MaQzoQ8S4MYim6v/59gVY5MnMW/zI8PLttoe0tXy 4ZI4T5WiK0aCpsCPJRm67qHueOw4jBsfNU/nKy0LauYq3vNIizovRW1Suw/ZRmfVI4xK PqJmorOPh9aSR45teVAQToskTmCErtvSWAx/Tj+pmSfxcYUHQhnQvs/kM/rEDb6TOBLf QabyIB/OLosJ6dpyMgTrzOhqTbyGmfZPSIPKlCiM6SfrWkUFwj/UoJdumATWW+7vTIJN 3S8A== X-Gm-Message-State: AOAM532iQo3uDcQQD+SHZsymW4OquCwv1UIBVq0sLbYQTr0W+n1iMWui +8pcdeXJObj3J6EI0vDVf7Cur9DsRIM= X-Google-Smtp-Source: ABdhPJyZqmfHsYHfDM9Z8zw9xtRjC7XvTDkyRwC+UoBnDxYx3eVRxUzWuxg8tZB3RpZpfl9p+OM6Xg== X-Received: by 2002:a05:6122:d06:: with SMTP id az6mr2759918vkb.17.1634518913581; Sun, 17 Oct 2021 18:01:53 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 04/15] target/ppc: adding user read/write functions for PMCs Date: Sun, 17 Oct 2021 22:01:22 -0300 Message-Id: <20211018010133.315842-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::a2f; envelope-from=danielhb413@gmail.com; helo=mail-vk1-xa2f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519178286100001 Content-Type: text/plain; charset="utf-8" Problem state needs to be able to read and write the PMU counters, otherwise it won't be aware of any sampling result that the PMU produces after a Perf run. This patch does that in a similar fashion as already done in the previous patches. PMCs 5 and 6 have a special condition, aside from the constraints that are common with PMCs 1-4, where they are not part of the PMU if MMCR0_PMCC is 0b11. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu_init.c | 12 +++--- target/ppc/power8-pmu-regs.c.inc | 70 ++++++++++++++++++++++++++++++++ target/ppc/spr_tcg.h | 4 ++ 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index ad88e54950..65545ba9ca 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6879,27 +6879,27 @@ static void register_book3s_pmu_user_sprs(CPUPPCSta= te *env) &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC1, "UPMC1", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC14_ureg, &spr_write_PMC14_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC2, "UPMC2", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC14_ureg, &spr_write_PMC14_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC3, "UPMC3", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC14_ureg, &spr_write_PMC14_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC4, "UPMC4", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC14_ureg, &spr_write_PMC14_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC5, "UPMC5", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC56_ureg, &spr_write_PMC56_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_UPMC6, "UPMC6", - &spr_read_ureg, SPR_NOACCESS, + &spr_read_PMC56_ureg, &spr_write_PMC56_ureg, &spr_read_ureg, &spr_write_ureg, 0x00000000); spr_register(env, SPR_POWER_USIAR, "USIAR", diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index fb95175183..7391851238 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -169,6 +169,56 @@ void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn,= int gprn) =20 tcg_temp_free(masked_gprn); } + +void spr_read_PMC14_ureg(DisasContext *ctx, int gprn, int sprn) +{ + if (!spr_groupA_read_allowed(ctx)) { + return; + } + + spr_read_ureg(ctx, gprn, sprn); +} + +void spr_read_PMC56_ureg(DisasContext *ctx, int gprn, int sprn) +{ + /* + * If PMCC =3D 0b11, PMC5 and PMC6 aren't included in the Performance + * Monitor, and a read attempt results in a Facility Unavailable + * Interrupt. + */ + if (ctx->mmcr0_pmcc0 && ctx->mmcr0_pmcc1) { + gen_hvpriv_exception(ctx, POWERPC_EXCP_FU); + return; + } + + /* The remaining steps are similar to PMCs 1-4 userspace read */ + spr_read_PMC14_ureg(ctx, gprn, sprn); +} + +void spr_write_PMC14_ureg(DisasContext *ctx, int sprn, int gprn) +{ + if (!spr_groupA_write_allowed(ctx)) { + return; + } + + spr_write_ureg(ctx, sprn, gprn); +} + +void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, int gprn) +{ + /* + * If PMCC =3D 0b11, PMC5 and PMC6 aren't included in the Performance + * Monitor, and a write attempt results in a Facility Unavailable + * Interrupt. + */ + if (ctx->mmcr0_pmcc0 && ctx->mmcr0_pmcc1) { + gen_hvpriv_exception(ctx, POWERPC_EXCP_FU); + return; + } + + /* The remaining steps are similar to PMCs 1-4 userspace write */ + spr_write_PMC14_ureg(ctx, sprn, gprn); +} #else void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) { @@ -189,4 +239,24 @@ void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn,= int gprn) { spr_noaccess(ctx, gprn, sprn); } + +void spr_read_PMC14_ureg(DisasContext *ctx, int gprn, int sprn) +{ + spr_read_ureg(ctx, gprn, sprn); +} + +void spr_read_PMC56_ureg(DisasContext *ctx, int gprn, int sprn) +{ + spr_read_ureg(ctx, gprn, sprn); +} + +void spr_write_PMC14_ureg(DisasContext *ctx, int sprn, int gprn) +{ + spr_noaccess(ctx, gprn, sprn); +} + +void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, int gprn) +{ + spr_noaccess(ctx, gprn, sprn); +} #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index cb7f40eedf..520f1ef233 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -34,6 +34,8 @@ void spr_write_ctr(DisasContext *ctx, int sprn, int gprn); void spr_read_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_MMCR2_ureg(DisasContext *ctx, int gprn, int sprn); +void spr_read_PMC14_ureg(DisasContext *ctx, int gprn, int sprn); +void spr_read_PMC56_ureg(DisasContext *ctx, int gprn, int sprn); void spr_read_tbl(DisasContext *ctx, int gprn, int sprn); void spr_read_tbu(DisasContext *ctx, int gprn, int sprn); void spr_read_atbl(DisasContext *ctx, int gprn, int sprn); @@ -44,6 +46,8 @@ void spr_read_spefscr(DisasContext *ctx, int gprn, int sp= rn); void spr_write_spefscr(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR2_ureg(DisasContext *ctx, int sprn, int gprn); +void spr_write_PMC14_ureg(DisasContext *ctx, int sprn, int gprn); +void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, int gprn); =20 #ifndef CONFIG_USER_ONLY void spr_write_generic32(DisasContext *ctx, int sprn, int gprn); --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519323561759.366500460489; Sun, 17 Oct 2021 18:08:43 -0700 (PDT) Received: from localhost ([::1]:49332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH8s-0007R7-KK for importer@patchew.org; Sun, 17 Oct 2021 21:08:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2N-0006Ye-9P; Sun, 17 Oct 2021 21:01:59 -0400 Received: from mail-vk1-xa33.google.com ([2607:f8b0:4864:20::a33]:43974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2L-0000bl-8w; Sun, 17 Oct 2021 21:01:58 -0400 Received: by mail-vk1-xa33.google.com with SMTP id u206so946687vke.10; Sun, 17 Oct 2021 18:01:56 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CfzFuoci4sUi/wHAUja0jOT8nYXJtzL6smP+zg6/Z0I=; b=PWiZGERMgzyUGwbL/dbz2a9dOdC8a85y0ysfIkhJhmoKgLS701Didz550opJ8DpElO E8ojPeRyfWAWN2eqjE40UgU+c3pALnNyhUVM/qbBofdkH00+/h9dx4vFrpC+mkm5Md2n foyuOEnZVu0+iVisOA64+PjbJG1oXt2v+3HQY1FUB26v6yZSuZV2F2Suy/7HRcn2Jk+f UE9irV4eMO7kfToGvCj6H953uFjF0qe20FwmWftLy5pOUg/NHFesY0w5UHvkFTBhKaXG elqLA+xMJQVxht+CZwSo0OO1OlVSVk9LSpSc7u9nNxQBrSbY4dlMk+vLpwuMhxke5I5Y L7EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CfzFuoci4sUi/wHAUja0jOT8nYXJtzL6smP+zg6/Z0I=; b=3kzylNfyV5lA5BFaX3HPHDViQEUHkDNGB1MaSsw5UU27EVlK2fn2Jnp+D3MyO+k8b1 MbhXGDZbZy5KrB69fBDXVszVdBFi+8twM3QM3e4BzllHnYrETEUEfrqISRDnjhJBegQ/ rvkK0SPrvmq6PkAcT9rz7ujCjAwSQs8qA0BbZ8ylzCVvAuOE1rhCm3J1mVBGHmB6R5MN SXh7hRytsT0mu8TnMcSd30qgl7TeFGDSl46WzdE2Zj/Cp6wICbnVKc+GHOHwnwHI4eGk oPCClxxsHfiWXHS8oFJg3UExUTGplRht/SAUr0fUfGRx/6k/rvfbwImXsp4h9IGD+ACo CeYg== X-Gm-Message-State: AOAM532C+H4gBWKbmVl9hGPRDEvZhULPmJYSBo2oFXLx9VuLGC6iK2Qv 0ihtnmFooCLoOpZGE0l641fijRxISWs= X-Google-Smtp-Source: ABdhPJwaMlx+nSy38oAuG1luVCXZkEGwlW6AQPTedEtiMP2HSOYb2mdEMptUAejCzf5Tzzc5oYcCqg== X-Received: by 2002:a05:6122:d05:: with SMTP id az5mr6033152vkb.19.1634518915830; Sun, 17 Oct 2021 18:01:55 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 05/15] target/ppc: introduce PMU events Date: Sun, 17 Oct 2021 22:01:23 -0300 Message-Id: <20211018010133.315842-6-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::a33; envelope-from=danielhb413@gmail.com; helo=mail-vk1-xa33.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519325414100001 Content-Type: text/plain; charset="utf-8" This patch starts an IBM Power8+ compatible PMU implementation by adding the representation of PMU events that we are going to sample, PMUEvent. This struct represents a Perf event, determined by the PMUEventType enum, that is being sampled by a specific counter 'sprn'. PMUEvent also contains an overflow timer that will be used to trigger cycle overflows when cycle events are being sampled. This timer will call cpu_ppc_pmu_timer_cb(), which in turn calls fire_PMC_interrupt(). Both functions are stubs that will be implemented later on when EBB support is added. The PMU has 6 PMUEvents all the time, one for each counter. Events that aren't available (i.e. the counter isn't running) will be of type 'PMU_EVENT_INVALID'. Other types added in this patch are PMU_EVENT_CYCLES and PMU_EVENT_INSTRUCTIONS. More types will be added later on. Two new helper files are created to host this new logic. cpu_ppc_pmu_init() will init all PMUEvents during CPU init time. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_cpu_core.c | 6 ++++ target/ppc/cpu.h | 22 ++++++++++++ target/ppc/meson.build | 1 + target/ppc/power8-pmu.c | 75 +++++++++++++++++++++++++++++++++++++++++ target/ppc/power8-pmu.h | 25 ++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 target/ppc/power8-pmu.c create mode 100644 target/ppc/power8-pmu.h diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 58e7341cb7..45abffd891 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -20,6 +20,7 @@ #include "target/ppc/kvm_ppc.h" #include "hw/ppc/ppc.h" #include "target/ppc/mmu-hash64.h" +#include "target/ppc/power8-pmu.h" #include "sysemu/numa.h" #include "sysemu/reset.h" #include "sysemu/hw_accel.h" @@ -266,6 +267,11 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprM= achineState *spapr, return false; } =20 + /* Init PMU interrupt timer (TCG only) */ + if (!kvm_enabled()) { + cpu_ppc_pmu_init(env); + } + if (!sc->pre_3_0_migration) { vmstate_register(NULL, cs->cpu_index, &vmstate_spapr_cpu_state, cpu->machine_data); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 33e3a91f6f..21591ec725 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -296,6 +296,26 @@ typedef struct ppc_v3_pate_t { uint64_t dw1; } ppc_v3_pate_t; =20 +/* PMU related structs and defines */ +#define PMU_EVENTS_NUM 6 +typedef enum { + PMU_EVENT_INVALID =3D 0, + PMU_EVENT_CYCLES, + PMU_EVENT_INSTRUCTIONS, +} PMUEventType; + +typedef struct PMUEvent { + int sprn; + PMUEventType type; + + /* + * Timer used to fire performance monitor alerts + * when counting cycles. + */ + QEMUTimer *cyc_overflow_timer; + +} PMUEvent; + /*************************************************************************= ****/ /* Machine state register bits definition = */ #define MSR_SF 63 /* Sixty-four-bit mode hfla= gs */ @@ -1190,6 +1210,8 @@ struct CPUPPCState { uint32_t tm_vscr; uint64_t tm_dscr; uint64_t tm_tar; + + PMUEvent pmu_events[PMU_EVENTS_NUM]; }; =20 #define SET_FIT_PERIOD(a_, b_, c_, d_) \ diff --git a/target/ppc/meson.build b/target/ppc/meson.build index b85f295703..a49a8911e0 100644 --- a/target/ppc/meson.build +++ b/target/ppc/meson.build @@ -51,6 +51,7 @@ ppc_softmmu_ss.add(when: 'TARGET_PPC64', if_true: files( 'mmu-book3s-v3.c', 'mmu-hash64.c', 'mmu-radix64.c', + 'power8-pmu.c', )) =20 target_arch +=3D {'ppc': ppc_ss} diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c new file mode 100644 index 0000000000..42452b5870 --- /dev/null +++ b/target/ppc/power8-pmu.c @@ -0,0 +1,75 @@ +/* + * PMU emulation helpers for TCG IBM POWER chips + * + * Copyright IBM Corp. 2021 + * + * Authors: + * Daniel Henrique Barboza + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "power8-pmu.h" +#include "cpu.h" +#include "helper_regs.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" +#include "qemu/error-report.h" +#include "qemu/main-loop.h" +#include "hw/ppc/ppc.h" + +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) + +static void fire_PMC_interrupt(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &cpu->env; + + if (!(env->spr[SPR_POWER_MMCR0] & MMCR0_EBE)) { + return; + } + + /* PMC interrupt not implemented yet */ + return; +} + +static void cpu_ppc_pmu_timer_cb(void *opaque) +{ + PowerPCCPU *cpu =3D opaque; + + fire_PMC_interrupt(cpu); +} + +void cpu_ppc_pmu_init(CPUPPCState *env) +{ + PowerPCCPU *cpu =3D env_archcpu(env); + int i; + + /* + * PMC1 event first, PMC2 second and so on. PMC5 and PMC6 + * PMUEvent are always the same regardless of MMCR1. + */ + for (i =3D 0; i < PMU_EVENTS_NUM; i++) { + PMUEvent *event =3D &env->pmu_events[i]; + + event->sprn =3D SPR_POWER_PMC1 + i; + event->type =3D PMU_EVENT_INVALID; + + if (event->sprn =3D=3D SPR_POWER_PMC5) { + event->type =3D PMU_EVENT_INSTRUCTIONS; + continue; + } + + if (event->sprn =3D=3D SPR_POWER_PMC6) { + event->type =3D PMU_EVENT_CYCLES; + } + + event->cyc_overflow_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + &cpu_ppc_pmu_timer_cb, + cpu); + } +} + +#endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/power8-pmu.h b/target/ppc/power8-pmu.h new file mode 100644 index 0000000000..49a813a443 --- /dev/null +++ b/target/ppc/power8-pmu.h @@ -0,0 +1,25 @@ +/* + * PMU emulation helpers for TCG IBM POWER chips + * + * Copyright IBM Corp. 2021 + * + * Authors: + * Daniel Henrique Barboza + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef POWER8_PMU +#define POWER8_PMU + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" +#include "qemu/error-report.h" +#include "qemu/main-loop.h" + +void cpu_ppc_pmu_init(CPUPPCState *env); + +#endif --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519368217217.2198883820937; Sun, 17 Oct 2021 18:09:28 -0700 (PDT) Received: from localhost ([::1]:50798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH9b-0008QJ-76 for importer@patchew.org; Sun, 17 Oct 2021 21:09:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2P-0006ZS-Em; Sun, 17 Oct 2021 21:02:03 -0400 Received: from mail-vk1-xa30.google.com ([2607:f8b0:4864:20::a30]:34423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2N-0000op-Eh; Sun, 17 Oct 2021 21:02:01 -0400 Received: by mail-vk1-xa30.google.com with SMTP id bc10so869555vkb.1; Sun, 17 Oct 2021 18:01:58 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ufmSvaZ4C/uK4Pv1xGj73IfBDohJJr9Vtbjnj3wHkiI=; b=hHzN+9RxTL+oTfJnsAib3JQsHbhgNNjELmFDMAPRinSkkfewuqKX8UodvSp+Ib2zDV cmlzET6eYQSKlHxpiopq0S9MSBDl/+qNd7MBP9RzvUF5JXkIsAU6/3+GMc0X119926v+ i27imDGHIKZhCFfyjIfmhiuR4kbeZb5zTMBGBTsBA+r2yqOr81vbo4mfW6GXg2IZ7EmD XmTHjUCFV/m5R92IJC4NwSsDVMQOMTyCTGtjjgsshnuwNlsrb+wEOjOOk5Qde0tqEtCs /aUSSzOVS7E/lzDV+Wf+VdD/62tSZkaVqwguV1Q13LEa6XPJSnYOlZjOiOyvEhPr4Jy/ XcWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ufmSvaZ4C/uK4Pv1xGj73IfBDohJJr9Vtbjnj3wHkiI=; b=0rMwYz+haSOKELN74QXjM7F4ygrwnfvoyLcXrfKkMBG7mekposx9JACwpw59yP9fQB crdY9M7gIQYejYzOemOdIIk/DMI1PiP1Rwsrf/4GDe35rA5O5Q71wLqSBTWuwwnmfYbp 2U4DJScQTQj5EpKPScokXvrMLbQHzcNbIU5cwQD7mKLuZgdxWHCrjeyAKxERmY+aDYV0 JxUVQufWQrxnK6XB/A1LneZmywbi1jztjJ+ku/eCAsYl8vPQDLi8gYEwHbHRX4YqbId7 qgJ1o9j5bE303A1FO8vfsGgsiu+oUm8SZY6EMcBPoxNoO/PRpISDmKElZqnNNHFJxizR yLpA== X-Gm-Message-State: AOAM533FktDYmuRyPhfguyeF/0jafP3N5dlDYwtlMlxAgDjxKficR341 cNRv76DbQNuC9JoJ2ROYIVt5ZjrHhYc= X-Google-Smtp-Source: ABdhPJz10gI7iKlLqjOVEJhMjQr2ugw++BO7HzyQApdrD9DCnb0FP7d2OA2VoPAVy4UatudlZE4KhA== X-Received: by 2002:a1f:1409:: with SMTP id 9mr21877001vku.25.1634518917972; Sun, 17 Oct 2021 18:01:57 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 06/15] target/ppc: initialize PMUEvents on MMCR1 write Date: Sun, 17 Oct 2021 22:01:24 -0300 Message-Id: <20211018010133.315842-7-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::a30; envelope-from=danielhb413@gmail.com; helo=mail-vk1-xa30.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519369107100001 Content-Type: text/plain; charset="utf-8" The value of MMCR1 determines the events that are going to be sampled by the programmable counters (PMCs 1-4). PMCs 5 and 6 are always counting instructions and cycles respectively and aren't affected by MMCR1. This patch adds a helper to initialize PMCs 1-4 PMUEvents when writing the MMCR1 register. The following events are considered valid at this moment: - For PMCs 1-4, event 0x2 is the implementation dependent value of PMU_EVENT_INSTRUCTIONS and event 0x1E is the implementation dependent value of PMU_EVENT_CYCLES. These events are supported by IBM Power chips since Power8, at least, and the Linux Perf driver makes use of these events until kernel v5.15; - for PMC1, event 0xF0 is the architected PowerISA event for cycles. Event 0xFE is the architected PowerISA event for instructions. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 11 ++++++ target/ppc/cpu_init.c | 2 +- target/ppc/helper.h | 1 + target/ppc/power8-pmu-regs.c.inc | 16 +++++++++ target/ppc/power8-pmu.c | 59 ++++++++++++++++++++++++++++++++ target/ppc/spr_tcg.h | 1 + 6 files changed, 89 insertions(+), 1 deletion(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 21591ec725..aaf503c8ff 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -382,6 +382,17 @@ typedef struct PMUEvent { #define MMCR2_UREG_MASK (MMCR2_FC1P0 | MMCR2_FC2P0 | MMCR2_FC3P0 | \ MMCR2_FC4P0 | MMCR2_FC5P0 | MMCR2_FC6P0) =20 +#define MMCR1_EVT_SIZE 8 +/* extract64() does a right shift before extracting */ +#define MMCR1_PMC1SEL_START 32 +#define MMCR1_PMC1EVT_EXTR (64 - MMCR1_PMC1SEL_START - MMCR1_EVT_SIZE) +#define MMCR1_PMC2SEL_START 40 +#define MMCR1_PMC2EVT_EXTR (64 - MMCR1_PMC2SEL_START - MMCR1_EVT_SIZE) +#define MMCR1_PMC3SEL_START 48 +#define MMCR1_PMC3EVT_EXTR (64 - MMCR1_PMC3SEL_START - MMCR1_EVT_SIZE) +#define MMCR1_PMC4SEL_START 56 +#define MMCR1_PMC4EVT_EXTR (64 - MMCR1_PMC4SEL_START - MMCR1_EVT_SIZE) + /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) #define LPCR_VPM1 PPC_BIT(1) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 65545ba9ca..7c9ed5dfe1 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6824,7 +6824,7 @@ static void register_book3s_pmu_sup_sprs(CPUPPCState = *env) KVM_REG_PPC_MMCR0, 0x00000000); spr_register_kvm(env, SPR_POWER_MMCR1, "MMCR1", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_MMCR1, KVM_REG_PPC_MMCR1, 0x00000000); spr_register_kvm(env, SPR_POWER_MMCRA, "MMCRA", SPR_NOACCESS, SPR_NOACCESS, diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 4076aa281e..fc5bae8330 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -20,6 +20,7 @@ DEF_HELPER_1(rfscv, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) DEF_HELPER_2(store_pcr, void, env, tl) +DEF_HELPER_2(store_mmcr1, void, env, tl) #endif DEF_HELPER_1(check_tlb_flush_local, void, env) DEF_HELPER_1(check_tlb_flush_global, void, env) diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index 7391851238..a0a64e76ad 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -219,6 +219,17 @@ void spr_write_PMC56_ureg(DisasContext *ctx, int sprn,= int gprn) /* The remaining steps are similar to PMCs 1-4 userspace write */ spr_write_PMC14_ureg(ctx, sprn, gprn); } + +void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_mmcr1(cpu_env, cpu_gpr[gprn]); + + /* + * Writes in MMCR1 must force a new translation block, allowing + * the PMU to calculate events with more accuracy. + */ + ctx->base.is_jmp =3D DISAS_EXIT_UPDATE; +} #else void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, int sprn) { @@ -259,4 +270,9 @@ void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, = int gprn) { spr_noaccess(ctx, gprn, sprn); } + +void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn) +{ + spr_write_generic(ctx, sprn, gprn); +} #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 42452b5870..9a0b544b04 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -23,6 +23,65 @@ =20 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) =20 +/* + * For PMCs 1-4, IBM POWER chips has support for an implementation + * dependent event, 0x1E, that enables cycle counting. The Linux kernel + * makes extensive use of 0x1E, so let's also support it. + * + * Likewise, event 0x2 is an implementation-dependent event that IBM + * POWER chips implement (at least since POWER8) that is equivalent to + * PM_INST_CMPL. Let's support this event on PMCs 1-4 as well. + */ +static void define_enabled_events(CPUPPCState *env) +{ + uint8_t mmcr1_evt_extr[] =3D { MMCR1_PMC1EVT_EXTR, MMCR1_PMC2EVT_EXTR, + MMCR1_PMC3EVT_EXTR, MMCR1_PMC4EVT_EXTR }; + int i; + + for (i =3D 0; i < 4; i++) { + uint8_t pmcsel =3D extract64(env->spr[SPR_POWER_MMCR1], + mmcr1_evt_extr[i], + MMCR1_EVT_SIZE); + PMUEvent *event =3D &env->pmu_events[i]; + + switch (pmcsel) { + case 0x2: + event->type =3D PMU_EVENT_INSTRUCTIONS; + break; + case 0x1E: + event->type =3D PMU_EVENT_CYCLES; + break; + case 0xF0: + /* + * PMC1SEL =3D 0xF0 is the architected PowerISA v3.1 + * event that counts cycles using PMC1. + */ + if (event->sprn =3D=3D SPR_POWER_PMC1) { + event->type =3D PMU_EVENT_CYCLES; + } + break; + case 0xFE: + /* + * PMC1SEL =3D 0xFE is the architected PowerISA v3.1 + * event to sample instructions using PMC1. + */ + if (event->sprn =3D=3D SPR_POWER_PMC1) { + event->type =3D PMU_EVENT_INSTRUCTIONS; + } + break; + default: + event->type =3D PMU_EVENT_INVALID; + } + } +} + +void helper_store_mmcr1(CPUPPCState *env, uint64_t value) +{ + env->spr[SPR_POWER_MMCR1] =3D value; + + define_enabled_events(env); +} + static void fire_PMC_interrupt(PowerPCCPU *cpu) { CPUPPCState *env =3D &cpu->env; diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index 520f1ef233..85852f236e 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -25,6 +25,7 @@ void spr_noaccess(DisasContext *ctx, int gprn, int sprn); void spr_read_generic(DisasContext *ctx, int gprn, int sprn); void spr_write_generic(DisasContext *ctx, int sprn, int gprn); +void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn); void spr_read_xer(DisasContext *ctx, int gprn, int sprn); void spr_write_xer(DisasContext *ctx, int sprn, int gprn); void spr_read_lr(DisasContext *ctx, int gprn, int sprn); --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519309376151.3488376171788; Sun, 17 Oct 2021 18:08:29 -0700 (PDT) Received: from localhost ([::1]:48914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcH8e-0007Aj-9N for importer@patchew.org; Sun, 17 Oct 2021 21:08:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2S-0006cB-6n; Sun, 17 Oct 2021 21:02:04 -0400 Received: from mail-ua1-x936.google.com ([2607:f8b0:4864:20::936]:41956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2P-0000za-V6; Sun, 17 Oct 2021 21:02:03 -0400 Received: by mail-ua1-x936.google.com with SMTP id r17so4674372uaf.8; Sun, 17 Oct 2021 18:02:01 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pGiyPnLuA/xqUZQq9SktNT0IPulutKDntAZtHFZNn7A=; b=LYhtnEYiMMVe9RfatcGtK+fUg6HZ3dDLuZevQtUdOcZ64f6XT7R8GQpvgUIpjvpfv+ G+kOPHTi4ME5/L7/7vD9A8zg2Jl/uG1/nluatFqQybZdWikvVm88QmWnOql4EbYxzgT9 eU88WXlng6qfpxarWhjs4CtHeU6AUKc1SbKdaSSNKIpVJG+PDZFDG2Steu4AZjF07tKV lLpRFtC8rxO1Z3/rzuRsrmdILOZ6Wjociy5W9PHhafIjA7LVA6nCiz4yEp6/v0mX8qd6 H658iUZahjA47YFTrtM172uJpFWaMGM9IT1IGs+BSSOplN6TtBv/rxTbgVzJsI2dbHef IA4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pGiyPnLuA/xqUZQq9SktNT0IPulutKDntAZtHFZNn7A=; b=wTgyG93goHU+jVDjjTzN11MPJxQWDD6ZYjGtTihAkPNGfBcFKC+8AyPsOazlPlUqEk W/2uZeognXZ4ZpnCMlSQg9cscNUrYdx+dx5H8krb1kSgbizDEGctlbmlItQm+gy5FC9L PhMb8V9qTq1J4nOX8/9P68xdqHvovrw0xxMhqYIeBZxTqFEPwbSSTMubLcwL1KkbnbwP pHNZTyT0nIN/kAgKp3LnakEF2p9/QUgkDOZWB+xhxwmt4XDotrd5bfHbfGX2d6+rryvX H5NgoRt57cm3p86ZKEBpg9ZcHHqORBU+vziSu4/mgoJ6JBs3dv4ArhLzv6N4Wi70AnMy A8Dg== X-Gm-Message-State: AOAM533U/6Rp1YSaPqtucuP8Sf2R8iMcWqbtuqSeio2BNbw7OMJ9oSDx M7cE7kFKBs++sCAARwKeYBMkpBIg9NQ= X-Google-Smtp-Source: ABdhPJwhxkcBXq8eSylnJepo+dhtteYzBgUFKzhrfJ/6CK3SBK8cSbShlBlQ2yxtO7USoUX9uY1vOQ== X-Received: by 2002:a67:e0d1:: with SMTP id m17mr25353015vsl.22.1634518920461; Sun, 17 Oct 2021 18:02:00 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 07/15] target/ppc: PMU basic cycle count for pseries TCG Date: Sun, 17 Oct 2021 22:01:25 -0300 Message-Id: <20211018010133.315842-8-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::936; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x936.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519310832100003 Content-Type: text/plain; charset="utf-8" This patch adds the barebones of the PMU logic by enabling cycle counting. The overall logic goes as follows: - a helper is added to control the PMU state on each MMCR0 write. This allows for the PMU to start/stop as the frozen counter bit (MMCR0_FC) is cleared or set; - MMCR0 reg initial value is set to 0x80000000 (MMCR0_FC set) to avoid having to spin the PMU right at system init; - the intended usage is to freeze the counters by setting MMCR0_FC, do any additional setting of events to be counted via MMCR1 and enable the PMU by zeroing MMCR0_FC. Software must freeze counters to read the results - on the fly reading of the PMCs will return the starting value of each one. This act of unfreezing the PMU, counting cycles and then freezing the PMU again is being called a cycle count session. Our base CPU frequency is fixed at 1Ghz for both powernv and pseries clock, so this assumption is also carried on here to determine that 1 nanosecond equals 1 CPU cycle. Cycle value is then calculated by subtracting the current time the PMU was frozen against the time in which the PMU started spining. The counter specific frozen bits MMCR0_FC14 and MMCR0_FC56 were also added as a mean to further control which PMCs were supposed to be counting cycles during the session. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 9 ++++ target/ppc/cpu_init.c | 6 +-- target/ppc/helper.h | 1 + target/ppc/power8-pmu-regs.c.inc | 23 ++++++++- target/ppc/power8-pmu.c | 83 ++++++++++++++++++++++++++++++++ target/ppc/spr_tcg.h | 1 + 6 files changed, 119 insertions(+), 4 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index aaf503c8ff..e6bb55cb1a 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -370,6 +370,9 @@ typedef struct PMUEvent { #define MMCR0_FCECE PPC_BIT(38) /* FC on Enabled Cond or Event */ #define MMCR0_PMCC0 PPC_BIT(44) /* PMC Control bit 0 */ #define MMCR0_PMCC1 PPC_BIT(45) /* PMC Control bit 1 */ +#define MMCR0_PMCC PPC_BITMASK(44, 45) /* PMC Control */ +#define MMCR0_FC14 PPC_BIT(58) /* PMC Freeze Counters 1-4 bit */ +#define MMCR0_FC56 PPC_BIT(59) /* PMC Freeze Counters 5-6 bit */ /* MMCR0 userspace r/w mask */ #define MMCR0_UREG_MASK (MMCR0_FC | MMCR0_PMAO | MMCR0_PMAE) /* MMCR2 userspace r/w mask */ @@ -1223,6 +1226,12 @@ struct CPUPPCState { uint64_t tm_tar; =20 PMUEvent pmu_events[PMU_EVENTS_NUM]; + + /* + * PMU base time value used by the PMU to calculate + * running cycles. + */ + uint64_t pmu_base_time; }; =20 #define SET_FIT_PERIOD(a_, b_, c_, d_) \ diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 7c9ed5dfe1..ffcd08a947 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6820,8 +6820,8 @@ static void register_book3s_pmu_sup_sprs(CPUPPCState = *env) { spr_register_kvm(env, SPR_POWER_MMCR0, "MMCR0", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, - KVM_REG_PPC_MMCR0, 0x00000000); + &spr_read_generic, &spr_write_MMCR0, + KVM_REG_PPC_MMCR0, 0x80000000); spr_register_kvm(env, SPR_POWER_MMCR1, "MMCR1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_MMCR1, @@ -6869,7 +6869,7 @@ static void register_book3s_pmu_user_sprs(CPUPPCState= *env) spr_register(env, SPR_POWER_UMMCR0, "UMMCR0", &spr_read_MMCR0_ureg, &spr_write_MMCR0_ureg, &spr_read_ureg, &spr_write_ureg, - 0x00000000); + 0x80000000); spr_register(env, SPR_POWER_UMMCR1, "UMMCR1", &spr_read_ureg, SPR_NOACCESS, &spr_read_ureg, &spr_write_ureg, diff --git a/target/ppc/helper.h b/target/ppc/helper.h index fc5bae8330..ea82d08ad5 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -20,6 +20,7 @@ DEF_HELPER_1(rfscv, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) DEF_HELPER_2(store_pcr, void, env, tl) +DEF_HELPER_2(store_mmcr0, void, env, tl) DEF_HELPER_2(store_mmcr1, void, env, tl) #endif DEF_HELPER_1(check_tlb_flush_local, void, env) diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index a0a64e76ad..8b3ffd9c1a 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -104,6 +104,17 @@ void spr_read_MMCR0_ureg(DisasContext *ctx, int gprn, = int sprn) tcg_temp_free(t0); } =20 +static void write_MMCR0_common(DisasContext *ctx, TCGv val) +{ + /* + * helper_store_mmcr0 will make clock based operations that + * will cause 'bad icount read' errors if we do not execute + * gen_icount_io_start() beforehand. + */ + gen_icount_io_start(ctx); + gen_helper_store_mmcr0(cpu_env, val); +} + void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn) { TCGv masked_gprn; @@ -119,7 +130,7 @@ void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, = int gprn) */ masked_gprn =3D masked_gprn_for_spr_write(gprn, SPR_POWER_MMCR0, MMCR0_UREG_MASK); - gen_store_spr(SPR_POWER_MMCR0, masked_gprn); + write_MMCR0_common(ctx, masked_gprn); =20 tcg_temp_free(masked_gprn); } @@ -220,6 +231,11 @@ void spr_write_PMC56_ureg(DisasContext *ctx, int sprn,= int gprn) spr_write_PMC14_ureg(ctx, sprn, gprn); } =20 +void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn) +{ + write_MMCR0_common(ctx, cpu_gpr[gprn]); +} + void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn) { gen_helper_store_mmcr1(cpu_env, cpu_gpr[gprn]); @@ -271,6 +287,11 @@ void spr_write_PMC56_ureg(DisasContext *ctx, int sprn,= int gprn) spr_noaccess(ctx, gprn, sprn); } =20 +void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn) +{ + spr_write_generic(ctx, sprn, gprn); +} + void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn) { spr_write_generic(ctx, sprn, gprn); diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 9a0b544b04..55906c70a2 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -82,6 +82,89 @@ void helper_store_mmcr1(CPUPPCState *env, uint64_t value) define_enabled_events(env); } =20 +static bool pmu_event_is_active(CPUPPCState *env, PMUEvent *event) +{ + if (event->sprn < SPR_POWER_PMC5) { + return !(env->spr[SPR_POWER_MMCR0] & MMCR0_FC14); + } + + return !(env->spr[SPR_POWER_MMCR0] & MMCR0_FC56); +} + +static void pmu_events_update_cycles(CPUPPCState *env) +{ + uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint64_t time_delta =3D now - env->pmu_base_time; + int i; + + for (i =3D 0; i < PMU_EVENTS_NUM; i++) { + PMUEvent *event =3D &env->pmu_events[i]; + + if (!pmu_event_is_active(env, event) || + event->type !=3D PMU_EVENT_CYCLES) { + continue; + } + + /* + * The pseries and powernv clock runs at 1Ghz, meaning + * that 1 nanosec equals 1 cycle. + */ + env->spr[event->sprn] +=3D time_delta; + } + + /* + * Update base_time for future calculations if we updated + * the PMCs while the PMU was running. + */ + if (!(env->spr[SPR_POWER_MMCR0] & MMCR0_FC)) { + env->pmu_base_time =3D now; + } +} + +/* + * A cycle count session consists of the basic operations we + * need to do to support PM_CYC events: redefine a new base_time + * to be used to calculate PMC values and start overflow timers. + */ +static void start_cycle_count_session(CPUPPCState *env) +{ + /* Just define pmu_base_time for now */ + env->pmu_base_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); +} + +void helper_store_mmcr0(CPUPPCState *env, target_ulong value) +{ + target_ulong curr_value =3D env->spr[SPR_POWER_MMCR0]; + bool curr_FC =3D curr_value & MMCR0_FC; + bool new_FC =3D value & MMCR0_FC; + + env->spr[SPR_POWER_MMCR0] =3D value; + + /* MMCR0 writes can change HFLAGS_PMCCCLEAR and HFLAGS_MMCR0FC */ + if (((curr_value & MMCR0_PMCC) !=3D (value & MMCR0_PMCC)) || + (curr_FC !=3D new_FC)) { + hreg_compute_hflags(env); + } + + /* + * In an frozen count (FC) bit change: + * + * - if PMCs were running (curr_FC =3D false) and we're freezing + * them (new_FC =3D true), save the PMCs values in the registers. + * + * - if PMCs were frozen (curr_FC =3D true) and we're activating + * them (new_FC =3D false), set the new base_time for future cycle + * calculations. + */ + if (curr_FC !=3D new_FC) { + if (!curr_FC) { + pmu_events_update_cycles(env); + } else { + start_cycle_count_session(env); + } + } +} + static void fire_PMC_interrupt(PowerPCCPU *cpu) { CPUPPCState *env =3D &cpu->env; diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index 85852f236e..82f9dc16a4 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -25,6 +25,7 @@ void spr_noaccess(DisasContext *ctx, int gprn, int sprn); void spr_read_generic(DisasContext *ctx, int gprn, int sprn); void spr_write_generic(DisasContext *ctx, int sprn, int gprn); +void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn); void spr_read_xer(DisasContext *ctx, int gprn, int sprn); void spr_write_xer(DisasContext *ctx, int sprn, int gprn); --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519524339933.189784862064; Sun, 17 Oct 2021 18:12:04 -0700 (PDT) Received: from localhost ([::1]:57988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHC7-0004wB-9X for importer@patchew.org; Sun, 17 Oct 2021 21:12:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2U-0006jU-M3; Sun, 17 Oct 2021 21:02:06 -0400 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]:41949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2S-0001Bj-Mx; Sun, 17 Oct 2021 21:02:06 -0400 Received: by mail-ua1-x92e.google.com with SMTP id r17so4674514uaf.8; Sun, 17 Oct 2021 18:02:03 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qaoy0P+j4qWwYzJ3qiP7aAF/XN+LRh73RT8pCL5I+1c=; b=YM/YycFug0vTLykKb5c8rnUBlrDTK4WWfvJWpqWWt4Cxhmi6f3jOYa+kcFmoymWFM3 4WTH+Sw6WfAx4s3ZxwkQrbUcdliLT77R3wHGUk5uKdLxZkcxARm52Oa/UgOOz7hJttwg 5ebFncu0rYFdvP3Wn/jIfViD+H5BkosF3Gn0H/8X7nV+riHNT+xN9B3wWJLtuzZAsiBS 5p4Sah8deykDNu5uIULHe83H53YnumTYUMCjAcpXrxYdixJ6fDUadiYL7h9T8lHm4bT0 c+6d13yla8tBhNp9Uf+0hxbPJ0TkNBeytBhRQqjIPM7aS/ZEp/n/pTyWVK/eiFCCzGmC jtpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qaoy0P+j4qWwYzJ3qiP7aAF/XN+LRh73RT8pCL5I+1c=; b=SvYqyzsUdhcoma28ZTJTgKL/nOJ2J4D0VWBmuP+8IZG6qC/VJUQexGaplxfVQRVo0T x0/hWNB1NpyOXBN48n7JtluN/gkhI+rhLsCDJbRCVM1CTrC7Hcq8LgHf8Afw5Ek0WsMr 4UoCvgw7/QIsHpAI8PDVvu4BvmFDmnUTnwM5XyQIWg1QXN99eyu1kiY37qajiAd4MCZm nSDHzlKv39/WxBEkB++0+dlQJ2moqf+vmHA40ZmMqhrNLSt3bS0hod6RxDS6lS06qn6e iKFJjwAXP0ezBsSJ7TOm8A3cx/gF9aZbBlFNl5WJjBgDVj8hR6RkAG7ly7fzYWbQWdPG loUA== X-Gm-Message-State: AOAM5330v6sAmYzrtS52VDfLlCun8dGnVKixXfB0JZekKag4r7QSdMS/ fGS3PpxR/jy7lpNhnSnq7dBFEXUSXP0= X-Google-Smtp-Source: ABdhPJy3rIw4pfBMg/F7E0As247oYGdg3doWipTrex0BcgeWSvWklZ8u02arR5BX1E3AltMUYtMoaA== X-Received: by 2002:ab0:6d8d:: with SMTP id m13mr22877756uah.113.1634518923148; Sun, 17 Oct 2021 18:02:03 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 08/15] target/ppc: enable PMU counter overflow with cycle events Date: Sun, 17 Oct 2021 22:01:26 -0300 Message-Id: <20211018010133.315842-9-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::92e; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x92e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519525400100001 Content-Type: text/plain; charset="utf-8" The PowerISA v3.1 defines that if the proper bits are set (MMCR0_PMC1CE for PMC1 and MMCR0_PMCjCE for the remaining PMCs), counter negative conditions are enabled. This means that if the counter value overflows (i.e. exceeds 0x80000000) a performance monitor alert will occur. This alert can trigger an event-based exception (to be implemented in the next patches) if the MMCR0_EBE bit is set. For now, overflowing the counter when the PMC is counting cycles will just trigger a performance monitor alert. This is done by starting the overflow timer of the PMUEvent to expire in the moment the overflow would be occuring. The timer will call fire_PMC_interrupt() (via cpu_ppc_pmu_timer_cb) which will trigger the PMU alert and, if the conditions are met, an EBB exception. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 2 ++ target/ppc/power8-pmu.c | 75 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index e6bb55cb1a..074d844741 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -373,6 +373,8 @@ typedef struct PMUEvent { #define MMCR0_PMCC PPC_BITMASK(44, 45) /* PMC Control */ #define MMCR0_FC14 PPC_BIT(58) /* PMC Freeze Counters 1-4 bit */ #define MMCR0_FC56 PPC_BIT(59) /* PMC Freeze Counters 5-6 bit */ +#define MMCR0_PMC1CE PPC_BIT(48) /* MMCR0 PMC1 Condition Enabled */ +#define MMCR0_PMCjCE PPC_BIT(49) /* MMCR0 PMCj Condition Enabled */ /* MMCR0 userspace r/w mask */ #define MMCR0_UREG_MASK (MMCR0_FC | MMCR0_PMAO | MMCR0_PMAE) /* MMCR2 userspace r/w mask */ diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 55906c70a2..724a1a4038 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -23,6 +23,8 @@ =20 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) =20 +#define COUNTER_NEGATIVE_VAL 0x80000000 + /* * For PMCs 1-4, IBM POWER chips has support for an implementation * dependent event, 0x1E, that enables cycle counting. The Linux kernel @@ -91,6 +93,15 @@ static bool pmu_event_is_active(CPUPPCState *env, PMUEve= nt *event) return !(env->spr[SPR_POWER_MMCR0] & MMCR0_FC56); } =20 +static bool pmu_event_has_overflow_enabled(CPUPPCState *env, PMUEvent *eve= nt) +{ + if (event->sprn =3D=3D SPR_POWER_PMC1) { + return env->spr[SPR_POWER_MMCR0] & MMCR0_PMC1CE; + } + + return env->spr[SPR_POWER_MMCR0] & MMCR0_PMCjCE; +} + static void pmu_events_update_cycles(CPUPPCState *env) { uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); @@ -121,6 +132,52 @@ static void pmu_events_update_cycles(CPUPPCState *env) } } =20 +static void pmu_delete_timers(CPUPPCState *env) +{ + int i; + + for (i =3D 0; i < PMU_EVENTS_NUM; i++) { + PMUEvent *event =3D &env->pmu_events[i]; + + if (event->sprn =3D=3D SPR_POWER_PMC5) { + continue; + } + + timer_del(event->cyc_overflow_timer); + } +} + +static void pmu_events_start_overflow_timers(CPUPPCState *env) +{ + uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int64_t timeout; + int i; + + env->pmu_base_time =3D now; + + /* + * Scroll through all PMCs ad start counter overflow timers for + * PM_CYC events, if needed. + */ + for (i =3D 0; i < PMU_EVENTS_NUM; i++) { + PMUEvent *event =3D &env->pmu_events[i]; + + if (!pmu_event_is_active(env, event) || + !(event->type =3D=3D PMU_EVENT_CYCLES) || + !pmu_event_has_overflow_enabled(env, event)) { + continue; + } + + if (env->spr[event->sprn] >=3D COUNTER_NEGATIVE_VAL) { + timeout =3D 0; + } else { + timeout =3D COUNTER_NEGATIVE_VAL - env->spr[event->sprn]; + } + + timer_mod(event->cyc_overflow_timer, now + timeout); + } +} + /* * A cycle count session consists of the basic operations we * need to do to support PM_CYC events: redefine a new base_time @@ -128,8 +185,22 @@ static void pmu_events_update_cycles(CPUPPCState *env) */ static void start_cycle_count_session(CPUPPCState *env) { - /* Just define pmu_base_time for now */ - env->pmu_base_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + bool overflow_enabled =3D env->spr[SPR_POWER_MMCR0] & + (MMCR0_PMC1CE | MMCR0_PMCjCE); + + /* + * Always delete existing overflow timers when starting a + * new cycle counting session. + */ + pmu_delete_timers(env); + + if (!overflow_enabled) { + /* Define pmu_base_time and leave */ + env->pmu_base_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + return; + } + + pmu_events_start_overflow_timers(env); } =20 void helper_store_mmcr0(CPUPPCState *env, target_ulong value) --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519518029913.3488936882592; Sun, 17 Oct 2021 18:11:58 -0700 (PDT) Received: from localhost ([::1]:57394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHC0-0004X4-Jb for importer@patchew.org; Sun, 17 Oct 2021 21:11:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2W-0006lY-Qc; Sun, 17 Oct 2021 21:02:13 -0400 Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]:37642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2U-0001NB-OU; Sun, 17 Oct 2021 21:02:08 -0400 Received: by mail-ua1-x934.google.com with SMTP id f4so2786778uad.4; Sun, 17 Oct 2021 18:02:05 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xxc0QrayLnTzdYodLLcQx5La71tqMn6pFlgKk9oNMCg=; b=MgS/yuk9fTpzg7/OKyoNKrAtR4pLN59Uya8VNeLS/hZmhdJLi+P1J1v7QqfcyLe6Hd JAnUNZwC2l5ITt9tdN9+jRdduPgxIMcYB20K5yD36JMLxy87Gar7ASfzNCxME1XYK4mo ti0DC6NsF9QfOhn4cVXoOmDbokZ1hsAGhyUWr5A0MLqxngBXYw31g97/LCG7F7EKrQpL S2e7q9cj+xKJfMuHA01N0KPoAoi+sejJAGtGWixnxEclik4xJ0Ch/Uc6tm4Mby9kuGVf kq2wvuUa/8ymCrzxkwBfOWtf7lXhjXep288sEZUtywIoFhWNbherh2MZsqBuzhcuQHVm AgTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xxc0QrayLnTzdYodLLcQx5La71tqMn6pFlgKk9oNMCg=; b=TrbNk+9O/5l2k8BE7YFgbQ1aX7wgd965dgTbiD5w2TDffodxEUW8pJZo3e4Ki3ru6y UmAyxNmQS1+4MDRs401D5/wYi0TXYLmDMCowwWqQe0VBX8Hge03OXIlHMvcyiAH86lmS rOWDRkT7j2afqlLQqlU6ULHP4tMv+2aTstO7k0A7EFgNAUbIzwTQVePYqIwbey3MmrBn pbGqS+dIQgwOm3Opk8Xak0OpiTOSYcVZq+Mx5X0rcxtM0IyTiNdYL1gLRez3KRa2VMnp ZI4D22p2kJK7rm73axW7rn6VblwD75mfvpRyTJ9u/K6NhvBIvrvQxYQbWG362A5m3+f6 rP/A== X-Gm-Message-State: AOAM5315oCDKuIL9P0zPIP80EidjlSARwTVvtMtKKCMHevGI25zOgQZJ 3GGBycabKV0AsHZG7zd6jBqyEYtyqv4= X-Google-Smtp-Source: ABdhPJz2q3es2Q3voqMNzLTgnd2QcLaZHkyf7LBIRq0nXzn75hBlRHrw22EUfP+5wS0IUAqm9bK6TQ== X-Received: by 2002:ab0:56c1:: with SMTP id c1mr23827281uab.6.1634518925209; Sun, 17 Oct 2021 18:02:05 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 09/15] target/ppc: enable PMU instruction count Date: Sun, 17 Oct 2021 22:01:27 -0300 Message-Id: <20211018010133.315842-10-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::934; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x934.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519519291100001 Content-Type: text/plain; charset="utf-8" The PMU is already counting cycles by calculating time elapsed in nanoseconds. Counting instructions is a different matter and requires another approach. This patch adds the capability of counting completed instructions (Perf event PM_INST_CMPL) by counting the amount of instructions translated in each translation block right before exiting it. A new pmu_count_insns() helper in translation.c was added to do that. After verifying that the PMU is running (MMCR0_FC bit not set), call helper_insns_inc(). This new helper from power8-pmu.c will add the instructions to the relevant counters. It'll also be responsible for triggering counter negative overflows as it is already being done with cycles. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 1 + target/ppc/helper.h | 1 + target/ppc/helper_regs.c | 4 +++ target/ppc/power8-pmu-regs.c.inc | 6 ++++ target/ppc/power8-pmu.c | 41 ++++++++++++++++++++++++++++ target/ppc/translate.c | 47 ++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 074d844741..185a6166aa 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -665,6 +665,7 @@ enum { HFLAGS_PR =3D 14, /* MSR_PR */ HFLAGS_PMCC0 =3D 15, /* MMCR0 PMCC bit 0 */ HFLAGS_PMCC1 =3D 16, /* MMCR0 PMCC bit 1 */ + HFLAGS_MMCR0FC =3D 17, /* MMCR0 FC bit */ HFLAGS_VSX =3D 23, /* MSR_VSX if cpu has VSX */ HFLAGS_VR =3D 25, /* MSR_VR if cpu has VRE */ =20 diff --git a/target/ppc/helper.h b/target/ppc/helper.h index ea82d08ad5..5814e2f251 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -22,6 +22,7 @@ DEF_HELPER_2(store_lpcr, void, env, tl) DEF_HELPER_2(store_pcr, void, env, tl) DEF_HELPER_2(store_mmcr0, void, env, tl) DEF_HELPER_2(store_mmcr1, void, env, tl) +DEF_HELPER_2(insns_inc, void, env, i32) #endif DEF_HELPER_1(check_tlb_flush_local, void, env) DEF_HELPER_1(check_tlb_flush_global, void, env) diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c index 99562edd57..875c2fdfc6 100644 --- a/target/ppc/helper_regs.c +++ b/target/ppc/helper_regs.c @@ -115,6 +115,10 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState = *env) if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCC1) { hflags |=3D 1 << HFLAGS_PMCC1; } + if (env->spr[SPR_POWER_MMCR0] & MMCR0_FC) { + hflags |=3D 1 << HFLAGS_MMCR0FC; + } + =20 #ifndef CONFIG_USER_ONLY if (!env->has_hv_mode || (msr & (1ull << MSR_HV))) { diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index 8b3ffd9c1a..f8ca44cfdc 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -113,6 +113,12 @@ static void write_MMCR0_common(DisasContext *ctx, TCGv= val) */ gen_icount_io_start(ctx); gen_helper_store_mmcr0(cpu_env, val); + + /* + * End the translation block because MMCR0 writes can change + * ctx->pmu_frozen. + */ + ctx->base.is_jmp =3D DISAS_EXIT_UPDATE; } =20 void spr_write_MMCR0_ureg(DisasContext *ctx, int sprn, int gprn) diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 724a1a4038..e9c6b9dfec 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -102,6 +102,33 @@ static bool pmu_event_has_overflow_enabled(CPUPPCState= *env, PMUEvent *event) return env->spr[SPR_POWER_MMCR0] & MMCR0_PMCjCE; } =20 +static bool pmu_events_increment_insns(CPUPPCState *env, uint32_t num_insn= s) +{ + bool overflow_triggered =3D false; + int i; + + /* PMC6 never counts instructions. */ + for (i =3D 0; i < PMU_EVENTS_NUM - 1; i++) { + PMUEvent *event =3D &env->pmu_events[i]; + + if (!pmu_event_is_active(env, event) || + event->type !=3D PMU_EVENT_INSTRUCTIONS) { + continue; + } + + env->spr[event->sprn] +=3D num_insns; + + if (env->spr[event->sprn] >=3D COUNTER_NEGATIVE_VAL && + pmu_event_has_overflow_enabled(env, event)) { + + overflow_triggered =3D true; + env->spr[event->sprn] =3D COUNTER_NEGATIVE_VAL; + } + } + + return overflow_triggered; +} + static void pmu_events_update_cycles(CPUPPCState *env) { uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); @@ -248,6 +275,20 @@ static void fire_PMC_interrupt(PowerPCCPU *cpu) return; } =20 +/* This helper assumes that the PMC is running. */ +void helper_insns_inc(CPUPPCState *env, uint32_t num_insns) +{ + bool overflow_triggered; + PowerPCCPU *cpu; + + overflow_triggered =3D pmu_events_increment_insns(env, num_insns); + + if (overflow_triggered) { + cpu =3D env_archcpu(env); + fire_PMC_interrupt(cpu); + } +} + static void cpu_ppc_pmu_timer_cb(void *opaque) { PowerPCCPU *cpu =3D opaque; diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 96e8703dd1..acc0e50194 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -178,6 +178,7 @@ struct DisasContext { bool hr; bool mmcr0_pmcc0; bool mmcr0_pmcc1; + bool pmu_frozen; ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ int singlestep_enabled; uint32_t flags; @@ -4304,6 +4305,31 @@ static inline void gen_update_cfar(DisasContext *ctx= , target_ulong nip) #endif } =20 +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) +static void pmu_count_insns(DisasContext *ctx) +{ + /* Do not bother calling the helper if the PMU is frozen */ + if (ctx->pmu_frozen) { + return; + } + + /* + * The PMU insns_inc() helper stops the internal PMU timer if a + * counter overflows happens. In that case, if the guest is + * running with icount and we do not handle it beforehand, + * the helper can trigger a 'bad icount read'. + */ + gen_icount_io_start(ctx); + + gen_helper_insns_inc(cpu_env, tcg_constant_i32(ctx->base.num_insns)); +} +#else +static void pmu_count_insns(DisasContext *ctx) +{ + return; +} +#endif + static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) { return translator_use_goto_tb(&ctx->base, dest); @@ -4318,9 +4344,18 @@ static void gen_lookup_and_goto_ptr(DisasContext *ct= x) } else if (sse & (CPU_SINGLE_STEP | CPU_BRANCH_STEP)) { gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_= dbgex(ctx))); } else { + pmu_count_insns(ctx); tcg_gen_exit_tb(NULL, 0); } } else { + /* + * tcg_gen_lookup_and_goto_ptr will exit the TB if + * CF_NO_GOTO_PTR is set. Count insns now. + */ + if (ctx->base.tb->flags & CF_NO_GOTO_PTR) { + pmu_count_insns(ctx); + } + tcg_gen_lookup_and_goto_ptr(); } } @@ -4332,6 +4367,7 @@ static void gen_goto_tb(DisasContext *ctx, int n, tar= get_ulong dest) dest =3D (uint32_t) dest; } if (use_goto_tb(ctx, dest)) { + pmu_count_insns(ctx); tcg_gen_goto_tb(n); tcg_gen_movi_tl(cpu_nip, dest & ~3); tcg_gen_exit_tb(ctx->base.tb, n); @@ -8565,6 +8601,7 @@ static void ppc_tr_init_disas_context(DisasContextBas= e *dcbase, CPUState *cs) ctx->hr =3D (hflags >> HFLAGS_HR) & 1; ctx->mmcr0_pmcc0 =3D (hflags >> HFLAGS_PMCC0) & 1; ctx->mmcr0_pmcc1 =3D (hflags >> HFLAGS_PMCC1) & 1; + ctx->pmu_frozen =3D (hflags >> HFLAGS_MMCR0FC) & 1; =20 ctx->singlestep_enabled =3D 0; if ((hflags >> HFLAGS_SE) & 1) { @@ -8685,6 +8722,7 @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, = CPUState *cs) switch (is_jmp) { case DISAS_TOO_MANY: if (use_goto_tb(ctx, nip)) { + pmu_count_insns(ctx); tcg_gen_goto_tb(0); gen_update_nip(ctx, nip); tcg_gen_exit_tb(ctx->base.tb, 0); @@ -8695,6 +8733,14 @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase,= CPUState *cs) gen_update_nip(ctx, nip); /* fall through */ case DISAS_CHAIN: + /* + * tcg_gen_lookup_and_goto_ptr will exit the TB if + * CF_NO_GOTO_PTR is set. Count insns now. + */ + if (ctx->base.tb->flags & CF_NO_GOTO_PTR) { + pmu_count_insns(ctx); + } + tcg_gen_lookup_and_goto_ptr(); break; =20 @@ -8702,6 +8748,7 @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, = CPUState *cs) gen_update_nip(ctx, nip); /* fall through */ case DISAS_EXIT: + pmu_count_insns(ctx); tcg_gen_exit_tb(NULL, 0); break; =20 --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519548004248.96577617761602; Sun, 17 Oct 2021 18:12:28 -0700 (PDT) Received: from localhost ([::1]:59728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHCV-00065h-0g for importer@patchew.org; Sun, 17 Oct 2021 21:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2Y-0006lb-Dt; Sun, 17 Oct 2021 21:02:17 -0400 Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]:37632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2W-0001ZM-Mr; Sun, 17 Oct 2021 21:02:10 -0400 Received: by mail-ua1-x929.google.com with SMTP id f4so2786860uad.4; Sun, 17 Oct 2021 18:02:07 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OqR/4FXpSKMXflowJdvTANNRTOQST1LZ+4RP3Lswx0A=; b=O5lZQKblIoEaroCAW/2aiqhi60vwvPKp1lE7K7d/Kni449Cr/0aiFoZuT7JwyUFR8F +qWNlviZ+TwhodfMLc342Jz2c85QqqOh3rTEGjJjx7lHNXNPvIqrkJKjVpoM4xS6ZXs8 RfRoMcfSWK3NkMJ++cbXEOw1kvNL7DAAwzEeoNAk0Gtw72XPooUSZqJ0xT8NAeBrPzKu hZbRbX/asmH1YtoD1uFiS6zO9kyYeeSCcgmkKGCePLMLDobO82Yb5u9F/ZoanCwNo1uo U7VMXcj1tTQXIUL6vPVFNx+MkEbgkTkdRJOkVZ5L4hPaHA/xISdORQhWn3dIfvcMhKJg AqwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OqR/4FXpSKMXflowJdvTANNRTOQST1LZ+4RP3Lswx0A=; b=aEal3TwvnFaHLcyTqxYQT1aAEk+6bQJglNNlLdJa4rDl7z4UAPP8h7ucW06pJ/6C3n yb2/7yaNhydZvylN1snmqqAddLg3NwROd2WQf5F/03uofZoU+6gerx9/FwKPB00GqpKp ZYVhYw8RlYgS8IdIrwK1VADqmCyUx7r3neYCUPoTN4VgQjJzRqmndxBqO1cc0dZoqFxt LL0x515OxecXdt5vbFijCPVM9d7yqIc6eSvPbNTTWU6a/7eEov/xADA9oMrl493Qo8X4 be9DfyJIraOv9c4KiCG7HhiE67b4X4Ug3fiCs9qhwlsVTdFEFtY3vtKRV+dqIwzy3ZpT WZIQ== X-Gm-Message-State: AOAM531sKx1mAxVbT750UCUJQZUzTFSh3JxV9vFX43smbPDtvzc8/Ld8 X4sVuNWpSI9IsM1YdLRvjkUHgsFsc1I= X-Google-Smtp-Source: ABdhPJzwI1ijd2RCFW5Xfe0p333JMB0PyGmP6D444krfzD8pbEGiCaMA6+fykOWMbHGW/nZV1nPA+g== X-Received: by 2002:a67:c18c:: with SMTP id h12mr24659264vsj.27.1634518927385; Sun, 17 Oct 2021 18:02:07 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 10/15] target/ppc/power8-pmu.c: add PM_RUN_INST_CMPL (0xFA) event Date: Sun, 17 Oct 2021 22:01:28 -0300 Message-Id: <20211018010133.315842-11-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::929; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x929.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519550019100005 Content-Type: text/plain; charset="utf-8" PM_RUN_INST_CMPL, instructions completed with the run latch set, is the architected PowerISA v3.1 event defined with PMC4SEL =3D 0xFA. Implement it by checking for the CTRL RUN bit before incrementing the counter. To make this work properly we also need to force a new translation block each time SPR_CTRL is written. A small tweak in pmu_events_increment_insns() is then needed to only increment this event if the thread has the run latch. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 4 ++++ target/ppc/cpu_init.c | 2 +- target/ppc/power8-pmu.c | 23 ++++++++++++++++++++--- target/ppc/spr_tcg.h | 1 + target/ppc/translate.c | 12 ++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 185a6166aa..6f9a48a5a1 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -302,6 +302,7 @@ typedef enum { PMU_EVENT_INVALID =3D 0, PMU_EVENT_CYCLES, PMU_EVENT_INSTRUCTIONS, + PMU_EVENT_INSN_RUN_LATCH, } PMUEventType; =20 typedef struct PMUEvent { @@ -398,6 +399,9 @@ typedef struct PMUEvent { #define MMCR1_PMC4SEL_START 56 #define MMCR1_PMC4EVT_EXTR (64 - MMCR1_PMC4SEL_START - MMCR1_EVT_SIZE) =20 +/* PMU uses CTRL_RUN to sample PM_RUN_INST_CMPL */ +#define CTRL_RUN PPC_BIT(63) + /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) #define LPCR_VPM1 PPC_BIT(1) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index ffcd08a947..eb1a0320b9 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6748,7 +6748,7 @@ static void register_book3s_ctrl_sprs(CPUPPCState *en= v) { spr_register(env, SPR_CTRL, "SPR_CTRL", SPR_NOACCESS, SPR_NOACCESS, - SPR_NOACCESS, &spr_write_generic, + SPR_NOACCESS, &spr_write_CTRL, 0x00000000); spr_register(env, SPR_UCTRL, "SPR_UCTRL", &spr_read_ureg, SPR_NOACCESS, diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index e9c6b9dfec..3946314e9c 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -62,6 +62,15 @@ static void define_enabled_events(CPUPPCState *env) event->type =3D PMU_EVENT_CYCLES; } break; + case 0xFA: + /* + * PMC4SEL =3D 0xFA is the "instructions completed + * with run latch set" event. + */ + if (event->sprn =3D=3D SPR_POWER_PMC4) { + event->type =3D PMU_EVENT_INSN_RUN_LATCH; + } + break; case 0xFE: /* * PMC1SEL =3D 0xFE is the architected PowerISA v3.1 @@ -110,13 +119,21 @@ static bool pmu_events_increment_insns(CPUPPCState *e= nv, uint32_t num_insns) /* PMC6 never counts instructions. */ for (i =3D 0; i < PMU_EVENTS_NUM - 1; i++) { PMUEvent *event =3D &env->pmu_events[i]; + bool insn_event =3D event->type =3D=3D PMU_EVENT_INSTRUCTIONS || + event->type =3D=3D PMU_EVENT_INSN_RUN_LATCH; =20 - if (!pmu_event_is_active(env, event) || - event->type !=3D PMU_EVENT_INSTRUCTIONS) { + if (!pmu_event_is_active(env, event) || !insn_event) { continue; } =20 - env->spr[event->sprn] +=3D num_insns; + if (event->type =3D=3D PMU_EVENT_INSTRUCTIONS) { + env->spr[event->sprn] +=3D num_insns; + } + + if (event->type =3D=3D PMU_EVENT_INSN_RUN_LATCH && + env->spr[SPR_CTRL] & CTRL_RUN) { + env->spr[event->sprn] +=3D num_insns; + } =20 if (env->spr[event->sprn] >=3D COUNTER_NEGATIVE_VAL && pmu_event_has_overflow_enabled(env, event)) { diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index 82f9dc16a4..28126da6e2 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -27,6 +27,7 @@ void spr_read_generic(DisasContext *ctx, int gprn, int sp= rn); void spr_write_generic(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn); +void spr_write_CTRL(DisasContext *ctx, int sprn, int gprn); void spr_read_xer(DisasContext *ctx, int gprn, int sprn); void spr_write_xer(DisasContext *ctx, int sprn, int gprn); void spr_read_lr(DisasContext *ctx, int gprn, int sprn); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index acc0e50194..e2839883be 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -404,6 +404,18 @@ void spr_write_generic(DisasContext *ctx, int sprn, in= t gprn) spr_store_dump_spr(sprn); } =20 +void spr_write_CTRL(DisasContext *ctx, int sprn, int gprn) +{ + spr_write_generic(ctx, sprn, gprn); + + /* + * SPR_CTRL writes must force a new translation block, + * allowing the PMU to calculate the run latch events with + * more accuracy. + */ + ctx->base.is_jmp =3D DISAS_EXIT_UPDATE; +} + #if !defined(CONFIG_USER_ONLY) void spr_write_generic32(DisasContext *ctx, int sprn, int gprn) { --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519640229945.9757073789693; Sun, 17 Oct 2021 18:14:00 -0700 (PDT) Received: from localhost ([::1]:36072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHDz-0000j2-8Q for importer@patchew.org; Sun, 17 Oct 2021 21:13:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2d-0006m2-FR; Sun, 17 Oct 2021 21:02:17 -0400 Received: from mail-ua1-x936.google.com ([2607:f8b0:4864:20::936]:33409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2Z-0001ee-9t; Sun, 17 Oct 2021 21:02:12 -0400 Received: by mail-ua1-x936.google.com with SMTP id i15so2011699uap.0; Sun, 17 Oct 2021 18:02:10 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F+99HG8eac446L2n75fRM4jwi9udlnj1/OOSf7a8Hws=; b=fPR0SHCm9Dk7bVe92wS2mf0qoJMriuap6p7neFT8hBV86Uelvnrb3ROTHIxjwq4y59 XsbCURFDZshLVd+C71Z7REn7yrNUyJYRd50MISf5sOIibAgC1/q9BStSqNOd6WEr+/9m YMUg+sHV+DQCC02V1ckifAEL0qoA9eyN8c4BRIOvSKI2OHuLMkAOUgJXaUtkgHi9MZOy dohCwm7tIFSD28xYwBFrvMcAMMOWONcdX6CJ4V9Qw//ixO1iGF2ZH0e0EWWmtMJ10bCv tHPRsk12t1Qo01P6yDWT7kBtWGp/VJVbvVA4WEJYfXnMUz/ntnjGoLb7Sgskqdzh6/8C 2HAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F+99HG8eac446L2n75fRM4jwi9udlnj1/OOSf7a8Hws=; b=PfVAAJ8RcX/v7Asx+NExKnXNy8hxes9fmLdgXyKd76SDn5fp2Lwk7MWIPkYh4Z4T0M KmcOP4b9as+vGhFOB3ODjLEOIJWBys1AXlVc+kwzl2cD9TvweKF4M/6GEGpPD+8q55+h j+S4MocY87jSNMmsq9tningu9u5mU5xDQicPy8S0WN1xZTwlvJJUAmK3BKiD/jRxPiWX dygskuSO9CylKeGPcfYucvmrtph7VRujXA1XA6JDFhCTU5RhQ5bKktcwwQg6XYDaXpFT vEP5L38VdRYZC0q2NCOZHBIsgrZMazE6L6x0hdGb8YxsIAm5qBKTOPX0JZ/x5UjXCUym 3eQA== X-Gm-Message-State: AOAM533IbCzfqlw9rJoLUQ6Ax9PAl/DAS7dqcIwTVooCJsDOBRVhhjCt j0V/n7uKeJ66FBp0L9SPM0VWPG2Ulkc= X-Google-Smtp-Source: ABdhPJzNOy3XuQEoBlvHU7pVoik38GmdnuzBk7FQhxDKzQjb1YBALsWZ1dkYf7MwJTvUawnmzRrS2Q== X-Received: by 2002:a05:6102:3ec3:: with SMTP id n3mr24787981vsv.48.1634518929672; Sun, 17 Oct 2021 18:02:09 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 11/15] target/ppc: PMU: handle setting of PMCs while running Date: Sun, 17 Oct 2021 22:01:29 -0300 Message-Id: <20211018010133.315842-12-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::936; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x936.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519640769100001 Content-Type: text/plain; charset="utf-8" The initial PMU support were made under the assumption that the counters would be set before running the PMU and read after either freezing the PMU manually or via a performance monitor alert. Turns out that some EBB powerpc kernel tests set the counters after unfreezing the counters. Setting a PMC value when the PMU is running means that, at that moment, the baseline for calculating cycle events needs to be updated. Updating this baseline means that we need to update all the PMCs with their actual value at that moment. Any existing counter negative timer needs to be discarded an a new one, with the updated values, must be set again. This patch does that via a new 'helper_store_pmc()' that is called in the mtspr() callbacks of PMU counters. Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu_init.c | 12 ++++++------ target/ppc/helper.h | 1 + target/ppc/power8-pmu-regs.c.inc | 17 ++++++++++++++++- target/ppc/power8-pmu.c | 18 ++++++++++++++++++ target/ppc/spr_tcg.h | 1 + 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index eb1a0320b9..cf68e2c5a7 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6832,27 +6832,27 @@ static void register_book3s_pmu_sup_sprs(CPUPPCStat= e *env) KVM_REG_PPC_MMCRA, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC1, "PMC1", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC1, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC2, "PMC2", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC2, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC3, "PMC3", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC3, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC4, "PMC4", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC4, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC5, "PMC5", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC5, 0x00000000); spr_register_kvm(env, SPR_POWER_PMC6, "PMC6", SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_PMC, KVM_REG_PPC_PMC6, 0x00000000); spr_register_kvm(env, SPR_POWER_SIAR, "SIAR", SPR_NOACCESS, SPR_NOACCESS, diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 5814e2f251..b0ebfaff51 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -22,6 +22,7 @@ DEF_HELPER_2(store_lpcr, void, env, tl) DEF_HELPER_2(store_pcr, void, env, tl) DEF_HELPER_2(store_mmcr0, void, env, tl) DEF_HELPER_2(store_mmcr1, void, env, tl) +DEF_HELPER_3(store_pmc, void, env, i32, i64) DEF_HELPER_2(insns_inc, void, env, i32) #endif DEF_HELPER_1(check_tlb_flush_local, void, env) diff --git a/target/ppc/power8-pmu-regs.c.inc b/target/ppc/power8-pmu-regs.= c.inc index f8ca44cfdc..8a9e1f41ef 100644 --- a/target/ppc/power8-pmu-regs.c.inc +++ b/target/ppc/power8-pmu-regs.c.inc @@ -212,13 +212,23 @@ void spr_read_PMC56_ureg(DisasContext *ctx, int gprn,= int sprn) spr_read_PMC14_ureg(ctx, gprn, sprn); } =20 +void spr_write_PMC(DisasContext *ctx, int sprn, int gprn) +{ + TCGv_i32 t_sprn =3D tcg_const_i32(sprn); + + gen_icount_io_start(ctx); + gen_helper_store_pmc(cpu_env, t_sprn, cpu_gpr[gprn]); + + tcg_temp_free_i32(t_sprn); +} + void spr_write_PMC14_ureg(DisasContext *ctx, int sprn, int gprn) { if (!spr_groupA_write_allowed(ctx)) { return; } =20 - spr_write_ureg(ctx, sprn, gprn); + spr_write_PMC(ctx, sprn + 0x10, gprn); } =20 void spr_write_PMC56_ureg(DisasContext *ctx, int sprn, int gprn) @@ -302,4 +312,9 @@ void spr_write_MMCR1(DisasContext *ctx, int sprn, int g= prn) { spr_write_generic(ctx, sprn, gprn); } + +void spr_write_PMC(DisasContext *ctx, int sprn, int gprn) +{ + spr_write_generic(ctx, sprn, gprn); +} #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 3946314e9c..3fc09cebe4 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -343,4 +343,22 @@ void cpu_ppc_pmu_init(CPUPPCState *env) } } =20 +void helper_store_pmc(CPUPPCState *env, uint32_t sprn, uint64_t value) +{ + bool pmu_frozen =3D env->spr[SPR_POWER_MMCR0] & MMCR0_FC; + + if (pmu_frozen) { + env->spr[sprn] =3D value; + return; + } + + /* + * Update counters with the events counted so far, define + * the new value of the PMC and start a new cycle count + * session. + */ + pmu_events_update_cycles(env); + env->spr[sprn] =3D value; + start_cycle_count_session(env); +} #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */ diff --git a/target/ppc/spr_tcg.h b/target/ppc/spr_tcg.h index 28126da6e2..01fded3c15 100644 --- a/target/ppc/spr_tcg.h +++ b/target/ppc/spr_tcg.h @@ -28,6 +28,7 @@ void spr_write_generic(DisasContext *ctx, int sprn, int g= prn); void spr_write_MMCR0(DisasContext *ctx, int sprn, int gprn); void spr_write_MMCR1(DisasContext *ctx, int sprn, int gprn); void spr_write_CTRL(DisasContext *ctx, int sprn, int gprn); +void spr_write_PMC(DisasContext *ctx, int sprn, int gprn); void spr_read_xer(DisasContext *ctx, int gprn, int sprn); void spr_write_xer(DisasContext *ctx, int sprn, int gprn); void spr_read_lr(DisasContext *ctx, int gprn, int sprn); --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519636040768.9060380145308; Sun, 17 Oct 2021 18:13:56 -0700 (PDT) Received: from localhost ([::1]:35720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHDv-0000Uu-0Z for importer@patchew.org; Sun, 17 Oct 2021 21:13:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2f-0006mG-07; Sun, 17 Oct 2021 21:02:17 -0400 Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]:43953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2d-0001rs-Gx; Sun, 17 Oct 2021 21:02:16 -0400 Received: by mail-ua1-x934.google.com with SMTP id i22so882490ual.10; Sun, 17 Oct 2021 18:02:12 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cIBxAEzk03kgT4b2tUQ2VAzjElnv0mZD6r9v+To1Y7E=; b=R0pQozuDIN0i4f42Bwyivb3MA+tlh0oszDRBEeMwy4++/K3C/rD/Pjf2t7le/+IFmS Yz0Y/Qh/vqdXF9TU6nz+3I8MKy8P7StQ+y45GwDgXZmrASqdtvmMFoFBKgFEWddeZXoQ dhbKTqERIJmBMMqjx5xGg/JgfITaNEmbk5BQYtwgtvSRuRQbAYr+5RqlKJ8bvYgbD3wX FjK7b6cZrYY0ogDlIanW7fkfn89RV84PPybtwbLUSd1Hkt6exu4w6uriusIO5kT1xHx7 jRfuxbj0xqWv6weGVaiQ6dGFDm2hX7JdBpJE3HpBqHeM9qcMBRp5ZaMGZwTyQXIpdMD3 0/yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cIBxAEzk03kgT4b2tUQ2VAzjElnv0mZD6r9v+To1Y7E=; b=yalL1/rSmH7lioJVZLD5PQJWaIjtZvRg2rUnSUgd/E91apxnXTSG6d59gvWcUeyste TgfD5NXcEYP8d9i9aYWyeIm+Jf+DVJJuc07eaNrGRV0GvO6pVpqdIWVDYJKylMhdtw22 RJcLAR3ShERxTHv2N+Ru068gcv1k4ofvR/k+QG0XeUiZIZc2XsFeBVwv+nTGlZSygdeX bCuI4FUph9OHWnZ6cIWdSXw3qNE1ELjHaRCNW4bvclAclheIGHFOHGf6KI6e9/54X6Nd fxSbI1+DutaFjKB45YJwhCnvFEue1DzreeUUYKDPb5DhMNiCeNrB3xAbfKLlRJOfN97O RsOQ== X-Gm-Message-State: AOAM533KRXolgEuaYORrD3efSAaXEoh3NCNXLb+PMzj+peS2Nn6Qk8y2 eyll6E+6KVb/e3yHJnZvGvtWey30QIs= X-Google-Smtp-Source: ABdhPJyEgliJv8x66rRw7Now8bFw3jXmmx50omK7taSadiy9Yje4ygaUJBOgiFei0ydyd5EnPqZV1A== X-Received: by 2002:a05:6102:32d6:: with SMTP id o22mr12565091vss.32.1634518931889; Sun, 17 Oct 2021 18:02:11 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 12/15] target/ppc/power8-pmu.c: handle overflow bits when PMU is running Date: Sun, 17 Oct 2021 22:01:30 -0300 Message-Id: <20211018010133.315842-13-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::934; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x934.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519636523100001 Content-Type: text/plain; charset="utf-8" Up until this moment we were assuming that the counter negative enabled bits, PMC1CE and PMCjCE, would never be changed when the PMU is already started. Turns out that there is no such restriction in the PowerISA v3.1, and software can enable/disable overflow conditions of the counters at any time. To support this scenario, track the overflow bits state when a write in MMCR0 is made in which the run state of the PMU (MMCR0_FC bit) didn't change and, if some overflow bit were changed in the middle of a cycle count session, restart it. Signed-off-by: Daniel Henrique Barboza --- target/ppc/power8-pmu.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 3fc09cebe4..4bd07ba865 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -277,6 +277,30 @@ void helper_store_mmcr0(CPUPPCState *env, target_ulong= value) } else { start_cycle_count_session(env); } + } else { + /* + * No change in MMCR0_FC state, but if the PMU is running and + * a change in the counter negative overflow bits is made, + * we need to restart a new cycle count session to restart + * the appropriate overflow timers. + */ + if (curr_FC) { + return; + } + + bool pmc1ce_curr =3D curr_value & MMCR0_PMC1CE; + bool pmc1ce_new =3D value & MMCR0_PMC1CE; + bool pmcjce_curr =3D curr_value & MMCR0_PMCjCE; + bool pmcjce_new =3D value & MMCR0_PMCjCE; + + if (pmc1ce_curr =3D=3D pmc1ce_new && pmcjce_curr =3D=3D pmcjce_new= ) { + return; + } + + /* Update the counter with the events counted so far */ + pmu_events_update_cycles(env); + + start_cycle_count_session(env); } } =20 --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519713202960.6831121540527; Sun, 17 Oct 2021 18:15:13 -0700 (PDT) Received: from localhost ([::1]:38584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHFA-0002PQ-52 for importer@patchew.org; Sun, 17 Oct 2021 21:15:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2f-0006no-T9; Sun, 17 Oct 2021 21:02:21 -0400 Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]:39680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2d-000257-GJ; Sun, 17 Oct 2021 21:02:17 -0400 Received: by mail-ua1-x933.google.com with SMTP id f3so4748285uap.6; Sun, 17 Oct 2021 18:02:14 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eRE1vTD16G0zofRanu6U3rQerdaIrRMjzzaKnlikiUo=; b=VXNsYwc78bRZeAh+SZ4oQ0M7lFz7Wl1xvdubceD6p0mQ5sOHUcY8iJ//qZTVdmcJJg 31yq3pqetOYU8KzUFVqHmrET6p91MWD21IOmF/h4Z4ILCLubF1ASND9VSEy1F2RQc4UE TyqE0flIQOBRRv2hmMsHLOsTUusw6xLQNFbFVTpuJRkOov9FOVm7gL+5HkEFJh0QMdko 8d2aR89ZQ0lyFgBHQDTdcLIZZIts5hKXWbbiwtAGLK4Tuz9KhlqCjfnjDrjUfropU3kB 2ckTwsP32JzVGNVUhcTHf3G9coZtLIGPqqU7sj6bDdpkmMC+kmDamE0BmKa8v1VjwGJE ASKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eRE1vTD16G0zofRanu6U3rQerdaIrRMjzzaKnlikiUo=; b=NhN9myx1QIxa1IgKGnvtupRMmSkvjdxymoOabwEKcCyPtnZN+fF6I53/VK8aSvX0NZ L4G4ZlSE3WkPFtEY5S4Daymk1Pm5VGMDXAxBkJ7nhHEWcugs2zxuB2vS1aUbVhCAc2Ca Zinw+7QDy+tOpZT+g5eu+f6EDQ2w4M+fw48l0qRlulxxfbjzTECh8DALFNn4K6FbCFPX Bz53z7/krf6E1soOkwM+v9U8NigutiBoPKsMPaPRzew5lXCC7kTML0qCw6w7epJpYcgd TxMvVD+ANhZ2oRA44pc390mrl3bVT7jYO+e/ib/Uxb8f8tTPVsqjs3NRmEPGA8mOvja1 G3EA== X-Gm-Message-State: AOAM530tyeKquOxyK5BQBt3Bc4o2vz5qTcvVMLpfEcH/AJG95B+SzmMB /LXvtaEPc9V+dMGc7DY23BJfrVGGTag= X-Google-Smtp-Source: ABdhPJyOsP5GK1O3YBtNJuOWLzshBZVAa6dFOzlwzDjGhTSTAhpDBAS2tuxoU0XuS7DvYBUyM6ZGBA== X-Received: by 2002:a05:6102:c01:: with SMTP id x1mr7053338vss.8.1634518934074; Sun, 17 Oct 2021 18:02:14 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 13/15] PPC64/TCG: Implement 'rfebb' instruction Date: Sun, 17 Oct 2021 22:01:31 -0300 Message-Id: <20211018010133.315842-14-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::933; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x933.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519713888100001 Content-Type: text/plain; charset="utf-8" An Event-Based Branch (EBB) allows applications to change the NIA when a event-based exception occurs. Event-based exceptions are enabled by setting the Branch Event Status and Control Register (BESCR). If the event-based exception is enabled when the exception occurs, an EBB happens. The following operations happens during an EBB: - Global Enable (GE) bit of BESCR is set to 0; - bits 0-61 of the Event-Based Branch Return Register (EBBRR) are set to the the effective address of the NIA that would have executed if the EBB didn't happen; - Instruction fetch and execution will continue in the effective address contained in the Event-Based Branch Handler Register (EBBHR). The EBB Handler will process the event and then execute the Return From Event-Based Branch (rfebb) instruction. rfebb sets BESCR_GE and then redirects execution to the address pointed in EBBRR. This process is described in the PowerISA v3.1, Book II, Chapter 6 [1]. This patch implements the rfebb instruction. Descriptions of all relevant BESCR bits are also added - this patch is only using BESCR_GE, but the next patches will use the remaining bits. [1] https://wiki.raptorcs.com/w/images/f/f5/PowerISA_public.v3.1.pdf Reviewed-by: Matheus Ferst Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 13 ++++++++++ target/ppc/excp_helper.c | 31 ++++++++++++++++++++++++ target/ppc/helper.h | 1 + target/ppc/insn32.decode | 5 ++++ target/ppc/translate.c | 2 ++ target/ppc/translate/branch-impl.c.inc | 33 ++++++++++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 target/ppc/translate/branch-impl.c.inc diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 6f9a48a5a1..bccf135847 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -402,6 +402,19 @@ typedef struct PMUEvent { /* PMU uses CTRL_RUN to sample PM_RUN_INST_CMPL */ #define CTRL_RUN PPC_BIT(63) =20 +/* EBB/BESCR bits */ +/* Global Enable */ +#define BESCR_GE PPC_BIT(0) +/* External Event-based Exception Enable */ +#define BESCR_EE PPC_BIT(30) +/* Performance Monitor Event-based Exception Enable */ +#define BESCR_PME PPC_BIT(31) +/* External Event-based Exception Occurred */ +#define BESCR_EEO PPC_BIT(62) +/* Performance Monitor Event-based Exception Occurred */ +#define BESCR_PMEO PPC_BIT(63) +#define BESCR_INVALID PPC_BITMASK(32, 33) + /* LPCR bits */ #define LPCR_VPM0 PPC_BIT(0) #define LPCR_VPM1 PPC_BIT(1) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index b7d1767920..7be334e007 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -1248,6 +1248,37 @@ void helper_hrfid(CPUPPCState *env) } #endif =20 +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) +void helper_rfebb(CPUPPCState *env, target_ulong s) +{ + target_ulong msr =3D env->msr; + + /* + * Handling of BESCR bits 32:33 according to PowerISA v3.1: + * + * "If BESCR 32:33 !=3D 0b00 the instruction is treated as if + * the instruction form were invalid." + */ + if (env->spr[SPR_BESCR] & BESCR_INVALID) { + raise_exception_err(env, POWERPC_EXCP_PROGRAM, + POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL); + } + + env->nip =3D env->spr[SPR_EBBRR]; + + /* Switching to 32-bit ? Crop the nip */ + if (!msr_is_64bit(env, msr)) { + env->nip =3D (uint32_t)env->spr[SPR_EBBRR]; + } + + if (s) { + env->spr[SPR_BESCR] |=3D BESCR_GE; + } else { + env->spr[SPR_BESCR] &=3D ~BESCR_GE; + } +} +#endif + /*************************************************************************= ****/ /* Embedded PowerPC specific helpers */ void helper_40x_rfci(CPUPPCState *env) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index b0ebfaff51..8bc38b5e4b 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -18,6 +18,7 @@ DEF_HELPER_2(pminsn, void, env, i32) DEF_HELPER_1(rfid, void, env) DEF_HELPER_1(rfscv, void, env) DEF_HELPER_1(hrfid, void, env) +DEF_HELPER_2(rfebb, void, env, tl) DEF_HELPER_2(store_lpcr, void, env, tl) DEF_HELPER_2(store_pcr, void, env, tl) DEF_HELPER_2(store_mmcr0, void, env, tl) diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode index 9fd8d6b817..deb7374ea4 100644 --- a/target/ppc/insn32.decode +++ b/target/ppc/insn32.decode @@ -124,3 +124,8 @@ SETNBCR 011111 ..... ..... ----- 0111100000 - = @X_bi ## Vector Bit Manipulation Instruction =20 VCFUGED 000100 ..... ..... ..... 10101001101 @VX + +### rfebb +&XL_s s:uint8_t +@XL_s ......-------------- s:1 .......... - &XL_s +RFEBB 010011-------------- . 0010010010 - @XL_s diff --git a/target/ppc/translate.c b/target/ppc/translate.c index e2839883be..cdb1171b88 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7554,6 +7554,8 @@ static int times_4(DisasContext *ctx, int x) =20 #include "translate/spe-impl.c.inc" =20 +#include "translate/branch-impl.c.inc" + /* Handles lfdp, lxsd, lxssp */ static void gen_dform39(DisasContext *ctx) { diff --git a/target/ppc/translate/branch-impl.c.inc b/target/ppc/translate/= branch-impl.c.inc new file mode 100644 index 0000000000..29cfa11854 --- /dev/null +++ b/target/ppc/translate/branch-impl.c.inc @@ -0,0 +1,33 @@ +/* + * Power ISA decode for branch instructions + * + * Copyright IBM Corp. 2021 + * + * Authors: + * Daniel Henrique Barboza + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) + +static bool trans_RFEBB(DisasContext *ctx, arg_XL_s *arg) +{ + REQUIRE_INSNS_FLAGS2(ctx, ISA207S); + + gen_icount_io_start(ctx); + gen_update_cfar(ctx, ctx->cia); + gen_helper_rfebb(cpu_env, cpu_gpr[arg->s]); + + ctx->base.is_jmp =3D DISAS_CHAIN; + + return true; +} +#else +static bool trans_RFEBB(DisasContext *ctx, arg_XL_s *arg) +{ + gen_invalid(ctx); + return true; +} +#endif --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634519874231284.19566904191583; Sun, 17 Oct 2021 18:17:54 -0700 (PDT) Received: from localhost ([::1]:44106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHHl-0006Db-4V for importer@patchew.org; Sun, 17 Oct 2021 21:17:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2l-0006o9-A0; Sun, 17 Oct 2021 21:02:28 -0400 Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]:33407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2g-0002Ks-53; Sun, 17 Oct 2021 21:02:22 -0400 Received: by mail-ua1-x933.google.com with SMTP id i15so2012021uap.0; Sun, 17 Oct 2021 18:02:17 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GLP+INvU7AVLudP+9WEJdtGNrlv+vIQQsKgHDiZszmE=; b=EOCrn1TSBYctNoO/IJ/uksayD4S51m4CmqlOXhxt3DETPxmAdjedOqsy+Y63Cm104H FASnqgcXHAx+u+NW/vf8Y/BRaVH+OkXCso9zrN17a9Sbai5uZaIyFl+MCLUf/AlnJcWm Qu73Yf4Afg9RtdmIrGaRvup/yJJaSiLYKElDd/g+UrbK7V3IfNZ3j81GwhYoaAE/zjRw lbugBv4LhScZM9Qh2krPOu59LVtZ2cH+PfxKuKEq6TDF8Xi+YHg5kBrNfqRneRwnfllV a4naIgfYnKT1PoOgIBRqVVWmFNvQoOArJPtiM3kKe6nFF3Wql+fn8wgl33CWn7KUEUpp A9xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GLP+INvU7AVLudP+9WEJdtGNrlv+vIQQsKgHDiZszmE=; b=l4rRQ7ZLCIJUNGI96rHqxrIY2jyyrUbheWh8Sh4dFxcxCDE7ffTiB//8uODwKng2SS H+15h3oH6IwMrdaoOn+5s5Zc3cVNPobEWdDmn7816cKc+84S2Gw9RTIjQ0rmxe2MxpgK icuO0diEtHPHZ/Fz7MIwOtDPcMi6Y3mNxrdU2sFbUro559dv4mU6KSxuTDLGFdmjLotD wrxstTk9ybFS43zXAiCNTI9Idw+C2llzFjYtQyxHeqCNH7h/d5FwwFOAcBW6Jrshaqyi SpsOIpy06p3ITagZNlKw0K3sA2KGHmizVlSbtLRlEcZ5+JEqGg5hPmupQ4jVuwVVnoFi aWgA== X-Gm-Message-State: AOAM5306gkM3ZijLpkx22gnVaVpK804AZM7TLgLkRuuSIQ/ud97hiXec czrlDyn0AJ60/fVgRcEHCN31gWt6CEI= X-Google-Smtp-Source: ABdhPJysGApxsanmEm9aPc/JOw85rpwRE1TgDxHrKDHDViQceP49UWQtBmHNeJ6/EACCl7TY7qMGsg== X-Received: by 2002:a67:cb91:: with SMTP id h17mr25702128vsl.30.1634518936762; Sun, 17 Oct 2021 18:02:16 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 14/15] target/ppc: PMU Event-Based exception support Date: Sun, 17 Oct 2021 22:01:32 -0300 Message-Id: <20211018010133.315842-15-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::933; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x933.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gustavo Romero , Gustavo Romero , Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519875245100001 Content-Type: text/plain; charset="utf-8" From: Gustavo Romero Following up the rfebb implementation, this patch adds the EBB exception support that are triggered by Performance Monitor alerts. This exception occurs when an enabled PMU condition or event happens and both MMCR0_EBE and BESCR_PME are set. The supported PM alerts will consist of counter negative conditions of the PMU counters. This will be achieved by a timer mechanism that will predict when a counter becomes negative. The PMU timer callback will set the appropriate bits in MMCR0 and fire a PMC interrupt. The EBB exception code will then set the appropriate BESCR bits, set the next instruction pointer to the address pointed by the return register (SPR_EBBRR), and redirect execution to the handler (pointed by SPR_EBBHR). This patch sets the basic structure of interrupts and timers. The following patches will add the counter negative logic for the registers. CC: Gustavo Romero Signed-off-by: Gustavo Romero Signed-off-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 5 ++++- target/ppc/excp_helper.c | 28 ++++++++++++++++++++++++++++ target/ppc/power8-pmu.c | 26 ++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index bccf135847..98b6d6bfb5 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -129,8 +129,10 @@ enum { /* ISA 3.00 additions */ POWERPC_EXCP_HVIRT =3D 101, POWERPC_EXCP_SYSCALL_VECTORED =3D 102, /* scv exception = */ + POWERPC_EXCP_EBB =3D 103, /* Event-based branch exception = */ + /* EOL = */ - POWERPC_EXCP_NB =3D 103, + POWERPC_EXCP_NB =3D 104, /* QEMU exceptions: special cases we want to stop translation = */ POWERPC_EXCP_SYSCALL_USER =3D 0x203, /* System call in user mode only = */ }; @@ -2461,6 +2463,7 @@ enum { PPC_INTERRUPT_HMI, /* Hypervisor Maintenance interrupt */ PPC_INTERRUPT_HDOORBELL, /* Hypervisor Doorbell interrupt = */ PPC_INTERRUPT_HVIRT, /* Hypervisor virtualization interrupt = */ + PPC_INTERRUPT_PMC, /* Hypervisor virtualization interrupt = */ }; =20 /* Processor Compatibility mask (PCR) */ diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 7be334e007..88aa0a84f8 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -797,6 +797,22 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) cpu_abort(cs, "Non maskable external exception " "is not implemented yet !\n"); break; + case POWERPC_EXCP_EBB: /* Event-based branch exception = */ + if ((env->spr[SPR_BESCR] & BESCR_GE) && + (env->spr[SPR_BESCR] & BESCR_PME)) { + target_ulong nip; + + env->spr[SPR_BESCR] &=3D ~BESCR_GE; /* Clear GE */ + env->spr[SPR_BESCR] |=3D BESCR_PMEO; /* Set PMEO */ + env->spr[SPR_EBBRR] =3D env->nip; /* Save NIP for rfebb in= sn */ + nip =3D env->spr[SPR_EBBHR]; /* EBB handler */ + powerpc_set_excp_state(cpu, nip, env->msr); + } + /* + * This interrupt is handled by userspace. No need + * to proceed. + */ + return; default: excp_invalid: cpu_abort(cs, "Invalid PowerPC exception %d. Aborting\n", excp); @@ -1044,6 +1060,18 @@ static void ppc_hw_interrupt(CPUPPCState *env) powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_THERM); return; } + /* PMC -> Event-based branch exception */ + if (env->pending_interrupts & (1 << PPC_INTERRUPT_PMC)) { + /* + * Performance Monitor event-based exception can only + * occur in problem state. + */ + if (msr_pr =3D=3D 1) { + env->pending_interrupts &=3D ~(1 << PPC_INTERRUPT_PMC); + powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_EBB); + return; + } + } } =20 if (env->resume_as_sreset) { diff --git a/target/ppc/power8-pmu.c b/target/ppc/power8-pmu.c index 4bd07ba865..7ccdd03902 100644 --- a/target/ppc/power8-pmu.c +++ b/target/ppc/power8-pmu.c @@ -312,8 +312,30 @@ static void fire_PMC_interrupt(PowerPCCPU *cpu) return; } =20 - /* PMC interrupt not implemented yet */ - return; + if (env->spr[SPR_POWER_MMCR0] & MMCR0_FCECE) { + env->spr[SPR_POWER_MMCR0] &=3D ~MMCR0_FCECE; + env->spr[SPR_POWER_MMCR0] |=3D MMCR0_FC; + + /* Changing MMCR0_FC demands a new hflags compute */ + hreg_compute_hflags(env); + + /* + * Delete all pending timers if we need to freeze + * the PMC. We'll restart them when the PMC starts + * running again. + */ + pmu_delete_timers(env); + } + + pmu_events_update_cycles(env); + + if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMAE) { + env->spr[SPR_POWER_MMCR0] &=3D ~MMCR0_PMAE; + env->spr[SPR_POWER_MMCR0] |=3D MMCR0_PMAO; + } + + /* Fire the PMC hardware exception */ + ppc_set_irq(cpu, PPC_INTERRUPT_PMC, 1); } =20 /* This helper assumes that the PMC is running. */ --=20 2.31.1 From nobody Tue May 21 22:26:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163451991928237.529059107821695; Sun, 17 Oct 2021 18:18:39 -0700 (PDT) Received: from localhost ([::1]:46320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcHIU-0007j8-7D for importer@patchew.org; Sun, 17 Oct 2021 21:18:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcH2k-0006nx-1A; Sun, 17 Oct 2021 21:02:26 -0400 Received: from mail-ua1-x936.google.com ([2607:f8b0:4864:20::936]:42531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcH2i-0002Xw-39; Sun, 17 Oct 2021 21:02:21 -0400 Received: by mail-ua1-x936.google.com with SMTP id j8so805911uak.9; Sun, 17 Oct 2021 18:02:19 -0700 (PDT) Received: from rekt.COMFAST ([179.247.137.170]) by smtp.gmail.com with ESMTPSA id m15sm8271607vsh.31.2021.10.17.18.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 18:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BMK2Tx+kwGAmYMCHy6MUgl+RIwVRP6pzB3y+fnPF6hY=; b=icT/EVpbpcNXR0M823a/RG3Ej3yu4qxx7VTmaq+YT20QlhdvJVEHzAAuBGcszzm6WX wZeIylInIJYXif8cl1HkC+2LoSjTKm+erG+cLdCTpvMVR7qwmUiO664ubbFKJHX42aiw ZWvLK6PQewIoOnkaWuZ+O3MwuAZIrpmkcBfYFwnuNJ2qcp/AQJj9tdrBdzefCSDix1K4 mMWSebno84wHC13iJ2VrW9c6apqwGRUisHFb/pKsU1l/KeMsmPZY0AaDaJUmFn+E7/Up +iygZ8SD5g7kRWcLZH4MOzMor1s24+rEpX0Nq2x6vsVd7jj/lkkJLlEkI3evYEYBX/P8 5myg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BMK2Tx+kwGAmYMCHy6MUgl+RIwVRP6pzB3y+fnPF6hY=; b=eqeiLr5nkG/ZP2NPuVTdm5v5YZdMF/tcz7Cj93QTOy5Hjo3sv8ULB0FH9UdeNQ8m3x GqNuOKpTc0c2qbyjA7XfRLxtWK6Uxr/vpGkrZT5Xn4pxNYPPSXhy6cS7bHzPwCHvYIua LWxXwwUghcLjPHANgNlKV+pb85jI2+f+LIpkuHy/u9aKFHj3GU36DXms1xR9spE7/zOH PPc8hzAJ9QHrh8pOYt/7thDtchJM8pud2RYQGaC7My4nXHWVFKDHFA2FczQWT9dY3dDN LcpMrg2Wa8vxX+vHkZKvcxPTbX8RJv493j9V2Z5QBopZDV4ENkhkIzaF2VBkiOy/duWt UhFQ== X-Gm-Message-State: AOAM533NYikNQkIxwks7JrOCgahlFsLb3BIn4uhXmu5SMhIoCp83soZX mDhdRKW24fataF1Z4slwD+yVpWlWIIA= X-Google-Smtp-Source: ABdhPJx1ujorHbSAaEgko4apiqqzbNdeIOfDDTYJ0t5l7LlxWAu/22RqCcW1Ct1CaGADX3gFweH9Ww== X-Received: by 2002:a05:6102:274e:: with SMTP id p14mr24568449vsu.24.1634518938886; Sun, 17 Oct 2021 18:02:18 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v4 15/15] target/ppc/excp_helper.c: EBB handling adjustments Date: Sun, 17 Oct 2021 22:01:33 -0300 Message-Id: <20211018010133.315842-16-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018010133.315842-1-danielhb413@gmail.com> References: <20211018010133.315842-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::936; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x936.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , richard.henderson@linaro.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634519920325100001 Content-Type: text/plain; charset="utf-8" The current logic is only considering event-based exceptions triggered by the performance monitor. This is true now, but we might want to add support for external event-based exceptions in the future. Let's make it a bit easier to do so by adding the bit logic that would happen in case we were dealing with an external event-based exception. While we're at it, add a few comments explaining why we're setting and clearing BESCR bits. Signed-off-by: Daniel Henrique Barboza --- target/ppc/excp_helper.c | 45 ++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 88aa0a84f8..d30020d991 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -798,14 +798,47 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int = excp_model, int excp) "is not implemented yet !\n"); break; case POWERPC_EXCP_EBB: /* Event-based branch exception = */ - if ((env->spr[SPR_BESCR] & BESCR_GE) && - (env->spr[SPR_BESCR] & BESCR_PME)) { + if (env->spr[SPR_BESCR] & BESCR_GE) { target_ulong nip; =20 - env->spr[SPR_BESCR] &=3D ~BESCR_GE; /* Clear GE */ - env->spr[SPR_BESCR] |=3D BESCR_PMEO; /* Set PMEO */ - env->spr[SPR_EBBRR] =3D env->nip; /* Save NIP for rfebb in= sn */ - nip =3D env->spr[SPR_EBBHR]; /* EBB handler */ + /* + * If we have Performance Monitor Event-Based exception + * enabled (BESCR_PME) and a Performance Monitor alert + * occurred (MMCR0_PMAO), clear BESCR_PME and set BESCR_PMEO + * (Performance Monitor Event-Based Exception Occurred). + * + * Software is responsible for clearing both BESCR_PMEO and + * MMCR0_PMAO after the event has been handled. + */ + if ((env->spr[SPR_BESCR] & BESCR_PME) && + (env->spr[SPR_POWER_MMCR0] & MMCR0_PMAO)) { + env->spr[SPR_BESCR] &=3D ~BESCR_PME; + env->spr[SPR_BESCR] |=3D BESCR_PMEO; + } + + /* + * In the case of External Event-Based exceptions, do a + * similar logic with BESCR_EE and BESCR_EEO. BESCR_EEO must + * also be cleared by software. + * + * PowerISA 3.1 considers that we'll not have BESCR_PMEO and + * BESCR_EEO set at the same time. We can check for BESCR_PMEO + * being not set in step above to see if this exception was + * trigged by an external event. + */ + if (env->spr[SPR_BESCR] & BESCR_EE && + !(env->spr[SPR_BESCR] & BESCR_PMEO)) { + env->spr[SPR_BESCR] &=3D ~BESCR_EE; + env->spr[SPR_BESCR] |=3D BESCR_EEO; + } + + /* + * Clear BESCR_GE, save NIP for 'rfebb' and point the + * execution to the event handler (SPR_EBBHR) address. + */ + env->spr[SPR_BESCR] &=3D ~BESCR_GE; + env->spr[SPR_EBBRR] =3D env->nip; + nip =3D env->spr[SPR_EBBHR]; powerpc_set_excp_state(cpu, nip, env->msr); } /* --=20 2.31.1