Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp165838lqb; Tue, 16 Apr 2024 11:47:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUT3jrW7JeoGKDOBbrP17n//ojEBazkkyI64dLsRMqmRPFgabBY98RvhlCZGz/p3YLfwmnrCU4s7N7T+op2gK6vvbgs8LA+0oIWX+Fc9A== X-Google-Smtp-Source: AGHT+IHnwa+fRIw3h7USVSFEfavU7hn6Jxiex4RQzD+4g6Neb+Rym734Ivsr2ArCoQZTNuephu3q X-Received: by 2002:a05:6a00:1407:b0:6ed:2fb8:467b with SMTP id l7-20020a056a00140700b006ed2fb8467bmr12987885pfu.26.1713293263681; Tue, 16 Apr 2024 11:47:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713293263; cv=pass; d=google.com; s=arc-20160816; b=lFo4jp91OZ1re/cVxALC6klA4Az9za/Br6wz/8gXBQOjFKyXaLcVIKCmjQIULZAFlz YBT7KlDCZwGHB68361ugKDc8SJDKA62aUfRtk1uLbFMEoj3BO1aBiNSSlUA6Wex1avTs DlRUcyx6HUjJ46z15a83m5bpCWXSKnGUPqhct8km0mRqyHc7BD3lLRnHKpqNJJWEe1ok e61If37xbG+Vr9GGQaq1MuPPt092lE00hDAwM1T6zkF8y4JZppeLWd+wVfFbY4tn3pBQ ePe8g+oSSpuU8LowpaQ+LBnQ62w46y0EwdyVQP5M6Cx2BYEn1qtMGGHs0dZ2akRbC1pj UqnQ== 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=fUdjqPblbE6Q25Ekp/l365V3YEPrpPkLHh57fhpvEHQ=; fh=RByI2eGr4ol7r12ux5WA/NZnPs0ouKeqFTo2w48GMlk=; b=YRWKE05vWMvNlGn8ayHXVKiK0I7CJP0ago4CgeEMMWSA7NG4IZ05yu2raij+p4UcMC x+BntPXUTaHeCjFDs/5h6D1n66Fo9Z34IsoA1YEbylpF9gI+c9Sd8W1+ZIfmqYSZ2Tfy 3PVk8gS5wtMB7tzQpxUZZIVjNUL4x1j/1U62e1o+GtLENW+Zz+WDPyAKGM8jfPZq80rB XDPJNroizvRbYn9BZi6bhBA4skTuB8slqHvDE8YcjmCv7/pd9hAQ99/UfjGaWp2h4qEs z/9VP8XFknrfUvh9W43y7IBAztq4jAW+GbL6jU0b+gc+fboIYn4rOStrTb2Pbx80+rVp x+Fw==; 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=SXeJMtoK; 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-147402-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147402-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j23-20020a62b617000000b006ed89d1cc23si9999831pff.356.2024.04.16.11.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147402-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SXeJMtoK; 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-147402-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147402-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E50E8B22AD0 for ; Tue, 16 Apr 2024 18:46:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C8FB13958E; Tue, 16 Apr 2024 18:44:49 +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="SXeJMtoK" Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 33495137C52 for ; Tue, 16 Apr 2024 18:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293088; cv=none; b=ZcaqOxGNoNpSPqgrHWnsH2UEVDhqaxpiofDmZCqLd3RmmB7rTA8Tn2NGhjTr/FY5j2IMPHDWfAzrRsPKO+p1c2Z/frIxKCStEGAAvjv3OPzMK8fEGvmHiO2V1jv+MsG06vxwbKGtciH8Fxz/5tGHhxtLeNDeKf0Mq5Lq8fYxSpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293088; c=relaxed/simple; bh=PCH+9nz39V3BSztS1z+ZZiAV+qP9h7YwF5oYKnRz76Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i3hSJu14oM0CUyPJE0LzD2Zqn6c4b0BV015n+0MNd7NcDueuaH2uLHUdc2cZYfMofuUnrJwUNSfNyNIuzv6MmbsAR4a1R0KmYIbitNIDYj/8BSfRV2D8sllzAgZ4x7izonveuekviVhmCT7xqUsvBLJPuEJRsQBF0FAAlXfWbgI= 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=SXeJMtoK; arc=none smtp.client-ip=209.85.210.173 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-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ed3cafd766so3847753b3a.0 for ; Tue, 16 Apr 2024 11:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713293085; x=1713897885; 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=fUdjqPblbE6Q25Ekp/l365V3YEPrpPkLHh57fhpvEHQ=; b=SXeJMtoK8OF5Az0+b0QgnNwHTM0EtplgcBVKh+Jm0Y/anEe8HYIc10kY5G775VBfTA C/YCSeujSviDyNN2TNifZJ+GLrcYpTYLvrkFyPsCrVSXSMBFh6KqVeSFVUWiUL0f/UGf TjnI9B3tkYoNz626Ji47ET+Mv7lY8qJJEh7uYP4RINokUf7mGENXqWmnwXDTWfpDiZ6v ynGRxce5IuBKp/hPsbPLCONi2kBPpFNNloMQCFNdU5eBI012yr+YM61bOG8IZkVml4r6 6xWRGNoUTzD9FwAJvgqdPkATggr5VRkITnjUMoWcSUigTDS9lGOg7ILF1MF4YxHMVc+0 QLvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713293085; x=1713897885; 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=fUdjqPblbE6Q25Ekp/l365V3YEPrpPkLHh57fhpvEHQ=; b=II/zuJqR4fgE4Vg8v7FlZY+aCNRKRZxPdWfkFmLFXjOUPg50YskXwDKHEDiJon9WP5 jSHGaPS3jcyhp/irgmaXfhiPE/RRYSglApjTGPMTNmiSbtLZ4o3FJJaOZvfSAN7R8JBb SILZIP47QRcV0Et+VizPYBdpUhLZZ9LSvrlHK/JzvYv/7sCHZRvLjMuoRpqaou1+cRS0 sxtV/aRqhVeBgZO1wuTFC+GZVPEApLclIVzPO+i7ovzp/DkqL7iR24Nk5VkPMj9ynWyh YRznrq6lujOaOZ+0FvdsNDE3fLAXvxePHIeO57QhPdsSDRWveU0RlQgmVxt9Bn8wR2bD pLQA== X-Gm-Message-State: AOJu0Yy4dGRa0FYJVVfLTBXyDn77H21bfxpX8sBxoegsFc3xDz62JE5g zyPjKb8TtmUJa0JlpwXrZY+hs26L1E/ekwFrph4S3PWVtaOhZQyVOPX29uho3FSFrjUtw2icBYj Y X-Received: by 2002:a05:6a20:3c9e:b0:1a8:2cd1:e437 with SMTP id b30-20020a056a203c9e00b001a82cd1e437mr14111733pzj.11.1713293085603; Tue, 16 Apr 2024 11:44:45 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a269828bb8sm8883645pjq.40.2024.04.16.11.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:44:45 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Palmer Dabbelt , Conor Dooley , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , 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, Will Deacon , x86@kernel.org Subject: [PATCH v7 03/24] drivers/perf: riscv: Read upper bits of a firmware counter Date: Tue, 16 Apr 2024 11:44:00 -0700 Message-Id: <20240416184421.3693802-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416184421.3693802-1-atishp@rivosinc.com> References: <20240416184421.3693802-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..1823ffb25d35 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: %ld\n", + 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