From nobody Tue Feb 10 23:55:14 2026 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=1697195002; cv=none; d=zohomail.com; s=zohoarc; b=ZVNWsJdNDXR437niJ+GanSd9R5mfE6ldMzH4YEi/9rJwY2xQAVMdNjn5naX3r1VKo5RDNRzAFApG9BqrXSJmJraG69JtjuTDH08AMXElEPd9mNeoAMRzbQNNH8ckY3QVjIFnv7uKMmsvsOhkagmafZt4wEelYnD1OkbVfkvWmbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195002; h=Content-Transfer-Encoding:Cc:Cc: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; bh=rzGngqylYHpKDCiaLpKrbx65UfqvHRS/0as6l/bM/+g=; b=b6NKyJNxDcSKcJTOczLvRQhiIOgDzoNpRBSlMd6CSEfD83dfoq/D7xLcV2Epnk/Pa+Fmh5XUWnFmLTBbzyClnIFteO3F1Rx0pDG26+Z+kBx8g2YsXU0fnDXzVfl8H4KeROS3JPoetQw25UEInIPfkbTGIM3VGAabK44lT8TbxqU= 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 169719500288837.44790626870554; Fri, 13 Oct 2023 04:03:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFvC-0000CT-J5; Fri, 13 Oct 2023 07:01:34 -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 1qrFvA-0000Ai-M7 for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:32 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFv5-00026Y-Qd for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:32 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3296b49c546so1647891f8f.3 for ; Fri, 13 Oct 2023 04:01:26 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194885; x=1697799685; 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=rzGngqylYHpKDCiaLpKrbx65UfqvHRS/0as6l/bM/+g=; b=cDch8EPd6VGrxuyuHK0ZgcLhFoNp87imtLNdmpXuw0ssFBoM0HaZz6rpA8vbwoZgGp Y5GtCfBAUv/IS3VLv9xmA0FB0DbTxnO/219isJkGcYSaMkzx036yDQOXq/qKRGKXqq24 C402+N4xCyXXeGWIwQUpJWEf7G9iFOKM5BvNxOu8OaJtjC4PMqrvkHStSsXWVrc1m9nd YNflevPaFg5ABdBXYYFfGjNnwVvO3xKUwaevwYB8ggZ7if7Tj75Vta12szKfPpnIIZns RJsHrCU14HXdmrSH5XAsy9oHJs+R1X0kjreHsSFc6hQZAsk9C0stRgytDOm9P7e5ue+k d99Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194885; x=1697799685; 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=rzGngqylYHpKDCiaLpKrbx65UfqvHRS/0as6l/bM/+g=; b=asIpX4SUqyyD+obxpHEzumF/OWePEH8vFrSTTLz+f6Nni05yTxkSQG4wjed2hZtuDl WJwc2cHyj9JfjbvgFAmetetuiWxr2Wrkf2Qf99apvKh2xVYR5we9+5LPHQ4uVSjQumwR 4J1ZIBm8H0LnZRaQCkoNQj4pMSyBAWtb5FHGLXUjeC01IrqicWwgoKDaKUYbME94U+CL 911PRjrvhXkz032H7wdSTxBQAJ6/biiPaWa3eFvpyFMIxczaORKDc7B532+EPZS2FgpP AIRYi73HTkOu7fF1b9elI3F04odZFJD9dvtlH1essVqgj107VAZUqeCSBFBtCMVc1tsA vj9Q== X-Gm-Message-State: AOJu0YyRz1PZ6ag0NJOf/VfmQe/VfW83E/cZg8m+dW5t5YrAfKS4eeJI Ks9lm0DE4XxJ+EEHf5VCy1pNFVaZC4+yvJVIy1Y= X-Google-Smtp-Source: AGHT+IGR4q1WmBFNVCN08rblp6GVFD57rbwqv0NURjqMvE9vDTug6EmIWzq1k5Z2wVIM6Tm6JmDLrA== X-Received: by 2002:adf:a41e:0:b0:32d:3e9d:fddf with SMTP id d30-20020adfa41e000000b0032d3e9dfddfmr8282332wra.50.1697194885402; Fri, 13 Oct 2023 04:01:25 -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 v3 1/6] target/riscv: Propagate error from PMU setup Date: Fri, 13 Oct 2023 11:54:43 +0100 Message-ID: <20231013110111.34619-2-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::42b; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x42b.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: 1697195004447100002 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 Reviewed-by: LIU Zhiwei --- 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 ac2b94b6a6..c9d8fc12fe 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 Tue Feb 10 23:55:14 2026 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=1697195039; cv=none; d=zohomail.com; s=zohoarc; b=UnpBXbVhghc68sCUF0FCnnmlrEnodswSIFnktPaNeIKGolcUB3N0Sh826AvOQN/NhtRGr3932ffiDpRf8l7ZfhrQSj8AJHYH4GoUmZiHN1dliuvvGNWhehsHCVLlTyD1Apa2ZZUskqlQNcTSxm7So7sJqPXF3NrgnwNZ/JLhJok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195039; h=Content-Transfer-Encoding:Cc:Cc: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; bh=wiq5mYEHEn3DJSzjIjqQH0t31AsiITQ4TuY7AydRTuI=; b=AV/1MzOpB1AfSHeAFV11WhSlM9DpwGQdyC9k7Xx4lG1f8RBmlpAHYjV78MDHXaj8ytmyDkPIT6bjxwgsBqWoq/Fdc8J7gbwIigg3ezjsFeufBNZ6ypOpJ7n+e0yoYcLJ/ESCoto4jDbURCXFvZpdZJ493R5VabWdas6wreh6S2E= 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 1697195039015473.2105766144597; Fri, 13 Oct 2023 04:03:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFvb-0000Lj-66; Fri, 13 Oct 2023 07:01:59 -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 1qrFvP-0000Ij-Dk for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:53 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFvA-00028Q-5p for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:47 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-317c3ac7339so1823957f8f.0 for ; Fri, 13 Oct 2023 04:01:29 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194888; x=1697799688; 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=wiq5mYEHEn3DJSzjIjqQH0t31AsiITQ4TuY7AydRTuI=; b=woW+taUr7jw52HjELew9KAFAEnC3fK3Afdxdia4ruxwYFF78RUORX1h4bMEmIR1khV yfFc8FlwAvB6wUCUodzhsm2/ATPH6NAaTfJum4gR/OlCqpwNnImninJHpcagsxD2Dsy8 JAUwcuUpGqcNnlyHEl+P1a/eSkFEcH4bz66osjYDwmJjG8gcG7JuMOCYFOXzasIsMGiz El7MnvAfQo7SagiacmN1lJuHDg8kkHAqc2ViDsrBOgCZzuzT3u3tBL6pwYCKWd1wRbfZ ZrnUa/Vvc2fWQVKoMdl8x3qXz389+JTTKQErOByC9y3SerOubWj/cXuwRGWAacMNEjMa 0QTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194888; x=1697799688; 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=wiq5mYEHEn3DJSzjIjqQH0t31AsiITQ4TuY7AydRTuI=; b=Ie1OovjaPvQE1r3R/eNe/lwckkzcwVf25xI3WG1zJsFb0QHlcGUBhQFXxO2f60fLbE x8AW8vtfVbhJSpjAqIblLmp8Itw6GqgEXd7L4iLXAYFaHZtCTVueDhnARJUUHK12u8Cc TPPID1HRM+Hae6N5U7CqOFKsPOkzZuvobqLb71Igj4HXHUAv/d7W6uvGmqxC7/s3DULa /RIxEp2k36j4If9o97GDfWFIBqw9jv7+wx5V92ShI8kehf9LKVzva9KoFF+GQD3PE4o/ Fx3eNA2Far02Xwqbhtl6r6AXfuCD6sFG9Scsn03rkvVFoNkBvb26J5kD2IPg6rowtIGN F1AA== X-Gm-Message-State: AOJu0YysgNaKTrQ3riJmJ+KLjJTIMSa+v8/sV8TfkzrlNhZi0+kgP5dx 9M6M6BY+x297jYBBwvrOX6A11XqGUkCkA44SwMY= X-Google-Smtp-Source: AGHT+IFQVguXGtsTC1c6pAmwumLdkeP1nKzBm6PlV6v7YBNOO085m4T7iDXvDE6v2QvddiE4hX1CQQ== X-Received: by 2002:a05:6000:110b:b0:31f:a259:73c with SMTP id z11-20020a056000110b00b0031fa259073cmr22491533wrw.27.1697194887820; Fri, 13 Oct 2023 04:01:27 -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 v3 2/6] target/riscv: Don't assume PMU counters are continuous Date: Fri, 13 Oct 2023 11:54:44 +0100 Message-ID: <20231013110111.34619-3-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::433; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x433.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, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: 1697195040003100003 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 Reviewed-by: Alistair Francis --- 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..4383805fa3 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 env_archcpu(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 From nobody Tue Feb 10 23:55:14 2026 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=1697195033; cv=none; d=zohomail.com; s=zohoarc; b=cqaZ9ZplzIpi4eB3L/9Nur5g2whYzqgUx35/t+abtWHZdpvHpB75eagE1NFyLb/8IqzAlRud2xIDaJEH2K8tEtI01lrLV5+V5cvETat3udgFe91bL+nXUbX9Ff0GSaucoPi/A61cR0Okncr470ibCA5Yg2Blb4pop2SBZsBFir4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195033; h=Content-Transfer-Encoding:Cc:Cc: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; bh=+T1o7c6jOO1qih6JAKenu+zKIks7hzIqe4wyjYwbkaU=; b=Ey23ttQC6N9wCg0hpDuLx+wtvs4ZIajxGV6zctsVjtYLy9fIG9Zf7Yfx9A9I79NIxn8yP/cWwf2q+YjDfYwtZEDsqRDNhfu0/vW1fLFIM1Rl98p9RIm0DLznot2qO6IPbGgznarhZSkoMtcdrjcZB4ZQNu0yLaMpKh2S7syKBY4= 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 1697195033592688.0166883085082; Fri, 13 Oct 2023 04:03:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFvI-0000GU-Gi; Fri, 13 Oct 2023 07:01:41 -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 1qrFvF-0000GD-EN for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:37 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFvA-00029G-BO for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:37 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-307d20548adso1789966f8f.0 for ; Fri, 13 Oct 2023 04:01:31 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194890; x=1697799690; 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=+T1o7c6jOO1qih6JAKenu+zKIks7hzIqe4wyjYwbkaU=; b=J+S0x5REs25IiK8jvvQkMn2Kf8FPLK//BnpHSqA1Spqkm/Lo1XmPwFko4dJDRIzH2z r/vdXosmBJFi8XuDojgurQsZzDVSinsftOmqM+sg6mpZNAT+IYhiQ+SjiJj7uuntjEE1 wWWu224bQ/iixaRIWWQReSaUTI8258P+GcqxELZm+Ky+BIdTgtod1tDvpHKZhuZvetOB uoe+Mxs7n07Vm0cvuuHFQTQpUYpoMiTCB3vBjopgA9nnzG9oM105SGDkR1fpdh4R2odC fVKdEag2J40rqvfv7yAarbs6Rmjv3tM7oo8ZrP3b5u5jHJTMsYg2itYcID2nGUFfsh8J 58xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194890; x=1697799690; 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=+T1o7c6jOO1qih6JAKenu+zKIks7hzIqe4wyjYwbkaU=; b=mlj7a6Dj40zIH/XoblWxr+DH3y2c8BHyzjx41vZagSECBQRkUuybXjbkOjRCyK0w/S kw2k/CwwZt/6rJd61GbCCCrzozYKA3bRDTLlBxI2rcGXX9NXkKvj78N46QduemE82MJX t5om2NSShvC9j6D8Sv68cygF2DM8PTp+gomeH+2nOyK/dwQjTPT0kV0tJnD3u2aXmFqX G/HVB8mRg5+T3bLznOQ/vAITZ4B3CUILZyqhu8CbKnWr/tTfs71Sesy1Pq222fAxcUYa ZbQlrjLxg5Gc7l15vnBhBQAFmepnsCgJGJYOpcPToLQGGXJZMeHjLdlUWdBl4Ykwc7Ua JV6A== X-Gm-Message-State: AOJu0YyN6mvZCAAQXijgJ0p2b3VKFSHO0D+GliA0LtQjDbcD2wH4ERjJ NnFZ3wnKgXlRbaddSVjNo9iwhAp6Zvnu3iF6hdI= X-Google-Smtp-Source: AGHT+IEXFZuM/MmF+AOp9KRP86//Dw437EDivy1ExFV195og1C+ZU8YvW9o2VcfhNISkkxn7kGQH8A== X-Received: by 2002:a5d:4fd2:0:b0:31f:f829:49aa with SMTP id h18-20020a5d4fd2000000b0031ff82949aamr20768512wrw.23.1697194890067; Fri, 13 Oct 2023 04:01:30 -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 v3 3/6] target/riscv: Use existing PMU counter mask in FDT generation Date: Fri, 13 Oct 2023 11:54:45 +0100 Message-ID: <20231013110111.34619-4-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::433; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x433.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, T_SPF_TEMPERROR=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: 1697195034064100001 Content-Type: text/plain; charset="utf-8" During the FDT generation use the existing mask containing the enabled counters rather then generating a new one. Using the existing mask will support the use of discontinuous counters. Signed-off-by: Rob Bradford Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 2 +- target/riscv/pmu.c | 6 +----- target/riscv/pmu.h | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 5edc1d98d2..acdbaf9da5 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -722,7 +722,7 @@ static void create_fdt_pmu(RISCVVirtState *s) pmu_name =3D g_strdup_printf("/pmu"); qemu_fdt_add_subnode(ms->fdt, pmu_name); qemu_fdt_setprop_string(ms->fdt, pmu_name, "compatible", "riscv,pmu"); - riscv_pmu_generate_fdt_node(ms->fdt, hart.cfg.pmu_num, pmu_name); + riscv_pmu_generate_fdt_node(ms->fdt, hart.pmu_avail_ctrs, pmu_name); =20 g_free(pmu_name); } diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 13801ccb78..7ddf4977b1 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -34,13 +34,9 @@ * to provide the correct value as well. Heterogeneous PMU per hart is not * supported yet. Thus, number of counters are same across all harts. */ -void riscv_pmu_generate_fdt_node(void *fdt, int num_ctrs, char *pmu_name) +void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name) { uint32_t fdt_event_ctr_map[15] =3D {}; - uint32_t cmask; - - /* All the programmable counters can map to any event */ - cmask =3D MAKE_32BIT_MASK(3, num_ctrs); =20 /* * The event encoding is specified in the SBI specification diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h index 88e0713296..505fc850d3 100644 --- a/target/riscv/pmu.h +++ b/target/riscv/pmu.h @@ -28,6 +28,6 @@ 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); -void riscv_pmu_generate_fdt_node(void *fdt, int num_counters, char *pmu_na= me); +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); --=20 2.41.0 From nobody Tue Feb 10 23:55:14 2026 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=1697195003; cv=none; d=zohomail.com; s=zohoarc; b=VmZyApW4KTkbRCTzEGmZrwtXikfiJcK2bYfu187rtj5EUSDcr23ZQMRsRYRPQa4IPzHsvm341MldRfrlSvHewZUBKqy76rpv9Hhc2QneGVRXK8wcRK/wvK0g74/VIRzp+XQg15XOcbey7f4m3F6mr7lnjelyutA0Dai2PsNKwGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195003; h=Content-Transfer-Encoding:Cc:Cc: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; bh=T2umt+7OFn/qt6ZAkoTUCWSOYO+xVn32zwvp+RkPFAE=; b=L+b/30C2akg/yJ+i+i6ec6gXMSOnPiCDpRWHsNuOA5szFMzO4dmlL9RRYdy6UNF3Ire8Nfnm5/k4xwP6bj4RYcyZOweW25s7B9zm61sSWv7KDbytnZe/Cr99sZ/IF7aCj9rmmbg08LK5j6spPV7obRxwNOy6vZSbvzhHY08fGFY= 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 169719500318617.88527764437822; Fri, 13 Oct 2023 04:03:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFvY-0000Kg-UP; Fri, 13 Oct 2023 07:01:56 -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 1qrFvK-0000Hp-8p for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:43 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFvC-0002A8-2n for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:42 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-32d80ae19f8so1599912f8f.2 for ; Fri, 13 Oct 2023 04:01:33 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194892; x=1697799692; 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=T2umt+7OFn/qt6ZAkoTUCWSOYO+xVn32zwvp+RkPFAE=; b=aZa7vC8ewCs4NDGyjEeLKHR3zww9xWfJ5VHKaE6M74oken29wn52dPhHoL19VJP2lw rTx2W4qi2zZ0P0ozmzVYNobbLSpP5nvK2BkybzwX1Wbxj4d1jUS9yG2yl/f9VAZPUZWl B9nbVAUe7fk5HUVYBN1JxEue/iwTFI3vmWV0XggyHsF2++6s7K5iPyBpaCtL7Cu6UdH8 1Eu+obs3M9a+kfJCFv37g4xqRtnD2Xmngvmcmn/LuJT5hjOL6ZmYW+2iEYGkJCf32TbQ oPRoquL43448E4ALkWdkEnnhbJSIm2chJz/QKoltLZUWMsmecxtpHaQ9mEf36szY6/1i gzsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194892; x=1697799692; 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=T2umt+7OFn/qt6ZAkoTUCWSOYO+xVn32zwvp+RkPFAE=; b=dkWskC8K2Ot1P/5CvWghYVa/F3w8Bfy7YhQd2fehbCbs09PiRpLNNAT2JuqXAcY1W4 NssyIXkxg3WpC7FcOZ865MYzIbulXeNrubgxX+OG2tGwL+VHUYniPEB3vybXTCr4oy8h KeQTy/cFC4lvUTvkobJ34C6erKygXIhhs4NAGV1a2cRw2aiATIWi0aeFIO+ys5Rgt7mc pZJ0NQc4OOj9PkzMUmGg4tz7UQI2j2aHQFqiG5XBkC/6F8WKJlMiED5x+dDpC3SAx8sz T+7VSgn5aI+pKCeYwYrX/T0eN1BzwE5QoZ9WAaocUta3/55PG0ULITrY+1B50VCFwRSs l/Nw== X-Gm-Message-State: AOJu0YyeacQa1+f9uVxT1mrlUC73ygoFdbTQ4RGBjaE11csaxP7A1wNa iJ98KEJeuFjaxtiDRRhziwlAx+LJthQevd8rWCM= X-Google-Smtp-Source: AGHT+IGu/GCjpH3q4/HtjWgoRbijO64osdY04FTQNZO+QFmYRU4SsE5AwbHtlJ4lDtplQPvy3caZDA== X-Received: by 2002:a5d:4d12:0:b0:316:efb9:101d with SMTP id z18-20020a5d4d12000000b00316efb9101dmr23251797wrt.25.1697194891458; Fri, 13 Oct 2023 04:01:31 -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 v3 4/6] target/riscv: Add "pmu-mask" property to replace "pmu-num" Date: Fri, 13 Oct 2023 11:54:46 +0100 Message-ID: <20231013110111.34619-5-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::433; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x433.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: 1697195004445100001 Content-Type: text/plain; charset="utf-8" Using a mask instead of the number of PMU devices supports the accurate emulation of platforms that have a discontinuous set of PMU counters. Generate a warning if the old property changed from the default but still go ahead and use it to generate the mask if the user has changed it from the default Signed-off-by: Rob Bradford --- target/riscv/cpu.c | 5 +++-- target/riscv/cpu_cfg.h | 3 ++- target/riscv/machine.c | 2 +- target/riscv/pmu.c | 20 ++++++++++++++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index c9d8fc12fe..420673b491 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1487,7 +1487,7 @@ static void riscv_cpu_realize_tcg(DeviceState *dev, E= rror **errp) riscv_timer_init(cpu); } =20 - if (cpu->cfg.pmu_num) { + if (cpu->cfg.pmu_mask) { riscv_pmu_init(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); @@ -1812,7 +1812,8 @@ static void riscv_cpu_add_misa_properties(Object *cpu= _obj) =20 static Property riscv_cpu_extensions[] =3D { /* Defaults for standard extensions */ - DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), + DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), /* Deprecated= */ + DEFINE_PROP_UINT32("pmu-mask", RISCVCPU, cfg.pmu_mask, MAKE_64BIT_MASK= (3, 16)), 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..d273487040 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -123,7 +123,8 @@ struct RISCVCPUConfig { bool ext_xtheadsync; bool ext_XVentanaCondOps; =20 - uint8_t pmu_num; + uint8_t pmu_num; /* Deprecated */ + uint32_t pmu_mask; char *priv_spec; char *user_spec; char *bext_spec; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index c7c862cdd3..9f6e3f7a6d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -313,7 +313,7 @@ static bool pmu_needed(void *opaque) { RISCVCPU *cpu =3D opaque; =20 - return cpu->cfg.pmu_num; + return (cpu->cfg.pmu_mask > 0); } =20 static const VMStateDescription vmstate_pmu_ctr_state =3D { diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 7ddf4977b1..9253e5f17a 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -18,6 +18,7 @@ =20 #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/error-report.h" #include "cpu.h" #include "pmu.h" #include "sysemu/cpu-timers.h" @@ -184,7 +185,7 @@ int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_ev= ent_idx event_idx) CPURISCVState *env =3D &cpu->env; gpointer value; =20 - if (!cpu->cfg.pmu_num) { + if (!cpu->cfg.pmu_mask) { return 0; } value =3D g_hash_table_lookup(cpu->pmu_event_ctr_map, @@ -434,7 +435,13 @@ void riscv_pmu_init(RISCVCPU *cpu, Error **errp) { uint8_t pmu_num =3D cpu->cfg.pmu_num; =20 - if (pmu_num > (RV_MAX_MHPMCOUNTERS - 3)) { + if (cpu->cfg.pmu_mask & (COUNTEREN_CY | COUNTEREN_TM | COUNTEREN_IR)) { + error_setg(errp, "\"pmu-mask\" contains invalid bits (0-2) set"); + return; + } + + if (ctpop32(cpu->cfg.pmu_mask) > (RV_MAX_MHPMCOUNTERS - 3) || + (pmu_num > RV_MAX_MHPMCOUNTERS - 3)) { error_setg(errp, "Number of counters exceeds maximum available"); return; } @@ -445,6 +452,11 @@ 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); + /* Check if user set it by comparing against default */ + if (pmu_num !=3D 16) { + warn_report("\"pmu-num\" property is deprecated; use \"pmu-mask\""= ); + cpu->cfg.pmu_mask =3D MAKE_32BIT_MASK(3, pmu_num); + } + + cpu->pmu_avail_ctrs =3D cpu->cfg.pmu_mask; } --=20 2.41.0 From nobody Tue Feb 10 23:55:14 2026 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=1697195033; cv=none; d=zohomail.com; s=zohoarc; b=SMzX4Bfym4GcuzjD1Hnb65BndJ/7XRZ66af9hQpB4G5SJcoBHm6BKlqJFe1rcBPESkD/f5SfAeOmtik56TzDibF1Tn2wNa/B4TerATSyOzyS0Wag+d+8sFu7sB9MSCLm1CBKMXAgiEUdCafAbkSWnskoD1gMTjWdw9C/w/mdL10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195033; h=Content-Transfer-Encoding:Cc:Cc: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; bh=3JZHdSiwRUYjXMXaey8Jc3lrt8drXtY7mpembZSBrZM=; b=ByV19sBvTluHk7ZbA/qWJN9FlT+DLUzO3s6HWBGTnZdDLrqYvG7ea9778S6jJyqaBXiOE6g9m7xIpTFVYttnvILbOIX1JZO5YItFADWT3EaYI//DtpEGDFMFI6KGthlkt/hvze0Lw06+TiMzq7+RvVtKbXBU4U+mHwh8Yzbku2g= 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 1697195033626790.7629356371008; Fri, 13 Oct 2023 04:03:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFvf-0000OE-GN; Fri, 13 Oct 2023 07:02:03 -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 1qrFvO-0000Id-0U for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:53 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFvE-0002E7-Kb for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:45 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-32d895584f1so1761446f8f.1 for ; Fri, 13 Oct 2023 04:01:36 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194895; x=1697799695; 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=3JZHdSiwRUYjXMXaey8Jc3lrt8drXtY7mpembZSBrZM=; b=mdV0dJVVloEqIn1/8rvGJjPPyek+VYSQumC1IdnVhayVb+UFraQR4sZsuWy9xroOKq deckm+lQFhMMyC6ZQ68bsTpuDoYSM3keZ+geOaUWkI4/mCE+A2QThRbowfCrh1jX2vOG 0Gpfb5lIHAEK5UbXkQKaQxxRPMHi0GXWayQKrlfmeXYmk4RTJ34JxeK7fhtng5NiXtU6 5+T9dU2lfngmigi3dc2vTLaoJaRTpzZBOzhrTtLqGh9UnIsqxA8+1JaahoCd+M15Awgb nQuNhm1wB6az5sOszhnTf2wWi9hrEFOxgvuPw1KoWzsKOlTWHrA5/9N9U++IGibdDs2n RGjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194895; x=1697799695; 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=3JZHdSiwRUYjXMXaey8Jc3lrt8drXtY7mpembZSBrZM=; b=BxCgpi1la4P/YtX9QZlpSUGashB7/OzIFptS/XbQ4NuT2e0FOrDrf5Df1BLQpPWgX7 cWFp6YahiM0qj811bN3hQ2eUHlRb1OxJjeqyESl6bpKdTX1bP+0COcI/kewpvk9HVdzg uNkI28J6pxs3LPrygUlVU08Fc6c+a7UolF+nmECnto/STOkfNOHQHrznY/87aWiPHOaW PywJQYEWm06D5Vci7fRYtHDFXbF5TJWaQ1FqYGKGALy/pCkKwTZPWzCH7TJFIRXqpKGu yeda9/gE6Hd1SQ1e0GEvTSGeMjj+RPqY9lYhd2TLJfQpPHBQW8xq16ge8YUl/FK02wBt sKNA== X-Gm-Message-State: AOJu0YxYc6DVM7SsU6jEP8NJLrV5taUSUD4Km2Ndz/oYKnee/t67AlRh NMEQ5zXxSd1k9NI/AqkCZtqTePvnYiGnW3i14ZY= X-Google-Smtp-Source: AGHT+IFr3NpAaKU8Gcmmez6Yi2VUO+0WdWeeXa8Xu3lmT3hO3K/LgbapK9DcF8RPMwhZE3VEI6HHkA== X-Received: by 2002:adf:e550:0:b0:32d:9e48:faed with SMTP id z16-20020adfe550000000b0032d9e48faedmr913006wrm.25.1697194894878; Fri, 13 Oct 2023 04:01:34 -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 , libvir-list@redhat.com (reviewer:Incompatible changes) Subject: [PATCH v3 5/6] docs/about/deprecated: Document RISC-V "pmu-num" deprecation Date: Fri, 13 Oct 2023 11:54:47 +0100 Message-ID: <20231013110111.34619-6-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::42e; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1697195034068100002 Content-Type: text/plain; charset="utf-8" This has been replaced by a "pmu-mask" property that provides much more flexibility. Signed-off-by: Rob Bradford Acked-by: LIU Zhiwei --- docs/about/deprecated.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 8b136320e2..37f3414ef8 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -361,6 +361,16 @@ Specifying the iSCSI password in plain text on the com= mand line using the used instead, to refer to a ``--object secret...`` instance that provides a password via a file, or encrypted. =20 +CPU device properties +''''''''''''''''''''' + +``pmu-num=3Dx`` on RISC-V CPUs (since 8.2) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In order to support more flexible counter configurations this has been +replaced by a ``pmu-mask`` property + + Backwards compatibility ----------------------- =20 --=20 2.41.0 From nobody Tue Feb 10 23:55:14 2026 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=1697195034; cv=none; d=zohomail.com; s=zohoarc; b=FnFZiIHA1LpJsC6FgdtZEJozg0+AyXMf9qKi31JkAE9FdgWdCmyFSCojhsHTFDxXkOVWQdxi9omcEDWlhALj2uYbZJU1y2IMDVtNfpvJgksg4TIRqKuRRVmoY0v3F7ElPf+C3BeFIMRieF00lkmkMUjCiG1T23l/RvF7Mr9FzoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697195034; h=Content-Transfer-Encoding:Cc:Cc: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; bh=iINLba3Z9IRPyClB9itO+7onNYKObdnht5URrf2joic=; b=ht/KFwt5tlnspIGXZO58ACFt6CCSmLgQhG7LoZY/G0g5HWbBouskrWKEWVrQ+ure1oWcMTrsFI1vAex8VoXVSUhiGL7H5DFldlUOs4JMu3Wh6xPX3IHESZr19c5YWMZp31p3YoLBrPD2rvn2zyqnDmsuMkiVt1rdf9NwfgwH3HM= 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 169719503459182.48406223916936; Fri, 13 Oct 2023 04:03:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrFva-0000LT-9y; Fri, 13 Oct 2023 07:01:58 -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 1qrFvM-0000I8-1k for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:45 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrFvH-0002Hl-OK for qemu-devel@nongnu.org; Fri, 13 Oct 2023 07:01:43 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3248ac76acbso1665789f8f.1 for ; Fri, 13 Oct 2023 04:01:38 -0700 (PDT) Received: from rockhopper.. (214.11.169.217.in-addr.arpa. [217.169.11.214]) by smtp.gmail.com with ESMTPSA id p8-20020adfce08000000b003271be8440csm20455185wrn.101.2023.10.13.04.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697194897; x=1697799697; 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=iINLba3Z9IRPyClB9itO+7onNYKObdnht5URrf2joic=; b=xkEl22lYMJW86pqpLEiYF8xRSkNDuuzi5u13mON/MPU5R1AHdu9Y2sYfP2u+b5LsPr YNnC89fH4rPbesRw9YBJ45UQaOoLMI4jz2GZu0A5CSJA/MBiR3JqYeWHYAPi3PZdUXVV drAgMQJy2y04eT8dtrPZQ9VEuZ0KsrisJpBIZ5ZUuGx9VA+16WjX2Rnwaik3YnvFiyWB MdKlO7cTKbBfcgzA5lR2xhM+EgKLV63Es9G8JeuPi50SFAIWqSbaNwAO4h0aUmMH69zL tojMvUEwcCgD6jrfxz/26Rh3CNMuXdA8DWRVsIltWyvIzH9r5IeHmIIxhPQ4EtYZ+9kE c++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697194897; x=1697799697; 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=iINLba3Z9IRPyClB9itO+7onNYKObdnht5URrf2joic=; b=mgo0MpPRauVeIjM5u/IXzBMUk2ZWA3ULgMHazliWDfpWYYpyb4rzbQvdzgQY2+WWzo PqFHYydizeYeZz3MiSbzegUS14IrO+rapfbZanrNOcUwHWbK7QKt2hYff6gokujd4EQ7 z3XJpP7HhLgLvFDeICxv17qmq0HkQ4pe1KciK/lgdUGsEJpUc0ZpaI4mF0jnCGV5I5h5 iJtzFYi18c7SvQDWZ/KjyVTF9LFg8qhuxdo5xE9lZPon479dRX72xzTUJ51KM8AvNTtF z3Os1fntM2ojm8GCG45Z0uYU21BTwars7rUZRF5B6XWbnZQEO/ifwEL8+awUZz5g87Hl 3MGg== X-Gm-Message-State: AOJu0Yza35+8MJdLbarQP/BOVHxA7w497RWptInRS7Adx590UFSccZSg sGGdLaYtBVZjcujo+ewJ7mbQnXyoaojVmcnR7QQ= X-Google-Smtp-Source: AGHT+IFcI+6OY+haosN8G/SBb++UYo3pMErPptRA0Ak8u46NlvDD3LePkXqeiHLxn72w3kvlzgfobg== X-Received: by 2002:a05:6000:cb:b0:321:7050:6fb6 with SMTP id q11-20020a05600000cb00b0032170506fb6mr21299814wrx.67.1697194897383; Fri, 13 Oct 2023 04:01: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 v3 6/6] target/riscv: Use MAKE_64BIT_MASK instead of custom macro Date: Fri, 13 Oct 2023 11:54:48 +0100 Message-ID: <20231013110111.34619-7-rbradford@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013110111.34619-1-rbradford@rivosinc.com> References: <20231013110111.34619-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::429; envelope-from=rbradford@rivosinc.com; helo=mail-wr1-x429.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: 1697195036027100011 Content-Type: text/plain; charset="utf-8" A 32-bit mask can be trivially created using the 64-bit macro so make use of that instead. Signed-off-by: Rob Bradford Reviewed-by: Alistair Francis --- target/riscv/pmu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 9253e5f17a..052d5b1164 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -25,8 +25,6 @@ #include "sysemu/device_tree.h" =20 #define RISCV_TIMEBASE_FREQ 1000000000 /* 1Ghz */ -#define MAKE_32BIT_MASK(shift, length) \ - (((uint32_t)(~0UL) >> (32 - (length))) << (shift)) =20 /* * To keep it simple, any event can be mapped to any programmable counters= in @@ -455,7 +453,7 @@ void riscv_pmu_init(RISCVCPU *cpu, Error **errp) /* Check if user set it by comparing against default */ if (pmu_num !=3D 16) { warn_report("\"pmu-num\" property is deprecated; use \"pmu-mask\""= ); - cpu->cfg.pmu_mask =3D MAKE_32BIT_MASK(3, pmu_num); + cpu->cfg.pmu_mask =3D MAKE_64BIT_MASK(3, pmu_num); } =20 cpu->pmu_avail_ctrs =3D cpu->cfg.pmu_mask; --=20 2.41.0