linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] perf symbols: Add documentation to struct symbol.
@ 2021-11-12  3:51 Ian Rogers
  2021-11-12  3:51 ` [PATCH 2/3] perf symbols: Bit pack to save a byte Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ian Rogers @ 2021-11-12  3:51 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Martin Liška, James Clark, Kajol Jain, linux-perf-users,
	linux-kernel
  Cc: eranian, Ian Rogers

Refactor some existing comments and then infer the rest.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/symbol.h | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 166196686f2e..3586fa549f44 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
 			     GElf_Shdr *shp, const char *name, size_t *idx);
 #endif
 
-/** struct symbol - symtab entry
- *
- * @ignore - resolvable but tools ignore it (e.g. idle routines)
+/**
+ * A symtab entry. When allocated this may be preceded by an annotation (see
+ * symbol__annotation), a browser_index (see symbol__browser_index) and rb_node
+ * to sort by name (see struct symbol_name_rb_node).
  */
 struct symbol {
 	struct rb_node	rb_node;
+	/** Range of symbol [start, end). */
 	u64		start;
 	u64		end;
+	/** Length of the string name. */
 	u16		namelen;
+	/** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */
 	u8		type:4;
+	/** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */
 	u8		binding:4;
+	/** Set true for kernel symbols of idle routines. */
 	u8		idle:1;
+	/** Resolvable but tools ignore it (e.g. idle routines). */
 	u8		ignore:1;
+	/** Symbol for an inlined function. */
 	u8		inlined:1;
+	/** Architecture specific. Unused except on PPC where it holds st_other. */
 	u8		arch_sym;
+	/** Has symbol__annotate2 been performed. */
 	bool		annotate2;
+	/** The name of length namelen associated with the symbol. */
 	char		name[];
 };
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] perf symbols: Bit pack to save a byte
  2021-11-12  3:51 [PATCH 1/3] perf symbols: Add documentation to struct symbol Ian Rogers
@ 2021-11-12  3:51 ` Ian Rogers
  2021-11-12  3:51 ` [PATCH 3/3] perf symbols: Factor out annotation init/exit Ian Rogers
  2021-11-12  4:04 ` [PATCH 1/3] perf symbols: Add documentation to struct symbol Namhyung Kim
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2021-11-12  3:51 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Martin Liška, James Clark, Kajol Jain, linux-perf-users,
	linux-kernel
  Cc: eranian, Ian Rogers

Use a bit field alongside the earlier bit fields.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/annotate.c | 2 +-
 tools/perf/util/symbol.h   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 8511af55fc3a..5d982933b3a2 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -3132,7 +3132,7 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel,
 	notes->nr_events = nr_pcnt;
 
 	annotation__update_column_widths(notes);
