From nobody Sun May 19 12:26:31 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=1696337591; cv=none; d=zohomail.com; s=zohoarc; b=EBBX5GM9n6YJOY2psGR5McOvPv9MD+/GOvVAyGzTEf8FNaSV1kesyAXWRJH/F8r+cN9cHb8K8cU3MVhwfmGxbbgeBbqGi8ZhnnyJzNcDRNCub/OojghK5crfBGe3aeRioHXdOWJqFD8xVI7M3O6qqPmPJ9RSGvqA63HHzpHcHmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696337591; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xXhilRIuHBWjF+VFkRUlon5++d01L6abqEDqyII/pAU=; b=kJm3x6EuoQ6oq3dsC1qaudXCqdXNjyYvhwZl2p/lSgE1mTuNOLLklVVZv03YtDQmTFpbYfN30X1q//KZvDq5PPeZVRz6hkA2QWGsrw+kWsQ3DQbu7yFbllBXHlAIyJi8fVo9UWEnlctKjBoVqehsGtkPw5worR5T88HlGJswOzs= 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 169633759102828.203411879620717; Tue, 3 Oct 2023 05:53:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnesJ-0007fL-9w; Tue, 03 Oct 2023 08:51:43 -0400 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 1qnesH-0007dX-CN for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:41 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnesB-00049F-IE for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:41 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4066692ad35so8509325e9.1 for ; Tue, 03 Oct 2023 05:51:35 -0700 (PDT) Received: from rockhopper.ba.rivosinc.com (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id l21-20020a7bc455000000b0040531f5c51asm1240335wmi.5.2023.10.03.05.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 05:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696337494; x=1696942294; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xXhilRIuHBWjF+VFkRUlon5++d01L6abqEDqyII/pAU=; b=QkU2sB0TBc47gN2rDCZ12etMJhPyFh2Uq1PBDLrkEmnmG65ER4Ra5xnk/jDi9VnKni WlJs93JovqPH24M+eVifEyUeaBPVfCfhf9AJCrJ4H5tJVZhLHi8tjjvF95Nh4G3ehMkL 0pg5qBjXv3nUh4KZgiZzTK9aOTXj0w/FbR8oJVyJoOTVdmc+Gz8aGobgUrqnYBNFBg4t Wc/Y4GykFfz5S2zkYCbVoVYsTnM8yYi9UzS4Jn6bXir9owUQUvx8dc5lreU7RGtRI0Qu 3liNe41TSky0IgX/Ac1h3trWG/sO2RieNHQ8GhVHG7arhgaYJCUNmfW41mq7d45cE9Nq iysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696337494; x=1696942294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xXhilRIuHBWjF+VFkRUlon5++d01L6abqEDqyII/pAU=; b=UjaH9YU62sL5ize/Zae5t8RuGbJqT4YHDsmkgqX/H+qT8kAKUrN3ACgZIMpIGRCRvJ YEaB9cQ2JbNA2urtYTk0+ZlbQZ0/ud9L8Hw5E2hMXsV/KiCjAs2LpRnhVhTn6gLGI2uq 3VRHXudrFi+0o9JdpNkXPp4PGJ5lOc4uR/dvCGl6mCWI5hFnv8ijgSgz2ccyOH933SvO FPWspGaXuG7VMjzJwEkBWDQG4lp0WNruz8kCt1OApM8LHTu+9zkjxqGHMZQ/X2e175Ov mrIofOLcJ2u0/Q/I0D01najiZ7UlwehmCQ23NhUdWfGj1Q9JmiWrKSBCUfh6Rn5kDldu Sl0Q== X-Gm-Message-State: AOJu0YzIChWm21dnMRw4P4R+RqN++M4ApzBi3bGeEMkjmmYR6sy/RMxA HeiVZOJhgbCgXz50el3NvRebe3FY13D3m60qbnbIHaHB X-Google-Smtp-Source: AGHT+IH6GVpej7xZn6Yxzg3GgzCjaVGBNreSLcpEFF6eIYJiWRLcVbHcMZQRLS5UmIoB1ZL9SgAY3A== X-Received: by 2002:a1c:720c:0:b0:3fe:5501:d293 with SMTP id n12-20020a1c720c000000b003fe5501d293mr11881208wmc.30.1696337493748; Tue, 03 Oct 2023 05:51:33 -0700 (PDT) From: Rob Bradford To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, atishp@rivosinc.com, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, Rob Bradford Subject: [PATCH 1/3] target/riscv: Propagate error from PMU setup Date: Tue, 3 Oct 2023 13:49:35 +0100 Message-ID: <20231003125107.34859-2-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003125107.34859-1-rbradford@rivosinc.com> References: <20231003125107.34859-1-rbradford@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=2a00:1450:4864:20::335; envelope-from=rbradford@rivosinc.com; helo=mail-wm1-x335.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 autolearn=unavailable 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: 1696337592280100005 Content-Type: text/plain; charset="utf-8" More closely follow the QEMU style by returning an Error and propagating it there is an error relating to the PMU setup. Further simplify the function by removing the num_counters parameter as this is available from the passed in cpu pointer. Signed-off-by: Rob Bradford Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 8 +++++++- target/riscv/pmu.c | 19 +++++++++---------- target/riscv/pmu.h | 3 ++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4140899c52..9d79c20c1a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1488,7 +1488,13 @@ static void riscv_cpu_realize_tcg(DeviceState *dev, = Error **errp) } =20 if (cpu->cfg.pmu_num) { - if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpm= f) { + riscv_pmu_init(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + + if (cpu->cfg.ext_sscofpmf) { cpu->pmu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, riscv_pmu_timer_cb, cpu); } diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 36f6307d28..13801ccb78 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -434,22 +434,21 @@ int riscv_pmu_setup_timer(CPURISCVState *env, uint64_= t value, uint32_t ctr_idx) } =20 =20 -int riscv_pmu_init(RISCVCPU *cpu, int num_counters) +void riscv_pmu_init(RISCVCPU *cpu, Error **errp) { - if (num_counters > (RV_MAX_MHPMCOUNTERS - 3)) { - return -1; + uint8_t pmu_num =3D cpu->cfg.pmu_num; + + if (pmu_num > (RV_MAX_MHPMCOUNTERS - 3)) { + error_setg(errp, "Number of counters exceeds maximum available"); + return; } =20 cpu->pmu_event_ctr_map =3D g_hash_table_new(g_direct_hash, g_direct_eq= ual); if (!cpu->pmu_event_ctr_map) { - /* PMU support can not be enabled */ - qemu_log_mask(LOG_UNIMP, "PMU events can't be supported\n"); - cpu->cfg.pmu_num =3D 0; - return -1; + error_setg(errp, "Unable to allocate PMU event hash table"); + return; } =20 /* Create a bitmask of available programmable counters */ - cpu->pmu_avail_ctrs =3D MAKE_32BIT_MASK(3, num_counters); - - return 0; + cpu->pmu_avail_ctrs =3D MAKE_32BIT_MASK(3, pmu_num); } diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h index 2bfb71ba87..88e0713296 100644 --- a/target/riscv/pmu.h +++ b/target/riscv/pmu.h @@ -17,13 +17,14 @@ */ =20 #include "cpu.h" +#include "qapi/error.h" =20 bool riscv_pmu_ctr_monitor_instructions(CPURISCVState *env, uint32_t target_ctr); bool riscv_pmu_ctr_monitor_cycles(CPURISCVState *env, uint32_t target_ctr); void riscv_pmu_timer_cb(void *priv); -int riscv_pmu_init(RISCVCPU *cpu, int num_counters); +void riscv_pmu_init(RISCVCPU *cpu, Error **errp); int riscv_pmu_update_event_map(CPURISCVState *env, uint64_t value, uint32_t ctr_idx); int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_event_idx event_idx); --=20 2.41.0 From nobody Sun May 19 12:26:31 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=1696337590; cv=none; d=zohomail.com; s=zohoarc; b=Kw1Z8fb8gDxSS8Xv7sj371bw7BBCzkqhOWIDF2AVF9Px0/D4yrnmt9dViipIlURDNHJiNP2wBdD54dO8WUKVgn6dJurBfJiAzEtGzeQvk/T2l7oh8xwM8byyEbFbwysW/iZgb8C6doMbT1OhcMJjHDbJpuiY68E7yFXtRFkjhyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696337590; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A202aSukY2P5Lap0mZ3nGZWrKZpOd3+Lv+2bAHWsO9A=; b=X1rTLnPY1qRYnsNhR6zBiU4n9EPGVlG+Ud4IdNk5nAfU8Oxx+FUc4XZ/2WKiQHSeiBuNukOS79o+EEXq/PF1z29RhgDpDaRqyK6RKYkkP0ZiXVjEHVAlcYSt7oRSe+gybxor1AregpeCmpcpQZ0YQsSlWkcs1ZL3X2q0VdyNZEw= 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 1696337590946278.27755792416326; Tue, 3 Oct 2023 05:53:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnesK-0007gG-KH; Tue, 03 Oct 2023 08:51:44 -0400 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 1qnesI-0007eF-4D for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:42 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnesD-00049V-Nx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:41 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-405361bb94eso9174175e9.0 for ; Tue, 03 Oct 2023 05:51:37 -0700 (PDT) Received: from rockhopper.ba.rivosinc.com (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id l21-20020a7bc455000000b0040531f5c51asm1240335wmi.5.2023.10.03.05.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 05:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696337496; x=1696942296; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A202aSukY2P5Lap0mZ3nGZWrKZpOd3+Lv+2bAHWsO9A=; b=hnqBiAlGNVFQqwlkxyIilsA4jmtWWIgvmssiXyJBtlS6pBcP7YkBiwEciHOWePykKg T6jagh9sRQQ3h3GUfeJv/jX0VEV6lBHTXPrFF79011SUtcoVMKcZK7lbIfHa5Vezahoi 2eDjDvu1UdNZuYd6Eq8U6b9XmFKGlKsuc49ZOMZKUCVEyv+6meoQLJUlbtiV2wYA/ZKx zZdGvD9rcEfRc5IKF9EDW3fAb7FmsNZ9DJdu2wDRb2BJJNoMOg+GiuQe91J2Bq4hbCnL q4QCj/Dlim75ThlD3o5VGyebcWvmGEHgi4v2/wKe0Px9ovoAOs5vO2hGGj6vwrN2wGVd 9W7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696337496; x=1696942296; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A202aSukY2P5Lap0mZ3nGZWrKZpOd3+Lv+2bAHWsO9A=; b=SuN306cU0NDEUwrahMpLwlmv94reehoz0bcevU4yy2+pxzhXTth9AzS7Rom/sFB6nt rYuxMUsCmjn5ONxTryVbMMEJeU2+IuH2NXNJJKgpBUZINVCfks3ca+HWERAdLxVBvMZz +FrC5Hg1131XUgl+NP3rBpV8fKbggaH31ZhbxADf2Bby6l52Hymt6n/JXd3ERSuGCTXH q3KDassGoaM37ECz0e3XtKTyprjkjPAVMGW14t2cWsMWmLkoLcIpZ6GD15klrVgHvsbF AEmUGaYwaoGGOGvxvh+KNuxR6MFy22nOy7KklSh3QZc/a5m+YlURx7EcMjLoIh9YzqtF Tj8Q== X-Gm-Message-State: AOJu0Yyypm0E8dEo24nKevX9uhX3swvdOZFlJQOzq7zPXVqnsmW+1v/T LIN6Gr3sU/wsdf/LvEbfnZuIflZT+z9Z+KS0QSmcHA== X-Google-Smtp-Source: AGHT+IF6VtE3A9iaXtbSyp+cqmsT6L/6e5EbrSzfN9H4OOXMw5+5monjJIXDAx9Mr8qCEVb6UyGJGQ== X-Received: by 2002:a05:600c:3b0e:b0:406:53ab:a9af with SMTP id m14-20020a05600c3b0e00b0040653aba9afmr12265757wms.10.1696337495744; Tue, 03 Oct 2023 05:51:35 -0700 (PDT) From: Rob Bradford To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, atishp@rivosinc.com, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, Rob Bradford Subject: [PATCH 2/3] target/riscv: Support discontinuous PMU counters Date: Tue, 3 Oct 2023 13:49:36 +0100 Message-ID: <20231003125107.34859-3-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003125107.34859-1-rbradford@rivosinc.com> References: <20231003125107.34859-1-rbradford@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=2a00:1450:4864:20::329; envelope-from=rbradford@rivosinc.com; helo=mail-wm1-x329.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 autolearn=unavailable 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: 1696337591449100002 Content-Type: text/plain; charset="utf-8" There is no requirement that the enabled counters in the platform are continuously numbered. Add a "pmu-mask" property that, if specified, can be used to specify the enabled PMUs. In order to avoid ambiguity if "pmu-mask" is specified then "pmu-num" must also match the number of bits set in the mask. Signed-off-by: Rob Bradford --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/pmu.c | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 9d79c20c1a..b89b006a76 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1817,6 +1817,7 @@ static void riscv_cpu_add_misa_properties(Object *cpu= _obj) static Property riscv_cpu_extensions[] =3D { /* Defaults for standard extensions */ DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), + DEFINE_PROP_UINT32("pmu-mask", RISCVCPU, cfg.pmu_mask, 0), DEFINE_PROP_BOOL("sscofpmf", RISCVCPU, cfg.ext_sscofpmf, false), DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 0e6a0f245c..40f7d970bc 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -124,6 +124,7 @@ struct RISCVCPUConfig { bool ext_XVentanaCondOps; =20 uint8_t pmu_num; + uint32_t pmu_mask; char *priv_spec; char *user_spec; char *bext_spec; diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 13801ccb78..f97e25a1f6 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -437,6 +437,13 @@ int riscv_pmu_setup_timer(CPURISCVState *env, uint64_t= value, uint32_t ctr_idx) void riscv_pmu_init(RISCVCPU *cpu, Error **errp) { uint8_t pmu_num =3D cpu->cfg.pmu_num; + uint32_t pmu_mask =3D cpu->cfg.pmu_mask; + + if (pmu_mask && ctpop32(pmu_mask) !=3D pmu_num) { + error_setg(errp, "Mismatch between number of enabled counters in " + "\"pmu-mask\" and \"pmu-num\""); + return; + } =20 if (pmu_num > (RV_MAX_MHPMCOUNTERS - 3)) { error_setg(errp, "Number of counters exceeds maximum available"); @@ -449,6 +456,10 @@ void riscv_pmu_init(RISCVCPU *cpu, Error **errp) return; } =20 - /* Create a bitmask of available programmable counters */ - cpu->pmu_avail_ctrs =3D MAKE_32BIT_MASK(3, pmu_num); + /* Create a bitmask of available programmable counters if none supplie= d */ + if (pmu_mask) { + cpu->pmu_avail_ctrs =3D pmu_mask; + } else { + cpu->pmu_avail_ctrs =3D MAKE_32BIT_MASK(3, pmu_num); + } } --=20 2.41.0 From nobody Sun May 19 12:26:31 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=1696337600; cv=none; d=zohomail.com; s=zohoarc; b=IzH2Ix4VLKiIOxnzD6+YOnvH1hFyF22HyjVICHdE2yymGVM/epTgS/oDMDlCAmKRaPZYs5JmdtoBL/2ltopaBal4UAzeyMls5OJxu1JPjVOfN1QSloxYa+3m9dTUf5nh86+gzBPkgqFkihxBgBRjrxQ9sSUeSBr0zRtHRagLZz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696337600; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sxGT1Wl6J3xowqZP+oPYuTY8pg3VyoUcjhFPxfi6Z1A=; b=FYCbO/hU+tvsAH7c5L0Sc3+1cZGTCft9RnvXH1b5Zsc0lkCJsT3GKE/zR9sYRPn/hd/8pew5+kf6fnzX70oODGyEG5G09Ml2iW+cjggz4Ccs1pZ532vTqoZOLaVJzhCa1izhFI6fE05cp0w4yAKP8EGVmuXKoWWlFgUsynL4/Kk= 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 1696337600044655.975050171739; Tue, 3 Oct 2023 05:53:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnesK-0007fi-3f; Tue, 03 Oct 2023 08:51:44 -0400 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 1qnesI-0007ej-Ns for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:42 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnesF-00049k-Lv for qemu-devel@nongnu.org; Tue, 03 Oct 2023 08:51:42 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4066241289bso8604615e9.0 for ; Tue, 03 Oct 2023 05:51:39 -0700 (PDT) Received: from rockhopper.ba.rivosinc.com (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id l21-20020a7bc455000000b0040531f5c51asm1240335wmi.5.2023.10.03.05.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 05:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696337497; x=1696942297; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sxGT1Wl6J3xowqZP+oPYuTY8pg3VyoUcjhFPxfi6Z1A=; b=U22Eg+HK4m9Z2VsLfPNSNKLmKRp815/qG/que8XxdgAbrHkquZf9jSkgNaJLAPgvhu 5bHG7zmvpQWog6bqfgqHasIKEDOeCLHdnqO4R8SG0vWYjvmMVOhb4RFVZqHzXbLx59NP Lfxr5QAfcFlOv9JRAS1vOjXilyBhZEu/Djsn2vC3KufGn/34KFqLRO4OE1mLixglaWDF MD0ba8hpetZMqdeyyx7JKku+HtDCBI+TdA6fzePqFImuddExLu9gn2XsH0ZYsbdtQZYJ o2w6ZZ+oZ/NvMqmxmv9elyffKDaLtGK2J7SQfS8GZKaaKibZIkXkvjjkRsXBxHTGEhjl XImA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696337497; x=1696942297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sxGT1Wl6J3xowqZP+oPYuTY8pg3VyoUcjhFPxfi6Z1A=; b=ATDCAH0wxu/xWUbKy50OpnLIgD2D3dvziNydA/dYsBsoupUtvcHNRmehU1sFIr4h+8 qRo67Li8bzyVtwvGr6iKky8LZC15eiMo3grY89TbA0EvMh/o0dvTXEO/gRCcY1Tw9ypX Hw3rYE1rL+ZA6/sJLwMU1TkbraNkDMiJ7YzF3duXf7eLc5daxmPcs1usHEPStA0zm2hA w0KxNuHq1MN8eYfjzqqSu6MhS5jlx5SjNyT9GyM/xx1JtW2kx7w25p9YlEC3yzV+MV84 k7cWNTjOSJF3P+XXin7p7pa6cjtJt7vjaiF/eniANBZSZ3ZeQNACStyNpuPryxO7dCc+ LEVA== X-Gm-Message-State: AOJu0Yz6g0ZbsKhTjrunqzkjB07YyXwvnr5omIQE316j4Ch4jyftM0av ueCO4lUx+GaCiNZFkaezDB3thvKF0MlLtJPtvvu/sQ== X-Google-Smtp-Source: AGHT+IFIQzKQOxT7BKOJyykQ09+ozYYXUA4EYFSwLz3/m2DmpqcQrF14+nBe+omb9QdgExVQH1DfAQ== X-Received: by 2002:a7b:cbc9:0:b0:406:3f62:e591 with SMTP id n9-20020a7bcbc9000000b004063f62e591mr12315479wmi.41.1696337497593; Tue, 03 Oct 2023 05:51:37 -0700 (PDT) From: Rob Bradford To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, atishp@rivosinc.com, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, Rob Bradford Subject: [PATCH 3/3] target/riscv: Don't assume PMU counters are continuous Date: Tue, 3 Oct 2023 13:49:37 +0100 Message-ID: <20231003125107.34859-4-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003125107.34859-1-rbradford@rivosinc.com> References: <20231003125107.34859-1-rbradford@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=2a00:1450:4864:20::334; envelope-from=rbradford@rivosinc.com; helo=mail-wm1-x334.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 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: 1696337600963100003 Content-Type: text/plain; charset="utf-8" Check the PMU available bitmask when checking if a counter is valid rather than comparing the index against the number of PMUs. Signed-off-by: Rob Bradford Reviewed-by: LIU Zhiwei --- target/riscv/csr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 85a31dc420..3e126219ba 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -182,7 +182,8 @@ static RISCVException zcmt(CPURISCVState *env, int csrn= o) #if !defined(CONFIG_USER_ONLY) static RISCVException mctr(CPURISCVState *env, int csrno) { - int pmu_num =3D riscv_cpu_cfg(env)->pmu_num; + RISCVCPU *cpu =3D RISCV_CPU(env_cpu(env)); + uint32_t pmu_avail_ctrs =3D cpu->pmu_avail_ctrs; int ctr_index; int base_csrno =3D CSR_MHPMCOUNTER3; =20 @@ -191,7 +192,7 @@ static RISCVException mctr(CPURISCVState *env, int csrn= o) base_csrno +=3D 0x80; } ctr_index =3D csrno - base_csrno; - if (!pmu_num || ctr_index >=3D pmu_num) { + if ((BIT(ctr_index) & pmu_avail_ctrs >> 3) =3D=3D 0) { /* The PMU is not enabled or counter is out of range */ return RISCV_EXCP_ILLEGAL_INST; } --=20 2.41.0