From nobody Tue Nov 26 20:22:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1703810923; cv=none; d=zohomail.com; s=zohoarc; b=A0dPh4fuBHreLzn77x4l8eTvknF1O1I9x3bLjRX9uFDrpiYr3GzKm48SibLFSXJCkTfLZqNW0l8XWLj6erxMJfK0IHh4/nq1bySzP2tTc2voGszkcSZT9zlOeXxdVFj1GuZTI0KHRgc5ZvtWsfvRilGm6qc644Va7FcxdmQVmyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703810923; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=fWSemVhRUsCz8p0+3ae6g0l+nSsjC5vmMvnfzltKtbw=; b=RNacU2RjkyONqf/6pRSSmS6n99ysyMqrRm1ZVrh8NWvQjKc1TgUkHynxk4fBKSkngH42GSwY7MIjRq8XnQKxgkAQhsFxJXM8E0LjrU4N8itYt8oPuNqj98ewIgGprx0kY6PGag1/LgSrRIKc0dof7C2iWjNE0CZ5rLBF7bTHpms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703810923283608.592306199109; Thu, 28 Dec 2023 16:48:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJ12K-0003QW-VX; Thu, 28 Dec 2023 19:47:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJ12J-0003QA-6s for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:39 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJ12H-0002uf-3q for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:38 -0500 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3bbd6e377dfso571522b6e.3 for ; Thu, 28 Dec 2023 16:47:36 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z3-20020a170902ee0300b001d3561680aasm14393949plb.82.2023.12.28.16.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 16:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703810855; x=1704415655; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=fWSemVhRUsCz8p0+3ae6g0l+nSsjC5vmMvnfzltKtbw=; b=SPFABhWtMmVPK8KXArrj0anJoC5R0nkn9gySu0NwabNitbB1YwH27fLtK37wecF7kI Nf9PWN//b3EJ1cGtCMPtjTf7A1/Vz+Fcyg6vKxxKXWJYPZMGtflplsjAo1T24pwwY/xo PqBMNcxjM6av6DEuupYZ+JbUMWRLSG3dq+p8B20YbeDozlCshz7YkJcS5q39O8OvGhpc OlhbnxqQTHvYCkmgTZ13VaLXbfOGvRJRHibdON+xwOpBx3xHZMZ+X+MCn1Pzy8pbivIO E/WzJkTQOCjUjxmadbM0SpYzt8eAgl8fhO2LWeba6cUvsPkaHYd/XFc+rI/39W7Qf3g5 TgpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703810855; x=1704415655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fWSemVhRUsCz8p0+3ae6g0l+nSsjC5vmMvnfzltKtbw=; b=uZwCs2bUiGfQbDpHMTYS4iT8pTa0FZ45EdMayudtUof5Rb0w+Ur6+Y6pvakBeiPQCd eBM9kZ/vY4sxGTmT3mEqS0p/pclIcRJvaT450e9maOLi9Vc77cmZ5ZuZvQ/ObyNn85NX /KSw2GxVHTGJ5cN40DGyIMujrMF06MDtwfvRCUkOhwbw4ngoK5CWk+M6c7hVFUrQgfih TAtcUsLYXjHDiqp8GAGr66s4qI96NOEmlBMTy9l+cde7bW9ditejaVLp9T5CIvDu4A/b Oy0/aVxDNjvh/CDCSMERfbYdpTZUXdxw9oGdKG2AjBRqj5ZlWHR/D+tITX+bJKKM+kfP 2GCA== X-Gm-Message-State: AOJu0YzLNHMATwwNpC69gzlNhxoS6JZhLrPgbFO8RBprBQuya7ldNo7o dsiJJEvqTfBAzKe7xv8rssaXJjJOoLQkB5plrdKEZyS2S7o= X-Google-Smtp-Source: AGHT+IGWL99JSXrfQt1hLslELS7qHukBhVrplXLAX/6YUceD3K6iqQeVhISo05SZGOer5PKb765Oxg== X-Received: by 2002:a05:6808:640f:b0:3bb:df3c:8d49 with SMTP id fg15-20020a056808640f00b003bbdf3c8d49mr525915oib.116.1703810855090; Thu, 28 Dec 2023 16:47:35 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [v2 1/5] target/riscv: Fix the predicate functions for mhpmeventhX CSRs Date: Thu, 28 Dec 2023 16:47:27 -0800 Message-Id: <20231229004731.3841550-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231229004731.3841550-1-atishp@rivosinc.com> References: <20231229004731.3841550-1-atishp@rivosinc.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::231; envelope-from=atishp@rivosinc.com; helo=mail-oi1-x231.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703810925423100011 Content-Type: text/plain; charset="utf-8" mhpmeventhX CSRs are available for RV32. The predicate function should check that first before checking sscofpmf extension. Fixes: 14664483457b ("target/riscv: Add sscofpmf extension support") Signed-off-by: Atish Patra --- target/riscv/csr.c | 67 ++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index fde7ce1a5336..283468bbc652 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -224,6 +224,15 @@ static RISCVException sscofpmf(CPURISCVState *env, int= csrno) return RISCV_EXCP_NONE; } =20 +static RISCVException sscofpmf_32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return sscofpmf(env, csrno); +} + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -4972,91 +4981,91 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_mhpmevent, write_mhpmevent }, =20 - [CSR_MHPMEVENT3H] =3D { "mhpmevent3h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT3H] =3D { "mhpmevent3h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT4H] =3D { "mhpmevent4h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT4H] =3D { "mhpmevent4h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT5H] =3D { "mhpmevent5h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT5H] =3D { "mhpmevent5h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT6H] =3D { "mhpmevent6h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT6H] =3D { "mhpmevent6h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT7H] =3D { "mhpmevent7h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT7H] =3D { "mhpmevent7h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT8H] =3D { "mhpmevent8h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT8H] =3D { "mhpmevent8h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT9H] =3D { "mhpmevent9h", sscofpmf, read_mhpmevent= h, + [CSR_MHPMEVENT9H] =3D { "mhpmevent9h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT10H] =3D { "mhpmevent10h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT10H] =3D { "mhpmevent10h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT11H] =3D { "mhpmevent11h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT11H] =3D { "mhpmevent11h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT12H] =3D { "mhpmevent12h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT12H] =3D { "mhpmevent12h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT13H] =3D { "mhpmevent13h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT13H] =3D { "mhpmevent13h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT14H] =3D { "mhpmevent14h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT14H] =3D { "mhpmevent14h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT15H] =3D { "mhpmevent15h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT15H] =3D { "mhpmevent15h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT16H] =3D { "mhpmevent16h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT16H] =3D { "mhpmevent16h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT17H] =3D { "mhpmevent17h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT17H] =3D { "mhpmevent17h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT18H] =3D { "mhpmevent18h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT18H] =3D { "mhpmevent18h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT19H] =3D { "mhpmevent19h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT19H] =3D { "mhpmevent19h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT20H] =3D { "mhpmevent20h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT20H] =3D { "mhpmevent20h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT21H] =3D { "mhpmevent21h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT21H] =3D { "mhpmevent21h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT22H] =3D { "mhpmevent22h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT22H] =3D { "mhpmevent22h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT23H] =3D { "mhpmevent23h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT23H] =3D { "mhpmevent23h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT24H] =3D { "mhpmevent24h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT24H] =3D { "mhpmevent24h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT25H] =3D { "mhpmevent25h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT25H] =3D { "mhpmevent25h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT26H] =3D { "mhpmevent26h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT26H] =3D { "mhpmevent26h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT27H] =3D { "mhpmevent27h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT27H] =3D { "mhpmevent27h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT28H] =3D { "mhpmevent28h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT28H] =3D { "mhpmevent28h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT29H] =3D { "mhpmevent29h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT29H] =3D { "mhpmevent29h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT30H] =3D { "mhpmevent30h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT30H] =3D { "mhpmevent30h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MHPMEVENT31H] =3D { "mhpmevent31h", sscofpmf, read_mhpmeven= th, + [CSR_MHPMEVENT31H] =3D { "mhpmevent31h", sscofpmf_32, read_mhpme= venth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, =20 --=20 2.34.1 From nobody Tue Nov 26 20:22:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1703810957; cv=none; d=zohomail.com; s=zohoarc; b=l4khPbDfvVufooeswyLVxvLOEvOr3nRekOO34uEWcuk/35n9WFW+bLtLtvMAABeOptEF6hFQw+qw05D3E1vPXciXu6Mf8e3+MTRe5vVXvO62QN4V6R7gdIdo9whts+F16Qc2nd/ooD8eLL3wZHNTBP9Hhx00hke1cw3TRMaWHYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703810957; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=AVDVq7i2S5ZvAV5+/0uStEZfRYh+joB7RC2I6xYSmWs=; b=GZz5imZlbsWwJrP+0cxpqH4IV2yWsU7fWaoUHEFQJHWL6xbVRv4NIFsNfnUNl9TjA933jflydXqtYQgn+ydt43ohjhzl+w/t+r/pgxCqWBj0Tcr4DkCyd/Ufha+q4pAULZ2imI0tmKYXaIGQhdDXS8KgzWaN7FQCCWRaKm482kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703810957422205.72450621749726; Thu, 28 Dec 2023 16:49:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJ12L-0003RF-GN; Thu, 28 Dec 2023 19:47:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJ12K-0003QJ-4m for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:40 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJ12I-0002yO-HF for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:39 -0500 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-35fea35c432so42915515ab.0 for ; Thu, 28 Dec 2023 16:47:38 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z3-20020a170902ee0300b001d3561680aasm14393949plb.82.2023.12.28.16.47.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 16:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703810856; x=1704415656; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AVDVq7i2S5ZvAV5+/0uStEZfRYh+joB7RC2I6xYSmWs=; b=QcpNufAuIrTEy/yRRaoPJGXDJ4dhh20fycy/yRzr22MLmwkWluF59ExSJII7uqjN0q AN6kaX4zC6/B0AzJ1DCpCw6dK4yxo22wNOj3hp2eVwdI5dukijL4JKEOZWjrKINa96Gy 2qg88koytJGbMfj+XkpjTAeR4WUsWgnMTNkevJ/SZCy/FvPZo06yjFwwQvKMRR7vZENp uzfW4bIn/WAkeG89SyQ9Zfib1TqaFyL3lxVwKCd7LJHAPJCB6Yndrn1ZnJheisZ/so+Z OrAa//sS8RZygWXIJ6CR9poeS25UP4iWUsN0zt4fbiPPb58Ypr8xXfp2BuYgj7EgfXXF AnNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703810856; x=1704415656; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AVDVq7i2S5ZvAV5+/0uStEZfRYh+joB7RC2I6xYSmWs=; b=J6avN4yr/vryeXsdyLmGAt2PPVJJyl1V+4lzFSD26T0kyBxHet3/TZqdw8AbBvrE+5 2COi4HMYO0l/89jzIxAi5BF1osx/L5xH3ImxEWe7in3p9AdXJ4EESAoKmPinZqqxiEiD jvpOV2oXdggs02QtKf5hwa5J0FZ5gBRalh2n19J+zjeEfkONjrrmUfRNeV6BWN6XYPsc KSPpskmsvWXACsaHWv552uGpcWn2Ox7fwpom/F3lDdlkV30cuE92WjfOwuAAyqQl1PhI ORfl9CajPbC5O/cgiX9IINNdh3zKxd4EWcQZz3ihhXXf0pK7vFCwEtS3S5S9Zaox1jkq b6CQ== X-Gm-Message-State: AOJu0Yz5d6p0FMtRicjMNWBknRykDdi3E9XIyxyErkhY9zUQVtKjjlCC Y+qZg/ng8/hRRl6QiuVWVNnL7cALMOk9g/r9DUpGUqUji1s= X-Google-Smtp-Source: AGHT+IHkqRzxPcpDiIOyVvaL60M736+G9vz4QgXSMqEif8MZY5enJ1aRoQrhSp+QW0ZcgOWlYUvZQQ== X-Received: by 2002:a05:6e02:18ca:b0:35f:f819:b2a7 with SMTP id s10-20020a056e0218ca00b0035ff819b2a7mr13686302ilu.115.1703810856095; Thu, 28 Dec 2023 16:47:36 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [v2 2/5] target/riscv: Add cycle & instret privilege mode filtering properties Date: Thu, 28 Dec 2023 16:47:28 -0800 Message-Id: <20231229004731.3841550-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231229004731.3841550-1-atishp@rivosinc.com> References: <20231229004731.3841550-1-atishp@rivosinc.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::130; envelope-from=atishp@rivosinc.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703810959474100005 Content-Type: text/plain; charset="utf-8" From: Kaiwen Xue This adds the properties for ISA extension smcntrpmf. Patches implementing it will follow. Signed-off-by: Atish Patra Signed-off-by: Kaiwen Xue --- target/riscv/cpu.c | 3 ++- target/riscv/cpu_cfg.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 83c7c0cf07be..da3f05cd5373 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -148,6 +148,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), + ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu), ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), @@ -1296,6 +1297,7 @@ const char *riscv_get_misa_ext_description(uint32_t b= it) const RISCVCPUMultiExtConfig riscv_cpu_extensions[] =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), + DEFINE_PROP_BOOL("smcntrpmf", RISCVCPU, cfg.ext_smcntrpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), @@ -1308,7 +1310,6 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), - MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false), MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index f4605fb190b9..00c34fdd3209 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -72,6 +72,7 @@ struct RISCVCPUConfig { bool ext_zihpm; bool ext_smstateen; bool ext_sstc; + bool ext_smcntrpmf; bool ext_svadu; bool ext_svinval; bool ext_svnapot; --=20 2.34.1 From nobody Tue Nov 26 20:22:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1703810941; cv=none; d=zohomail.com; s=zohoarc; b=H1h+tSPeXqiJK7QF9zpL2FUACwYJMVJsH875N5wGTlQdXmqAVI4k+9CcTe3HV/2RJ+ApzhW7EQge7e2gJjFwRJEwGXFbB8H6EJUHMXYEaDVa333dzHf7wUV2CQnz7hJH9J3jt3A+bZZtHEsk+Ip6PrgzWnjjTuL1ccmAdwxeGvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703810941; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=KT0dgX+fbfi05uQpO/YMpPX7vZZAzvk8bOn5ql7e53k=; b=fJ3YFiF50ceO26Jm0caugCMNqdRFagpJr26nNFwPgC1KLDiRGfcPnShYWer2szVBH4wudYyZ9sLRIkJ+QzH7ZzNKQE0yQGoaLavRJMBXXQunOdslBDCJEhkWWHd2ClYEQDP74/PpWK9A0Mk6sQqLiu0F7CLaNbOlX3pj/Lz8jRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703810941580145.77526442744738; Thu, 28 Dec 2023 16:49:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJ12M-0003Ro-Pf; Thu, 28 Dec 2023 19:47:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJ12L-0003Ql-4M for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:41 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJ12J-0002yT-Es for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:40 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5cdfa676fa3so3095281a12.1 for ; Thu, 28 Dec 2023 16:47:39 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z3-20020a170902ee0300b001d3561680aasm14393949plb.82.2023.12.28.16.47.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 16:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703810857; x=1704415657; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KT0dgX+fbfi05uQpO/YMpPX7vZZAzvk8bOn5ql7e53k=; b=ulxC2axbHHzsCgtsPXMs1NHCfFI+nsKnwIafxjTspqPFX8L6ToHKoVcyu3AD5h2W+V 791OJyFTLLrZ5Dgngf9vKDzv7VowI5OtYTTaZ1cvMiI246MyRYsqonJNBDk1MyydrMNE at2r31tLumXQjwAPfnwFly+EoX0GkT89lCb76Z5b3L9Z6O3ju2nCY7dCBr08NwQcZRLd Tp8rRa0K2cXW46kVhBXULKnRXrunHLdBmgM0Jd9+XC+e1BJEWi3GiL6Wc3S+ra/XOsSU oW75E68JUcEYnCvOE7hH61eZJmN2PzVz7etf4Iz02xMYBSXZZPAd6PjI/oTEm9cUo99H woTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703810857; x=1704415657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KT0dgX+fbfi05uQpO/YMpPX7vZZAzvk8bOn5ql7e53k=; b=YVuu+52PPMO3zKBkOIgD70tF7FzysxAvROhVXaaQvFDeRrEcnn4S59PiLk3vf8B5he AUfiTIF8oObsC3ma5s/+8KS04mxPnOUt5ospNSIiBJGi4swP/jqsso370fFWM/+y8zIK FRXyNq8LIokILq11ZOYHwvtJgYorfTOlHFnFpI4PMkfkROoaPBJ871Ws5i/qoZwGb4HX PavcbWxE2t1J3ydA+ua3b6W1osHsYR143+Hq/x5PXPNT8RM7R6O+hGlSEUAihC9/EWAU 0sIJR5nFGHBZ/A7ZX86V2QM6AyiCT60x4iXguL9NU40/ouugiEyVWj4L32Il5bBgVKGs q91A== X-Gm-Message-State: AOJu0YwLCP10EapE9xZsqAIGzEFpUAhBmvCWyTvP5Qq78RwRyrNe8d7J qTQD+oSo5qT9IOPcQZuvwX2xUyB8iNzLmead4u1De2JoiPY= X-Google-Smtp-Source: AGHT+IEE+awqnuXnv9wfkqPuuq2HD46EPQ8bY2SmOduADCedh8PArl0J60mleimxX3bgrXczdJq6Dg== X-Received: by 2002:a17:90a:740c:b0:28b:bd8a:1bf8 with SMTP id a12-20020a17090a740c00b0028bbd8a1bf8mr12684743pjg.35.1703810857583; Thu, 28 Dec 2023 16:47:37 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [v2 3/5] target/riscv: Add cycle & instret privilege mode filtering definitions Date: Thu, 28 Dec 2023 16:47:29 -0800 Message-Id: <20231229004731.3841550-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231229004731.3841550-1-atishp@rivosinc.com> References: <20231229004731.3841550-1-atishp@rivosinc.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::52a; envelope-from=atishp@rivosinc.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703810943304100003 Content-Type: text/plain; charset="utf-8" From: Kaiwen Xue This adds the definitions for ISA extension smcntrpmf. Signed-off-by: Kaiwen Xue Signed-off-by: Atish Patra --- target/riscv/cpu.c | 1 - target/riscv/cpu.h | 6 ++++++ target/riscv/cpu_bits.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index da3f05cd5373..54395f95b299 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1297,7 +1297,6 @@ const char *riscv_get_misa_ext_description(uint32_t b= it) const RISCVCPUMultiExtConfig riscv_cpu_extensions[] =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), - DEFINE_PROP_BOOL("smcntrpmf", RISCVCPU, cfg.ext_smcntrpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d74b361be641..34617c4c4bab 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -319,6 +319,12 @@ struct CPUArchState { =20 target_ulong mcountinhibit; =20 + /* PMU cycle & instret privilege mode filtering */ + target_ulong mcyclecfg; + target_ulong mcyclecfgh; + target_ulong minstretcfg; + target_ulong minstretcfgh; + /* PMU counter state */ PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS]; =20 diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index ebd7917d490a..0ee91e502e8f 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -401,6 +401,10 @@ /* Machine counter-inhibit register */ #define CSR_MCOUNTINHIBIT 0x320 =20 +/* Machine counter configuration registers */ +#define CSR_MCYCLECFG 0x321 +#define CSR_MINSTRETCFG 0x322 + #define CSR_MHPMEVENT3 0x323 #define CSR_MHPMEVENT4 0x324 #define CSR_MHPMEVENT5 0x325 @@ -431,6 +435,9 @@ #define CSR_MHPMEVENT30 0x33e #define CSR_MHPMEVENT31 0x33f =20 +#define CSR_MCYCLECFGH 0x721 +#define CSR_MINSTRETCFGH 0x722 + #define CSR_MHPMEVENT3H 0x723 #define CSR_MHPMEVENT4H 0x724 #define CSR_MHPMEVENT5H 0x725 @@ -885,6 +892,28 @@ typedef enum RISCVException { /* PMU related bits */ #define MIE_LCOFIE (1 << IRQ_PMU_OVF) =20 +#define MCYCLECFG_BIT_MINH BIT_ULL(62) +#define MCYCLECFGH_BIT_MINH BIT(30) +#define MCYCLECFG_BIT_SINH BIT_ULL(61) +#define MCYCLECFGH_BIT_SINH BIT(29) +#define MCYCLECFG_BIT_UINH BIT_ULL(60) +#define MCYCLECFGH_BIT_UINH BIT(28) +#define MCYCLECFG_BIT_VSINH BIT_ULL(59) +#define MCYCLECFGH_BIT_VSINH BIT(27) +#define MCYCLECFG_BIT_VUINH BIT_ULL(58) +#define MCYCLECFGH_BIT_VUINH BIT(26) + +#define MINSTRETCFG_BIT_MINH BIT_ULL(62) +#define MINSTRETCFGH_BIT_MINH BIT(30) +#define MINSTRETCFG_BIT_SINH BIT_ULL(61) +#define MINSTRETCFGH_BIT_SINH BIT(29) +#define MINSTRETCFG_BIT_UINH BIT_ULL(60) +#define MINSTRETCFGH_BIT_UINH BIT(28) +#define MINSTRETCFG_BIT_VSINH BIT_ULL(59) +#define MINSTRETCFGH_BIT_VSINH BIT(27) +#define MINSTRETCFG_BIT_VUINH BIT_ULL(58) +#define MINSTRETCFGH_BIT_VUINH BIT(26) + #define MHPMEVENT_BIT_OF BIT_ULL(63) #define MHPMEVENTH_BIT_OF BIT(31) #define MHPMEVENT_BIT_MINH BIT_ULL(62) --=20 2.34.1 From nobody Tue Nov 26 20:22:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1703810957; cv=none; d=zohomail.com; s=zohoarc; b=aMzQzEFqgqYMtj/qlmatFRunl/NuPYQBe7htsHGkdaxfwz/LfAEDznzcRk7rJ/RDtCVYw7IfToufP43BbCN311b83qSYad4by/PEdTIRy99YjijeB0JgonZeYsa/wkMnEBtjnKkS/iGFzpv2IhDnOmZ6ivlNdpv4NVDAZUjWP6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703810957; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=RMkfNrfu3BNKw2loqhAx42IyUfatsJHkamEf6PqwbN8=; b=oLJSAnaNxcISgGcue5DS9xlUAijHfYpLAO+N40YcU7OtS2Ar+Iubama7RPCwT/7SVbJCbjSe/XcYS8J9z8LRbRBBJIov+NbcrMJBF5SzoKCdk6En853ZIB+Wa0u/O7/KL77/Fla5nHqXj5UesSuUTJJi3yCW6ceIJFEfeA76610= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703810957933968.1142770595708; Thu, 28 Dec 2023 16:49:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJ12N-0003Rs-HI; Thu, 28 Dec 2023 19:47:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJ12M-0003RM-Bu for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:42 -0500 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJ12K-0002zZ-Hh for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:42 -0500 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-35fe9a6609eso43429115ab.2 for ; Thu, 28 Dec 2023 16:47:40 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z3-20020a170902ee0300b001d3561680aasm14393949plb.82.2023.12.28.16.47.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 16:47:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703810858; x=1704415658; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RMkfNrfu3BNKw2loqhAx42IyUfatsJHkamEf6PqwbN8=; b=U6uerYm9jUzsKRDU1J3w8riVnJsuiDpMss8P14eEZmunBIlZ3VsrA2g7kQeQHIrPGq C3gEH9LSDJwbCwvV/Z7okqtbQ5EAjklQiHxtF4llXQcY/HTBs5an/51cYf+afoBuMkzi VLYdx/3/EZTb9LnG44IS/sxYPHfJgxe59Nb3E3kfJF/7/jZb/7W9486h2A1UasdfX2n3 3xKqOg7hulq9ELsC2Y/U87+N0xIDnpTYEJJKX5nyEfw/NWvF9Nos/bIr9KLuDOvz7Uyx Tr/nDVeKud7MzMeTM9IO9fBzM+pZdNIeez/xuQm1jeSYi3JY6cz9wUrDBfCqfMxKnlv4 jkCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703810858; x=1704415658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMkfNrfu3BNKw2loqhAx42IyUfatsJHkamEf6PqwbN8=; b=aXlL155MVnEN3x5qV9Y3jt05/OuPCJbMY39FwUmAocdVLHLBkpEcx+plrZP7f6LUWM jytNxv9FP0Bm2KWvdhJgNzot+ZzzPQWieJLarN99XcTBgOQZ1mskohpwqvAjwTMkAfy4 wrch1BPKXQPrJxQ/x5IuyMLMoffiV1ICxKxmNM7kSwjGyIfPYZXgz1ln+NaTXJg9tl64 id9qTFuqUVIgiEf+597TCozkjvP4VbR9T6xbjL5e/bPEhyAS1hLAGx0C11z8FOojluP5 80b+XapNJ9f45ORtwhQz0PhsuXQa4XuhXkLOCwYMf2u0s+wDveriuoKwJ7jfKvGQXIlU 5hqw== X-Gm-Message-State: AOJu0YxA9YD+5ilkXgMfQmGRnQKeENagHvNEqwPtmjiHW1L/pKt2zPJz RegSQIrsFBM7AOoma2Z4vdQPZ7YabDgfyrVap5aAh3GtNU8= X-Google-Smtp-Source: AGHT+IF60Kep03IMceK5E6GmPRnrkUbQ/IfjVTwBk0h1H8MmGRpWCBwrRQPmCV6ReOqHZ8DvWNeMBQ== X-Received: by 2002:a05:6e02:1446:b0:360:c7:72a4 with SMTP id p6-20020a056e02144600b0036000c772a4mr9977070ilo.72.1703810858618; Thu, 28 Dec 2023 16:47:38 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [v2 4/5] target/riscv: Add cycle & instret privilege mode filtering support Date: Thu, 28 Dec 2023 16:47:30 -0800 Message-Id: <20231229004731.3841550-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231229004731.3841550-1-atishp@rivosinc.com> References: <20231229004731.3841550-1-atishp@rivosinc.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::12e; envelope-from=atishp@rivosinc.com; helo=mail-il1-x12e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703810959497100006 Content-Type: text/plain; charset="utf-8" From: Kaiwen Xue QEMU only calculates dummy cycles and instructions, so there is no actual means to stop the icount in QEMU. Hence this patch merely adds the functionality of accessing the cfg registers, and cause no actual effects on the counting of cycle and instret counters. Signed-off-by: Atish Patra Signed-off-by: Kaiwen Xue --- target/riscv/cpu.c | 1 + target/riscv/csr.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 54395f95b299..d24f7ff8b55b 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1297,6 +1297,7 @@ const char *riscv_get_misa_ext_description(uint32_t b= it) const RISCVCPUMultiExtConfig riscv_cpu_extensions[] =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), + MULTI_EXT_CFG_BOOL("smcntrpmf", ext_smcntrpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 283468bbc652..618e801a7612 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -233,6 +233,27 @@ static RISCVException sscofpmf_32(CPURISCVState *env, = int csrno) return sscofpmf(env, csrno); } =20 +static RISCVException smcntrpmf(CPURISCVState *env, int csrno) +{ + RISCVCPU *cpu =3D env_archcpu(env); + + if (!cpu->cfg.ext_smcntrpmf) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + +static RISCVException smcntrpmf_32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smcntrpmf(env, csrno); +} + + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -818,6 +839,54 @@ static int read_hpmcounterh(CPURISCVState *env, int cs= rno, target_ulong *val) =20 #else /* CONFIG_USER_ONLY */ =20 +static int read_mcyclecfg(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->mcyclecfg; + return RISCV_EXCP_NONE; +} + +static int write_mcyclecfg(CPURISCVState *env, int csrno, target_ulong val) +{ + env->mcyclecfg =3D val; + return RISCV_EXCP_NONE; +} + +static int read_mcyclecfgh(CPURISCVState *env, int csrno, target_ulong *va= l) +{ + *val =3D env->mcyclecfgh; + return RISCV_EXCP_NONE; +} + +static int write_mcyclecfgh(CPURISCVState *env, int csrno, target_ulong va= l) +{ + env->mcyclecfgh =3D val; + return RISCV_EXCP_NONE; +} + +static int read_minstretcfg(CPURISCVState *env, int csrno, target_ulong *v= al) +{ + *val =3D env->minstretcfg; + return RISCV_EXCP_NONE; +} + +static int write_minstretcfg(CPURISCVState *env, int csrno, target_ulong v= al) +{ + env->minstretcfg =3D val; + return RISCV_EXCP_NONE; +} + +static int read_minstretcfgh(CPURISCVState *env, int csrno, target_ulong *= val) +{ + *val =3D env->minstretcfgh; + return RISCV_EXCP_NONE; +} + +static int write_minstretcfgh(CPURISCVState *env, int csrno, target_ulong = val) +{ + env->minstretcfgh =3D val; + return RISCV_EXCP_NONE; +} + static int read_mhpmevent(CPURISCVState *env, int csrno, target_ulong *val) { int evt_index =3D csrno - CSR_MCOUNTINHIBIT; @@ -4922,6 +4991,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { write_mcountinhibit, .min_priv_ver =3D PRIV_VERSION_1_11_0 }, =20 + [CSR_MCYCLECFG] =3D { "mcyclecfg", smcntrpmf, read_mcyclecfg, + write_mcyclecfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MINSTRETCFG] =3D { "minstretcfg", smcntrpmf, read_minstretcfg, + write_minstretcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_mhpmevent, write_mhpmevent }, [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_mhpmevent, @@ -4981,6 +5057,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_mhpmevent, write_mhpmevent }, =20 + [CSR_MCYCLECFGH] =3D { "mcyclecfgh", smcntrpmf_32, read_mcyclecf= gh, + write_mcyclecfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MINSTRETCFGH] =3D { "minstretcfgh", smcntrpmf_32, read_minstret= cfgh, + write_minstretcfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MHPMEVENT3H] =3D { "mhpmevent3h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, --=20 2.34.1 From nobody Tue Nov 26 20:22:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1703810923; cv=none; d=zohomail.com; s=zohoarc; b=hrE5fNPTNrsi7t+uWKL4ENO8mLA7OeoRBi1J++5t0CD/DNsPOXk0dbLd37Ps7E232QndrRDywT9abcvWgOdgfMHhxBwym5OAaZLcQtT1eumxWq0e8wuRnBsxX3H+g1utSovltEl4Oiaft2noN9NTGhTHVw3/+DYkKQq5hGn/+9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703810923; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=9GBvTeUzoQUlng6UwMoBMsETSZDpZRfh33b6/yNi3L0=; b=AegZuM/PZNbsOUhrdRhX2STbGJG3RJqqiKP5ke+m8OOjP7yjf/COfpRG3fU32KqqPy1bEFIPUO/D7KxaNSJLL20V6t5x1c5XYT67eCKo9oMlRoH7iH1ohngmzM2z8BBRUe0BCaGrmo2i+oPYszyc/yGI2aqMWLAJrIQaNr6HUdk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703810923305142.3035684864284; Thu, 28 Dec 2023 16:48:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJ12R-0003SJ-D8; Thu, 28 Dec 2023 19:47:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJ12P-0003SA-4h for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:45 -0500 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJ12M-00030S-5H for qemu-devel@nongnu.org; Thu, 28 Dec 2023 19:47:44 -0500 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7ba737ee9b5so465179339f.0 for ; Thu, 28 Dec 2023 16:47:41 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z3-20020a170902ee0300b001d3561680aasm14393949plb.82.2023.12.28.16.47.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 16:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703810860; x=1704415660; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9GBvTeUzoQUlng6UwMoBMsETSZDpZRfh33b6/yNi3L0=; b=eYA2bD9z6wIPBeu24Fl5lHnqaG+qcIDTRQV+FuObaExkEHWN+Gc2EpSBLzcBU8GbbU 5bj1jjQkJNAJbLF44k8tn/5VQvkZhK+QvLjbR7QHJuO1wZGoD/xr+UDv17Fnhq+35x5n 64TFBvO0ooJERbqL3eTiDz59hv0r61scu0227iOtVPDsCoo8/HnmfxpxC5igk36EmZLU VfDCGdKyIEfCyRApyynK8PoRhq3Tp1hrfm+uJgkI9ThPgEUIWaDs8wLedtXfx+740a3q kH1MfBdeWVXb/zODQm04htKQWCsBULPM22FXgJCVRMkv939WREGhPLL9B1RZUiRHIkF6 vJiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703810860; x=1704415660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9GBvTeUzoQUlng6UwMoBMsETSZDpZRfh33b6/yNi3L0=; b=Vm+OSE4n6Xfih45Q4ChMyufKB13TkZhZU4z6YLqgkxolGnMkH9qaHNPBqEE/bOF+Oo XS9S5Ct9w9UFyxzfSPS3UAvnMkGwiEq5zwmXD1TTmtMwysKYzgBd5EVKiUY4icshQtSI 3Z2xsxsS8loqH7OKoHTkTv7qNdJcuKVN1BICy11lTBwUbU2uKXgvcKBGQwxhaxmyu9IY gQs9EjW8xjwZT+OC1bfQk5C2I42zCJbl3HOrJZI8kvdcsaZqleft8quVCH8ty4PQgEmm B8R88EKMCy8wCqAgVV3OLj/4dsfA0RDjoIulWz4sCeWnEM50kufT7kSJUU54J97iv1J0 hjdA== X-Gm-Message-State: AOJu0YzEZfE1Qhz3uTveOp0XIlx+SuQGpz1Q4oc1sKmYUx8JPCjBUKZy k/VurspMdr0dWbhjbVSv1TqruFGqf8/2TD6sqfdJMVutwVY= X-Google-Smtp-Source: AGHT+IGq/f3tK4ofMtMxepDnr/zCp0bEs6792hpoQXq60cUwUM3ITiNr26HK3KZ6AKQ6eoojEVtK0A== X-Received: by 2002:a05:6e02:1805:b0:35f:d1aa:f41c with SMTP id a5-20020a056e02180500b0035fd1aaf41cmr19660584ilv.10.1703810860025; Thu, 28 Dec 2023 16:47:40 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [v2 5/5] target/riscv: Implement privilege mode filtering for cycle/instret Date: Thu, 28 Dec 2023 16:47:31 -0800 Message-Id: <20231229004731.3841550-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231229004731.3841550-1-atishp@rivosinc.com> References: <20231229004731.3841550-1-atishp@rivosinc.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::d36; envelope-from=atishp@rivosinc.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703810925369100009 Content-Type: text/plain; charset="utf-8" Privilege mode filtering can also be emulated for cycle/instret by tracking host_ticks/icount during each privilege mode switch. This patch implements that for both cycle/instret and mhpmcounters. The first one requires Smcntrpmf while the other one requires Sscofpmf to be enabled. The cycle/instret are still computed using host ticks when icount is not enabled. Otherwise, they are computed using raw icount which is more accurate in icount mode. Signed-off-by: Atish Patra --- target/riscv/cpu.h | 11 +++++ target/riscv/cpu_helper.c | 9 +++- target/riscv/csr.c | 95 ++++++++++++++++++++++++++++++--------- target/riscv/pmu.c | 43 ++++++++++++++++++ target/riscv/pmu.h | 2 + 5 files changed, 136 insertions(+), 24 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 34617c4c4bab..40d10726155b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -136,6 +136,15 @@ typedef struct PMUCTRState { target_ulong irq_overflow_left; } PMUCTRState; =20 +typedef struct PMUFixedCtrState { + /* Track cycle and icount for each privilege mode */ + uint64_t counter[4]; + uint64_t counter_prev[4]; + /* Track cycle and icount for each privilege mode when V =3D 1*/ + uint64_t counter_virt[2]; + uint64_t counter_virt_prev[2]; +} PMUFixedCtrState; + struct CPUArchState { target_ulong gpr[32]; target_ulong gprh[32]; /* 64 top bits of the 128-bit registers */ @@ -334,6 +343,8 @@ struct CPUArchState { /* PMU event selector configured values for RV32 */ target_ulong mhpmeventh_val[RV_MAX_MHPMEVENTS]; =20 + PMUFixedCtrState pmu_fixed_ctrs[2]; + target_ulong sscratch; target_ulong mscratch; =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e7e23b34f455..3dddb1b433e8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -715,8 +715,13 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulo= ng newpriv) { g_assert(newpriv <=3D PRV_M && newpriv !=3D PRV_RESERVED); =20 - if (icount_enabled() && newpriv !=3D env->priv) { - riscv_itrigger_update_priv(env); + if (newpriv !=3D env->priv) { + if (icount_enabled()) { + riscv_itrigger_update_priv(env); + riscv_pmu_icount_update_priv(env, newpriv); + } else { + riscv_pmu_cycle_update_priv(env, newpriv); + } } /* tlb_flush is unnecessary as mode is contained in mmu_idx */ env->priv =3D newpriv; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 618e801a7612..9926968e8e7d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -785,32 +785,16 @@ static int write_vcsr(CPURISCVState *env, int csrno, = target_ulong val) return RISCV_EXCP_NONE; } =20 +#if defined(CONFIG_USER_ONLY) /* User Timers and Counters */ static target_ulong get_ticks(bool shift) { - int64_t val; - target_ulong result; - -#if !defined(CONFIG_USER_ONLY) - if (icount_enabled()) { - val =3D icount_get(); - } else { - val =3D cpu_get_host_ticks(); - } -#else - val =3D cpu_get_host_ticks(); -#endif - - if (shift) { - result =3D val >> 32; - } else { - result =3D val; - } + int64_t val =3D cpu_get_host_ticks(); + target_ulong result =3D shift ? val >> 32 : val; =20 return result; } =20 -#if defined(CONFIG_USER_ONLY) static RISCVException read_time(CPURISCVState *env, int csrno, target_ulong *val) { @@ -935,6 +919,70 @@ static int write_mhpmeventh(CPURISCVState *env, int cs= rno, target_ulong val) return RISCV_EXCP_NONE; } =20 +static target_ulong riscv_pmu_ctr_get_fixed_counters_val(CPURISCVState *en= v, + int counter_idx, + bool upper_half) +{ + uint64_t curr_val =3D 0; + target_ulong result =3D 0; + uint64_t *counter_arr =3D icount_enabled() ? env->pmu_fixed_ctrs[1].co= unter : + env->pmu_fixed_ctrs[0].counter; + uint64_t *counter_arr_virt =3D icount_enabled() ? + env->pmu_fixed_ctrs[1].counter_virt : + env->pmu_fixed_ctrs[0].counter_virt; + uint64_t cfg_val =3D 0; + + if (counter_idx =3D=3D 0) { + cfg_val =3D upper_half ? ((uint64_t)env->mcyclecfgh << 32) : + env->mcyclecfg; + } else if (counter_idx =3D=3D 2) { + cfg_val =3D upper_half ? ((uint64_t)env->minstretcfgh << 32) : + env->minstretcfg; + } else { + cfg_val =3D upper_half ? + ((uint64_t)env->mhpmeventh_val[counter_idx] << 32) : + env->mhpmevent_val[counter_idx]; + } + + if (!cfg_val) { + if (icount_enabled()) { + curr_val =3D icount_get_raw(); + } else { + curr_val =3D cpu_get_host_ticks(); + } + goto done; + } + + if (!(cfg_val & MCYCLECFG_BIT_MINH)) { + curr_val +=3D counter_arr[PRV_M]; + } + + if (!(cfg_val & MCYCLECFG_BIT_SINH)) { + curr_val +=3D counter_arr[PRV_S]; + } + + if (!(cfg_val & MCYCLECFG_BIT_UINH)) { + curr_val +=3D counter_arr[PRV_U]; + } + + if (!(cfg_val & MCYCLECFG_BIT_VSINH)) { + curr_val +=3D counter_arr_virt[PRV_S]; + } + + if (!(cfg_val & MCYCLECFG_BIT_VUINH)) { + curr_val +=3D counter_arr_virt[PRV_U]; + } + +done: + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + result =3D upper_half ? curr_val >> 32 : curr_val; + } else { + result =3D curr_val; + } + + return result; +} + static int write_mhpmcounter(CPURISCVState *env, int csrno, target_ulong v= al) { int ctr_idx =3D csrno - CSR_MCYCLE; @@ -944,7 +992,8 @@ static int write_mhpmcounter(CPURISCVState *env, int cs= rno, target_ulong val) counter->mhpmcounter_val =3D val; if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { - counter->mhpmcounter_prev =3D get_ticks(false); + counter->mhpmcounter_prev =3D riscv_pmu_ctr_get_fixed_counters_val= (env, + ctr_idx, f= alse); if (ctr_idx > 2) { if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { mhpmctr_val =3D mhpmctr_val | @@ -971,7 +1020,8 @@ static int write_mhpmcounterh(CPURISCVState *env, int = csrno, target_ulong val) mhpmctr_val =3D mhpmctr_val | (mhpmctrh_val << 32); if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { - counter->mhpmcounterh_prev =3D get_ticks(true); + counter->mhpmcounterh_prev =3D riscv_pmu_ctr_get_fixed_counters_va= l(env, + ctr_idx, = true); if (ctr_idx > 2) { riscv_pmu_setup_timer(env, mhpmctr_val, ctr_idx); } @@ -1012,7 +1062,8 @@ static RISCVException riscv_pmu_read_ctr(CPURISCVStat= e *env, target_ulong *val, */ if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { - *val =3D get_ticks(upper_half) - ctr_prev + ctr_val; + *val =3D riscv_pmu_ctr_get_fixed_counters_val(env, ctr_idx, upper_= half) - + ctr_prev + ctr_val; } else { *val =3D ctr_val; } diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 0e7d58b8a5c2..8b6cc4c6bb4d 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/error-report.h" +#include "qemu/timer.h" #include "cpu.h" #include "pmu.h" #include "sysemu/cpu-timers.h" @@ -176,6 +177,48 @@ static int riscv_pmu_incr_ctr_rv64(RISCVCPU *cpu, uint= 32_t ctr_idx) return 0; } =20 +void riscv_pmu_icount_update_priv(CPURISCVState *env, target_ulong newpriv) +{ + uint64_t delta; + uint64_t *counter_arr; + uint64_t *counter_arr_prev; + uint64_t current_icount =3D icount_get_raw(); + + if (env->virt_enabled) { + counter_arr =3D env->pmu_fixed_ctrs[1].counter_virt; + counter_arr_prev =3D env->pmu_fixed_ctrs[1].counter_virt_prev; + } else { + counter_arr =3D env->pmu_fixed_ctrs[1].counter; + counter_arr_prev =3D env->pmu_fixed_ctrs[1].counter_prev; + } + + counter_arr_prev[newpriv] =3D current_icount; + delta =3D current_icount - counter_arr_prev[env->priv]; + + counter_arr[env->priv] +=3D delta; +} + +void riscv_pmu_cycle_update_priv(CPURISCVState *env, target_ulong newpriv) +{ + uint64_t delta; + uint64_t *counter_arr; + uint64_t *counter_arr_prev; + uint64_t current_host_ticks =3D cpu_get_host_ticks(); + + if (env->virt_enabled) { + counter_arr =3D env->pmu_fixed_ctrs[0].counter_virt; + counter_arr_prev =3D env->pmu_fixed_ctrs[0].counter_virt_prev; + } else { + counter_arr =3D env->pmu_fixed_ctrs[0].counter; + counter_arr_prev =3D env->pmu_fixed_ctrs[0].counter_prev; + } + + counter_arr_prev[newpriv] =3D current_host_ticks; + delta =3D current_host_ticks - counter_arr_prev[env->priv]; + + counter_arr[env->priv] +=3D delta; +} + int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_event_idx event_idx) { uint32_t ctr_idx; diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h index 505fc850d38e..50de6031a730 100644 --- a/target/riscv/pmu.h +++ b/target/riscv/pmu.h @@ -31,3 +31,5 @@ int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_even= t_idx event_idx); void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name= ); int riscv_pmu_setup_timer(CPURISCVState *env, uint64_t value, uint32_t ctr_idx); +void riscv_pmu_icount_update_priv(CPURISCVState *env, target_ulong newpriv= ); +void riscv_pmu_cycle_update_priv(CPURISCVState *env, target_ulong newpriv); --=20 2.34.1