From patchwork Wed Apr 3 08:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1919078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=N0Bs0yq3; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=iyCeihnH; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=o1s3h3Xf; dkim-atps=neutral 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=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V8ckS6D8cz23tf for ; Wed, 3 Apr 2024 19:05:36 +1100 (AEDT) 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=MM8mfSLnocuAq6bAVmSiqvBfzXy9IN1JN1qTXClNyzY=; b=N0Bs0yq3k/329r 3qaEQa5MeAADVs9rD4Fflu+Yvi8y5sxhZ0RSZHc+aDLiFaXVWtuR+4My571r+1JLRf6kNCTEUHC+f qzKSO0WPe1oir4yY54qx3FzI+h8q0apGxpl/Lwke1G6xTMM/gQdGQo2GroNHkwFJeCWKUJMAphVxa iW9gcPVq71usV4Iw/ZNeNYBkH49/C4u4UatQE5vAbbUAG7hhYd6TKjQkVN/ZWmflGVwD+JlehQtoV YC5xCkGJo1Lt1ZxcVCVWjm8XrB3hvgoXz+pWkaHgRuIbuYwntKTzkjFBT3MAn0mFA7lqlSZWUG2uD 3VVrzwIaUYeHbXZL6p2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrvcl-0000000Eihd-1vkV; Wed, 03 Apr 2024 08:05:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrvch-0000000EieB-3pSL for kvm-riscv@bombadil.infradead.org; Wed, 03 Apr 2024 08:05:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=2ukUdwvkRaeQmBPwRJpu6uMxNPU93zNWp+RJiBVsFw4=; b=iyCeihnHE6l9/YvAqSjEPi3YWw qvbUEVURjXo9VN95Ve5FIekXahhbaeO923ClVMBMxW5aEt/4QSaq/zHz/T4g4ASGLFkRNLXGyi00n bDseD9zf83iGS5T5tIa4droFF2jwqNtlhsZklsZ9Mn5OfpxKa5yFcNHM7GA/Sl0IVw1MhhhQ1rAET HL7feresSKqHt4DIs0Y/1nzDUrdJWpUmyluJSQElbnQOBYW+DAZ6CFrBK4mk8SqmNtL+lZjj9fiZd e3zZ2VKgAFjk8DpsuBEadrZAGF5MHoLihmx0vBeAReDWnHd52hMm94+Hu56xltOmvfHFmY7IJ0y0C 7L2TEODg==; Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrvcX-000000044k0-0frC for kvm-riscv@lists.infradead.org; Wed, 03 Apr 2024 08:05:30 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e0b889901bso49280295ad.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=lists.infradead.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=o1s3h3XfZDwP3TZfKsxI9qRup2EDYQLh/pBQxocq6GRVpHHcMfMzCG8vtT3tjQAJyS hwkoT5AG5C2fpfZBlogKiB+v0v/RkylF0f2w3HAzzEsPJxfovUCNy3vjT4HZ2Q5Yn3pU ttC0LCJh1RI5erkwQBEQI2CZnIKKiF3gAaY5bcCWVXCMtSCx2vjQCsytSXu1Reflg2iQ TKxRGw/wVoMjWW02+iPWOQh/BjQJk2qTAR8QaOlm+3i9G11x3jBHE/vMRf7IHB77Rx2N XOY+ZLXJPSQeWvklZWx5IDwV3lnjQGKZ61Xyfs24E7tsLA61Opg5grmmeQI8Quc1DoKf 8qKw== 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=F2OL5Vnu+/j9mMwKETIOkVwvGGFJiJoZco7HQRQroW64x7soxrNt7f3pU0ipxLsDqp gt8JXJH8IvgAvLDG9w+W+6YhEnGYqZociZkhEG4WV3KAy714g7kxeNgdguAcjKOqehEe v0bOrk40P+G3aC6lUY38Pbpmy/VF8qYLHqqZJr2/JSlmAxe/ulyzMA9IitEe0jeMsEo1 XnhRG41k6DZHgkZfokAQetEJdmG/EEtB39Xd9IdFt+SQAD5P2h9Nkwad20vU4Fa3hQjl zpQPQwA5gpdB69G8XeSonkVMdOyDLVMmoFgOy8W4/T16Ol3gyLTzR99z6/8mrpHbWAHU /6vw== X-Forwarded-Encrypted: i=1; AJvYcCXnc5EU+WyTC3EYOSvloqDzykidEWEdO9LGaAx/bqFO8SmFKbxlSO+B/HF7Xfo4MwVU3AN8DeeIN1sxrPp817JsdxCa3USJGvZwCi9jLg== X-Gm-Message-State: AOJu0Yzbx0/+KiK+RJLDhxD5g+fIr8+JkMLmp7xLlv0x0k2bX3FWZU71 97wZPX62pG4fyYFIR8L7eoofktmbGNvVnePfnTg8ZJCDslhQ8iIPrt2uhISDzjk= X-Google-Smtp-Source: AGHT+IGzCaqR/FZVf4jG8/W5aRGI+FZChKgtdmsu22b2KjgU9hzL33Vhb0robWHwzAUPtLmResHVWQ== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240403_090521_573878_4398F9A2 X-CRM114-Status: GOOD ( 15.97 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: 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 [...] 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 [2607:f8b0:4864:20:0:0:0:636 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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);