Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp94586lqg; Wed, 10 Apr 2024 17:09:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXK8gOiY+OarlOWYIGS47ZfEpIAiq3wK9pxZBd0oT3gBPlSEm8r/azD8YD+Gc1RSwDBxkwhAJYQNJB8RtAjbJoU70I2iCbWqEwg9snPwg== X-Google-Smtp-Source: AGHT+IFR5u2dJLsbhBblS01iauT4BnplACLrnf4o7x6YnlB9/ZuSJOIZ2lqeSCLj3BxWSsq+Pfnd X-Received: by 2002:a05:6808:108:b0:3c5:f365:16cb with SMTP id b8-20020a056808010800b003c5f36516cbmr4220320oie.37.1712794164958; Wed, 10 Apr 2024 17:09:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712794164; cv=pass; d=google.com; s=arc-20160816; b=SXPWhzQTZoSh/9owOjowJ4gHW/flhbAE+nbNY99SMUIp6SbooI905EdNONqs+LVjSk 1IdkgsRpujA5H5rSaOksvrkSUCpXj1s6YkxeMdjl7p9oB7SsKyUah2IUHz69NGZO0at0 i9i0jE2wx+yvLwEhX5DLbYxTYqKs7riOjCC5motOyKBiyBpKpINzHK2RtMW3XpOXy0R6 OYJlL7bCFfyjsWAErjqOoZWNQm5pOv1XC/RgOuHAkSOhk1pusbh9UaM2gQJP5oGnEvG6 3lPDeHz3tYqPFMxUcxnx+Er75pT8AXgXLLEVluIyL+jxPNkfHkGjPAPlL2cOA5JmpVJI oSqw== 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=PIjs3Rfz3HFaocZnLwKcAxsYd9hSivTpqRR/GnZZPyM=; b=hjL6pe8UCb9ub28Us1DAaLfvJIXOLC1HCJfM2quwdcY1iImhNU/tgcoxlqPyWUG3e9 yNj9hP2IX864SHUUMFhfqWALRReUkLgTIEqJEGUOgfOrcDo2zgxWlIHJP0KX2SsgP8Mr GyjSjFxxayMk8VGMDLDEaOt7/bJvsjME2mWng0dMNAMYdW+Swugj/V9n+aWa0SiNtwmO 0oAVUFDN+gFdG/aOG4wsJvr2PUkKpsgngW/bdd6Smbqsb90y4snEVU402JoqLuyggUul /dozFActDpn5FevhUl7/nZwiO/VR+Z2pb2MYkdbJFpdb9n1RQ8TZhNIvTm34dYudQLn4 z4jQ==; 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=Zo6tCDoP; 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-139558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139558-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 h11-20020ac85e0b000000b004347364575asi325586qtx.665.2024.04.10.17.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:09:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139558-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=Zo6tCDoP; 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-139558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139558-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 9BC971C2243B for ; Thu, 11 Apr 2024 00:09:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EB37FC0A; Thu, 11 Apr 2024 00:08:19 +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="Zo6tCDoP" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 C168FDDB2 for ; Thu, 11 Apr 2024 00:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712794098; cv=none; b=aBr4ZIZKaa7C6pCd5I4alz4WpYlgsersHDBcQPktmGXlMwqAtE8jKSVO7wDO4wTmergtsqnevTjQdEpoaNRcCknxqGjrwSkyNcrrPnawRqZ+VMWoDXr/5YmTcfDznTyudJMQE7UNyRCKwZmDCu1dVaHtq9CQR2hUWFK6ezVDJTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712794098; c=relaxed/simple; bh=PCH+9nz39V3BSztS1z+ZZiAV+qP9h7YwF5oYKnRz76Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EJVjhZV8cYVELHLkTH5ZWQnROtR4SnbrGALEyjOZg6g5XaIScQMhrVdY7gBDXQ7IoSHWSbrNsdt7OoNEmLg5/8U+soS3MqVw68b1+x5EkXHvyHrLuJAzquyIrgi+iWhfHz0ao1//shpcyrCEHSMpR2IwO3C+4emdXAzifNlHRbw= 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=Zo6tCDoP; arc=none smtp.client-ip=209.85.214.178 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-f178.google.com with SMTP id d9443c01a7336-1e51398cc4eso7940065ad.2 for ; Wed, 10 Apr 2024 17:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712794095; x=1713398895; 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=Zo6tCDoPQ8FgQ4krFL9MjaWkDjlOGFnTnb5e8hN6PAOUMclPRRjTWuC/lF/Cwh/SgF /FkLFivzHVermsT6l6UWK2n6k9TJg4be6M7t2k4EVVuOzVRnhr7M+5FYLGmWA1Qk8FtK YbMADxHdfcCcLDaYyylqlKyZvj3L9lElrcc5+xs2ctFpYelXCZn0B1FSSBBB9UDsyJg7 wxOB2a+9g0McJVz/f9zsQS2YtdLNI/VIb/71OOnKiNQx+rvszaWWMNuHJ9VjDZUjt5c2 sl/zwnFrR2VVMDZrQ6si5XeU0yDE7ruH5sSyI80lSZmySM5OvjXzV/wIb42T3NLET4Jd Hfxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712794095; x=1713398895; 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=rCZShlF+3DMSPYHacmEsy6Qw11LpSpl4sHTF+Nv4/QLYbNSfVrN6w8TvBNN3elYCoj RcM9bQpiLVIhafvfdBjn2vYm6LMS//MYTXMOjogMx2Zs2tYSvjqxDBme16QDp+B8OdTY tQFUa1sdY87gt3RrVr11fO9qnCL0GP2UNSXXVL+DKyEfBA4jqCkuWBRPhcee2Rre2j17 S+fdaJz0DdFDzu2bF/pvYaONEWo+1X+G4xAa9bPhllEKeqXVoUHX5HndO3z6NvMFdC/z y3VlADzHzw824GJ32nOsFCwIQ9ON2P3iA1eLU1G8TL+wn9NBNDfKtLuUrJvGUR+iIRbM EfaA== X-Gm-Message-State: AOJu0YxnIlElgbMsWHFUMfO4gI3FQp1L9GyEGmac4/s5pBcvLaxC1wP3 Ah/iVrmujpM6kpaRz+frD0JR7M+v/q7FveyCbgpTgmT8AV0S65IBC+coTVrbNE6X4VOIludlNfe W X-Received: by 2002:a17:902:7618:b0:1e4:fd4:48db with SMTP id k24-20020a170902761800b001e40fd448dbmr4188157pll.43.1712794095332; Wed, 10 Apr 2024 17:08:15 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f7-20020a170902684700b001e3d8a70780sm130351pln.171.2024.04.10.17.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:08:14 -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 , Alexey Makhalov , Atish Patra , Broadcom internal kernel review list , 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 v6 03/24] drivers/perf: riscv: Read upper bits of a firmware counter Date: Wed, 10 Apr 2024 17:07:31 -0700 Message-Id: <20240411000752.955910-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240411000752.955910-1-atishp@rivosinc.com> References: <20240411000752.955910-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