Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp22854rdb; Mon, 4 Dec 2023 18:44:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVU63mM4vFZ8jscDEnFBjbvYISi1rWt2Z+e31s81MlnTvjU2m6XtbAvcUyy5O1GSu5/Few X-Received: by 2002:a05:6870:e2d6:b0:1fb:39ab:bf8b with SMTP id w22-20020a056870e2d600b001fb39abbf8bmr3033557oad.111.1701744265255; Mon, 04 Dec 2023 18:44:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701744265; cv=none; d=google.com; s=arc-20160816; b=ab4NwPY2zHCtKoCFj9rn9Nesx6oINoQHxzxsfNzW6YZq3hE4sPqaHp28agsadoHRAT RxWqJkzHNrq4nIyVYeTidUqTeG4TDiazbcN10XtVV3qUxWwf2HuU+gG+4EB/xviPZcS4 Alt6hmDpOShEjj/mp0LuER+R9caOAK34iV0OeWy/22QvqIdkIWOrPNswMoR1FeSQtH1g DvZoOsdJ5ijWtGrD3hEazO+aq1kD/XWriL4+QRaZ459VKD9oJ+oKO7u0Gv6IXMNZtRnq wcRlK0n24eJmcTlEQ1HLrEQmqNSHJ78lYo9Vjn3yDXiJjgkL7YBMmgdXWsv3QJEaOxix hEUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ezsx5Eqv7C1IIJcHeXVdQzYdP4PWuNbr/jfR9i9uc+E=; fh=hdWWmqr42gXb2LKR5pVlTakVhLV/lVdx71bRf5NvIOA=; b=gYZu6nMedgV/LbhofYIShlOE2te4jR+Tu/W6G9n/BPhrXhuvUyAJ9ynU7r8oxBPHBz xsEu4//JzLsZYO5zGe9uYWplAPaP1vN+MKhzUJF46z2uXEPCAxEImc7tq/bK2FskKHcH OCaKJnQKbxhIUsqCkrE+lvz3lgDqUYCFP3W0/854LG5DdbUc9pjwkVpcKzZgOAE4rwQ8 /xnYwnPulAbeCeQJD3xvFDambbpSfSPMTebKcnbttR0vYhUH5O4kfA4HelcnMVoIfIkq hR1q+8DD/r7gHKYb+sfMDSqQspx+je6RF2FzKOt8S0P7TKWW0y3QBB9zDqIz6aywAxtw 0z6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FKH1Gs8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q16-20020a656850000000b005c1754b3d4fsi4135890pgt.159.2023.12.04.18.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:44:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FKH1Gs8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1FFB680AD972; Mon, 4 Dec 2023 18:44:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346748AbjLECnh (ORCPT + 99 others); Mon, 4 Dec 2023 21:43:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346687AbjLECnd (ORCPT ); Mon, 4 Dec 2023 21:43:33 -0500 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2550A109 for ; Mon, 4 Dec 2023 18:43:39 -0800 (PST) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6d84ddd642fso2807758a34.0 for ; Mon, 04 Dec 2023 18:43:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701744217; x=1702349017; darn=vger.kernel.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=ezsx5Eqv7C1IIJcHeXVdQzYdP4PWuNbr/jfR9i9uc+E=; b=FKH1Gs8B1mqIu9eyoVmvKmmrtqbDrYKlv0vtgXtIxQJmNTeb5piflB3M9hRwo3r1JC f51kFxYpLx505XbsNejjSN353ZLlwQ5IMt4KqnW88yHFpPFGjYD9q5JhwfJyW9LZAmvK 6MSHbLFY5h4lk8taYY7dpw9CIDzsnMSKAMzKUJELD8k6JBkxkFffrCcruEh6kSlV4/1c Q3fxN3Gxm8XhgmVm3MFbDqqYWGsSdXZLH5/1aRmE8aHqhW2eiCmS0FfOfG+HC0hmkgB6 r37cx5zgfhxlDkX9137V+0E4O+NIqXJpFmWBAkamHiYP6oFAEZpZ25ezg16xC7ADMznH xKSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701744217; x=1702349017; 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=ezsx5Eqv7C1IIJcHeXVdQzYdP4PWuNbr/jfR9i9uc+E=; b=j0afK9KcjQh9CqA7FQxk2iwoCwXbgy2CrDPPZtFBS4aLEDGNXbCqqM/T2oVFPSJfyn A0KDOtrnSHTWLOXijlr4ZoQDDaFgERWGNOa4qBTlGBJ0rCNk5sF0nRoo3UJXgUZ/HFVQ Wxhvb2/lr8B2sWFO+0UE2qt4zrGDd/Ljll3MfIRXXryRFc6fjct7oSiUhDwUUgbRYy/j tOkBSsS36f6ZE0uUf3+C6g8ulJJr4bgxM5VR10ML7cjV+s8Y8L3mxR2B8lD0w3dg7Js+ E1XQV6hFcw1WvXQIeDZ94pDwHAP8oUimboPzDaGJoHgJLskADm2zWcVcdcMkGu3/If6L 23uQ== X-Gm-Message-State: AOJu0YwqUHVX+EP3Y6Y0nArPpfhFRbiuPqcSY2PHKHxEJIDFKmWa3pXP O7h5QcRQKujeKl+nCkaQPzMsroC2iChqA74cqMHB8Q== X-Received: by 2002:a9d:6398:0:b0:6d9:a17c:237 with SMTP id w24-20020a9d6398000000b006d9a17c0237mr2375646otk.23.1701744217652; Mon, 04 Dec 2023 18:43:37 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id z17-20020a9d62d1000000b006b9848f8aa7sm2157655otk.45.2023.12.04.18.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:43:37 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Anup Patel , Atish Patra , Conor Dooley , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [RFC 4/9] drivers/perf: riscv: Read upper bits of a firmware counter Date: Mon, 4 Dec 2023 18:43:05 -0800 Message-Id: <20231205024310.1593100-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231205024310.1593100-1-atishp@rivosinc.com> References: <20231205024310.1593100-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:44:22 -0800 (PST) SBI v2.0 introduced a explicit function to read the upper bits for any firmwar counter width that is longer than XLEN. Currently, this is only applicable for RV32 where firmware counter can be 64 bit. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 40a335350d08..1c9049e6b574 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -490,16 +490,23 @@ static u64 pmu_sbi_ctr_read(struct perf_event *event) struct hw_perf_event *hwc = &event->hw; int idx = hwc->idx; struct sbiret ret; - union sbi_pmu_ctr_info info; u64 val = 0; + union sbi_pmu_ctr_info info = pmu_ctr_list[idx]; if (pmu_sbi_is_fw_event(event)) { ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ, hwc->idx, 0, 0, 0, 0, 0); if (!ret.error) val = ret.value; +#if defined(CONFIG_32BIT) + if (sbi_v2_available && info.width >= 32) { + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ_HI, + hwc->idx, 0, 0, 0, 0, 0); + if (!ret.error) + val = val | ((u64)ret.value << 32); + } +#endif } else { - info = pmu_ctr_list[idx]; val = riscv_pmu_ctr_read_csr(info.csr); if (IS_ENABLED(CONFIG_32BIT)) val = ((u64)riscv_pmu_ctr_read_csr(info.csr + 0x80)) << 31 | val; -- 2.34.1