Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp991258lqt; Fri, 19 Apr 2024 18:08:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMP1ZvBHqDpmv/sc3L3WC4sM8J8PWK1WzMjuEJafQFfoADJQKhYkM34AIiyaeDau7m2cKahkRS1DpSo9ZlqUkCgQpshH6M94sqFWfQog== X-Google-Smtp-Source: AGHT+IF1AlBzDJmNMekMMT9MSeiqFoNrnJSlee24NgjOzUvLyVecMCyjq/eXtAO8qaHKEcyUwd8F X-Received: by 2002:a05:6a00:1413:b0:6ed:879:f533 with SMTP id l19-20020a056a00141300b006ed0879f533mr4194972pfu.26.1713575323135; Fri, 19 Apr 2024 18:08:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713575323; cv=pass; d=google.com; s=arc-20160816; b=i3YfPcqhQI7QJHCP/WGw9mEv5F6ASBhKagkFpjhzjZMR5YkVJ4pgul60q2iHs3thJh Cvr7za3m4pFKLgg88ifJxLkT1HKVV+GjG8nX2PntGztmByi+e0nlqAncqksAmeiHZayZ H47Bpkn2mpMeUxGQQEcZxSjowTVlV4PNaCuB/XHxEHZ7aM2UhELMrVt6aAnWeB/B4S07 eXNZ6YP7euXrlDdGD12wpXwEjUBNIhD5WVLXH90+vNARaZOyK4+HgglJcMuRV7BKkUDq 1Bv19pjSK3fr7bgey+O72fe/CiAUo5xwebfharG2zSVyVunuMCBfucosxwkg7NErXJ3I 7Izw== ARC-Message-Signature: i=2; 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=FopOoJVqlKLyitM+vV+llThPHlvMlGI12SmtWJmmk/0=; fh=WHo+Ia+7Ab3yPThjxj2SNVjcPx/G6r09RXCyhqMvK3E=; b=B7mWS1mwrzKZmT6eDmBanRS8ghyBQy6bi8VmDqs3XdWkaySgy6i3r4KoMmssjFm2j9 m2yA89cb2LfBf2NT8Y/4rqOT0bE42/m0O6jYGHNztvSwpTT6DlFXMB9i5OelPqW4Q8he 2dPHiKLXv53jkobfF1N9CenujnCPS2yLvjdWeJLD+IkHeIxsbuZ34SN5xZd7hmYRPvEM uPa0nXIaKZRKyN30dG7gi9tSPz32vpA6T33JEsRZn5pc9a20ailjVAGh2h02nvO/8foT ZzvGCK7lx2mz0l67RR+XB74b3b873TAyzZswwy2Zl0XO9bXIjTSGG9a4tVKf3+uwQauR aocA==; 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=TP8g5oyW; 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-152062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152062-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o6-20020a655206000000b005d81ba6649esi4076110pgp.891.2024.04.19.18.08.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 18:08:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TP8g5oyW; 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-152062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152062-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CB581B213FC for ; Sat, 20 Apr 2024 01:08:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 736EB6FD0; Sat, 20 Apr 2024 01:08:29 +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="TP8g5oyW" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 A29A238B for ; Sat, 20 Apr 2024 01:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713575308; cv=none; b=PAAHH2cyA9ZOR2IXZolocCDxiqc9FqE9JOaK4u7wAf6S7gDB0vkJpxiLr0WnYOw8/lu/fL2i3czPAy6H6EoESrYw+Rh7L9GkLlG3F3bvxbr3XmGeuKrGhgdOkVjUoH9EpUOAlc0nD2AsPxMIY+A4c4fkm7mCZ1kib9fDrVzxX/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713575308; c=relaxed/simple; bh=/v5DF/yr70RSo2cPlpFendzuWaxo1OWbch7DeiC/1po=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=g1oPF95KH1hSfn0ObhOsHvKmX6uwf5xeqatV/gTm+S7cPV8Xv43ByusSNpSwOEdo2sVcjOT5nOwLV42lAvVvNwQ+8mrLW7kdDots2HDjQqNRj5V5KSlqjNejEHI+pEj3QH0I1BynO0BE+Z5P3CchS9VlFJBIKo1c42VT044vja4= 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=TP8g5oyW; arc=none smtp.client-ip=209.85.167.46 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-lf1-f46.google.com with SMTP id 2adb3069b0e04-516d1ecaf25so3396760e87.2 for ; Fri, 19 Apr 2024 18:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713575304; x=1714180104; 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=FopOoJVqlKLyitM+vV+llThPHlvMlGI12SmtWJmmk/0=; b=TP8g5oyWZGaFY+FIx/xBLkzBYg5ipxmpMLGeLn7b3e392q0X+8vNxbgjwMYY0nKo5W RGzxXUXagCcv9Tm0VObNwoWVH34aKqX93CNzj9TiVsOcxzxGFZff0cLVYH2KXy8xWvli qYXhw7wnmnD2hX4DZg/Oi9o1tDNWH2Mbj4n3eE5T9RgXZUlgWdsEyjn4uhhpfPPhSqfQ HOJ/LxTGHpWUn8EqI+lC3/XxNuM3VBjUBVKVnSt8Sx6DdL3R5DESIMq4Uh/SmHuLNY0o +OPwBx1Gc4N6jPc0aABYWybC8EG01gW/O8sOAw/ZnHleMfMJHUzAYdML1J/c5SBygoNX v8Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713575304; x=1714180104; 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=FopOoJVqlKLyitM+vV+llThPHlvMlGI12SmtWJmmk/0=; b=LHkYTGOpfW5PJEaL0scQzAZt729dVwJtsCmgN1NmMeHdkq0+z/9DZj/D0jvU3FIrIp 698e5F2VnurDzw8/a1+S2En6pyjXMNv0Y7baC3ON+wcPYYaz0c83QyhvAnV141ZLQyUg AQU1Cag/q06+OAWJ+PGRR+0Edb+Q/4esAwTINR+ow81AzNBUR2QENgC0UVBO76xhTpMp 2Ft5uoWvhTfdY59FazZcBD9r54V8SAVhAVpDpXLxs1hcj+nlsaMsy6sxUiNEvT4JnKkW GvnpNkqAQubLr+E8qvq5U3qTLrEMWj0V+d32vb7g/mEJF2SxI/mFTALWEUzkU47h3CeH jbGg== X-Gm-Message-State: AOJu0Yww/3MWI4TuXbF3O2cB/FvgQ5jH02jrsDJcZZEufIEbfwTRVRF2 hTpAICQGBbgbAbusBEcAFCXo2tDjUu3IVUo2uNYx2yOB7uAXM+w20rC7zckW5diI8bRiZIRI2NE fPRtWqR0VUvEklzyV7jyJjkj0/HIDAYaaJsnNgw== X-Received: by 2002:ac2:5a1e:0:b0:519:296e:2c80 with SMTP id q30-20020ac25a1e000000b00519296e2c80mr1893557lfn.15.1713575303793; Fri, 19 Apr 2024 18:08:23 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240420151741.962500-1-atishp@rivosinc.com> <20240420151741.962500-9-atishp@rivosinc.com> <6fa06233-d572-48a7-a8ef-73a7c5879c06@sifive.com> In-Reply-To: <6fa06233-d572-48a7-a8ef-73a7c5879c06@sifive.com> From: Atish Kumar Patra Date: Fri, 19 Apr 2024 18:08:12 -0700 Message-ID: Subject: Re: [PATCH v8 08/24] drivers/perf: riscv: Fix counter mask iteration for RV32 To: Samuel Holland Cc: linux-kernel@vger.kernel.org, Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Anup Patel , Conor Dooley , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 19, 2024 at 5:37=E2=80=AFPM Samuel Holland wrote: > > Hi Atish, > > On 2024-04-20 10:17 AM, Atish Patra wrote: > > For RV32, used_hw_ctrs can have more than 1 word if the firmware choose= s > > to interleave firmware/hardware counters indicies. Even though it's a > > unlikely scenario, handle that case by iterating over all the words > > instead of just using the first word. > > > > Reviewed-by: Andrew Jones > > Signed-off-by: Atish Patra > > --- > > drivers/perf/riscv_pmu_sbi.c | 21 ++++++++++++--------- > > 1 file changed, 12 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.= c > > index f23501898657..4eacd89141a9 100644 > > --- a/drivers/perf/riscv_pmu_sbi.c > > +++ b/drivers/perf/riscv_pmu_sbi.c > > @@ -652,10 +652,12 @@ static inline void pmu_sbi_stop_all(struct riscv_= pmu *pmu) > > static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) > > { > > struct cpu_hw_events *cpu_hw_evt =3D this_cpu_ptr(pmu->hw_events)= ; > > + int i; > > > > - /* No need to check the error here as we can't do anything about = the error */ > > - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, 0, > > - cpu_hw_evt->used_hw_ctrs[0], 0, 0, 0, 0); > > + for (i =3D 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) > > + /* No need to check the error here as we can't do anythin= g about the error */ > > + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, i * BITS= _PER_LONG, > > + cpu_hw_evt->used_hw_ctrs[i], 0, 0, 0, 0); > > } > > > > /* > > @@ -667,7 +669,7 @@ static inline void pmu_sbi_stop_hw_ctrs(struct risc= v_pmu *pmu) > > static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, > > unsigned long ctr_ovf_mask= ) > > { > > - int idx =3D 0; > > + int idx =3D 0, i; > > struct cpu_hw_events *cpu_hw_evt =3D this_cpu_ptr(pmu->hw_events)= ; > > struct perf_event *event; > > unsigned long flag =3D SBI_PMU_START_FLAG_SET_INIT_VALUE; > > @@ -676,11 +678,12 @@ static inline void pmu_sbi_start_overflow_mask(st= ruct riscv_pmu *pmu, > > struct hw_perf_event *hwc; > > u64 init_val =3D 0; > > > > - ctr_start_mask =3D cpu_hw_evt->used_hw_ctrs[0] & ~ctr_ovf_mask; > > - > > - /* Start all the counters that did not overflow in a single shot = */ > > - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, 0, ctr_start_ma= sk, > > - 0, 0, 0, 0); > > + for (i =3D 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) { > > + ctr_start_mask =3D cpu_hw_evt->used_hw_ctrs[i] & ~ctr_ovf= _mask; > > This is applying the mask for the first 32 logical counters to the both s= ets of > 32 logical counters. ctr_ovf_mask needs to be 64 bits wide here, so each = loop > iteration can apply the correct half of the mask. > The 64bit wide support for ctr_ovf_mask is added in the next patch. > Regards, > Samuel > > > + /* Start all the counters that did not overflow in a sing= le shot */ > > + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, i * BIT= S_PER_LONG, ctr_start_mask, > > + 0, 0, 0, 0); > > + } > > > > /* Reinitialize and start all the counter that overflowed */ > > while (ctr_ovf_mask) { >