[PATCH v5 1/7] perf: Increase the maximum number of branches remove_loops() can process.

Anup Patel anup at brainfault.org
Thu Nov 19 07:15:48 PST 2026


On Wed, Nov 18, 2026 at 3:21 PM Vikram Singh
<vikram.singh3 at oss.qualcomm.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.
>
> Co-developed-by: Rajnesh Kanwal <rajnesh.kanwal49 at gmail.com>
> Signed-off-by: Rajnesh Kanwal <rajnesh.kanwal49 at gmail.com>
> Signed-off-by: Vikram Singh <vikram.singh3 at oss.qualcomm.com>
> Link: https://lore.kernel.org/r/20261106173942.3175069-2-vikram.singh3@oss.qualcomm.com
> Signed-off-by: Anup Patel <anup at brainfault.org>

I think you accidentally picked "Link:" and "Signed-off-by:" myself.
Please drop these lines from all patches.

Typically, the "Link:" and the following "Signed-off-by:" is added by
"b4 am -l -s" options so as a contributor don't use "-l -s" options
when using "b4 am".

> ---
>  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 076d167380f2..f1efd1120a95 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2334,25 +2334,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
>

Otherwise, LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup



More information about the linux-riscv mailing list