Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp186312rbe; Wed, 28 Feb 2024 17:06:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV69CwdYI6FWt4cuFPeLCBN9NawwPmmSC8XRiiqY3+Bkgf4iMUDjkTF7K5T3AH3YZcFSui7xd8Tm6xJlkzhpOHJHVmZhzAwX+gj2WOASw== X-Google-Smtp-Source: AGHT+IGlncFU9Z3wOiKKlRQocfcm9iVl73D9iQnbaNCZEC0fd+kwDzEMXNryuyUr8HuVwgrTpuh1 X-Received: by 2002:a17:90b:2392:b0:29a:f233:287d with SMTP id mr18-20020a17090b239200b0029af233287dmr841953pjb.29.1709168760579; Wed, 28 Feb 2024 17:06:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709168760; cv=pass; d=google.com; s=arc-20160816; b=wew47LgCttRFAsm5upSw6OFbRXllPgftmcxvlJ+5uGtMhwbHWMqn64o97U4qfMq2KT bGazylBiqcBX6Jd46xVL2wQMAJZqX+JQBKMXPMHL7XfAnAQ8QWk67S5D9NpBPMKjfP1e tKk+F0AypNHVyrI3iLpbHCJbLiRn0qOWBM9OkTviIwgqYdc25B0ww/KCPGQdU0hz4Xgn jP8sJdxYhENsdIN2Hn88RhgUOzwXsuh8bTeH7UW13vVyA5FEQia2Dl66vSC3TpCEp4c7 C4gl25FchWV9BEm++q/MpPJVxLi06qt+k6u0SFGf7ezhn15/3gBowf+uuEvzrTyoSCj6 RKYw== 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=y/Smp2oLhuu6GIJFXbIgbmjKI2p4Ava6d/2TN1s81h4=; fh=hQhkp2sTu5r/ox3e02q6NYbQaM9TNtDLmmjML1SqflY=; b=p7v4PZR9gjDIoV7Ny5PijTobiaZ8VD4iUS1nF3JOooUwF5ZZEASo6+kXRGrPBGoM/1 9qDEwQtvsjHw5k23pTK58eMwBbXrBIw6xtuiMUN5P551wYXQV2LRcKys7ig7z+le9Mm0 33mVS4Dv9Bl6WiRHTX992qJoGru3pJow2gQJNoeTCLHc1jipxTOslHoqMw7yntkZ5iy9 Wyp54GU/9mplkYppGra2xSuBnNobxjdw/U6sXpF/vwedDWtK+DJvVPzea7KgQPoYF+7B ZN5PnTf/136QUnoX2ykZMHO68Hvd9jMD4CAfp8moKdcA5vmnzPsGd4r+tEr2/mtttPOw BbIw==; 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=TXZg5mP1; 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-85970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85970-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id qd6-20020a17090b3cc600b0029acb1fa197si371986pjb.151.2024.02.28.17.06.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:06:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TXZg5mP1; 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-85970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85970-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 47B34285753 for ; Thu, 29 Feb 2024 01:06:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C0104778B; Thu, 29 Feb 2024 01:01:51 +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="TXZg5mP1" 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 A204F44C7B for ; Thu, 29 Feb 2024 01:01:48 +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=1709168510; cv=none; b=QeEaYB173xJkazChl0u1isDWbAmyLTn+Qb3n2NfzIzb08xlA/ufLnkAZzi6gMfvdncdNImKTLCkPqdf6a4bG2Yg7APqdZT8fqvBBHY3wSyNjVBOvXI+W7+uSx0+KcphE8LRDSb2DqqCaZyvPon/3o02in9cnrtcwJPN9vDtvmcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709168510; c=relaxed/simple; bh=ULMcUPZgsZy5s7AHs7JS+lYRRb/s3cg5atfyscwS9oY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l3EsEM6NJ+ELeAmUDepc94uX6DSsFtmSkKtruTkDB7HeF7dtCz60QMDh3of4n5cnlWzhw5oVgOKSkSAQYfu3Xd9f07i+ZhAYwn1WkS7GwcMqBfCGuYrDhNC8D09JY/TnCFN3indH0s6kGPnQc63iBMpGvo7l77pJlvwy1xtahhY= 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=TXZg5mP1; 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-1dcd6a3da83so1985585ad.3 for ; Wed, 28 Feb 2024 17:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709168507; x=1709773307; 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=TXZg5mP1FfuLO7QKPhZqp+oSPbiF/LglTSMIASd5Brt3EVGf2DhuG4XPx9mGPhfANy jJoCmxF6lzwmDtnsMd1hZhuRjaFLixCGCbE2+tytWbLBFi5SRw/DlKoWZOcqZ7ypDVmY at09iGenFM4nRhKY1Ey/KioH9Tb0ytPG6WuVnk2dulOZe+LhSktQD2tyq8f4H6EFpArh YS9HlVH+eGVOSdFXi7YqemkUEcxLyfiXLVsOgOFfxQGAbjX1SUJUe0lP73VON5iUnFpk QMIPLjOXOJotodqFJ6RIcFfG788+5EndhVEXo+dDrWjCuWtrBkjysDu00rBWuN88jsTd Ayuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709168507; x=1709773307; 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=phxHV0Rhnz0DTDSAI+7Lm9NNcTrpe6q577k6nF4OYD3nJ+fvJeBiwKzURNlDoow3p3 knVOISzzOVOU7fbeOs1KgUVXIQ5xLwWFd9nPW0IMyh7i+wbhqEnsnYBaFBRonxjEViKn Cojy3KL0UBlgnAdHfhavTrwKtMJPy863yPdAqm7h2yM39volPA+AK8BIyfFcxmjoV9qt IPWN6g7fLTC6JKPs7oTOPhetw7A8en1ZPSrsAz2dYaT3K67Q6n6mFnWO4zW/pw8q8KXO BTr/rCyhdbBMkIEB4pMZooyOND1AlvTQw1QTID2HjW49VxKmsh9xmcZ6FZORGHTM2wjq c0Bw== X-Gm-Message-State: AOJu0YwUs+qETXQw1RBPhVD+h5AC+sxyMBoMF82c0VV9qQ52L3IYj9DX kIs44KKOhXXUpckeV0gyCYqcbMrJCtwqEVVNHJtMaXiV7nrTP+bDG0ED0tUBtHVTQst/WPJfeEO h X-Received: by 2002:a17:902:ecc9:b0:1dc:a60f:4bef with SMTP id a9-20020a170902ecc900b001dca60f4befmr636692plh.63.1709168506981; Wed, 28 Feb 2024 17:01:46 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id j14-20020a170902da8e00b001dc8d6a9d40sm78043plx.144.2024.02.28.17.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:01:46 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Palmer Dabbelt , Conor Dooley , Anup Patel , Albert Ou , Alexandre Ghiti , Andrew Jones , Atish Patra , Guo Ren , Icenowy Zheng , 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 , Will Deacon Subject: [PATCH v4 03/15] drivers/perf: riscv: Read upper bits of a firmware counter Date: Wed, 28 Feb 2024 17:01:18 -0800 Message-Id: <20240229010130.1380926-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229010130.1380926-1-atishp@rivosinc.com> References: <20240229010130.1380926-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