[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAECbVCvPCsHVvm5QKQrw+DDLsZGaHMgCHyJ=cp_gFcAyiFA4ow@mail.gmail.com>
Date: Tue, 27 May 2025 10:59:41 +0100
From: Rajnesh Kanwal <rkanwal@...osinc.com>
To: ak@...ux.intel.com, Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Paul Walmsley <paul.walmsley@...ive.com>, Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>, Alexandre Ghiti <alex@...ti.fr>,
Atish Kumar Patra <atishp@...osinc.com>, Anup Patel <anup@...infault.org>, Will Deacon <will@...nel.org>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley <conor+dt@...nel.org>,
Beeman Strong <beeman@...osinc.com>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org, linux-arm-kernel@...ts.infradead.org,
Conor Dooley <conor@...nel.org>, devicetree@...r.kernel.org
Subject: Re: [PATCH v3 1/7] perf: Increase the maximum number of branches
remove_loops() can process.
Adding Andi Kleen as this was originally written by him.
-Rajnesh
On Fri, May 23, 2025 at 12:26 AM Rajnesh Kanwal <rkanwal@...osinc.com> wrote:
>
> RISCV CTR extension supports a maximum depth of 256 last branch records.
> Currently remove_loops() can only process 127 entries at max. This leads
> to samples with more than 127 entries being skipped. This change simply
> updates the remove_loops() logic to be able to process 256 entries.
>
> Signed-off-by: Rajnesh Kanwal <rkanwal@...osinc.com>
> ---
> tools/perf/util/machine.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 2d51badfbf2e2d1588fa4fdd42ef6c8fea35bf0e..5414528b9d336790decfb42a4f6a4da6c6b68b07 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2176,25 +2176,32 @@ static void save_iterations(struct iterations *iter,
> iter->cycles += be[i].flags.cycles;
> }
>
> -#define CHASHSZ 127
> -#define CHASHBITS 7
> -#define NO_ENTRY 0xff
> +#define CHASHBITS 8
> +#define NO_ENTRY 0xffU
>
> -#define PERF_MAX_BRANCH_DEPTH 127
> +#define PERF_MAX_BRANCH_DEPTH 256
>
> /* Remove loops. */
> +/* Note: Last entry (i==ff) will never be checked against NO_ENTRY
> + * so it's safe to have an unsigned char array to process 256 entries
> + * without causing clash between last entry and NO_ENTRY value.
> + */
> static int remove_loops(struct branch_entry *l, int nr,
> struct iterations *iter)
> {
> int i, j, off;
> - unsigned char chash[CHASHSZ];
> + unsigned char chash[PERF_MAX_BRANCH_DEPTH];
>
> memset(chash, NO_ENTRY, sizeof(chash));
>
> - BUG_ON(PERF_MAX_BRANCH_DEPTH > 255);
> + BUG_ON(PERF_MAX_BRANCH_DEPTH > 256);
>
> for (i = 0; i < nr; i++) {
> - int h = hash_64(l[i].from, CHASHBITS) % CHASHSZ;
> + /* Remainder division by PERF_MAX_BRANCH_DEPTH is not
> + * needed as hash_64 will anyway limit the hash
> + * to CHASHBITS
> + */
> + int h = hash_64(l[i].from, CHASHBITS);
>
> /* no collision handling for now */
> if (chash[h] == NO_ENTRY) {
>
> --
> 2.43.0
>
Powered by blists - more mailing lists