Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2553762lqz; Wed, 3 Apr 2024 01:06:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWY/pjilNJ9Ml6i8R7/RNDD3E/VmcnWM4ksj7+XznZ4a29qRweomFDd8Z2p7Z8E53vPwGX/q8mFslpaGUQ+IElcyYvR4medVGC3eViD/g== X-Google-Smtp-Source: AGHT+IG8ZdsvrwBe0R1Vz2VQHjuGZCbgHJ5s3gy19YBcv7DeJpupXTiMVlWPwEDDGinpGS/UbnXE X-Received: by 2002:a05:6808:2e92:b0:3c3:d89c:196a with SMTP id gt18-20020a0568082e9200b003c3d89c196amr21161502oib.54.1712131583579; Wed, 03 Apr 2024 01:06:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712131583; cv=pass; d=google.com; s=arc-20160816; b=cz5Ue1oofyN1rwZAXm8d2BDHlRAQbfKedLZ3jWJL69H7E3dBkMqhi21gnwD9S4ljtB hGy4EUh5YrdAyD6bl0uz/IQ3ij2rqr1Q0KoZBRPWqVeZqoxBF31suQF2n6dRLV3QyvVQ /IklfgiGGRAYYH3mVnYUu2oRu/4opn8vJVb6HbxTnBe8IzUAiM+O0a2wWHiPScB0ihyt 7xUtc8qXDsw2QGv5+eYhlSeQSd4TzKKvnscU37dk8rSEo29hvqZtGiKXZn6Riqhd55qL hv8TVbO9XVFCaD+ZkpYPDSknp78cEBfgDgFJNs3Zsq+Ch4EDMPijVY5XL+PC91Z32Dxw vzsQ== ARC-Message-Signature: i=2; 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=2ukUdwvkRaeQmBPwRJpu6uMxNPU93zNWp+RJiBVsFw4=; fh=fvKXVl9wA55aLU8ghf1ISNN48W1phgSFvAezJbv3hgM=; b=0DfIT4a/eByXHwe1H51HR+SLtbWI3r09nfulVJl4tWsFDKcG4Xcki7mMa23bDfQgt+ mXAmINVj5DeM5VKtzEGOPUfLcuYI+JmWmpXq6eD0LZS9XLswhQulzdq4dpyAt3cvrLnr Z5ay7iOgJM1wh9SNc3GE2rEwthYrrzyuiTtfl+i46y7u3mnnBycFL4IKjLu+nLy/9GOh xaGuPcAjvfjZn1mwn1oysWnhiJNKu28kxSvUujv81kub/YYOMuUCMNSu957bY5kqWle5 l+ONr/qfUJ0/4rpCPbk7aHLZljF+lFsv28lG3UyvSWdfm/egoZ6UhvmXtlr1fHDarZ5u FDHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uK75Skh/"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-129243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129243-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s13-20020a05622a1a8d00b00432d2f8478dsi8894772qtc.375.2024.04.03.01.06.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:06:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="uK75Skh/"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-129243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129243-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 48B321C254A7 for ; Wed, 3 Apr 2024 08:06:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A24071B4E; Wed, 3 Apr 2024 08:05:22 +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="uK75Skh/" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 DA2FB6FE0D for ; Wed, 3 Apr 2024 08:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131521; cv=none; b=jz8eGu06H1mvTozfwFYE7P+Q3ZT1f8tw6iWc8ey3MtVbkFGwWUSvIoiG+bVgw4s2f4JwNh0mqYLMRDSNrrYfT3MnB9ZeI3y+Qr1chSly0uo9BdFTU2zeyDAwsgRvL+1TfAS17VOKLKpYYac98Yi1srcJ5bzMMgsd0WKUn37+TTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131521; c=relaxed/simple; bh=5SixT0kcz+8IGtYwvZGhA9Q1KZ5SaAWo/BakwlxdqZM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KVgbMmYVQc9KCHyIRxsb72RNgHloQHXnfPTlMpQtVGFQs3P8BPkNtESg5I6hPhy9I1GkviIyQ9ATXIV4pXF7jYQwcB1/YoGFeYmxUYSGXNz9BkKE+UGK8ptvnwhlNXC5TRTJghrQieQu4SaftP2rl5r2qcqVi9hxJlyIZNWLyZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=uK75Skh/; arc=none smtp.client-ip=209.85.214.172 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-pl1-f172.google.com with SMTP id d9443c01a7336-1e0b889901bso49280525ad.1 for ; Wed, 03 Apr 2024 01:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712131518; x=1712736318; 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=2ukUdwvkRaeQmBPwRJpu6uMxNPU93zNWp+RJiBVsFw4=; b=uK75Skh/kr8v4RnArctSD7ENSLfakR6lkmYZzFmP10Hlu2kXP5spk6IQXSbS309AaS 9nbmQ4aRhTKH0iRWuaqGf6zCfxadSs2xbbF1T8ORRzclYNTfaQOwuOGETxdNIWfmEm8U p+CqL2TIKw4I3+/L6Q5T3lQl4JiL3qaYPBcj/PlhwrhVE8iEJOY/iM27X3hlAS+ZN2tv Gpml8cz1wynHkSUN1G2U14IRmkD/g3YTv5c2wNNneC94/mcK5Lmt1jBQ9OHoeFn+zgRu oGQennlWMs0RxBAo6lHuE8p69IWXe5O9cqfHqvgriT9PzQqbyvumCyJWNX9P8TMdmxzP 8SBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712131518; x=1712736318; 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=2ukUdwvkRaeQmBPwRJpu6uMxNPU93zNWp+RJiBVsFw4=; b=bbAbvWazcB3atJclHhytYU2GNsBN9v5mqzESri7XCewWKKWfBVp64G/Q3Fy8y7w7PQ 0FZm8wyHCkxMvnz298FkD76Vd//2nyUYQK+6mMvIh00OMYAwXemfVkQn+zfM+rc11Tcu OYOiNX0rjc39J4wdyohplbjyhebrz/DfHa55JVXQKWifrYJiy0pB/pdYAWpv/WaNb4ZA 9URZfOQf3blHE4ek7gmNJQx+WxiiqnO0kTgIMHQv75SNYlSid4ULpcX7r/1fN3YeSnuY Hz9zJWpCcN+/vkLFuIBx/HWP1YnCVmt6sXcXVb/1HMv/80W+bgDMkPyXclPC9CWv4E0X N3rg== X-Gm-Message-State: AOJu0YzxBdTQWuy6gJZKeyhf4cCh3fHVtKO9vOwOu0628id1j7htb8i1 Irx2rEHoXWmjEJB4VooMdH/D3tfl6tUxfwe3rJuPI34ltuOmLqyZCHuDpbEzFzS8S2e5ROQnaKx H X-Received: by 2002:a17:902:e741:b0:1dc:a605:5435 with SMTP id p1-20020a170902e74100b001dca6055435mr16071106plf.31.1712131518213; Wed, 03 Apr 2024 01:05:18 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c12-20020a170902d48c00b001e0b5d49fc7sm12557229plg.161.2024.04.03.01.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:05:17 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Palmer Dabbelt , Conor Dooley , Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org Subject: [PATCH v5 03/22] drivers/perf: riscv: Read upper bits of a firmware counter Date: Wed, 3 Apr 2024 01:04:32 -0700 Message-Id: <20240403080452.1007601-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403080452.1007601-1-atishp@rivosinc.com> References: <20240403080452.1007601-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 firmware counter width that is longer than 32bits. This is only applicable for RV32 where firmware counter can be 64 bit. Reviewed-by: Andrew Jones Acked-by: Palmer Dabbelt Reviewed-by: Conor Dooley Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 3e44d2fb8bf8..babf1b9a4dbe 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -57,6 +57,8 @@ asm volatile(ALTERNATIVE( \ 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, @@ -511,19 +513,29 @@ 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 + WARN_ONCE(1, "Unable to read upper 32 bits of firmware counter error: %d\n", + sbi_err_map_linux_errno(ret.error)); + } } 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; + val |= ((u64)riscv_pmu_ctr_read_csr(info.csr + 0x80)) << 32; } return val; @@ -1135,6 +1147,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