Re: [PATCH 22/23] perf annotate-data: Add a cache for global variable types

From: Namhyung Kim
Date: Tue Mar 19 2024 - 14:10:17 EST


On Tue, Mar 19, 2024 at 11:07 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> On Tue, Mar 19, 2024 at 11:05:04AM -0700, Namhyung Kim wrote:
> > On Mon, Mar 18, 2024 at 10:56 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > >
> > > They are often searched by many different places. Let's add a cache
> > > for them to reduce the duplicate DWARF access.
> > >
> > > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> > > ---
> > > tools/perf/util/annotate-data.c | 107 +++++++++++++++++++++++++++++++-
> > > tools/perf/util/annotate-data.h | 7 +++
> > > tools/perf/util/dso.c | 2 +
> > > tools/perf/util/dso.h | 6 +-
> > > 4 files changed, 118 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
> > > index 633fe125fcd8..4b3184b7c799 100644
> > > --- a/tools/perf/util/annotate-data.c
> > > +++ b/tools/perf/util/annotate-data.c
> > > @@ -433,6 +433,91 @@ static struct type_state_stack *findnew_stack_state(struct type_state *state,
> > > return stack;
> > > }
> > >
> > > +/* Maintain a cache for quick global variable lookup */
> > > +struct global_var_entry {
> > > + struct rb_node node;
> > > + char *name;
> > > + u64 start;
> > > + u64 end;
> > > + u64 die_offset;
> > > +};
> > > +
> > > +static int global_var_cmp(const void *_key, const struct rb_node *node)
> > > +{
> > > + const u64 addr = (uintptr_t)_key;
> > > + struct global_var_entry *gvar;
> > > +
> > > + gvar = rb_entry(node, struct global_var_entry, node);
> > > +
> > > + if (gvar->start <= addr && addr < gvar->end)
> > > + return 0;
> > > + return gvar->start > addr ? -1 : 1;
> > > +}
> > > +
> > > +static bool global_var_less(struct rb_node *node_a, const struct rb_node *node_b)
> > > +{
> > > + struct global_var_entry *gvar_a, *gvar_b;
> > > +
> > > + gvar_a = rb_entry(node_a, struct global_var_entry, node);
> > > + gvar_b = rb_entry(node_b, struct global_var_entry, node);
> > > +
> > > + return gvar_a->start < gvar_b->start;
> > > +}
> > > +
> > > +static struct global_var_entry *global_var__find(struct data_loc_info *dloc, u64 addr)
> > > +{
> > > + struct dso *dso = map__dso(dloc->ms->map);
> > > + struct rb_node *node;
> > > +
> > > + node = rb_find((void *)addr, &dso->global_vars, global_var_cmp);
> >
> > It seems to cause a build error on 32-bit systems. It needs one
> > more cast to suppress the "pointer cast w/ different size" warning.
> >
> > node = rb_find(void *)(uintptr_tr)addr, ...);
>
> I can add that, to speed up the process, ok?

That would be great!

Thanks,
Namhyung