Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp9333rdh; Mon, 18 Dec 2023 02:42:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDT40qFyANNdW96dNdtGTmjmIz0y/dsDNCRRMBWLTSYa9uaeA5uGlJV7mVmbcMKt3+vCIf X-Received: by 2002:a17:906:4ec1:b0:a23:5fe3:efff with SMTP id i1-20020a1709064ec100b00a235fe3efffmr387034ejv.110.1702896158342; Mon, 18 Dec 2023 02:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702896158; cv=none; d=google.com; s=arc-20160816; b=07xrahGbm0ksq5tzrQcNRuTB1+BYg0sOdY3GXyT9/l/QqYtk6pwP6vyPzXQXoJgT6Z rv+rOP6Y3F6lx7khVfMoSjLNEHVnbvJs5m4ffBBI3A4RQKiklLHEVkxFui2t14S/AGKZ vJ2rg9O1cYk9YbenJtmUGnoZUUeu0KgWQZCTtnxtg5Wf/eSpuvgA3TX+Wh9x1Gpf5Zhg X2TVEc1F3mt0FY4Nd8UeIB0jXh/vVF6JwarruXBCLm1kzWozkTvTQOV4w8k/yfnhqpgM s+LnG3hqpHmw36leBwLeqwnUyBh6q/n1RAZxyC/RXi/QAxG/qMy04bLRjU2H0pHk7Otl e6cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VSo5xMz9BHWeXpc9J2d4I3sRbXRS1RJF/2qH5J8y/oA=; fh=edP9Vyhdx3wHlRWwndjClkZeqsrAD5QaYzj9PwYQ7RY=; b=sf+S/FEIiS/OM3Iwuyh70UM3qn2NNaCwYIKMMqWAgKo/qx+p63Uupvg00Ei5cQ9Jwa ljxKusTjepjLRXt2lmpZMCeSYA7ssishiMb4qtPe0VvmX0sq+4AqoyofN0hF2OT+Qycu 4Zr6jNHHeGS1B3RyDuaVvRAXb+piiIeSyzx8Qa89VXl9owkMgfD4QcFScS3/jxCdetop vdauLSSsnf9nMPDjlcOcgJN+7+lBGjjmkPhihqulv/bGGtDH7QQVcuNXQcL/HwxHOExY vFtpEiELtakApJQ1SI4fsCQVJMUMAk81Vd8jq/LcBZxCQyaTZhoH4hEuxFm2a+yPKQY+ 1A7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QaVAqSbu; spf=pass (google.com: domain of linux-kernel+bounces-3350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3350-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lw26-20020a170906bcda00b00a232d57ae9fsi1771036ejb.10.2023.12.18.02.42.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 02:42:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QaVAqSbu; spf=pass (google.com: domain of linux-kernel+bounces-3350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3350-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1BD731F22FFA for ; Mon, 18 Dec 2023 10:42:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E8D61A5AB; Mon, 18 Dec 2023 10:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="QaVAqSbu" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7623D199BD for ; Mon, 18 Dec 2023 10:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-590711b416fso2031828eaf.2 for ; Mon, 18 Dec 2023 02:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702896082; x=1703500882; 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=VSo5xMz9BHWeXpc9J2d4I3sRbXRS1RJF/2qH5J8y/oA=; b=QaVAqSbu6wG0lw/XmeIzBkzv0hvwmHQdVcwlbE4f/7JQ2g51OiBxCX+dBr4h+8fmst IZplqTviue3hEGJA8ZNufXATcAGhU6Q2yjAhoZu0sbApRdK3MBeTNp1F2Oj7tJSFzsPk ZSWpVUwnZgPUOSLKfQOQ4GlbghZAq7y77B96E3Y/7IhiY9fm7LUkLIGs8gakDT28BvJl JTaImIqjhxim9AhndAo1G3eTB52Gx9ziRAuKX1x34W1TNUk/PdzCr2MFX9rJD8xy7Gxk qZx6SXo871HlWIc5Cs+UrLIGAZ3rIYgu2pFq34i7zcDB9yibRhP/5gsk5Nm4baf2cjIp a84w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702896082; x=1703500882; 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=VSo5xMz9BHWeXpc9J2d4I3sRbXRS1RJF/2qH5J8y/oA=; b=o52Oi1A7PgTvZXwX7+jSxgshciJj5kYFn9S3yNSi1HQ7GN/0P8KoB4PtiuTbyilkpT v3reByjAR3NCfYtc+DS808UErnhR7NdtiZqFKyGTZbZ07OjDR1bb1QEzFHO8ZZc0lIzC zHj1K65Qf6i7VC1jC/+5GjqPWHSGfEXeQ/s8snR6MC3iZ2lO1BQZJpT8Xxn3Ja6LtB11 f6LBAV3bjtzzJpCrPxgqMItU0GvAhKK0JJYy6o8gEO34RTzARU0qiHrNyow2xvn4MwxV xFPm0QIRwHW5/6tdtnN3/+MW3LLb5PPxgh+e+h4TQwOL86Mqt/vI5dlX+K4O4Q7ZiQyk zvDw== X-Gm-Message-State: AOJu0YzpVOp/qCtrS767LhX9JM51ZBTqvPHFiFAKlYbsSo5Jp3OOXY8/ l0NqYghjLzDQfxSgzkrBLxhOaYOV+h2mh7Gz7NY= X-Received: by 2002:a05:6820:1ad6:b0:590:8496:b5d1 with SMTP id bu22-20020a0568201ad600b005908496b5d1mr16558518oob.2.1702896081753; Mon, 18 Dec 2023 02:41:21 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 185-20020a4a1ac2000000b005907ad9f302sm574970oof.37.2023.12.18.02.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 02:41:21 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , 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: [v1 03/10] drivers/perf: riscv: Read upper bits of a firmware counter Date: Mon, 18 Dec 2023 02:41:00 -0800 Message-Id: <20231218104107.2976925-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218104107.2976925-1-atishp@rivosinc.com> References: <20231218104107.2976925-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit SBI v2.0 introduced a explicit function to read the upper 32 bits for any firmwar counter width that is longer than 32bits. This is only applicable for RV32 where firmware counter can be 64 bit. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 16acd4dcdb96..646604f8c0a5 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -35,6 +35,8 @@ PMU_FORMAT_ATTR(event, "config:0-47"); PMU_FORMAT_ATTR(firmware, "config:63"); +static bool sbi_v2_available; + static struct attribute *riscv_arch_formats_attr[] = { &format_attr_event.attr, &format_attr_firmware.attr, @@ -488,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 (ret.error) + return val; + + val = ret.value; + if (IS_ENABLED(CONFIG_32BIT) && 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 |= ((u64)ret.value << 32); + } } 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; @@ -1108,6 +1117,9 @@ static int __init pmu_sbi_devinit(void) return 0; } + if (sbi_spec_version >= sbi_mk_version(2, 0)) + sbi_v2_available = true; + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, "perf/riscv/pmu:starting", pmu_sbi_starting_cpu, pmu_sbi_dying_cpu); -- 2.34.1