Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1295163rdd; Wed, 10 Jan 2024 15:16:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKVgK/5bVT4DibUCVnsJasPSfJ9+mZA1EIeLdEQNyUbNeLy197+h+rB6toIiY1Lu1gHdGH X-Received: by 2002:a17:907:1109:b0:a2a:c113:2677 with SMTP id qu9-20020a170907110900b00a2ac1132677mr227787ejb.61.1704928581986; Wed, 10 Jan 2024 15:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704928581; cv=none; d=google.com; s=arc-20160816; b=sKWp14R1AUGyIdiLcrNu+sgKGJDfwz+faAkyInBP962DkhDk+NsEMcU9UWTUJZwqHX PScrXhABGwpO7iiV9rM1BjmD3R/vwgYLxKSX/VrhT5WMjVPZVm9L+HFq4K/JUt9Uf8vS Kn5B0kohruFXnGinCK6Zm3vkEsOE53W6JCfHlNoO8oLoNQ5q3jRChlZV9GTo7w+jeRnI ZV3ZWda2r9NQclW1dkMiWYzGBg0CWgsFnCusTXDWgNH2opr3ZBrvwDPayhnQlmIK7Ugo 5K5Z/cRZKNqr5tlat6BgvIzsA4Cda9KWTfkP83sDpB8uWHVKn4C0/nMVr1lj+wBmqGco C0PA== 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=y/Smp2oLhuu6GIJFXbIgbmjKI2p4Ava6d/2TN1s81h4=; fh=RJMMzO4nzSbhQ9E4iR+3cdpqEbkVbfotNqWTtuhUjUg=; b=yQ6fmf1d+/xZazkN3mO9+6jsG8mfx4IscCM9bM25Ysc8W5GOdDH++IhxNuREk60NfH 2v1HA9yEjLQAoFyQp4aanLWnlQwf4MnJWsn9evqdf/rMdsn2jPXNdASJOPTTa6j4dWTL YS7UnOqqWxu9+WWN307zHFZGYM/NQ6IwKdcV278JULRECdSNrGhX/oJWykBrbogf9083 gbDmu5GBgncqwWw6pjwCe+zJ4T6g3BjFanK0spB8lfz7FfRfy9GOh3AY5O463mIExmaz hq3Jtoq6w3Fn2hR0TYqfjT419OeTh1r1nL5NAwc2so55YXzD2ZsN31Py4EpZa+QJelYZ eRtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tDNJTu0k; spf=pass (google.com: domain of linux-kernel+bounces-22879-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22879-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 h1-20020a170906718100b00a2a6fc65de6si2099615ejk.60.2024.01.10.15.16.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:16:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22879-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=tDNJTu0k; spf=pass (google.com: domain of linux-kernel+bounces-22879-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22879-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 122731F22865 for ; Wed, 10 Jan 2024 23:16:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DF4D524A4; Wed, 10 Jan 2024 23:14:46 +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="tDNJTu0k" Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 4EECA50264 for ; Wed, 10 Jan 2024 23:14:44 +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-io1-f54.google.com with SMTP id ca18e2360f4ac-7bed9fb159fso75337139f.1 for ; Wed, 10 Jan 2024 15:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704928483; x=1705533283; 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=y/Smp2oLhuu6GIJFXbIgbmjKI2p4Ava6d/2TN1s81h4=; b=tDNJTu0k+yFq3L3KJ1TlvG0de0hqJNgp72hRJEcgyiPJerjd5+ENKWervVnJyxiElb eRzJ2JeH0db3SlvhNU21G507dUlxpi429f6KHY3Tr8OquJ/OOSC132bJRpwnYgYO4WjN sVz/XDNZzfg7fDNHreLqXJzoFrePfIyl8xbWPBaIsQFwoLrJEMQAqitBSCndrjiCji1b q2ByzrRpgPoNnCq+ErHE3m2dO02/zEvXWREuI/9UFHuXYfKZYqA6qDiJZoVDWHRXdBSw g9ZQ7VCW3z63LkRbMgi4VxjvuOwQ6CED5n3gKMeMTm4U/rvkzUfoKjjp3jk5ZgJY11bJ P8UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704928483; x=1705533283; 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=y/Smp2oLhuu6GIJFXbIgbmjKI2p4Ava6d/2TN1s81h4=; b=mbJIK+iKTDvHXuVP6P6NkpaEkRYOFzL02VkKxHyUgDuAWUCtLE2F+L8/us3Sd6I3Of 3FgLwU6CfpWDIGe1YYpr7wrNGWxIkWejbghp7Tf3yhEzxtWhFrRtvugL6h2/YgfB9NEH JgtdgH9FJ2iyJu844yVSRRha6rvb9uKsDXzf9B//F/tjudb91EC/uzNTpe3f0S1F7+Xl IaIOW6rxD7aYmYEhHZBgiCPS5YkFjHL53/OAr20+lL2OOeZb+K59/cgkIyKrQRg9LNIo vx4j4b5GPymWxcO+0JTgjTPLipwirGVxLpU6icJwaZyVV8rNsbkr6P3SyO+C4yT3S714 XPng== X-Gm-Message-State: AOJu0YxkS8i9HDgvzttU0u1RgF07gor4sQD9KKYQPuYi7ck4lYFCX1Cb 4xbZhzUzoh6lq/RtOQNilvCUPtGgPH8N3rZOsL9v10kvhrc= X-Received: by 2002:a05:6602:2819:b0:7ba:85e4:f8de with SMTP id d25-20020a056602281900b007ba85e4f8demr324455ioe.42.1704928483021; Wed, 10 Jan 2024 15:14:43 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id co13-20020a0566383e0d00b0046e3b925818sm1185503jab.37.2024.01.10.15.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:14:42 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Palmer Dabbelt , Conor Dooley , Anup Patel , Alexandre Ghiti , Andrew Jones , Atish Patra , 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 , Vladimir Isaev Subject: [v3 03/10] drivers/perf: riscv: Read upper bits of a firmware counter Date: Wed, 10 Jan 2024 15:13:52 -0800 Message-Id: <20240110231359.1239367-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110231359.1239367-1-atishp@rivosinc.com> References: <20240110231359.1239367-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. Acked-by: Palmer Dabbelt Reviewed-by: Conor Dooley Reviewed-by: Anup Patel 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..ea0fdb589f0d 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 0; + + 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