Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp184038lqg; Fri, 1 Mar 2024 01:52:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUpjWdSCAIdTyH8Q+N4EFrvIHkr6weIwOH+9kZ7tgn5REak1qw/z/vrKCBMlZhfnBEWzpCvZBS+SE0INH2s8iGP1Q1UZgrA+EpI/6VEaw== X-Google-Smtp-Source: AGHT+IFwETYVc+J3eTQSqsOJgopdFwfHnFGEgbnvQsuQgD4BRq4R95B403Hhjmk3ZAe3dpWXQuhN X-Received: by 2002:a17:906:46d8:b0:a44:2563:d30b with SMTP id k24-20020a17090646d800b00a442563d30bmr940044ejs.68.1709286776628; Fri, 01 Mar 2024 01:52:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709286776; cv=pass; d=google.com; s=arc-20160816; b=Iat4J5mY1S8PDQ9trB8fkayldS0+T4wXjd5NuKJu2UrUKBDSuGlfjLh2CiDy0lAxfo vggyJdMZxEQdYBdbT6L6RIKf1+EKmkh9NPKqYvZwcSNNqnsjHMxNnoh1K3r7FQEtdhoE MVcpjFU2yldBJcPvidkkBMiN2KNBRlifR62gr2Euzgh9m7/2FCU3ho4FfJEnqPP8BzFs IeGg/81TovVJDyP/Cc4IRs7phD1lwqLhSDLdH5S3+A/4HrHYX3wa4acFcOq4Ox46LeOx 3LlNbKD0qLF2tIOvYGH275vxXDqvcx5DrbGgzB2vEjkSt4YqYAdNYOXDFvjrSdJf0crK Qn7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=j9QHyWahfs9gCWf7uMaefOcLnvNGoebBSGi+N5cc4JQ=; fh=B/9oW17vV8chk9Fx+QHxyMODvptE7jtmQ+R/na8QaT0=; b=p/AaKuq2YrEPL5PrLs3hgKG26eD97kCPanpxbHIZwl9IYnHtGYgHEvox8fXliVCk6/ NTA7wY+CdScXhXmXzD0ZXIUgyRuz4tki6N78gCYjPwl4JEpemrP/fKJPVj1lffOTJdbb MqVtTNv6W/0S3F3Yp47i7cgr2Tj9Fdblxtp0qeJ5ohG4tyXSiUBcnJVd9KGsetFs/IrV iYMRKatxeFDsAzl6UzmvQEPBw57wmHh4D5kYrszBsZDIuXjWgatTWU37qFJXtiwDAWsN 0jrKGlRdPCJqtp01cW5CkVTrTtPfXGGr7E7zPn1+0vWaXuIse4JzzjFrdtp+NqBNK6A4 C7TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=coZWtSlb; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-88204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88204-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lb24-20020a170906add800b00a440ec6f49esi1329434ejb.21.2024.03.01.01.52.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:52:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=coZWtSlb; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-88204-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88204-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 357941F23673 for ; Fri, 1 Mar 2024 09:52:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 931916BB30; Fri, 1 Mar 2024 09:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="coZWtSlb" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 CA6906A8C9 for ; Fri, 1 Mar 2024 09:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709286756; cv=none; b=ZCIX2v5yOz4sCDK2LgTGPTxKGMk9y3ARXHfX4HKkSuhpu9mDX3ttqhkzJsupt1ZZMmsaDDZv12BZGeQxcRzWwkAvdGDjtwbCtOSjmmGayAyCAPzRzgEiM8vdWY+hPX6nP2viAvCS+NuocSQWTJGzBQylJG67RIg+AZEyvzyrRc0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709286756; c=relaxed/simple; bh=O5SoYzfgteCQ6ALh9ZQ0QFHLP3C0R6ls6LeO2LAOIIM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ioxSFYFNSwxUfdb4LqHM9LB/4fJM1oEP9m/89wh8OKciGx0Qe0NzV9FviwlKXzzlxk31vE+ZCjQKKxTqHa65NlfZiG7yCYpNEOiIupbJxO5y58cGBlzPL5l+PlMQ//P22jDZus/Y+rfzVtP1JKgKBwaA3Ko2vZ7xD3GvLZX3c7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=coZWtSlb; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a446478b04bso168710766b.3 for ; Fri, 01 Mar 2024 01:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1709286753; x=1709891553; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=j9QHyWahfs9gCWf7uMaefOcLnvNGoebBSGi+N5cc4JQ=; b=coZWtSlbLcar5hxTRopmsCqRZPL+6bX1HJWD97ntHVwgTwgLjoce/2QfC99qy92a16 BaC+aObyeOQCbLhizP0aJUmfCkRdyVh5cpnXXxLw+htQONdKaP8rvAMvoL90jK/wH/ue 2JyUf0UHrW7xX1UppkxyUboOttCC9xrC94m/ch343qPLroXuu/75rO1NqdZMEfL9y4/C 4u8TqVQZEPDVDjppnCKHH6NIpBhLjRugeY0pwevbygp1S6m+EcZO3dit0POmFhD/0QNU 8J1A9wyT0A3m5UyNrUxC7nrq1sFvNyVEJOx22LIyQfSjcJLmPbOIgcqFLdnpgCmkgQpu l8dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709286753; x=1709891553; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=j9QHyWahfs9gCWf7uMaefOcLnvNGoebBSGi+N5cc4JQ=; b=WSJE50LUarVqAFJoulj55Hmn6BbQjmRAb2fJqsqy+6jMms2bna5lDf9DkP6CON1wrD iOx8X8WZ1fv2jD8VDUPM7Hn5Le0r4aT1NyjuOsUIagegnusjZhlCgGsc14+PC1Cf1ifd waa36l91RR5xcnygqWw4yoG0lT3+lUrXfe1bgoIq/Xxqj1cvCkmK5U1VmzaCrl7Gyhth Hcf687m0P/TUvTwBJGpwshirggXc3WcvJjYCucykjX6JlNp+HxF9y1xjE7tKt4BIi/oO OhSiJvSy2bDyA/hMIycyOXbpBRrD3hLlB7BaOpzceGlA7+rHRbnGV1/Pm4WHajlee7XO o7Yg== X-Gm-Message-State: AOJu0YxqyBBD3cupi9jR8W6aIziY9xBXAUEsgyjoXBfVzUUgWwUTt9mt dPfZnDPQQwE+8l1kEtYJILfZEDtwTypedmBm0GEOhyRkfIOUghmL5MvT7kjDxZA= X-Received: by 2002:a17:906:a197:b0:a43:af0b:c1c0 with SMTP id s23-20020a170906a19700b00a43af0bc1c0mr980628ejy.16.1709286753092; Fri, 01 Mar 2024 01:52:33 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id vu2-20020a170907a64200b00a43bf7ef577sm1535120ejc.188.2024.03.01.01.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:52:32 -0800 (PST) Date: Fri, 1 Mar 2024 10:52:31 +0100 From: Andrew Jones To: Atish Patra Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Conor Dooley , Anup Patel , Albert Ou , Alexandre Ghiti , 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: Re: [PATCH v4 03/15] drivers/perf: riscv: Read upper bits of a firmware counter Message-ID: <20240301-36ababe3e198d3d7573f316e@orel> References: <20240229010130.1380926-1-atishp@rivosinc.com> <20240229010130.1380926-4-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240229010130.1380926-4-atishp@rivosinc.com> 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 > 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) 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