Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4973686rdb; Fri, 29 Dec 2023 23:56:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsR20NfKOtWFLIacifTj+VHW0xfMWdhA8OM5Ta5UUXOnLb+NQ4+U5PZwxYJBDFaic6MBKh X-Received: by 2002:a05:6e02:1a02:b0:35f:eb24:bb54 with SMTP id s2-20020a056e021a0200b0035feb24bb54mr18807139ild.99.1703922984633; Fri, 29 Dec 2023 23:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703922984; cv=none; d=google.com; s=arc-20160816; b=ORe/JRDVLgSww3/tB57JN1KYn539bTeNESwyQp7Aj15Cr6C9ETbm/c0kDc5KZavbTf VKnuxTxPLro+b8jccsFFIOMoO6bgo1nV6fcsDSBbK1emF+BypeNN9gNusGt58CgIPv5+ MYkBUH8F9Fkq0X3SHkPV7bH0sfyaPNByGkF5PlUM1SZitR6HIrMTQS0BQF7CMvvNx5eB 9lzLq6+OGByVZWCzNs9u1geO5XOGpX3cJlH55nDwRYGwxfTKfJvM48qPVDBfVyeN7Wad vNruKn5suSBLW5EmM1xQSY791sKVFT1pV6HdiCZ7xb8p8LIqu9bNQPeMb1fnoUpr47Pf TvWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=/sMoecNT/vWFjebRTXppuzNrFLVfC8SMHVt9ayXTH6k=; fh=npuPrcENSUGUXoQ0lZGomzH+f1RyRM3X1Ed/JQzq3X4=; b=sJFBmsPGtqnBzRHivzbUhxfNt1Y8kW1wkJrfz8pmRnkmyOst0Vwzbki6LB6ugyaOnr nTwDG8Wgo4N6nGmftFqS1VPp9UNVQXGsn6Ck0F+itFC1QEP8GYXllUJQ24gBqLJre6CV ECpjaTYiT+oxhTLmZrGzQuIKSAnyCdVXXLrDlI6RAf9v/mGpOCJ/vG0bcbD3C1BFGzFj gvsCu5K0FLUNtnK2dZrg8sz0eKTK6DnRSxX8NV5QQP0HCHBfIy9w1VVZhmdwSuJUbRAw z8q6N9RztXomoxWSYmrkSIL3NDawOaepN5OoMYQKmPjG4LtnVqooqaGwor3zPfojGFs1 0NdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=YjTnz5vq; spf=pass (google.com: domain of linux-kernel+bounces-13355-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13355-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 je10-20020a170903264a00b001d45b60358asi8978205plb.505.2023.12.29.23.56.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 23:56:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13355-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=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=YjTnz5vq; spf=pass (google.com: domain of linux-kernel+bounces-13355-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13355-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 487CC282261 for ; Sat, 30 Dec 2023 07:56:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E38D2917; Sat, 30 Dec 2023 07:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b="YjTnz5vq" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (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 394FE20EA for ; Sat, 30 Dec 2023 07:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=brainfault.org Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7ba737ee9b5so530247339f.0 for ; Fri, 29 Dec 2023 23:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1703922970; x=1704527770; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/sMoecNT/vWFjebRTXppuzNrFLVfC8SMHVt9ayXTH6k=; b=YjTnz5vqYjXD9uWfhPY8YnkkRgzhDhN2y9d7vlQGRw7CHQMAf+O8Z+b7Kg/i69+yzH l4jZqBP3R+yUcrYNguRxR4IEq8E2T3rwvcqJqvbHW1hJgv86ltbemSEjuIuvIlnfO58V UGal3kIHvvScdZZ6LHsXy9nsSH/STUOFgwIIyeqgC7I0+OiWo5AhQv2CTVB4kYo/mZ5o tLZjKI6t3XR6kwP0yPajDo5Zsclu9Wt2TfaU00Xwd6OvaczPXWwLGex502t5Vi7RALIP bck+OJCQ5OfjlVoulo7gsTfMkCZfG8voNlMblPeFWlBNvyV7BCGB/V5oaEoh2QlOPUko 3FTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703922970; x=1704527770; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/sMoecNT/vWFjebRTXppuzNrFLVfC8SMHVt9ayXTH6k=; b=TqVAVGbW0e1R5X7EQhbw99SwC80uQ+ukAxrX0NelC/orR1sPhJ45bFgmxj9Jyv8LT0 N6mXtsINlylsOOnVU/WEXob0THgZxaaCkTT0Jrdl8nEslk1D3o3VF4Atyd5CO2rinckQ NDOHexptTuyCJSPyVfappLwT1bZVP8f4Ng7TuI9TCz2cQ+fczxDSmWCbwSqMrOACV+AR FrlnU4RbWcI2tfSM+0fveRxkeD/v2IMqQpRClL9erh1rUVbzLYLJt9UetOtwzhh8DEY8 OKvzYQJBjSP9oaBOZ//3K7ghNu2UFc3aayCITlC3rNJCYRweirBC0eL1YlBqODfA2/sm viOQ== X-Gm-Message-State: AOJu0Yx61PwsekmIpDEndAiec56zT0zBCDP0QRXskpJf5cf1/uW2Ol+R 8TbtxLVVIIJS7aMHGeA6JITB8HWQkyVIjGJy4A5kypDZJxKahA== X-Received: by 2002:a05:6e02:184b:b0:35f:f59d:f334 with SMTP id b11-20020a056e02184b00b0035ff59df334mr17011843ilv.35.1703922970107; Fri, 29 Dec 2023 23:56:10 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231229214950.4061381-1-atishp@rivosinc.com> <20231229214950.4061381-4-atishp@rivosinc.com> In-Reply-To: <20231229214950.4061381-4-atishp@rivosinc.com> From: Anup Patel Date: Sat, 30 Dec 2023 13:25:59 +0530 Message-ID: Subject: Re: [v2 03/10] drivers/perf: riscv: Read upper bits of a firmware counter To: Atish Patra Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Jones , Atish Patra , Conor Dooley , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 30, 2023 at 3:20=E2=80=AFAM Atish Patra w= rote: > > 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 > Signed-off-by: Atish Patra LGTM. Reviewed-by: Anup Patel Regards, Anup > --- > 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..646604f8c0a5 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[] =3D { > &format_attr_event.attr, > &format_attr_firmware.attr, > @@ -488,16 +490,23 @@ static u64 pmu_sbi_ctr_read(struct perf_event *even= t) > struct hw_perf_event *hwc =3D &event->hw; > int idx =3D hwc->idx; > struct sbiret ret; > - union sbi_pmu_ctr_info info; > u64 val =3D 0; > + union sbi_pmu_ctr_info info =3D pmu_ctr_list[idx]; > > if (pmu_sbi_is_fw_event(event)) { > ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_REA= D, > hwc->idx, 0, 0, 0, 0, 0); > - if (!ret.error) > - val =3D ret.value; > + if (ret.error) > + return val; > + > + val =3D ret.value; > + if (IS_ENABLED(CONFIG_32BIT) && sbi_v2_available && info.= width >=3D 32) { > + ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTE= R_FW_READ_HI, > + hwc->idx, 0, 0, 0, 0, 0); > + if (!ret.error) > + val |=3D ((u64)ret.value << 32); > + } > } else { > - info =3D pmu_ctr_list[idx]; > val =3D riscv_pmu_ctr_read_csr(info.csr); > if (IS_ENABLED(CONFIG_32BIT)) > val =3D ((u64)riscv_pmu_ctr_read_csr(info.csr + 0= x80)) << 31 | val; > @@ -1108,6 +1117,9 @@ static int __init pmu_sbi_devinit(void) > return 0; > } > > + if (sbi_spec_version >=3D sbi_mk_version(2, 0)) > + sbi_v2_available =3D true; > + > ret =3D cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, > "perf/riscv/pmu:starting", > pmu_sbi_starting_cpu, pmu_sbi_dying= _cpu); > -- > 2.34.1 >