From patchwork Fri May 13 01:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12848293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BDA52C433EF for ; Fri, 13 May 2022 01:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OK1sP0hN7D/C2AJ+jOFINwORZ/rDKCxlIM7ThCKzfaI=; b=pNAkpvVakkQA7J /HhCtbiU4anlCFIXQBr9vJ3tM4SieUTUdNAgNPplFD71OJbAni2t5rFkVBtf1tTbEYFOa5cyzaedP KqLPBPrBv/vTodBaD3pZgPvLVgZGRZ7wcUZmYWlEf0AEakCuuti8ALlUHORIMP5aMcaDx91UgSzfk 8jfeu9Vc6dc3FEfw0DxHKBhAzE836VCZSPF6DZyRFkBFEl26kCJq/039hk0Bk5VjuFhJv4BCvtSEQ xOLzKswZzEXScEPNko9TkMDPrFlb6BBFY2eOA2OHz7Kf2rH3eacR3vlrenJqn+kET9XOkImuNP5GS lUXsVxI862rgRsCox6/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWt-00E8KT-EN; Fri, 13 May 2022 01:55:43 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWo-00E8Is-Kb for linux-riscv@lists.infradead.org; Fri, 13 May 2022 01:55:39 +0000 Received: by mail-pj1-x1030.google.com with SMTP id t11-20020a17090ad50b00b001d95bf21996so9480475pju.2 for ; Thu, 12 May 2022 18:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XLnu5Z1M7spTOfkxmzGNMq9mvJnGiQu2ymVbvg/7Y4o=; b=Gw9bQQPrN9NnofVD2CZg8l8560k0Eu4jmDNZcgA5mtLk3BTLKuqBahKfJOhcT/w+HK OcHyg8B7V8t/tKMDwTCzbyIZqlz41e7HY0vrshiOofh2SCWGRGU6vp7WVjGtfXB902AH CvA/5xrCJeVoELhc/hwxxiuF91TqeRLlf9GEUXrd4NGWXyRx5ENi2UYWvI8LeCTlzGB1 4SPJ3vbr5iDzq93NHAszxeIOOrsK8dPPL+s0r2HpwNazNR713H3ZnADeh33QR+NuNBpt QBO36hJEof9BEbvyFpe58WHDLZKbz1SmRN2r3IA6v8MjIRrqD1A2SHafZvpWEt36WyDL 3BqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XLnu5Z1M7spTOfkxmzGNMq9mvJnGiQu2ymVbvg/7Y4o=; b=lbx1HuxdkNw8B/EOL+EppdpKUicrDVWu8Rx7DtWgzO5rj1JdSFC+nH2ZLjH6geeheo pUZpONgD8Vg8nNILNqZIiEm1HyOH7ZYu21dlTEF7KTNYw6g1M0hwfVPu0SwFlLWIXU6q AI3XCyqrpRUWYIayA90pd9cIbWx4oT6RBfCYWtf2cVBqFF4lNBaJZ1ILXpZ1/X+nJaVq d0F3QQWdxlbf5wq7RRerpYEx5dXstkQD1yi60sIqH6BYvZmsClwBxtdLPm6GG+z4FSrj SC/ei2bWlpeUYXNTQNbIHOQKuyb584cJwCOH9oSapR9lt4jUKM8Xtk7gdg2ViHgoXPP2 26KQ== X-Gm-Message-State: AOAM533YH8k6QE3t10zdLcn/lg/tayVM/LnW6FvYmC1+qEl2D6Z+RlMC rOBYO0F/QL0eQstDr+qX+0/T0Q== X-Google-Smtp-Source: ABdhPJzO+Hcgg8hisxLU7ADgG8gGPtljLastMpjQQFp1cgf81i34Pr2jRZcEr4RkNp+OCFqqJd9VjA== X-Received: by 2002:a17:902:8504:b0:15d:2c7c:ceac with SMTP id bj4-20020a170902850400b0015d2c7cceacmr2623328plb.130.1652406936838; Thu, 12 May 2022 18:55:36 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id i1-20020a6561a1000000b003c14af5063fsm365883pgv.87.2022.05.12.18.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 18:55:36 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Heiko Stuebner , Anup Patel , Atish Patra , Jisheng Zhang , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v2 1/3] RISC-V: Fix counter restart during overflow for RV32 Date: Thu, 12 May 2022 18:55:20 -0700 Message-Id: <20220513015522.910856-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220513015522.910856-1-atishp@rivosinc.com> References: <20220513015522.910856-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220512_185538_711560_D514A005 X-CRM114-Status: UNSURE ( 8.46 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Pass the upper half of the initial value of the counter correctly for RV32. Fixes: 4905ec2fb7e6 ("RISC-V: Add sscofpmf extension support") Reviewed-by: Heiko Stuebner Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index a1317a483512..1e6c150c892a 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -525,8 +525,13 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, hwc = &event->hw; max_period = riscv_pmu_ctr_get_width_mask(event); init_val = local64_read(&hwc->prev_count) & max_period; +#if defined(CONFIG_32BIT) + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1, + flag, init_val, init_val >> 32, 0); +#else sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1, flag, init_val, 0, 0); +#endif } ctr_ovf_mask = ctr_ovf_mask >> 1; idx++; From patchwork Fri May 13 01:55:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12848295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D799C433FE for ; Fri, 13 May 2022 01:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5NhueCEy/jv9cDVo/rH0FdV2JZU4sWC9qKvSRrwoCrk=; b=Dywo9mq/3STOXs YHqR+d4gCgSPbnxuZPhmGBwguFjVFONKrxV95AaBNo8XoBz/SgwE6Mb79n9Q0tvyOvWoMikWyoVBu 8Znu0xWv4QEQjmcPAbJfzZcea4GMyAfWgqiPBzXvoNCOiFGSEZGujXwUUGUjaGUupIWIGNlFhSvLe xIZcJapGM2zxEiKB2FucUNKh5iYnA9T9B+qyIAvY6l3V2evKdjFTrOK0xTXwsqZlo594lGAjHGGu8 6sotlKVbcK/goBS53n9HXI9I/Xo70+awl/KroLmdwev29aUqbBI0Sr5OM612N//v770gKtV2SCxKe 17PpEk44AIid3SnACpGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWu-00E8LK-UV; Fri, 13 May 2022 01:55:44 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWp-00E8J0-Pa for linux-riscv@lists.infradead.org; Fri, 13 May 2022 01:55:41 +0000 Received: by mail-pj1-x102e.google.com with SMTP id fv2so6782806pjb.4 for ; Thu, 12 May 2022 18:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zwpzunAvrzpyNJwdCWF/epnILRDBBON3y9jarpPPVEU=; b=jn21sS9XmXyewU4HqxnDpg8Clt6oVSJiJy9/dzvwizTppgxJ4ATD5W8DkzU4MK4uGG RXp7gz1Tfo+f+k9qSNtOp4+qIl3++tOFwLmhSiqOr5oBSZ5ivYPXQ8LFk7qXNjDS9vq6 kzydwxWF4Ivso12ENq3uSgByo/9DaPpCDbfCcpgBkqYTU+Su5s4iJwaxddAr86ZK5Wi7 381m+o3ZHxVm8iYaSh/NygFxI9wjCXeGHZ4nin5B6ZlpPelKDPC3jSuu1xBsM1R2mvMa dK3OVNw438WaKzrUjF6y3PK5L2RGN3JP95T8qtHYZ2PqY3CFRYO2CZpo6UXlzOm5O2jT PwSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zwpzunAvrzpyNJwdCWF/epnILRDBBON3y9jarpPPVEU=; b=eZ9QBEm6JYDu+oHiu9MMt+GA8V8VKGcAtxSzqbEbuJK80nqMXxM3YKMdaqJlaohBkI vWsyHV58GN1xiK7JcF4dHUuxgUKS8h30HMdLQuFl9a4Hfg/00plk0eg2X/z2UMDiVqwv AzyOD4JgkVeWjxgTDegxyl9xDDIdoa1DTg+WJyfb8ko+cxmi+RTcNUx9Kc938DVaFwo9 5BWEkwa6o8WEwJk96ogz7mTOW1IsqNjnSMyAHWZ0M650GDurcN0uh1sWK63K0teSnF2U 1DjGY+acO104y6QFtnGYG1b7uLw2O+JH1/0HzX4v0DDrEfE/nLNos65YBk39I2ySQooO JmDg== X-Gm-Message-State: AOAM5306PufbtHEfAhc5tJ3tFlzeiiNJpdS92KYKvbgxE5HrsQDaiMNv xuqaPgfyVVEuQS5/kO5CxSWZt0aGZmZNTA== X-Google-Smtp-Source: ABdhPJw4gZ6OHEXgL59faCpkeiUSlt9ozUYGPPPvK4t1UxngjnGeG6isTHOmFxPQjvPQmoPyltbyag== X-Received: by 2002:a17:902:d54f:b0:15f:22cd:c6d2 with SMTP id z15-20020a170902d54f00b0015f22cdc6d2mr2572023plf.170.1652406938015; Thu, 12 May 2022 18:55:38 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id i1-20020a6561a1000000b003c14af5063fsm365883pgv.87.2022.05.12.18.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 18:55:37 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Atish Patra , Jisheng Zhang , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v2 2/3] RISC-V: Update user page mapping only once during start Date: Thu, 12 May 2022 18:55:21 -0700 Message-Id: <20220513015522.910856-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220513015522.910856-1-atishp@rivosinc.com> References: <20220513015522.910856-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220512_185539_867146_BD2CB4CD X-CRM114-Status: GOOD ( 11.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, riscv_pmu_event_set_period updates the userpage mapping. However, the caller of riscv_pmu_event_set_period should update the userpage mapping because the counter can not be updated/started from set_period function in counter overflow path. Invoke the perf_event_update_userpage at the caller so that it doesn't get invoked twice during counter start path. Fixes: f5bfa23f576f ("RISC-V: Add a perf core library for pmu drivers") Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu.c | 1 - drivers/perf/riscv_pmu_sbi.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/perf/riscv_pmu.c b/drivers/perf/riscv_pmu.c index b2b8d2074ed0..130b9f1a40e0 100644 --- a/drivers/perf/riscv_pmu.c +++ b/drivers/perf/riscv_pmu.c @@ -170,7 +170,6 @@ int riscv_pmu_event_set_period(struct perf_event *event) left = (max_period >> 1); local64_set(&hwc->prev_count, (u64)-left); - perf_event_update_userpage(event); return overflow; } diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 1e6c150c892a..7ad92039a718 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -532,6 +532,7 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1, flag, init_val, 0, 0); #endif + perf_event_update_userpage(event); } ctr_ovf_mask = ctr_ovf_mask >> 1; idx++; From patchwork Fri May 13 01:55:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12848292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5D8BC433F5 for ; Fri, 13 May 2022 01:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iQvlH/Os7hhiB15CFnESAv4lhzwIILNVTbnlzeTRnC4=; b=x8CP43htY65WiF OF4nh9/TuGSWiZCI+gFpDooK9u/RiHN+yrGY7cDcG9AT2/RdMHNrYWzxGLnPmJN+AOgmAK8KsalOx MgvebgX7WjPvfCeLycb2fF6qXIgC/ybHm0YnsQkwdaoO7OkXgHEklGNeSy9zmny386TgK15Hvz3u3 BWKYhCGUEdVReVFcdVOsMATKdSNIwFQs85n7/a7fdx3cs80p7aWmdNrbVlhSEKDsqEVJKulVRK2QU jYx+XvtqwwjUDZSFTUwJeiaBXVpPmZkaxBWhwvsINxagD4Fganw3imYV9vtJfG5yHDJR6DVm3zhwo U2HMASE8x7P9zQRCRdBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWw-00E8M1-Bn; Fri, 13 May 2022 01:55:46 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1npKWq-00E8JM-TW for linux-riscv@lists.infradead.org; Fri, 13 May 2022 01:55:42 +0000 Received: by mail-pj1-x1033.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so7166029pjb.0 for ; Thu, 12 May 2022 18:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pPoRCiwoBINJx2a5XFW6qeMxXLBrBULI+jQkr1qktFo=; b=yeI2vNN+2d/X/8BAKhk7NJTErNc0t3Ri4UeoW4oeDLfEfpOVAFzJbZEdJd4OL5zlBt 16CUDGhYrbnSYKwz5l4yd+yJBt2LGu1GYKKuQlU0JXxCrFhc0y0nLHz5FdBG0Cs/EC9Q 2PipFMEIgbgErRSSzo9pc90GpReM2RdMLVJ4wjj5s3T1kCqIHw4Gtn8LQHJ6hBclILTU eJ7PTZ7bi5WndFmDlxxf7NSTRrTcclZvJ/IHeF4p/XPtcyM4vfikQtmi6VqmJqgBGTXK Hr0r7MsGu0t773x6K2OfWDTIoChx6ZbNlZ+vb2Xj4VxnpND6eIUNLaTpZDztoDBFnqlZ MrOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pPoRCiwoBINJx2a5XFW6qeMxXLBrBULI+jQkr1qktFo=; b=ymmCJlnCU10K2hCeTbuikGpVjbleAqvMb04YUhwYNIxFN5ApASUT9bfsZhBp9LJB/s E4efxT1rXgspQSXf06IyTkFZuW2BwxRG85M2CY22CHEeB7c6ObF6lj70ZEk5rr8rBMvW whPAbBT/asmCBEsUnw/KOPxQQ0y7uIU7UA6aEvS6wf5uXjES3mN/8hauqNR2uW0vRem4 68jzaHTo21vTGhEOeZ6xwvMWkuf0iI8vABTU2Lyu6ttqfHpdSuh5/7fpejhco6qSXs1l EgF5ytKdBB8cpdNO46iBqgAmql2UJkP4j9cZdsCUsCGtQbMG5a/KrwJ3OSnDq9acKUZy 8FuQ== X-Gm-Message-State: AOAM530CCzFU+qhp9Jgv2iRlLaDquab1e1qM/63/+dscvIgVKBZNpiHa PwINdtsmE1XfIKjFsq8v/7gVZQ== X-Google-Smtp-Source: ABdhPJwufGXGbLuIccz3+zyq2wHIQcgZXVxMmyj1l/g/wWcffrG37DEvEdIXB93ZMBkLn+2Hl79Afw== X-Received: by 2002:a17:902:850b:b0:15f:2a59:1c02 with SMTP id bj11-20020a170902850b00b0015f2a591c02mr2595813plb.27.1652406939289; Thu, 12 May 2022 18:55:39 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id i1-20020a6561a1000000b003c14af5063fsm365883pgv.87.2022.05.12.18.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 18:55:38 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Atish Patra , Anup Patel , Jisheng Zhang , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v2 3/3] RISC-V: Fix SBI PMU calls for RV32 Date: Thu, 12 May 2022 18:55:22 -0700 Message-Id: <20220513015522.910856-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220513015522.910856-1-atishp@rivosinc.com> References: <20220513015522.910856-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220512_185540_988344_B5B51271 X-CRM114-Status: GOOD ( 11.08 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Some of the SBI PMU calls does not pass 64bit arguments correctly and not under RV32 compile time flags. Currently, this doesn't create any incorrect results as RV64 ignores any value in the additional register and qemu doesn't support raw events. Fix those SBI calls in order to set correct values for RV32. Fixes: e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension") Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- drivers/perf/riscv_pmu_sbi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 7ad92039a718..fab0dd497393 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -274,8 +274,13 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event) cflags |= SBI_PMU_CFG_FLAG_SET_UINH; /* retrieve the available counter index */ +#if defined(CONFIG_32BIT) + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask, + cflags, hwc->event_base, hwc->config, hwc->config >> 32); +#else ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask, cflags, hwc->event_base, hwc->config, 0); +#endif if (ret.error) { pr_debug("Not able to find a counter for event %lx config %llx\n", hwc->event_base, hwc->config); @@ -417,8 +422,13 @@ static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival) struct hw_perf_event *hwc = &event->hw; unsigned long flag = SBI_PMU_START_FLAG_SET_INIT_VALUE; +#if defined(CONFIG_32BIT) ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx, 1, flag, ival, ival >> 32, 0); +#else + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx, + 1, flag, ival, 0, 0); +#endif if (ret.error && (ret.error != SBI_ERR_ALREADY_STARTED)) pr_err("Starting counter idx %d failed with error %d\n", hwc->idx, sbi_err_map_linux_errno(ret.error));