From patchwork Thu Apr 13 14:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 1768495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0Q+YO/7M; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=LtSuV86G; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Py1X70B5kz1yZn for ; Fri, 14 Apr 2023 00:03:51 +1000 (AEST) 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=nEHVIv+XI3JBCMJ3FOpBE116OC3y0dyCbEP+QwJLGc8=; b=0Q+YO/7MyO5v0E nIZwqn1qZnGy+uXtL0Qg0MMkkVT0yASTS00O9WOy9uvdguYMe8USQt1yjkia2HE/X6IrqjNjaCD8V KndtZ8mxlcYzRudQq/X5wxR9N265sD3mv6cL6MAMyQvjkI9C1hjOSv0a9xtu7wHtG2SGgDjUUMj8e UCp85Ea9T/5Hqt730joD6IhPG3ziglxk2G3k4uNjAD0OYT4WIYbmrW6haaeT9/WR3bSuAFIYGNOyv +jYH+NkJHbhZmhYeKCfhApxKPm5zrDE8Tdv2LMTyGNLDMfd864zX+uKPAmgTqCVbbTjAas05BLocp TZrbzri3+X2XRo6FS/+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmxXt-006LFw-1l; Thu, 13 Apr 2023 14:03:29 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmxXq-006LEG-23 for opensbi@lists.infradead.org; Thu, 13 Apr 2023 14:03:27 +0000 Received: by mail-wm1-x32d.google.com with SMTP id v14-20020a05600c470e00b003f06520825fso13672577wmo.0 for ; Thu, 13 Apr 2023 07:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681394605; x=1683986605; 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=W4bU1GA0Ay273F5NiHsmauLlzulA+0+vl93uBx3yjNU=; b=LtSuV86G7ojHT4YOXjHTnPBFc8GIRYnw6bG2romMNEVZLUlxVB2bT+ZzJDeWxtUmxJ g+wT0CmV/C+VhqTSpNVtot1LaDB5lNO6AzkqUhya4RssmpB/o6VrWuWz25VzbA/r5rzL a0K3taCk96vzTLaRJPGaP4x1UKSTK9nVzS11Zk6xIaAVo6KL8QPFDUBxch+ZvJwxnpx+ 8xgDsSK+marEiRHAMKshBdZlvlRYkfz/TbqbunuI3vGtga58JvUeThawrgGxFqN4SahT 5zXQEC8pOx7XCrkRWSFUJ6TuayTNvG3vxCjd+HftazoVFLV0DJL6BrDDW51AHk+mIWXm oRHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681394605; x=1683986605; 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=W4bU1GA0Ay273F5NiHsmauLlzulA+0+vl93uBx3yjNU=; b=HAv1Yck/45Oa4JdouNs0O0iGXfKLVVw0d8ncrOu45EdzWD8I6kdte9ICwH5FgarWRx ruVlDl6RwaxEVefLDgqfvQHNI6+TLpnBFjzirDotRGyjWBGPPTgptDFwxRdYjbjenmFO zjtbkSUxxGi1wnoefznvRgQ4E6LgaMHDDt0ArueNanIScuRsrjnoLtdi5o5fK6fB6mPV Bs7tqBXjJr6bHbvyUjhU2yhbsCRb37BVg6hHt3zFagQXZyuetALlkpbHlTvmjRDGKlFV NJiCKOiFkBMg+S1rNqMYVA2s9res55mGHD0B8V4wxWj8hSSXXe/GCTEGGJvgYgAkmfny VQrg== X-Gm-Message-State: AAQBX9f2SvbCr5nNO5cveVW6I3VUJSMPTXK2obiBkadANedlIp/D5cD1 kffL4jWk6z+39Rm/qBeA51ts7HNAIqWYI/6QqM0= X-Google-Smtp-Source: AKy350bBYU3f1ah5kHAY1di27NltK/a0L/kDjunCQyoGYX26TVgI1RqcY4W6LHxbUkND4ocOvUz7yQ== X-Received: by 2002:a05:600c:21cf:b0:3ef:3ce6:7c54 with SMTP id x15-20020a05600c21cf00b003ef3ce67c54mr2046932wmj.35.1681394604971; Thu, 13 Apr 2023 07:03:24 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id k17-20020a7bc411000000b003f09fe8312csm1912977wmi.20.2023.04.13.07.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 07:03:24 -0700 (PDT) From: Alexandre Ghiti To: opensbi@lists.infradead.org Cc: Alexandre Ghiti , Atish Patra Subject: [PATCH v2 2/2] lib: sbi: Fix counter index calculation for SBI_PMU_CFG_FLAG_SKIP_MATCH Date: Thu, 13 Apr 2023 16:02:19 +0200 Message-Id: <20230413140219.189916-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230413140219.189916-1-alexghiti@rivosinc.com> References: <20230413140219.189916-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230413_070326_671478_4BD8B10C X-CRM114-Status: GOOD ( 10.77 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: As per the SBI specification, we should "unconditionally select the first counter from the set of counters specified by the counter_idx_base and counter_idx_mask", so implement this behaviour. Suggested-by: Atish Patra Signed-off-by: Alexandre Ghiti --- lib/sbi/sbi_pmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:32d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org As per the SBI specification, we should "unconditionally select the first counter from the set of counters specified by the counter_idx_base and counter_idx_mask", so implement this behaviour. Suggested-by: Atish Patra Signed-off-by: Alexandre Ghiti Reviewed-by: Atish Patra --- lib/sbi/sbi_pmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 2176cc7..f5dbe6d 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -735,10 +735,15 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, /* The caller wants to skip the match because it already knows the * counter idx for the given event. Verify that the counter idx * is still valid. + * As per the specification, we should "unconditionally select + * the first counter from the set of counters specified by the + * counter_idx_base and counter_idx_mask". */ - if (active_events[hartid][cidx_base] == SBI_PMU_EVENT_IDX_INVALID) + unsigned long cidx_first = cidx_base + sbi_ffs(cidx_mask); + + if (active_events[hartid][cidx_first] == SBI_PMU_EVENT_IDX_INVALID) return SBI_EINVAL; - ctr_idx = cidx_base; + ctr_idx = cidx_first; goto skip_match; }