Message ID | 20240229010130.1380926-4-atishp@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-85970-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp106302dyb; Wed, 28 Feb 2024 17:06:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLJuDUUxRxK9IDHCeHCgXbqlw28S/12LPKogA+bhTB+dchs7eubeDHOt4Ek1TRGpE9jzCHmqv3WSPaosMv1xfZuRcHQw== X-Google-Smtp-Source: AGHT+IEkRSKJ1NgS8NNFXPg2VTcbUV0IyELK7ckqWf54vPOrdqpiMAiOYq2AbEquuZzOFVOb/S6R X-Received: by 2002:a50:cc08:0:b0:565:7733:3c58 with SMTP id m8-20020a50cc08000000b0056577333c58mr374847edi.4.1709168783269; Wed, 28 Feb 2024 17:06:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709168783; cv=pass; d=google.com; s=arc-20160816; b=QcRzYoKIso5ySZlYwD+hDZ3mIJdvnv5cZIJuUrbcMS5/ZQQGwgmLDgLJk7jByGvCGJ f7I22EwtvrZQPJg8mpPTe39zn0WK5wej6zP6t2MAi+i2JZAFs2v6ysylR6sPS6GcZkQ5 8hd+ISZs9Tm2xMe2nJq75QlPJ5A7tIY9mvlsSmNXjqV3Wb2C9rH75ucyY2AQESODJ37a fZAeMEzbicI+gVrghEQn5h8OSv0JzfnIK9FP7OC1PvC8HEgn/JQgSbLon33eeqYXS3uV cz4g2zhp12PxNv03Iwz//4HNxR+ruJ4E75DfZJcGz8qXHz0ckPZm0jYHSGhd4E3z2Of9 UooA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85970-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y12-20020a056402440c00b00565b8e66cbfsi84935eda.146.2024.02.28.17.06.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85970-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85970-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id A164E1F24453 for <ouuuleilei@gmail.com>; Thu, 29 Feb 2024 01:06:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EE88482C7; Thu, 29 Feb 2024 01:01:53 +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 <linux-kernel@vger.kernel.org>; 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 <linux-kernel@vger.kernel.org>; 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 <atishp@rivosinc.com> To: linux-kernel@vger.kernel.org Cc: Atish Patra <atishp@rivosinc.com>, Palmer Dabbelt <palmer@rivosinc.com>, Conor Dooley <conor.dooley@microchip.com>, Anup Patel <anup@brainfault.org>, Albert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alexghiti@rivosinc.com>, Andrew Jones <ajones@ventanamicro.com>, Atish Patra <atishp@atishpatra.org>, Guo Ren <guoren@kernel.org>, Icenowy Zheng <uwu@icenowy.me>, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Paolo Bonzini <pbonzini@redhat.com>, Paul Walmsley <paul.walmsley@sifive.com>, Shuah Khan <shuah@kernel.org>, Will Deacon <will@kernel.org> 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792193365878106917 X-GMAIL-MSGID: 1792193365878106917 |
Series |
RISC-V SBI v2.0 PMU improvements and Perf sampling in KVM guest
|
|
Commit Message
Atish Patra
Feb. 29, 2024, 1:01 a.m. UTC
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 <palmer@rivosinc.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Atish Patra <atishp@rivosinc.com> --- drivers/perf/riscv_pmu_sbi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Comments
On Wed, Feb 28, 2024 at 05:01:18PM -0800, Atish Patra wrote: > SBI v2.0 introduced a explicit function to read the upper 32 bits > for any firmwar counter width that is longer than 32bits. firmware > This is only applicable for RV32 where firmware counter can be > 64 bit. > > Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > Reviewed-by: Anup Patel <anup@brainfault.org> > Signed-off-by: Atish Patra <atishp@rivosinc.com> > --- > 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) Getting an error here indicates a buggy SBI. Maybe we should have a warn-once? > + 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 > Either way, Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
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);