-	sym->annotate2 = true;
+	sym->annotate2 = 1;
 
 	return 0;
 
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 3586fa549f44..fbf866d82dcc 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -62,10 +62,10 @@ struct symbol {
 	u8		ignore:1;
 	/** Symbol for an inlined function. */
 	u8		inlined:1;
+	/** Has symbol__annotate2 been performed. */
+	u8		annotate2:1;
 	/** Architecture specific. Unused except on PPC where it holds st_other. */
 	u8		arch_sym;
-	/** Has symbol__annotate2 been performed. */
-	bool		annotate2;
 	/** The name of length namelen associated with the symbol. */
 	char		name[];
 };
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] perf symbols: Factor out annotation init/exit
  2021-11-12  3:51 [PATCH 1/3] perf symbols: Add documentation to struct symbol Ian Rogers
  2021-11-12  3:51 ` [PATCH 2/3] perf symbols: Bit pack to save a byte Ian Rogers
@ 2021-11-12  3:51 ` Ian Rogers
  2021-11-12  4:04 ` [PATCH 1/3] perf symbols: Add documentation to struct symbol Namhyung Kim
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2021-11-12  3:51 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Martin Liška, James Clark, Kajol Jain, linux-perf-users,
	linux-kernel
  Cc: eranian, Ian Rogers

The exit function fixes a memory leak with the src field as detected by
leak sanitizer. An example of which is:

Indirect leak of 25133184 byte(s) in 207 object(s) allocated from:
    #0 0x7f199ecfe987 in __interceptor_calloc libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55defe638224 in annotated_source__alloc_histograms util/annotate.c:803
    #2 0x55defe6397e4 in symbol__hists util/annotate.c:952
    #3 0x55defe639908 in symbol__inc_addr_samples util/annotate.c:968
    #4 0x55defe63aa29 in hist_entry__inc_addr_samples util/annotate.c:1119
    #5 0x55defe499a79 in hist_iter__report_callback tools/perf/builtin-report.c:182
    #6 0x55defe7a859d in hist_entry_iter__add util/hist.c:1236
    #7 0x55defe49aa63 in process_sample_event tools/perf/builtin-report.c:315
    #8 0x55defe731bc8 in evlist__deliver_sample util/session.c:1473
    #9 0x55defe731e38 in machines__deliver_event util/session.c:1510
    #10 0x55defe732a23 in perf_session__deliver_event util/session.c:1590
    #11 0x55defe72951e in ordered_events__deliver_event util/session.c:183
    #12 0x55defe740082 in do_flush util/ordered-events.c:244
    #13 0x55defe7407cb in __ordered_events__flush util/ordered-events.c:323
    #14 0x55defe740a61 in ordered_events__flush util/ordered-events.c:341
    #15 0x55defe73837f in __perf_session__process_events util/session.c:2390
    #16 0x55defe7385ff in perf_session__process_events util/session.c:2420
    ...

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/annotate.c | 11 +++++++++++
 tools/perf/util/annotate.h |  3 +++
 tools/perf/util/symbol.c   |  9 ++++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 5d982933b3a2..01900689dc00 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1255,6 +1255,17 @@ int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool r
 	return ins__scnprintf(&dl->ins, bf, size, &dl->ops, max_ins_name);
 }
 
+void annotation__init(struct annotation *notes)
+{
+	pthread_mutex_init(&notes->lock, NULL);
+}
+
+void annotation__exit(struct annotation *notes)
+{
+	annotated_source__delete(notes->src);
+	pthread_mutex_destroy(&notes->lock);
+}
+
 static void annotation_line__add(struct annotation_line *al, struct list_head *head)
 {
 	list_add_tail(&al->node, head);
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3757416bcf46..986f2bbe4870 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -299,6 +299,9 @@ struct annotation {
 	struct annotated_source *src;
 };
 
+void annotation__init(struct annotation *notes);
+void annotation__exit(struct annotation *notes);
+
 static inline int annotation__cycles_width(struct annotation *notes)
 {
 	if (notes->have_cycles && notes->options->show_minmax_cycle)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index aa1b7c12fd61..b2ed3140a1fa 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -274,7 +274,7 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *
 	if (symbol_conf.priv_size) {
 		if (symbol_conf.init_annotation) {
 			struct annotation *notes = (void *)sym;
-			pthread_mutex_init(&notes->lock, NULL);
+			annotation__init(notes);
 		}
 		sym = ((void *)sym) + symbol_conf.priv_size;
 	}
@@ -294,6 +294,13 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *
 
 void symbol__delete(struct symbol *sym)
 {
+	if (symbol_conf.priv_size) {
+		if (symbol_conf.init_annotation) {
+			struct annotation *notes = symbol__annotation(sym);
+
+			annotation__exit(notes);
+		}
+	}
 	free(((void *)sym) - symbol_conf.priv_size);
 }
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] perf symbols: Add documentation to struct symbol.
  2021-11-12  3:51 [PATCH 1/3] perf symbols: Add documentation to struct symbol Ian Rogers
  2021-11-12  3:51 ` [PATCH 2/3] perf symbols: Bit pack to save a byte Ian Rogers
  2021-11-12  3:51 ` [PATCH 3/3] perf symbols: Factor out annotation init/exit Ian Rogers
@ 2021-11-12  4:04 ` Namhyung Kim
  2021-11-12 14:46   ` Arnaldo Carvalho de Melo
  2 siblings, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2021-11-12  4:04 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Martin Liška,
	James Clark, Kajol Jain, linux-perf-users, linux-kernel,
	Stephane Eranian

Hi Ian,

On Thu, Nov 11, 2021 at 7:51 PM Ian Rogers <irogers@google.com> wrote:
>
> Refactor some existing comments and then infer the rest.
>
> Signed-off-by: Ian Rogers <irogers@google.com>

For all 3 patches,

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/symbol.h | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> index 166196686f2e..3586fa549f44 100644
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
> @@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
>                              GElf_Shdr *shp, const char *name, size_t *idx);
>  #endif
>
> -/** struct symbol - symtab entry
> - *
> - * @ignore - resolvable but tools ignore it (e.g. idle routines)
> +/**
> + * A symtab entry. When allocated this may be preceded by an annotation (see
> + * symbol__annotation), a browser_index (see symbol__browser_index) and rb_node
> + * to sort by name (see struct symbol_name_rb_node).
>   */
>  struct symbol {
>         struct rb_node  rb_node;
> +       /** Range of symbol [start, end). */
>         u64             start;
>         u64             end;
> +       /** Length of the string name. */
>         u16             namelen;
> +       /** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */
>         u8              type:4;
> +       /** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */
>         u8              binding:4;
> +       /** Set true for kernel symbols of idle routines. */
>         u8              idle:1;
> +       /** Resolvable but tools ignore it (e.g. idle routines). */
>         u8              ignore:1;
> +       /** Symbol for an inlined function. */
>         u8              inlined:1;
> +       /** Architecture specific. Unused except on PPC where it holds st_other. */
>         u8              arch_sym;
> +       /** Has symbol__annotate2 been performed. */
>         bool            annotate2;
> +       /** The name of length namelen associated with the symbol. */
>         char            name[];
>  };
>
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] perf symbols: Add documentation to struct symbol.
  2021-11-12  4:04 ` [PATCH 1/3] perf symbols: Add documentation to struct symbol Namhyung Kim
@ 2021-11-12 14:46   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-11-12 14:46 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Martin Liška, James Clark,
	Kajol Jain, linux-perf-users, linux-kernel, Stephane Eranian

Em Thu, Nov 11, 2021 at 08:04:35PM -0800, Namhyung Kim escreveu:
> Hi Ian,
> 
> On Thu, Nov 11, 2021 at 7:51 PM Ian Rogers <irogers@google.com> wrote:
> >
> > Refactor some existing comments and then infer the rest.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> 
> For all 3 patches,
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

b4 doesn't catch these Acked-by for the whole series when sent to one of
the patches, please consider to send your Acked-by/etc to the [PATCH
0/N] message in that case.

Thanks, applied!

- Arnaldo

 
> Thanks,
> Namhyung
> 
> 
> > ---
> >  tools/perf/util/symbol.h | 17 ++++++++++++++---
> >  1 file changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> > index 166196686f2e..3586fa549f44 100644
> > --- a/tools/perf/util/symbol.h
> > +++ b/tools/perf/util/symbol.h
> > @@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
> >                              GElf_Shdr *shp, const char *name, size_t *idx);
> >  #endif
> >
> > -/** struct symbol - symtab entry
> > - *
> > - * @ignore - resolvable but tools ignore it (e.g. idle routines)
> > +/**
> > + * A symtab entry. When allocated this may be preceded by an annotation (see
> > + * symbol__annotation), a browser_index (see symbol__browser_index) and rb_node
> > + * to sort by name (see struct symbol_name_rb_node).
> >   */
> >  struct symbol {
> >         struct rb_node  rb_node;
> > +       /** Range of symbol [start, end). */
> >         u64             start;
> >         u64             end;
> > +       /** Length of the string name. */
> >         u16             namelen;
> > +       /** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */
> >         u8              type:4;
> > +       /** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */
> >         u8              binding:4;
> > +       /** Set true for kernel symbols of idle routines. */
> >         u8              idle:1;
> > +       /** Resolvable but tools ignore it (e.g. idle routines). */
> >         u8              ignore:1;
> > +       /** Symbol for an inlined function. */
> >         u8              inlined:1;
> > +       /** Architecture specific. Unused except on PPC where it holds st_other. */
> >         u8              arch_sym;
> > +       /** Has symbol__annotate2 been performed. */
> >         bool            annotate2;
> > +       /** The name of length namelen associated with the symbol. */
> >         char            name[];
> >  };
> >
> > --
> > 2.34.0.rc1.387.gb447b232ab-goog
> >

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-12 14:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12  3:51 [PATCH 1/3] perf symbols: Add documentation to struct symbol Ian Rogers
2021-11-12  3:51 ` [PATCH 2/3] perf symbols: Bit pack to save a byte Ian Rogers
2021-11-12  3:51 ` [PATCH 3/3] perf symbols: Factor out annotation init/exit Ian Rogers
2021-11-12  4:04 ` [PATCH 1/3] perf symbols: Add documentation to struct symbol Namhyung Kim
2021-11-12 14:46   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).