dso/dsos memory savings and clean up
Subsystems (3)
Ian Rogers
reviewerv3 cover dso/dsos memory savings and clean up
12 more patches from:
https://lore.kernel.org/lkml/[email protected]/
a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking.
The changes migrate dsos code, the collection of dso structs, more into the dsos.c/dsos.h files. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduce by half.
As fixing the memory usage necessitates changing operations like find, modify these operations so that they increment the reference count to avoid races like a find in dsos and a remove. Similarly tighten up lock usage so that operations working on dsos state hold the appropriate lock.
Here are some questions (with answers) that I am expecting from reviewers:
- Why not refactor dso with accessors first and then do the other things?
My ambition with this change was to lower memory overhead not to particularly clean up and fix dso. Fixing the memory overhead, by refactoring and changing the internals, showed that locking discipline and reference counting discipline was lacking. The later changes try to fix these as a service to the community while I am changing the code and to also ensure that code is correct (more correct than it was wrt locking and reference counting than before the patches).
Reordering the patches to do the refactoring first will be a giant pain. It will merge conflict with every other patch in the series and is basically a request to reimplement everything from square 1. The only thing I'd have in my favor would be how the code should look at the end of the series, and reordering patches doesn't change the eventual outcome of applying the patches. Note also, were I to send the memory saving patches and then a week later send the API clean up and reference counting fix patches the patches would be merged in the order they are here. I've done my best, I know you may consider that I'm adding to your reviewing overhead but I've also got to think about the overhead to me.
- Please break apart this change...
The first changes are moving things, but when a broken API is spotted like the missing get on dsos__find I put it in a change to move the function and to add the missed get. Could this be two changes? Yes, it could. Does moving code materially change the behavior of the tool? No. I've done it in one patch to minimize churn and to some extent for my sanity. Such changes are less than 100 lines of code and all independently tested.
- The logic in dso around short, long name and id with sorting is weird
Yes, I've tried to make it less weird while retaining the existing behavior. It would be easy to make a series of patches just cleaning it up but I came here to save memory not change the dso API.
- Move the fixes in the 12th patch earlier.
This is possible but then impossible to test with reference count checking. This does mean there are broken reference counts before the patch is applied, but this is generally already the case. Yes, some hypothetical person may decide to fork midway through this patch series and my order would mean they wouldn't have a fix. I've done my best while working within the bounds of my time and trying to avoid churn.
v3. Rebases and drops merged "perf dso: Reorder variables to save
space in struct dso"
v2. Rebases on top of tmp.perf-tools-next resolving merge conflicts.
Ian Rogers (12):
perf dsos: Attempt to better abstract dsos internals perf dsos: Tidy reference counting and locking
perf dsos: Add dsos__for_each_dso
perf dso: Move dso functions out of dsos
perf dsos: Switch more loops to dsos__for_each_dso perf dsos: Switch backing storage to array from rbtree/list perf dsos: Remove __dsos__addnew
perf dsos: Remove __dsos__findnew_link_by_longname_id perf dsos: Switch hand code to bsearch
perf dso: Add reference count checking and accessor functions perf dso: Reference counting related fixes
perf dso: Use container_of to avoid a pointer in dso_data
tools/perf/builtin-annotate.c | 8 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 18 +- tools/perf/builtin-inject.c | 96 ++-- tools/perf/builtin-kallsyms.c | 2 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 8 +- tools/perf/builtin-top.c | 4 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 8 +- tools/perf/tests/dso-data.c | 67 ++- tools/perf/tests/hists_common.c | 6 +- tools/perf/tests/hists_cumulate.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/maps.c | 4 +- tools/perf/tests/symbols.c | 8 +- tools/perf/tests/vmlinux-kallsyms.c | 6 +- tools/perf/ui/browsers/annotate.c | 6 +- tools/perf/ui/browsers/hists.c | 8 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate-data.c | 14 +- tools/perf/util/annotate.c | 17 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/block-info.c | 2 +- tools/perf/util/bpf-event.c | 8 +- tools/perf/util/build-id.c | 136 ++--- tools/perf/util/build-id.h | 2 - tools/perf/util/callchain.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/db-export.c | 6 +- tools/perf/util/disasm.c | 34 +- tools/perf/util/dlfilter.c | 12 +- tools/perf/util/dso.c | 472 ++++++++++------ tools/perf/util/dso.h | 502 +++++++++++++++-- tools/perf/util/dsos.c | 529 +++++++++++------- tools/perf/util/dsos.h | 40 +- tools/perf/util/event.c | 8 +- tools/perf/util/header.c | 8 +- tools/perf/util/hist.c | 4 +- tools/perf/util/intel-pt.c | 22 +- tools/perf/util/machine.c | 192 ++----- tools/perf/util/machine.h | 2 + tools/perf/util/map.c | 82 ++- tools/perf/util/maps.c | 14 +- tools/perf/util/print_insn.c | 2 +- tools/perf/util/probe-event.c | 25 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 21 +- tools/perf/util/session.c | 21 + tools/perf/util/session.h | 2 + tools/perf/util/sort.c | 19 +- tools/perf/util/srcline.c | 65 ++- tools/perf/util/symbol-elf.c | 145 +++-- tools/perf/util/symbol-minimal.c | 4 +- tools/perf/util/symbol.c | 186 +++--- tools/perf/util/symbol_fprintf.c | 4 +- tools/perf/util/synthetic-events.c | 24 +- tools/perf/util/thread.c | 4 +- tools/perf/util/unwind-libunwind-local.c | 18 +- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/vdso.c | 56 +- 63 files changed, 1794 insertions(+), 1197 deletions(-)
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 1/12 perf dsos: Attempt to better abstract dsos internals
Move functions from machine and build-id to dsos. Pass dsos struct rather than internal state. Rename some functions to better represent which data structure they operate on.
--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/util/build-id.c | 38 +--------------------------- tools/perf/util/build-id.h | 2 -- tools/perf/util/dso.h | 6 ----- tools/perf/util/dsos.c | 49 ++++++++++++++++++++++++++++++++++--- tools/perf/util/dsos.h | 19 +++++++++++--- tools/perf/util/machine.c | 40 ++++++------------------------ tools/perf/util/machine.h | 2 ++ tools/perf/util/session.c | 21 ++++++++++++++++ tools/perf/util/session.h | 2 ++ 11 files changed, 97 insertions(+), 86 deletions(-)
tools/perf/builtin-inject.c +1 -1
@@ -2122,7 +2122,7 @@ static int __cmd_inject(struct perf_inject *inject)*/ if (perf_header__has_feat (&session->header,HEADER_BUILD_ID ) && inject->have_auxtrace && !inject->itrace_synth_opts.set) -dsos__hit_all (session); +perf_session__dsos_hit_all (session);/* * The AUX areas have been removed and replaced with * synthesized hardware events, so clear the feature flag.
tools/perf/builtin-record.c +1 -1
@@ -1790,7 +1790,7 @@ record__finish_output(struct record *rec)process_buildids (rec);if (rec->buildid_all) -dsos__hit_all (rec->session); +perf_session__dsos_hit_all (rec->session); }perf_session__write_header (rec->session, rec->evlist, fd, true);
tools/perf/util/build-id.c +1 -37
@@ -390,42 +390,6 @@ int perf_session__write_buildid_table(struct perf_session *session,return err; } -static int __dsos__hit_all (struct list_head *head) -{ -struct dso *pos; - -list_for_each_entry (pos, head, node) - pos->hit = true; - -return 0 ; -} - -static int machine__hit_all_dsos (struct machine *machine) -{ -return __dsos__hit_all (&machine->dsos.head); -} - -int dsos__hit_all (struct perf_session *session) -{ -struct rb_node *nd; -int err; - - err =machine__hit_all_dsos (&session->machines.host); -if (err) -return err; - -for (nd =rb_first_cached (&session->machines.guests); nd; - nd =rb_next (nd)) { - struct machine *pos = rb_entry(nd, struct machine, rb_node); - - err =machine__hit_all_dsos (pos); -if (err) -return err; - } - -return 0 ; -} -void disable_buildid_cache (void ) { no_buildid_cache = true;
@@ -992,7 +956,7 @@ int perf_session__cache_build_ids(struct perf_session *session)static bool machine__read_build_ids (struct machine *machine,bool with_hits) { -return __dsos__read_build_ids (&machine->dsos.head, with_hits); +return __dsos__read_build_ids (&machine->dsos, with_hits); }bool perf_session__read_build_ids (struct perf_session *session,bool with_hits)
tools/perf/util/build-id.h +0 -2
@@ -39,8 +39,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct evsel *evsel, struct machine *machine); -int dsos__hit_all (struct perf_session *session); -int perf_event__inject_buildid (struct perf_tool *tool,union perf_event *event,struct perf_sample *sample,struct evsel *evsel,struct machine *machine);
tools/perf/util/dso.h +0 -6
@@ -233,12 +233,6 @@ struct dso {#define dso__for_each_symbol (dso, pos, n) \ symbols__for_each_entry(&(dso)->symbols, pos, n) -#define dsos__for_each_with_build_id (pos, head) \ - list_for_each_entry(pos, head, node) \ - if (!pos->has_build_id) \ - continue; \ - else -static inline void dso__set_loaded (struct dso *dso) { dso->loaded = true;
tools/perf/util/dsos.c +46 -3
80 lines not on this page · raw message
tools/perf/util/dsos.h +15 -4
@@ -21,6 +21,15 @@ struct dsos {struct rw_semaphore lock; }; +#define dsos__for_each_with_build_id (pos, head) \ + list_for_each_entry(pos, head, node) \ + if (!pos->has_build_id) \ + continue; \ + else + +void dsos__init (struct dsos *dsos); +void dsos__exit (struct dsos *dsos); +void __dsos__add (struct dsos *dsos,struct dso *dso);void dsos__add (struct dsos *dsos,struct dso *dso);struct dso *__dsos__addnew (struct dsos *dsos,const char *name);
@@ -28,13 +37,15 @@ struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short);struct dso *dsos__findnew_id (struct dsos *dsos,const char *name,struct dso_id *id); +bool __dsos__read_build_ids (struct dsos *dsos,bool with_hits); +struct dso *__dsos__findnew_link_by_longname_id (struct rb_root *root,struct dso *dso,const char *name,struct dso_id *id); -bool __dsos__read_build_ids (struct list_head *head,bool with_hits); - -size_t __dsos__fprintf_buildid (struct list_head *head,FILE *fp, +size_t __dsos__fprintf_buildid (struct dsos *dsos,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm); -size_t __dsos__fprintf (struct list_head *head,FILE *fp); +size_t __dsos__fprintf (struct dsos *dsos,FILE *fp); + +int __dsos__hit_all (struct dsos *dsos);#endif /* __PERF_DSOS */
tools/perf/util/machine.c +8 -32
@@ -48,13 +48,6 @@ static struct dso *machine__kernel_dso(struct machine *machine)return map__dso (machine->vmlinux_map); } -static void dsos__init (struct dsos *dsos) -{ -INIT_LIST_HEAD (&dsos->head); - dsos->root =RB_ROOT ; -init_rwsem (&dsos->lock); -} -static int machine__set_mmap_name (struct machine *machine) {if (machine__is_host (machine))
@@ -165,28 +158,6 @@ struct machine *machine__new_kallsyms(void)return machine; } -static void dsos__purge (struct dsos *dsos) -{ -struct dso *pos, *n; - -down_write (&dsos->lock); - -list_for_each_entry_safe (pos, n, &dsos->head, node) { -RB_CLEAR_NODE (&pos->rb_node); - pos->root =NULL ; -list_del_init (&pos->node); -dso__put (pos); - } - -up_write (&dsos->lock); -} - -static void dsos__exit (struct dsos *dsos) -{ -dsos__purge (dsos); -exit_rwsem (&dsos->lock); -} -void machine__delete_threads (struct machine *machine) {threads__remove_all_threads (&machine->threads);
@@ -907,11 +878,11 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 startsize_t machines__fprintf_dsos (struct machines *machines,FILE *fp) {struct rb_node *nd; -size_t ret =__dsos__fprintf (&machines->host.dsos.head, fp); +size_t ret =__dsos__fprintf (&machines->host.dsos, fp);for (nd =rb_first_cached (&machines->guests); nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); - ret +=__dsos__fprintf (&pos->dsos.head, fp); + ret +=__dsos__fprintf (&pos->dsos, fp); }return ret;
@@ -920,7 +891,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)size_t machine__fprintf_dsos_buildid (struct machine *m,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm) { -return __dsos__fprintf_buildid (&m->dsos.head, fp, skip, parm); +return __dsos__fprintf_buildid (&m->dsos, fp, skip, parm); } size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
@@ -3306,3 +3277,8 @@ bool machine__is_lock_function(struct machine *machine, u64 addr)return false; } + +int machine__hit_all_dsos (struct machine *machine) +{ +return __dsos__hit_all (&machine->dsos); +}
tools/perf/util/machine.h +2 -0
@@ -306,4 +306,6 @@ int machine__map_x86_64_entry_trampolines(struct machine *machine,int machine__resolve (struct machine *machine,struct addr_location *al,struct perf_sample *sample); +int machine__hit_all_dsos (struct machine *machine); +#endif /* __PERF_MACHINE_H */
tools/perf/util/session.c +21 -0
@@ -2916,3 +2916,24 @@ int perf_event__process_id_index(struct perf_session *session, }return 0 ; } + +int perf_session__dsos_hit_all (struct perf_session *session) +{ +struct rb_node *nd; +int err; + + err =machine__hit_all_dsos (&session->machines.host); +if (err) +return err; + +for (nd =rb_first_cached (&session->machines.guests); nd; + nd =rb_next (nd)) { + struct machine *pos = rb_entry(nd, struct machine, rb_node); + + err =machine__hit_all_dsos (pos); +if (err) +return err; + } + +return 0 ; +}
tools/perf/util/session.h +2 -0
@@ -156,6 +156,8 @@ int perf_session__deliver_synth_event(struct perf_session *session,union perf_event *event, struct perf_sample *sample); +int perf_session__dsos_hit_all (struct perf_session *session); +int perf_event__process_id_index (struct perf_session *session,union perf_event *event);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 2/12 perf dsos: Tidy reference counting and locking
In reply to Ian RogersMove more functionality into dsos.c generally from machine, renaming functions to match their new usage. The find function is made to always "get" before returning a dso. Reduce the scope of locks in vdso to match the locking paradigm.
--- tools/perf/util/dsos.c | 73 +++++++++++++++++++++++++++++++++++---- tools/perf/util/dsos.h | 9 ++++- tools/perf/util/machine.c | 62 ++------------------------------- tools/perf/util/map.c | 4 +-- tools/perf/util/vdso.c | 48 +++++++++++-------------- 5 files changed, 97 insertions(+), 99 deletions(-)
tools/perf/util/dsos.c +66 -7
@@ -181,7 +181,7 @@ struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, struct dso* at the end of the list of duplicates. */ if (!dso || (dso == this)) -return this;/* Find matching dso */ +return dso__get (this);/* Find matching dso */ /* * The core kernel DSOs may have duplicated long name. * In this case, the short name should be different.
@@ -253,15 +253,20 @@ static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, struct dif (cmp_short) {list_for_each_entry (pos, &dsos->head, node)if (__dso__cmp_short_name (name, id, pos) ==0 ) -return pos; +return dso__get (pos);return NULL ; }return __dsos__findnew_by_longname_id (&dsos->root, name, id); } -struct dso *__dsos__find (struct dsos *dsos,const char *name,bool cmp_short) +struct dso *dsos__find (struct dsos *dsos,const char *name,bool cmp_short) { -return __dsos__find_id (dsos, name,NULL , cmp_short); +struct dso *res; + +down_read (&dsos->lock); + res =__dsos__find_id (dsos, name,NULL , cmp_short); +up_read (&dsos->lock); +return res; }static void dso__set_basename (struct dso *dso)
@@ -303,8 +308,6 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, structif (dso !=NULL ) {__dsos__add (dsos, dso);dso__set_basename (dso); -/* Put dso here because __dsos_add already got it */ -dso__put (dso); }return dso; }
@@ -328,7 +331,7 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id {struct dso *dso;down_write (&dsos->lock); - dso =dso__get (__dsos__findnew_id (dsos, name, id)); + dso =__dsos__findnew_id (dsos, name, id);up_write (&dsos->lock);return dso; }
@@ -374,3 +377,59 @@ int __dsos__hit_all(struct dsos *dsos)return 0 ; } + +struct dso *dsos__findnew_module_dso (struct dsos *dsos, +struct machine *machine, +struct kmod_path *m, +const char *filename) +{ +struct dso *dso; + +down_write (&dsos->lock); + + dso =__dsos__find_id (dsos, m->name,NULL ,/*cmp_short=*/ true); +if (!dso) { + dso =__dsos__addnew (dsos, m->name); +if (dso ==NULL ) + goto out_unlock; + +dso__set_module_info (dso, m, machine); +dso__set_long_name (dso,strdup (filename), true); + dso->kernel =DSO_SPACE__KERNEL ; + } + +out_unlock: +up_write (&dsos->lock); +return dso; +} + +struct dso *dsos__find_kernel_dso (struct dsos *dsos) +{ +struct dso *dso, *res =NULL ; + +down_read (&dsos->lock); +list_for_each_entry (dso, &dsos->head, node) { +/* +* The cpumode passed to is_kernel_module is not the cpumode of +* *this* event. If we insist on passing correct cpumode to +* is_kernel_module, we should record the cpumode when we adding +* this dso to the linked list. +* +* However we don't really need passing correct cpumode. We +* know the correct cpumode must be kernel mode (if not, we +* should not link it onto kernel_dsos list). +* +* Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN. +* is_kernel_module() treats it as a kernel cpumode. +*/ +if (!dso->kernel || +is_kernel_module (dso->long_name, +PERF_RECORD_MISC_CPUMODE_UNKNOWN )) +continue ; + + res =dso__get (dso); +break ; + } +up_read (&dsos->lock); +return res; +}
tools/perf/util/dsos.h +8 -1
@@ -10,6 +10,8 @@struct dso ;struct dso_id ; +struct kmod_path ; +struct machine ;/* * DSOs are put into both a list for fast iteration and rbtree for fast
@@ -33,7 +35,7 @@ void dsos__exit(struct dsos *dsos);void __dsos__add (struct dsos *dsos,struct dso *dso);void dsos__add (struct dsos *dsos,struct dso *dso);struct dso *__dsos__addnew (struct dsos *dsos,const char *name); -struct dso *__dsos__find (struct dsos *dsos,const char *name,bool cmp_short); +struct dso *dsos__find (struct dsos *dsos,const char *name,bool cmp_short);struct dso *dsos__findnew_id (struct dsos *dsos,const char *name,struct dso_id *id);
@@ -48,4 +50,9 @@ size_t __dsos__fprintf(struct dsos *dsos, FILE *fp);int __dsos__hit_all (struct dsos *dsos); +struct dso *dsos__findnew_module_dso (struct dsos *dsos,struct machine *machine, +struct kmod_path *m,const char *filename); + +struct dso *dsos__find_kernel_dso (struct dsos *dsos); +#endif /* __PERF_DSOS */
tools/perf/util/machine.c +2 -60
80 lines not on this page · raw message
tools/perf/util/map.c +1 -3
@@ -196,9 +196,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,* reading the header will have the build ID set and all future mmaps will * have it missing. */ -down_read (&machine->dsos.lock); - header_bid_dso =__dsos__find (&machine->dsos, filename, false); -up_read (&machine->dsos.lock); + header_bid_dso =dsos__find (&machine->dsos, filename, false);if (header_bid_dso && header_bid_dso->header_build_id) {dso__set_build_id (dso, &header_bid_dso->bid); dso->header_build_id =1 ;
tools/perf/util/vdso.c +20 -28
103 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 3/12 perf dsos: Add dsos__for_each_dso
In reply to Ian RogersTo better abstract the dsos internals, add dsos__for_each_dso that does a callback on each dso. This also means the read lock can be correctly held.
--- tools/perf/builtin-inject.c | 25 +++++++----- tools/perf/util/build-id.c | 76 ++++++++++++++++++++----------------- tools/perf/util/dsos.c | 16 ++++++++ tools/perf/util/dsos.h | 8 +--- tools/perf/util/machine.c | 40 +++++++++++-------- 5 files changed, 100 insertions(+), 65 deletions(-)
tools/perf/builtin-inject.c +15 -10
@@ -1187,23 +1187,28 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_ process_build_id, machine); } +static int guest_session__add_build_ids_cb (struct dso *dso,void *data) +{ +struct guest_session *gs = data; + struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); + +if (!dso->has_build_id) +return 0 ; + +return synthesize_build_id (inject, dso, gs->machine_pid); + +} +static int guest_session__add_build_ids (struct guest_session *gs) { struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); -struct machine *machine = &gs->session->machines.host; -struct dso *dso; -int ret;/* Build IDs will be put in the Build ID feature section */ perf_header__set_feat (&inject->session->header,HEADER_BUILD_ID ); -dsos__for_each_with_build_id (dso, &machine->dsos.head) { - ret =synthesize_build_id (inject, dso, gs->machine_pid); -if (ret) -return ret; - } - -return 0 ; +return dsos__for_each_dso (&gs->session->machines.host.dsos, + guest_session__add_build_ids_cb, + gs); } static int guest_session__ksymbol_event(struct perf_tool *tool,
tools/perf/util/build-id.c +42 -34
90 lines not on this page · raw message
tools/perf/util/dsos.c +16 -0
@@ -433,3 +433,19 @@ struct dso *dsos__find_kernel_dso(struct dsos *dsos)up_read (&dsos->lock);return res; } + +int dsos__for_each_dso (struct dsos *dsos,int (*cb)(struct dso *dso,void *data),void *data) +{ +struct dso *dso; + +down_read (&dsos->lock); +list_for_each_entry (dso, &dsos->head, node) { +int err; + + err =cb (dso, data); +if (err) +return err; + } +up_read (&dsos->lock); +return 0 ; +}
tools/perf/util/dsos.h +2 -6
@@ -23,12 +23,6 @@ struct dsos {struct rw_semaphore lock; }; -#define dsos__for_each_with_build_id (pos, head) \ - list_for_each_entry(pos, head, node) \ - if (!pos->has_build_id) \ - continue; \ - else -void dsos__init (struct dsos *dsos);void dsos__exit (struct dsos *dsos);
@@ -55,4 +49,6 @@ struct dso *dsos__findnew_module_dso(struct dsos *dsos, struct machine *machine,struct dso *dsos__find_kernel_dso (struct dsos *dsos); +int dsos__for_each_dso (struct dsos *dsos,int (*cb)(struct dso *dso,void *data),void *data); +#endif /* __PERF_DSOS */
tools/perf/util/machine.c +25 -15
@@ -1562,16 +1562,14 @@ int machine__create_kernel_maps(struct machine *machine)return ret; } -static bool machine__uses_kcore (struct machine *machine) +static int machine__uses_kcore_cb (struct dso *dso,void *data__maybe_unused ) { -struct dso *dso; - -list_for_each_entry (dso, &machine->dsos.head, node) { -if (dso__is_kcore (dso)) -return true; - } +return dso__is_kcore (dso) ?1 :0 ; +} -return false; +static bool machine__uses_kcore (struct machine *machine) +{ +return dsos__for_each_dso (&machine->dsos, machine__uses_kcore_cb,NULL ) !=0 ? true : false; } static bool perf_event__is_extra_kernel_mmap(struct machine *machine,
@@ -3137,16 +3135,28 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, chreturn sym->name; } +struct machine__for_each_dso_cb_args { +struct machine *machine; +machine__dso_t fn; +void *priv; +}; + +static int machine__for_each_dso_cb (struct dso *dso,void *data) +{ +struct machine__for_each_dso_cb_args *args = data; + +return args->fn (dso, args->machine, args->priv); +} +int machine__for_each_dso (struct machine *machine,machine__dso_t fn,void *priv) { -struct dso *pos; -int err =0 ; +struct machine__for_each_dso_cb_args args = { + .machine = machine, + .fn = fn, + .priv = priv, + }; -list_for_each_entry (pos, &machine->dsos.head, node) { -if (fn (pos, machine, priv)) - err =-1 ; - } -return err; +return dsos__for_each_dso (&machine->dsos, machine__for_each_dso_cb, &args); }int machine__for_each_kernel_map (struct machine *machine,machine__map_t fn,void *priv)
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 4/12 perf dso: Move dso functions out of dsos
In reply to Ian RogersMove dso and dso_id functions to dso.c to match the struct declarations.
--- tools/perf/util/dso.c | 61 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 4 +++ tools/perf/util/dsos.c | 61 ------------------------------------------ 3 files changed, 65 insertions(+), 61 deletions(-)
tools/perf/util/dso.c +61 -0
@@ -1269,6 +1269,67 @@ static void dso__set_long_name_id(struct dso *dso, const char *name, struct dso___dsos__findnew_link_by_longname_id (root, dso,NULL , id); } +static int __dso_id__cmp (struct dso_id *a,struct dso_id *b) +{ +if (a->maj > b->maj)return -1 ; +if (a->maj < b->maj)return 1 ; + +if (a->min > b->min)return -1 ; +if (a->min < b->min)return 1 ; + +if (a->ino > b->ino)return -1 ; +if (a->ino < b->ino)return 1 ; + +/* +* Synthesized MMAP events have zero ino_generation, avoid comparing +* them with MMAP events with actual ino_generation. +* +* I found it harmful because the mismatch resulted in a new +* dso that did not have a build ID whereas the original dso did have a +* build ID. The build ID was essential because the object was not found +* otherwise. - Adrian +*/ +if (a->ino_generation && b->ino_generation) { +if (a->ino_generation > b->ino_generation)return -1 ; +if (a->ino_generation < b->ino_generation)return 1 ; + } + +return 0 ; +} + +bool dso_id__empty (struct dso_id *id) +{ +if (!id) +return true; + +return !id->maj && !id->min && !id->ino && !id->ino_generation; +} + +void dso__inject_id (struct dso *dso,struct dso_id *id) +{ + dso->id.maj = id->maj; + dso->id.min = id->min; + dso->id.ino = id->ino; + dso->id.ino_generation = id->ino_generation; +} + +int dso_id__cmp (struct dso_id *a,struct dso_id *b) +{ +/* +* The second is always dso->id, so zeroes if not set, assume passing +* NULL for a means a zeroed id +*/ +if (dso_id__empty (a) ||dso_id__empty (b)) +return 0 ; + +return __dso_id__cmp (a, b); +} + +int dso__cmp_id (struct dso *a,struct dso *b) +{ +return __dso_id__cmp (&a->id, &b->id); +} +void dso__set_long_name (struct dso *dso,const char *name,bool name_allocated) {dso__set_long_name_id (dso, name,NULL , name_allocated);
tools/perf/util/dso.h +4 -0
@@ -238,6 +238,9 @@ static inline void dso__set_loaded(struct dso *dso) dso->loaded = true; } +int dso_id__cmp (struct dso_id *a,struct dso_id *b); +bool dso_id__empty (struct dso_id *id); +struct dso *dso__new_id (const char *name,struct dso_id *id);struct dso *dso__new (const char *name);void dso__delete (struct dso *dso);
@@ -245,6 +248,7 @@ void dso__delete(struct dso *dso);int dso__cmp_id (struct dso *a,struct dso *b);void dso__set_short_name (struct dso *dso,const char *name,bool name_allocated);void dso__set_long_name (struct dso *dso,const char *name,bool name_allocated); +void dso__inject_id (struct dso *dso,struct dso_id *id);int dso__name_len (const struct dso *dso);
tools/perf/util/dsos.c +0 -61
67 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 5/12 perf dsos: Switch more loops to dsos__for_each_dso
In reply to Ian RogersSwitch loops within dsos.c, add a version that isn't locked. Switch some unlocked loops to hold the read lock.
--- tools/perf/util/build-id.c | 2 +- tools/perf/util/dsos.c | 258 ++++++++++++++++++++++++------------- tools/perf/util/dsos.h | 8 +- tools/perf/util/machine.c | 8 +- 4 files changed, 174 insertions(+), 102 deletions(-)
tools/perf/util/build-id.c +1 -1
@@ -964,7 +964,7 @@ int perf_session__cache_build_ids(struct perf_session *session)static bool machine__read_build_ids (struct machine *machine,bool with_hits) { -return __dsos__read_build_ids (&machine->dsos, with_hits); +return dsos__read_build_ids (&machine->dsos, with_hits); }bool perf_session__read_build_ids (struct perf_session *session,bool with_hits)
tools/perf/util/dsos.c +165 -93
323 lines not on this page · raw message
tools/perf/util/dsos.h +4 -4
@@ -33,16 +33,16 @@ struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short);struct dso *dsos__findnew_id (struct dsos *dsos,const char *name,struct dso_id *id); -bool __dsos__read_build_ids (struct dsos *dsos,bool with_hits); +bool dsos__read_build_ids (struct dsos *dsos,bool with_hits);struct dso *__dsos__findnew_link_by_longname_id (struct rb_root *root,struct dso *dso,const char *name,struct dso_id *id); -size_t __dsos__fprintf_buildid (struct dsos *dsos,FILE *fp, +size_t dsos__fprintf_buildid (struct dsos *dsos,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm); -size_t __dsos__fprintf (struct dsos *dsos,FILE *fp); +size_t dsos__fprintf (struct dsos *dsos,FILE *fp); -int __dsos__hit_all (struct dsos *dsos); +int dsos__hit_all (struct dsos *dsos);struct dso *dsos__findnew_module_dso (struct dsos *dsos,struct machine *machine,struct kmod_path *m,const char *filename);
tools/perf/util/machine.c +4 -4
@@ -853,11 +853,11 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 startsize_t machines__fprintf_dsos (struct machines *machines,FILE *fp) {struct rb_node *nd; -size_t ret =__dsos__fprintf (&machines->host.dsos, fp); +size_t ret =dsos__fprintf (&machines->host.dsos, fp);for (nd =rb_first_cached (&machines->guests); nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); - ret +=__dsos__fprintf (&pos->dsos, fp); + ret +=dsos__fprintf (&pos->dsos, fp); }return ret;
@@ -866,7 +866,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)size_t machine__fprintf_dsos_buildid (struct machine *m,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm) { -return __dsos__fprintf_buildid (&m->dsos, fp, skip, parm); +return dsos__fprintf_buildid (&m->dsos, fp, skip, parm); } size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
@@ -3232,5 +3232,5 @@ bool machine__is_lock_function(struct machine *machine, u64 addr)int machine__hit_all_dsos (struct machine *machine) { -return __dsos__hit_all (&machine->dsos); +return dsos__hit_all (&machine->dsos); }
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 6/12 perf dsos: Switch backing storage to array from rbtree/list
In reply to Ian RogersDSOs were held on a list for fast iteration and in an rbtree for fast finds. Switch to using a lazily sorted array where iteration is just iterating through the array and binary searches are the same complexity as searching the rbtree. The find may need to sort the array first which does increase the complexity, but add operations have lower complexity and overall the complexity should remain about the same.
The set name operations on the dso just records that the array is no longer sorted, avoiding complexity in rebalancing the rbtree. Tighter locking discipline is enforced to avoid the array being resorted while long and short names or ids are changed.
The array is smaller in size, replacing 6 pointers with 2, and so even with extra allocated space in the array, the array may be 50% unoccupied, the memory saving should be at least 2x.
--- tools/perf/util/dso.c | 67 +++++++++------ tools/perf/util/dso.h | 10 +-- tools/perf/util/dsos.c | 188 ++++++++++++++++++++++++++--------------- tools/perf/util/dsos.h | 21 +++-- 4 files changed, 177 insertions(+), 109 deletions(-)
tools/perf/util/dso.c +42 -25
@@ -1241,35 +1241,35 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,return dso; } -static void dso__set_long_name_id (struct dso *dso,const char *name,struct dso_id *id,bool name_allocated) +static void dso__set_long_name_id (struct dso *dso,const char *name,bool name_allocated) { -struct rb_root *root = dso->root; +struct dsos *dsos = dso->dsos;if (name ==NULL )return ; -if (dso->long_name_allocated) -free ((char *)dso->long_name); - -if (root) { -rb_erase (&dso->rb_node, root); +if (dsos) {/* -* __dsos__findnew_link_by_longname_id() isn't guaranteed to -* add it back, so a clean removal is required here. +* Need to avoid re-sorting the dsos breaking by non-atomically +* renaming the dso. */ -RB_CLEAR_NODE (&dso->rb_node); - dso->root =NULL ; +down_write (&dsos->lock); } +if (dso->long_name_allocated) +free ((char *)dso->long_name); + dso->long_name = name; dso->long_name_len =strlen (name); dso->long_name_allocated = name_allocated; -if (root) -__dsos__findnew_link_by_longname_id (root, dso,NULL , id); +if (dsos) { + dsos->sorted = false; +up_write (&dsos->lock); + } } -static int __dso_id__cmp (struct dso_id *a,struct dso_id *b) +static int __dso_id__cmp (const struct dso_id *a,const struct dso_id *b) {if (a->maj > b->maj)return -1 ;if (a->maj < b->maj)return 1 ;
@@ -1297,7 +1297,7 @@ static int __dso_id__cmp(struct dso_id *a, struct dso_id *b)return 0 ; } -bool dso_id__empty (struct dso_id *id) +bool dso_id__empty (const struct dso_id *id) {if (!id)return true;
@@ -1305,15 +1305,22 @@ bool dso_id__empty(struct dso_id *id)return !id->maj && !id->min && !id->ino && !id->ino_generation; } -void dso__inject_id (struct dso *dso,struct dso_id *id) +void __dso__inject_id (struct dso *dso,struct dso_id *id) { +struct dsos *dsos = dso->dsos; + +/* dsos write lock held by caller. */ + dso->id.maj = id->maj; dso->id.min = id->min; dso->id.ino = id->ino; dso->id.ino_generation = id->ino_generation; + +if (dsos) + dsos->sorted = false; } -int dso_id__cmp (struct dso_id *a,struct dso_id *b) +int dso_id__cmp (const struct dso_id *a,const struct dso_id *b) {/* * The second is always dso->id, so zeroes if not set, assume passing
@@ -1332,20 +1339,34 @@ int dso__cmp_id(struct dso *a, struct dso *b)void dso__set_long_name (struct dso *dso,const char *name,bool name_allocated) { -dso__set_long_name_id (dso, name,NULL , name_allocated); +dso__set_long_name_id (dso, name, name_allocated); }void dso__set_short_name (struct dso *dso,const char *name,bool name_allocated) { +struct dsos *dsos = dso->dsos; +if (name ==NULL )return ; +if (dsos) { +/* +* Need to avoid re-sorting the dsos breaking by non-atomically +* renaming the dso. +*/ +down_write (&dsos->lock); + }if (dso->short_name_allocated)free ((char *)dso->short_name); dso->short_name = name; dso->short_name_len =strlen (name); dso->short_name_allocated = name_allocated; + +if (dsos) { + dsos->sorted = false; +up_write (&dsos->lock); + } }int dso__name_len (const struct dso *dso)
@@ -1381,7 +1402,7 @@ struct dso *dso__new_id(const char *name, struct dso_id *id)strcpy (dso->name, name);if (id) dso->id = *id; -dso__set_long_name_id (dso, dso->name, id, false); +dso__set_long_name_id (dso, dso->name, false);dso__set_short_name (dso, dso->name, false); dso->symbols =RB_ROOT_CACHED ; dso->symbol_names =NULL ;
@@ -1406,9 +1427,6 @@ struct dso *dso__new_id(const char *name, struct dso_id *id) dso->is_kmod =0 ; dso->needs_swap =DSO_SWAP__UNSET ; dso->comp =COMP_ID__NONE ; -RB_CLEAR_NODE (&dso->rb_node); - dso->root =NULL ; -INIT_LIST_HEAD (&dso->node);INIT_LIST_HEAD (&dso->data.open_entry);mutex_init (&dso->lock);refcount_set (&dso->refcnt,1 );
@@ -1424,9 +1442,8 @@ struct dso *dso__new(const char *name)void dso__delete (struct dso *dso) { -if (!RB_EMPTY_NODE (&dso->rb_node)) -pr_err ("DSO %s is still in rbtree when being deleted!\n" , - dso->long_name); +if (dso->dsos) +pr_err ("DSO %s is still in rbtree when being deleted!\n" , dso->long_name);/* free inlines first, as they reference symbols */ inlines__tree_delete (&dso->inlined_nodes);
tools/perf/util/dso.h +4 -6
@@ -146,9 +146,7 @@ struct auxtrace_cache;struct dso {struct mutex lock; -struct list_head node; -struct rb_node rb_node;/* rbtree node sorted by long name */ -struct rb_root *root;/* root of rbtree that rb_node is in */ +struct dsos *dsos;struct rb_root_cached symbols;struct symbol **symbol_names;size_t symbol_names_len;
@@ -238,8 +236,8 @@ static inline void dso__set_loaded(struct dso *dso) dso->loaded = true; } -int dso_id__cmp (struct dso_id *a,struct dso_id *b); -bool dso_id__empty (struct dso_id *id); +int dso_id__cmp (const struct dso_id *a,const struct dso_id *b); +bool dso_id__empty (const struct dso_id *id);struct dso *dso__new_id (const char *name,struct dso_id *id);struct dso *dso__new (const char *name);
@@ -248,7 +246,7 @@ void dso__delete(struct dso *dso);int dso__cmp_id (struct dso *a,struct dso *b);void dso__set_short_name (struct dso *dso,const char *name,bool name_allocated);void dso__set_long_name (struct dso *dso,const char *name,bool name_allocated); -void dso__inject_id (struct dso *dso,struct dso_id *id); +void __dso__inject_id (struct dso *dso,struct dso_id *id);int dso__name_len (const struct dso *dso);
tools/perf/util/dsos.c +118 -70
291 lines not on this page · raw message
tools/perf/util/dsos.h +13 -8
@@ -14,20 +14,22 @@ struct kmod_path;struct machine ;/* -* DSOs are put into both a list for fast iteration and rbtree for fast -* long name lookup. +* Collection of DSOs as an array for iteration speed, but sorted for O(n) +* lookup. */ struct dsos { -struct list_head head; -struct rb_root root;/* rbtree root sorted by long name */ struct rw_semaphore lock; +struct dso **dsos; +unsigned int cnt; +unsigned int allocated; +bool sorted; };void dsos__init (struct dsos *dsos);void dsos__exit (struct dsos *dsos); -void __dsos__add (struct dsos *dsos,struct dso *dso); -void dsos__add (struct dsos *dsos,struct dso *dso); +int __dsos__add (struct dsos *dsos,struct dso *dso); +int dsos__add (struct dsos *dsos,struct dso *dso);struct dso *__dsos__addnew (struct dsos *dsos,const char *name);struct dso *dsos__find (struct dsos *dsos,const char *name,bool cmp_short);
@@ -35,8 +37,11 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_idbool dsos__read_build_ids (struct dsos *dsos,bool with_hits); -struct dso *__dsos__findnew_link_by_longname_id (struct rb_root *root,struct dso *dso, -const char *name,struct dso_id *id); +struct dso *__dsos__findnew_link_by_longname_id (struct dsos *dsos, +struct dso *dso, +const char *name, +struct dso_id *id, +bool write_locked);size_t dsos__fprintf_buildid (struct dsos *dsos,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 7/12 perf dsos: Remove __dsos__addnew
In reply to Ian RogersFunction no longer used so remove.
--- tools/perf/util/dsos.c | 5 ----- tools/perf/util/dsos.h | 1 - 2 files changed, 6 deletions(-)
tools/perf/util/dsos.c +0 -5
@@ -341,11 +341,6 @@ static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, structreturn dso; } -struct dso *__dsos__addnew (struct dsos *dsos,const char *name) -{ -return __dsos__addnew_id (dsos, name,NULL ); -} -static struct dso *__dsos__findnew_id (struct dsos *dsos,const char *name,struct dso_id *id) {struct dso *dso =__dsos__find_id (dsos, name, id, false,/*write_locked=*/ true);
tools/perf/util/dsos.h +0 -1
@@ -30,7 +30,6 @@ void dsos__exit(struct dsos *dsos);int __dsos__add (struct dsos *dsos,struct dso *dso);int dsos__add (struct dsos *dsos,struct dso *dso); -struct dso *__dsos__addnew (struct dsos *dsos,const char *name);struct dso *dsos__find (struct dsos *dsos,const char *name,bool cmp_short);struct dso *dsos__findnew_id (struct dsos *dsos,const char *name,struct dso_id *id);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 8/12 perf dsos: Remove __dsos__findnew_link_by_longname_id
In reply to Ian RogersFunction was only called in dsos.c with the dso parameter as NULL. Remove the function and specialize for the dso being NULL case removing other unused functions along the way.
--- tools/perf/util/dsos.c | 51 +++++++++--------------------------------- tools/perf/util/dsos.h | 6 ----- 2 files changed, 10 insertions(+), 47 deletions(-)
tools/perf/util/dsos.c +10 -41
@@ -119,11 +119,6 @@ static int __dso__cmp_short_name(const char *short_name, struct dso_id *id, strureturn rc ?:dso_id__cmp (id, &b->id); } -static int dso__cmp_short_name (struct dso *a,struct dso *b) -{ -return __dso__cmp_short_name (a->short_name, &a->id, b); -} -static int dsos__cmp_long_name_id_short_name (const void *va,const void *vb) {const struct dso *a = *((const struct dso **)va);
@@ -143,20 +138,21 @@ static int dsos__cmp_long_name_id_short_name(const void *va, const void *vb)* Either one of the dso or name parameter must be non-NULL or the * function will not work. */ -struct dso *__dsos__findnew_link_by_longname_id (struct dsos *dsos, -struct dso *dso, -const char *name, -struct dso_id *id, -bool write_locked) +static struct dso *__dsos__find_by_longname_id (struct dsos *dsos, +const char *name, +struct dso_id *id, +bool write_locked) {int low =0 , high = dsos->cnt -1 ;if (!dsos->sorted) {if (!write_locked) { +struct dso *dso; +up_read (&dsos->lock);down_write (&dsos->lock); - dso =__dsos__findnew_link_by_longname_id (dsos, dso, name, id, -/*write_locked=*/ true); + dso =__dsos__find_by_longname_id (dsos, name, id, +/*write_locked=*/ true);up_write (&dsos->lock);down_read (&dsos->lock);return dso;
@@ -166,9 +162,6 @@ struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos, dsos->sorted = true; } -if (!name) - name = dso->long_name; -/* * Find node with the matching name */
@@ -178,31 +171,13 @@ struct dso *__dsos__findnew_link_by_longname_id(struct dsos *dsos,int rc =__dso__cmp_long_name (name, id, this);if (rc ==0 ) { -/* -* In case the new DSO is a duplicate of an existing -* one, print a one-time warning & put the new entry -* at the end of the list of duplicates. -*/ -if (!dso || (dso == this)) -return dso__get (this);/* Find matching dso */ -/* -* The core kernel DSOs may have duplicated long name. -* In this case, the short name should be different. -* Comparing the short names to differentiate the DSOs. -*/ - rc =dso__cmp_short_name (dso, this); -if (rc ==0 ) { -pr_err ("Duplicated dso name: %s\n" , name); -return NULL ; - } +return dso__get (this);/* Find matching dso */ }if (rc <0 ) high = mid -1 ;else low = mid +1 ; } -if (dso) -__dsos__add (dsos, dso);return NULL ; }
@@ -240,12 +215,6 @@ int dsos__add(struct dsos *dsos, struct dso *dso)return ret; } -static struct dso *__dsos__findnew_by_longname_id (struct dsos *dsos,const char *name, -struct dso_id *id,bool write_locked) -{ -return __dsos__findnew_link_by_longname_id (dsos,NULL , name, id, write_locked); -} -struct dsos__find_id_cb_args {const char *name;struct dso_id *id;
@@ -279,7 +248,7 @@ static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, struct d__dsos__for_each_dso (dsos, dsos__find_id_cb, &args);return args.res; } - res =__dsos__findnew_by_longname_id (dsos, name, id, write_locked); + res =__dsos__find_by_longname_id (dsos, name, id, write_locked);return res; }
tools/perf/util/dsos.h +0 -6
@@ -36,12 +36,6 @@ struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_idbool dsos__read_build_ids (struct dsos *dsos,bool with_hits); -struct dso *__dsos__findnew_link_by_longname_id (struct dsos *dsos, -struct dso *dso, -const char *name, -struct dso_id *id, -bool write_locked); -size_t dsos__fprintf_buildid (struct dsos *dsos,FILE *fp,bool (skip )(struct dso *dso,int parm),int parm);size_t dsos__fprintf (struct dsos *dsos,FILE *fp);
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 9/12 perf dsos: Switch hand code to bsearch
In reply to Ian RogersSwitch to using the bsearch library function rather than having a hand written binary search. Const-ify some static functions to avoid compiler warnings.
--- tools/perf/util/dsos.c | 46 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-)
tools/perf/util/dsos.c +27 -19
@@ -107,13 +107,15 @@ bool dsos__read_build_ids(struct dsos *dsos, bool with_hits)return args.have_build_id; } -static int __dso__cmp_long_name (const char *long_name,struct dso_id *id,struct dso *b) +static int __dso__cmp_long_name (const char *long_name,const struct dso_id *id, +const struct dso *b) {int rc =strcmp (long_name, b->long_name);return rc ?:dso_id__cmp (id, &b->id); } -static int __dso__cmp_short_name (const char *short_name,struct dso_id *id,struct dso *b) +static int __dso__cmp_short_name (const char *short_name,const struct dso_id *id, +const struct dso *b) {int rc =strcmp (short_name, b->short_name);return rc ?:dso_id__cmp (id, &b->id);
@@ -133,6 +135,19 @@ static int dsos__cmp_long_name_id_short_name(const void *va, const void *vb)return rc; } +struct dsos__key { +const char *long_name; +const struct dso_id *id; +}; + +static int dsos__cmp_key_long_name_id (const void *vkey,const void *vdso) +{ +const struct dsos__key *key = vkey; +const struct dso *dso = *((const struct dso **)vdso); + +return __dso__cmp_long_name (key->long_name, key->id, dso); +} +/* * Find a matching entry and/or link current entry to RB tree. * Either one of the dso or name parameter must be non-NULL or the
@@ -143,7 +158,11 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos, struct dso_id *id, bool write_locked) { - int low = 0, high = dsos->cnt - 1; +struct dsos__key key = { + .long_name = name, + .id = id, + }; +struct dso **res;if (!dsos->sorted) {if (!write_locked) {
@@ -162,23 +181,12 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos, dsos->sorted = true; } -/* -* Find node with the matching name -*/ -while (low <= high) { -int mid = (low + high) /2 ; -struct dso *this = dsos->dsos[mid]; -int rc =__dso__cmp_long_name (name, id, this); + res =bsearch (&key, dsos->dsos, dsos->cnt,sizeof (struct dso *), + dsos__cmp_key_long_name_id); +if (!res) +return NULL ; -if (rc ==0 ) { -return dso__get (this);/* Find matching dso */ - } -if (rc <0 ) - high = mid -1 ; -else - low = mid +1 ; - } -return NULL ; +return dso__get (*res); }int __dsos__add (struct dsos *dsos,struct dso *dso)
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Ian Rogers
reviewerPATCH v3 10/12 perf dso: Add reference count checking and accessor functions
In reply to Ian RogersAdd reference count checking to struct dso, this can help with implementing correct reference counting discipline. To avoid RC_CHK_ACCESS everywhere, add accessor functions for the variables in struct dso.
The majority of the change is mechanical in nature and not easy to split up.
--- tools/perf/builtin-annotate.c | 8 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 18 +- tools/perf/builtin-inject.c | 71 ++- tools/perf/builtin-kallsyms.c | 2 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 8 +- tools/perf/builtin-top.c | 4 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 8 +- tools/perf/tests/dso-data.c | 11 +- tools/perf/tests/hists_common.c | 6 +- tools/perf/tests/hists_cumulate.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/maps.c | 4 +- tools/perf/tests/symbols.c | 8 +- tools/perf/tests/vmlinux-kallsyms.c | 6 +- tools/perf/ui/browsers/annotate.c | 6 +- tools/perf/ui/browsers/hists.c | 8 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate-data.c | 14 +- tools/perf/util/annotate.c | 17 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/block-info.c | 2 +- tools/perf/util/bpf-event.c | 8 +- tools/perf/util/build-id.c | 38 +- tools/perf/util/callchain.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/db-export.c | 6 +- tools/perf/util/disasm.c | 34 +- tools/perf/util/dlfilter.c | 12 +- tools/perf/util/dso.c | 368 +++++++------ tools/perf/util/dso.h | 488 ++++++++++++++++-- tools/perf/util/dsos.c | 54 +- tools/perf/util/event.c | 8 +- tools/perf/util/header.c | 8 +- tools/perf/util/hist.c | 4 +- tools/perf/util/intel-pt.c | 22 +- tools/perf/util/machine.c | 46 +- tools/perf/util/map.c | 77 ++- tools/perf/util/maps.c | 14 +- tools/perf/util/print_insn.c | 2 +- tools/perf/util/probe-event.c | 25 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 21 +- tools/perf/util/sort.c | 19 +- tools/perf/util/srcline.c | 65 +-- tools/perf/util/symbol-elf.c | 94 ++-- tools/perf/util/symbol-minimal.c | 4 +- tools/perf/util/symbol.c | 186 +++---- tools/perf/util/symbol_fprintf.c | 4 +- tools/perf/util/synthetic-events.c | 24 +- tools/perf/util/thread.c | 4 +- tools/perf/util/unwind-libunwind-local.c | 18 +- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/vdso.c | 8 +- 57 files changed, 1165 insertions(+), 735 deletions(-)
tools/perf/builtin-annotate.c +4 -4
@@ -218,7 +218,7 @@ static int process_branch_callback(struct evsel *evsel, }if (a.map !=NULL ) -map__dso (a.map)->hit =1 ; +dso__set_hit (map__dso (a.map));hist__account_cycles (sample->branch_stack, al, sample, false,NULL );
@@ -253,7 +253,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,if (al->sym !=NULL ) {struct dso *dso =map__dso (al->map); -rb_erase_cached (&al->sym->rb_node, &dso->symbols); +rb_erase_cached (&al->sym->rb_node,dso__symbols (dso));symbol__delete (al->sym);dso__reset_find_symbol_cache (dso); }
@@ -344,7 +344,7 @@ static void print_annotated_data_header(struct hist_entry *he, struct evsel *evs }printf ("Annotate type: '%s' in %s (%d samples):\n" , - he->mem_type->self.type_name, dso->name, nr_samples); + he->mem_type->self.type_name,dso__name (dso), nr_samples);if (evsel__is_group_event (evsel)) {struct evsel *pos;
@@ -520,7 +520,7 @@ static void hists__find_annotations(struct hists *hists, struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);struct annotation *notes; -if (he->ms.sym ==NULL ||map__dso (he->ms.map)->annotate_warned) +if (he->ms.sym ==NULL ||dso__annotate_warned (map__dso (he->ms.map))) goto find_next; if (ann->sym_hist_filter &&
tools/perf/builtin-buildid-cache.c +1 -1
@@ -286,7 +286,7 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)pr_warning ("Problems with %s file, consider removing it from the cache\n" , filename); - }else if (memcmp (dso->bid.data, bid.data, bid.size)) { + }else if (memcmp (dso__bid (dso)->data, bid.data, bid.size)) {pr_warning ("Problems with %s file, consider removing it from the cache\n" , filename); }
tools/perf/builtin-buildid-list.c +10 -8
@@ -26,16 +26,18 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused) {const struct dso *dso =map__dso (map);char bid_buf[SBUILD_ID_SIZE ]; +const char *dso_long_name =dso__long_name (dso); +const char *dso_short_name =dso__short_name (dso);memset (bid_buf,0 ,sizeof (bid_buf)); -if (dso->has_build_id) -build_id__sprintf (&dso->bid, bid_buf); +if (dso__has_build_id (dso)) +build_id__sprintf (dso__bid_const (dso), bid_buf);printf ("%s %16" PRIx64" %16" PRIx64, bid_buf,map__start (map),map__end (map)); -if (dso->long_name !=NULL ) { -printf (" %s" , dso->long_name); - }else if (dso->short_name !=NULL ) { -printf (" %s" , dso->short_name); - } +if (dso_long_name !=NULL ) +printf (" %s" , dso_long_name); +else if (dso_short_name !=NULL ) +printf (" %s" , dso_short_name); +printf ("\n" );return 0 ;
@@ -76,7 +78,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)static bool dso__skip_buildid (struct dso *dso,int with_hits) { -return with_hits && !dso->hit; +return with_hits && !dso__hit (dso); }static int perf_session__list_build_ids (bool force,bool with_hits)
tools/perf/builtin-inject.c +35 -36
166 lines not on this page · raw message
tools/perf/builtin-kallsyms.c +1 -1
@@ -38,7 +38,7 @@ static int __cmd_kallsyms(int argc, const char **argv) dso =map__dso (map);printf ("%s: %s %s %#" PRIx64"-%#" PRIx64" (%#" PRIx64"-%#" PRIx64")\n" , - symbol->name, dso->short_name, dso->long_name, + symbol->name,dso__short_name (dso),dso__long_name (dso),map__unmap_ip (map, symbol->start),map__unmap_ip (map, symbol->end), symbol->start, symbol->end); }
tools/perf/builtin-mem.c +2 -2
@@ -213,7 +213,7 @@ dump_raw_samples(struct perf_tool *tool,if (al.map !=NULL ) { dso =map__dso (al.map);if (dso) - dso->hit =1 ; +dso__set_hit (dso); } field_sep = symbol_conf.field_sep;
@@ -255,7 +255,7 @@ dump_raw_samples(struct perf_tool *tool, symbol_conf.field_sep, sample->data_src, symbol_conf.field_sep, - dso ? dso->long_name :"???" , + dso ?dso__long_name (dso) :"???" , al.sym ? al.sym->name : "???"); out_put:addr_location__exit (&al);
tools/perf/builtin-report.c +3 -3
@@ -322,7 +322,7 @@ static int process_sample_event(struct perf_tool *tool, }if (al.map !=NULL ) -map__dso (al.map)->hit =1 ; +dso__set_hit (map__dso (al.map));if (ui__has_annotation () || rep->symbol_ipc || rep->total_cycles_mode) { hist__account_cycles(sample->branch_stack, &al, sample,
@@ -609,7 +609,7 @@ static void report__warn_kptr_restrict(const struct report *rep)return ;if (kernel_map ==NULL || - (map__dso (kernel_map)->hit && + (dso__hit (map__dso (kernel_map)) && (kernel_kmap->ref_reloc_sym ==NULL || kernel_kmap->ref_reloc_sym->addr ==0 ))) { const char *desc =
@@ -850,7 +850,7 @@ static int maps__fprintf_task_cb(struct map *map, void *data) prot &PROT_EXEC ?'x' :'-' ,map__flags (map) ?'s' :'p' ,map__pgoff (map), - dso->id.ino, dso->name); + dso__id_const(dso)->ino, dso__name(dso));if (ret <0 )return ret;
tools/perf/builtin-script.c +4 -4
@@ -1017,11 +1017,11 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, to = entries[i].to;if (thread__find_map_fb (thread, sample->cpumode, from, &alf) && - !map__dso (alf.map)->adjust_symbols) + !dso__adjust_symbols (map__dso (alf.map))) from =map__dso_map_ip (alf.map, from);if (thread__find_map_fb (thread, sample->cpumode, to, &alt) && - !map__dso (alt.map)->adjust_symbols) + !dso__adjust_symbols (map__dso (alt.map))) to =map__dso_map_ip (alt.map, to); printed +=fprintf (fp," 0x%" PRIx64, from);
@@ -1082,7 +1082,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,pr_debug ("\tcannot resolve %" PRIx64"-%" PRIx64"\n" , start, end); goto out; } -if (dso->data.status ==DSO_DATA_STATUS_ERROR ) { +if (dso__data (dso)->status ==DSO_DATA_STATUS_ERROR ) {pr_debug ("\tcannot resolve %" PRIx64"-%" PRIx64"\n" , start, end); goto out; }
@@ -1094,7 +1094,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end, len =dso__data_read_offset (dso, machine, offset, (u8 *)buffer, end - start +MAXINSN ); - *is64bit = dso->is_64_bit; + *is64bit =dso__is_64_bit (dso);if (len <=0 )pr_debug ("\tcannot fetch code for block at %" PRIx64"-%" PRIx64"\n" , start, end);
tools/perf/builtin-top.c +2 -2
@@ -129,7 +129,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)/* * We can't annotate with just /proc/kallsyms */ -if (dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso)) { +if (dso__symtab_type (dso) ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso)) {pr_err ("Can't annotate %s: No vmlinux file was found in the " "path\n" , sym->name);sleep (1 );
@@ -182,7 +182,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)"Tools: %s\n\n" "Not all samples will be on the annotation output.\n\n" "Please report to [email protected]\n" , - ip, dso->long_name,dso__symtab_origin (dso), + ip,dso__long_name (dso),dso__symtab_origin (dso),map__start (map),map__end (map), sym->start, sym->end, sym->binding ==STB_GLOBAL ?'g' : sym->binding == STB_LOCAL ? 'l' : 'w', sym->name,
tools/perf/builtin-trace.c +1 -1
@@ -2917,7 +2917,7 @@ static void print_location(FILE *f, struct perf_sample *sample, {if ((verbose >0 || print_dso) && al->map) -fprintf (f,"%s@" ,map__dso (al->map)->long_name); +fprintf (f,"%s@" ,dso__long_name (map__dso (al->map)));if ((verbose >0 || print_sym) && al->sym) fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/tests/code-reading.c +4 -4
@@ -253,9 +253,9 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, goto out; } dso =map__dso (al.map); -pr_debug ("File is: %s\n" , dso->long_name); +pr_debug ("File is: %s\n" ,dso__long_name (dso)); -if (dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso)) { +if (dso__symtab_type (dso) ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso)) {pr_debug ("Unexpected kernel address - skipping\n" ); goto out; }
@@ -274,7 +274,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,* modules to manage long jumps. Check if the ip offset falls in stubs * sections for kernel modules. And skip module address after text end */ -if (dso->is_kmod && al.addr > dso->text_end) { +if (dso__is_kmod (dso) && al.addr >dso__text_end (dso)) {pr_debug ("skipping the module address %#" PRIx64" after text end\n" , al.addr); goto out; }
@@ -315,7 +315,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, state->done[state->done_cnt++] =map__start (al.map); } - objdump_name = dso->long_name; + objdump_name =dso__long_name (dso);if (dso__needs_decompress (dso)) { if (dso__decompress_kmodule_path(dso, objdump_name, decomp_name,
tools/perf/tests/dso-data.c +6 -5
@@ -228,7 +228,8 @@ static void dsos__delete(int cnt)for (i =0 ; i < cnt; i++) {struct dso *dso = dsos[i]; -unlink (dso->name); +dso__data_close (dso); +unlink (dso__name (dso));dso__put (dso); }
@@ -289,14 +290,14 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt }/* verify the first one is already open */ -TEST_ASSERT_VAL ("dsos[0] is not open" , dsos[0 ]->data.fd !=-1 ); +TEST_ASSERT_VAL ("dsos[0] is not open" ,dso__data (dsos[0 ])->fd !=-1 );/* open +1 dso to reach the allowed limit */ fd =dso__data_fd (dsos[i], &machine);TEST_ASSERT_VAL ("failed to get fd" , fd >0 );/* should force the first one to be closed */ -TEST_ASSERT_VAL ("failed to close dsos[0]" , dsos[0 ]->data.fd ==-1 ); +TEST_ASSERT_VAL ("failed to close dsos[0]" ,dso__data (dsos[0 ])->fd ==-1 );/* cleanup everything */ dsos__delete (dso_cnt);
@@ -371,7 +372,7 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sub* dso_0 should get closed, because we reached * the file descriptor limit */ -TEST_ASSERT_VAL ("failed to close dso_0" , dso_0->data.fd ==-1 ); +TEST_ASSERT_VAL ("failed to close dso_0" ,dso__data (dso_0)->fd ==-1 );/* open dso_0 */ fd =dso__data_fd (dso_0, &machine);
@@ -381,7 +382,7 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sub* dso_1 should get closed, because we reached * the file descriptor limit */ -TEST_ASSERT_VAL ("failed to close dso_1" , dso_1->data.fd ==-1 ); +TEST_ASSERT_VAL ("failed to close dso_1" ,dso__data (dso_1)->fd ==-1 );/* cleanup everything */ close (fd_extra);
tools/perf/tests/hists_common.c +3 -3
@@ -146,7 +146,7 @@ struct machine *setup_fake_machine(struct machines *machines) goto out; } -symbols__insert (&dso->symbols, sym); +symbols__insert (dso__symbols (dso), sym); }dso__put (dso);
@@ -183,7 +183,7 @@ void print_hists_in(struct hists *hists)pr_info ("%2d: entry: %-8s [%-8s] %20s: period = %" PRIu64"\n" , i,thread__comm_str (he->thread), - dso->short_name, +dso__short_name (dso), he->ms.sym->name, he->stat.period); }
@@ -212,7 +212,7 @@ void print_hists_out(struct hists *hists)pr_info ("%2d: entry: %8s:%5d [%-8s] %20s: period = %" PRIu64"/%" PRIu64"\n" , i,thread__comm_str (he->thread),thread__tid (he->thread), - dso->short_name, +dso__short_name (dso), he->ms.sym->name, he->stat.period, he->stat_acc ? he->stat_acc->period :0 ); }
tools/perf/tests/hists_cumulate.c +2 -2
@@ -164,11 +164,11 @@ static void put_fake_samples(void)typedef int (*test_fn_t )(struct evsel *,struct machine *);#define COMM (he) (thread__comm_str(he->thread)) -#define DSO (he) (map__dso(he->ms.map)->short_name) +#define DSO (he) (dso__short_name(map__dso(he->ms.map)))#define SYM (he) (he->ms.sym->name)#define CPU (he) (he->cpu)#define DEPTH (he) (he->callchain->max_depth) -#define CDSO (cl) (map__dso(cl->ms.map)->short_name) +#define CDSO (cl) (dso__short_name(map__dso(cl->ms.map)))#define CSYM (cl) (cl->ms.sym->name)struct result {
tools/perf/tests/hists_output.c +1 -1
@@ -129,7 +129,7 @@ static void put_fake_samples(void)typedef int (*test_fn_t )(struct evsel *,struct machine *);#define COMM (he) (thread__comm_str(he->thread)) -#define DSO (he) (map__dso(he->ms.map)->short_name) +#define DSO (he) (dso__short_name(map__dso(he->ms.map)))#define SYM (he) (he->ms.sym->name)#define CPU (he) (he->cpu)#define PID (he) (thread__tid(he->thread))
tools/perf/tests/maps.c +2 -2
@@ -26,7 +26,7 @@ static int check_maps_cb(struct map *map, void *data)if (map__start (map) != merged->start ||map__end (map) != merged->end || -strcmp (map__dso (map)->name, merged->name) || +strcmp (dso__name (map__dso (map)), merged->name) ||refcount_read (map__refcnt (map)) !=1 ) {return 1 ; }
@@ -39,7 +39,7 @@ static int failed_cb(struct map *map, void *data __maybe_unused)pr_debug ("\tstart: %" PRIu64" end: %" PRIu64" name: '%s' refcnt: %d\n" ,map__start (map),map__end (map), -map__dso (map)->name, +dso__name (map__dso (map)),refcount_read (map__refcnt (map)));return 0 ;
tools/perf/tests/symbols.c +4 -4
@@ -81,7 +81,7 @@ static int create_map(struct test_info *ti, char *filename, struct map **map_p)* If 'filename' matches a current kernel module, must use a kernel * map. Find the one that already exists. */ -if (dso && dso->kernel) { +if (dso &&dso__kernel (dso) !=DSO_SPACE__USER ) { *map_p =find_module_map (ti->machine, dso);dso__put (dso);if (!*map_p) {
@@ -116,7 +116,7 @@ static int test_dso(struct dso *dso)if (verbose >1 )dso__fprintf (dso, stderr); -for (nd =rb_first_cached (&dso->symbols); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (dso__symbols (dso)); nd; nd =rb_next (nd)) { struct symbol *sym = rb_entry(nd, struct symbol, rb_node);if (sym->type !=STT_FUNC && sym->type !=STT_GNU_IFUNC )
@@ -145,7 +145,7 @@ static int subdivided_dso_cb(struct dso *dso, struct machine *machine __maybe_un {struct dso *text_dso = d; -if (dso != text_dso &&strstarts (dso->short_name, text_dso->short_name)) +if (dso != text_dso &&strstarts (dso__short_name (dso),dso__short_name (text_dso)))if (test_dso (dso) !=TEST_OK )return -1 ;
@@ -190,7 +190,7 @@ static int test_file(struct test_info *ti, char *filename) ret =test_dso (dso);/* Module dso is split into many dsos by section */ -if (ret ==TEST_OK && dso->kernel) +if (ret ==TEST_OK &&dso__kernel (dso) !=DSO_SPACE__USER ) ret =process_subdivided_dso (ti->machine, dso); out_put:map__put (map);
tools/perf/tests/vmlinux-kallsyms.c +3 -3
@@ -129,7 +129,7 @@ static int test__vmlinux_matches_kallsyms_cb1(struct map *map, void *data)* cases. */ struct map *pair =maps__find_by_name (args->kallsyms.kmaps, - (dso->kernel ? dso->short_name : dso->name)); + (dso__kernel (dso) ?dso__short_name (dso) :dso__name (dso)));if (pair) {map__set_priv (pair,1 );
@@ -162,11 +162,11 @@ static int test__vmlinux_matches_kallsyms_cb2(struct map *map, void *data) }pr_info ("WARN: %" PRIx64"-%" PRIx64" %" PRIx64" %s in kallsyms as" , -map__start (map),map__end (map),map__pgoff (map), dso->name); +map__start (map),map__end (map),map__pgoff (map),dso__name (dso));if (mem_end !=map__end (pair))pr_info (":\nWARN: *%" PRIx64"-%" PRIx64" %" PRIx64,map__start (pair),map__end (pair),map__pgoff (pair)); -pr_info (" %s\n" , dso->name); +pr_info (" %s\n" ,dso__name (dso));map__set_priv (pair,1 ); }map__put (pair);
tools/perf/ui/browsers/annotate.c +3 -3
@@ -438,7 +438,7 @@ static int sym_title(struct symbol *sym, struct map *map, char *title, size_t sz, int percent_type) {return snprintf (title, sz,"%s %s [Percent: %s]" , sym->name, -map__dso (map)->long_name, +dso__long_name (map__dso (map)),percent_type_str (percent_type)); }
@@ -967,14 +967,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,return -1 ; dso =map__dso (ms->map); -if (dso->annotate_warned) +if (dso__annotate_warned (dso))return -1 ;if (not_annotated) { err =symbol__annotate2 (ms, evsel, &browser.arch);if (err) {char msg[BUFSIZ ]; - dso->annotate_warned = true; +dso__set_annotate_warned (dso);symbol__strerror_disassemble (ms, err, msg,sizeof (msg));ui__error ("Couldn't annotate %s:\n%s" , sym->name, msg);return -1 ;
tools/perf/ui/browsers/hists.c +4 -4
@@ -2488,7 +2488,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused, {struct dso *dso; -if (!ms->map || (dso =map__dso (ms->map)) ==NULL || dso->annotate_warned) +if (!ms->map || (dso =map__dso (ms->map)) ==NULL ||dso__annotate_warned (dso))return 0 ;if (!ms->sym)
@@ -2581,7 +2581,7 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map }else {struct dso *dso =map__dso (map);ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"" , -__map__is_kernel (map) ?"the Kernel" : dso->short_name); +__map__is_kernel (map) ?"the Kernel" :dso__short_name (dso)); browser->hists->dso_filter = dso;perf_hpp__set_elide (HISTC_DSO , true);pstack__push (browser->pstack, &browser->hists->dso_filter);
@@ -2607,7 +2607,7 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,if (asprintf (optstr,"Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)" , browser->hists->dso_filter ?"out of" :"into" , -__map__is_kernel (map) ?"the Kernel" :map__dso (map)->short_name) <0 ) +__map__is_kernel (map) ?"the Kernel" :dso__short_name (map__dso (map))) <0 )return 0 ; act->ms.map = map;
@@ -3083,7 +3083,7 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *hif (!browser->selection || !browser->selection->map || !map__dso (browser->selection->map) || -map__dso (browser->selection->map)->annotate_warned) { +dso__annotate_warned (map__dso (browser->selection->map))) {continue ; }
tools/perf/ui/browsers/map.c +2 -2
@@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser) {int key; -if (ui_browser__show (&browser->b,map__dso (browser->map)->long_name, +if (ui_browser__show (&browser->b,dso__long_name (map__dso (browser->map)),"Press ESC to exit, %s / to search" , verbose >0 ?"" :"restart with -v to use" ) <0 )return -1 ;
@@ -106,7 +106,7 @@ int map__browse(struct map *map) {struct map_browser mb = { .b = { - .entries = &map__dso (map)->symbols, + .entries =dso__symbols (map__dso (map)), .refresh = ui_browser__rb_tree_refresh, .seek = ui_browser__rb_tree_seek, .write = map_browser__write,
tools/perf/util/annotate-data.c +7 -7
@@ -275,7 +275,7 @@ static struct annotated_data_type *dso__findnew_data_type(struct dso *dso,/* Check existing nodes in dso->data_types tree */ key.self.type_name = type_name; key.self.size = size; - node =rb_find (&key, &dso->data_types, data_type_cmp); + node =rb_find (&key,dso__data_types (dso), data_type_cmp);if (node) { result = rb_entry(node, struct annotated_data_type, node);free (type_name);
@@ -296,7 +296,7 @@ static struct annotated_data_type *dso__findnew_data_type(struct dso *dso,if (symbol_conf.annotate_data_member)add_member_types (result, type_die); -rb_add (&result->node, &dso->data_types, data_type_less); +rb_add (&result->node,dso__data_types (dso), data_type_less);return result; }
@@ -469,7 +469,7 @@ static struct global_var_entry *global_var__find(struct data_loc_info *dloc, u64struct dso *dso =map__dso (dloc->ms->map);struct rb_node *node; - node =rb_find ((void *)(uintptr_t )addr, &dso->global_vars, global_var_cmp); + node =rb_find ((void *)(uintptr_t )addr,dso__global_vars (dso), global_var_cmp);if (node ==NULL )return NULL ;
@@ -500,7 +500,7 @@ static bool global_var__add(struct data_loc_info *dloc, u64 addr, gvar->end = addr + size; gvar->die_offset =dwarf_dieoffset (type_die); -rb_add (&gvar->node, &dso->global_vars, global_var_less); +rb_add (&gvar->node,dso__global_vars (dso), global_var_less);return true; }
@@ -768,7 +768,7 @@ static void update_insn_state_x86(struct type_state *state,return ; tsr = &state->regs[dst->reg1]; -if (map__dso (dloc->ms->map)->kernel && +if (dso__kernel (map__dso (dloc->ms->map)) && src->segment ==INSN_SEG_X86_GS && src->imm) {u64 ip = dloc->ms->sym->start + dl->al.offset;u64 var_addr;
@@ -1255,7 +1255,7 @@ static int check_matching_type(struct type_state *state,return -1 ; } -if (map__dso (dloc->ms->map)->kernel &&arch__is (dloc->arch,"x86" )) { +if (dso__kernel (map__dso (dloc->ms->map)) &&arch__is (dloc->arch,"x86" )) {u64 addr;int offset;
@@ -1593,7 +1593,7 @@ struct annotated_data_type *find_data_type(struct data_loc_info *dloc)struct dso *dso =map__dso (dloc->ms->map);Dwarf_Die type_die; - dloc->di =debuginfo__new (dso->long_name); + dloc->di =debuginfo__new (dso__long_name (dso));if (dloc->di ==NULL ) {pr_debug_dtp ("cannot get the debug info\n" );return NULL ;
tools/perf/util/annotate.c +8 -9
@@ -1093,7 +1093,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel)int graph_dotted_len;char buf[512 ]; - filename =strdup (dso->long_name); + filename =strdup (dso__long_name (dso));if (!filename)return -ENOMEM ;
@@ -1258,7 +1258,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel) }fprintf (fp,"%s() %s\nEvent: %s\n\n" , - ms->sym->name,map__dso (ms->map)->long_name, ev_name); + ms->sym->name,dso__long_name (map__dso (ms->map)), ev_name);symbol__annotate_fprintf2 (ms->sym, fp);fclose (fp);
@@ -1516,7 +1516,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel)if (err) {char msg[BUFSIZ ]; - dso->annotate_warned = true; +dso__set_annotate_warned (dso);symbol__strerror_disassemble (ms, err, msg,sizeof (msg));ui__error ("Couldn't annotate %s:\n%s" , sym->name, msg);return -1 ;
@@ -1525,13 +1525,12 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel)if (annotate_opts.print_lines) { srcline_full_filename = annotate_opts.full_path;symbol__calc_lines (ms, &source_line); -print_summary (&source_line, dso->long_name); +print_summary (&source_line,dso__long_name (dso)); }hists__scnprintf_title (hists, buf,sizeof (buf));fprintf (stdout,"%s, [percent: %s]\n%s() %s\n" , - buf,percent_type_str (annotate_opts.percent_type), sym->name, - dso->long_name); + buf,percent_type_str (annotate_opts.percent_type), sym->name,dso__long_name (dso));symbol__annotate_fprintf2 (sym, stdout);annotated_source__purge (symbol__annotation (sym)->src);
@@ -1550,7 +1549,7 @@ int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel)if (err) {char msg[BUFSIZ ]; - dso->annotate_warned = true; +dso__set_annotate_warned (dso);symbol__strerror_disassemble (ms, err, msg,sizeof (msg));ui__error ("Couldn't annotate %s:\n%s" , sym->name, msg);return -1 ;
@@ -1561,7 +1560,7 @@ int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel)if (annotate_opts.print_lines) { srcline_full_filename = annotate_opts.full_path;symbol__calc_lines (ms, &source_line); -print_summary (&source_line, dso->long_name); +print_summary (&source_line,dso__long_name (dso)); }symbol__annotate_printf (ms, evsel);
@@ -2390,7 +2389,7 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) }/* This CPU access in kernel - pretend PC-relative addressing */ -if (map__dso (ms->map)->kernel &&arch__is (arch,"x86" ) && +if (dso__kernel (map__dso (ms->map)) &&arch__is (arch,"x86" ) && op_loc->segment ==INSN_SEG_X86_GS && op_loc->imm) { dloc.var_addr = op_loc->offset; op_loc->reg1 =DWARF_REG_PC ;
tools/perf/util/auxtrace.c +1 -1
@@ -2654,7 +2654,7 @@ static int addr_filter__entire_dso(struct addr_filter *filt, struct dso *dso) } filt->addr =0 ; - filt->size = dso->data.file_size; + filt->size =dso__data (dso)->file_size;return 0 ; }
tools/perf/util/block-info.c +1 -1
@@ -319,7 +319,7 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,if (map &&map__dso (map)) {return scnprintf (hpp->buf, hpp->size,"%*s" , block_fmt->width, -map__dso (map)->short_name); +dso__short_name (map__dso (map))); } return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
tools/perf/util/bpf-event.c +4 -4
@@ -59,10 +59,10 @@ static int machine__process_bpf_event_load(struct machine *machine,if (map) {struct dso *dso =map__dso (map); - dso->binary_type =DSO_BINARY_TYPE__BPF_PROG_INFO ; - dso->bpf_prog.id = id; - dso->bpf_prog.sub_id = i; - dso->bpf_prog.env = env; +dso__set_binary_type (dso,DSO_BINARY_TYPE__BPF_PROG_INFO ); +dso__bpf_prog (dso)->id = id; +dso__bpf_prog (dso)->sub_id = i; +dso__bpf_prog (dso)->env = env;map__put (map); } }
tools/perf/util/build-id.c +19 -19
@@ -60,7 +60,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,addr_location__init (&al);if (thread__find_map (thread, sample->cpumode, sample->ip, &al)) -map__dso (al.map)->hit =1 ; +dso__set_hit (map__dso (al.map));addr_location__exit (&al);thread__put (thread);
@@ -272,10 +272,10 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size,bool alloc = (bf ==NULL );int ret; -if (!dso->has_build_id) +if (!dso__has_build_id (dso))return NULL ; -build_id__sprintf (&dso->bid, sbuild_id); +build_id__sprintf (dso__bid_const (dso), sbuild_id); linkname =build_id_cache__linkname (sbuild_id,NULL ,0 );if (!linkname)return NULL ;
@@ -340,25 +340,25 @@ static int machine__write_buildid_table_cb(struct dso *dso, void *data)size_t name_len;bool in_kernel = false; -if (!dso->has_build_id) +if (!dso__has_build_id (dso))return 0 ; -if (!dso->hit && !dso__is_vdso (dso)) +if (!dso__hit (dso) && !dso__is_vdso (dso))return 0 ;if (dso__is_vdso (dso)) { - name = dso->short_name; - name_len = dso->short_name_len; + name =dso__short_name (dso); + name_len =dso__short_name_len (dso); }else if (dso__is_kcore (dso)) { name = args->machine->mmap_name; name_len =strlen (name); }else { - name = dso->long_name; - name_len = dso->long_name_len; + name =dso__long_name (dso); + name_len =dso__long_name_len (dso); } - in_kernel = dso->kernel ||is_kernel_module (name,PERF_RECORD_MISC_CPUMODE_UNKNOWN ); -return write_buildid (name, name_len, &dso->bid, args->machine->pid, + in_kernel =dso__kernel (dso) ||is_kernel_module (name,PERF_RECORD_MISC_CPUMODE_UNKNOWN ); +return write_buildid (name, name_len,dso__bid (dso), args->machine->pid, in_kernel ? args->kmisc : args->umisc, args->fd); }
@@ -876,11 +876,11 @@ static bool dso__build_id_mismatch(struct dso *dso, const char *name)struct build_id bid;bool ret = false; -mutex_lock (&dso->lock); -if (filename__read_build_id_ns (name, &bid, dso->nsinfo) >=0 ) +mutex_lock (dso__lock (dso)); +if (filename__read_build_id_ns (name, &bid,dso__nsinfo (dso)) >=0 ) ret = !dso__build_id_equal (dso, &bid); -mutex_unlock (&dso->lock); +mutex_unlock (dso__lock (dso));return ret; }
@@ -890,13 +890,13 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine, {bool is_kallsyms =dso__is_kallsyms (dso);bool is_vdso =dso__is_vdso (dso); -const char *name = dso->long_name; +const char *name =dso__long_name (dso);const char *proper_name =NULL ;const char *root_dir =NULL ;char *allocated_name =NULL ;int ret =0 ; -if (!dso->has_build_id) +if (!dso__has_build_id (dso))return 0 ;if (dso__is_kcore (dso)) {
@@ -921,10 +921,10 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,if (!is_kallsyms &&dso__build_id_mismatch (dso, name)) goto out_free; -mutex_lock (&dso->lock); - ret =build_id_cache__add_b (&dso->bid, name, dso->nsinfo, +mutex_lock (dso__lock (dso)); + ret =build_id_cache__add_b (dso__bid (dso), name,dso__nsinfo (dso), is_kallsyms, is_vdso, proper_name, root_dir); -mutex_unlock (&dso->lock); +mutex_unlock (dso__lock (dso)); out_free:free (allocated_name);return ret;
tools/perf/util/callchain.c +1 -1
@@ -1205,7 +1205,7 @@ char *callchain_list__sym_name(struct callchain_list *cl,if (show_dso)scnprintf (bf + printed, bfsize - printed," %s" , cl->ms.map ? -map__dso (cl->ms.map)->short_name : +dso__short_name (map__dso (cl->ms.map)) :"unknown" );return bf;
tools/perf/util/data-convert-json.c +1 -1
@@ -134,7 +134,7 @@ static void output_sample_callchain_entry(struct perf_tool *tool,output_json_key_string (out, false,5 ,"symbol" , al->sym->name);if (dso) { -const char *dso_name = dso->short_name; +const char *dso_name =dso__short_name (dso);if (dso_name &&strlen (dso_name) >0 ) {fputc (',' , out);
tools/perf/util/db-export.c +3 -3
@@ -146,10 +146,10 @@ int db_export__comm_thread(struct db_export *dbe, struct comm *comm,int db_export__dso (struct db_export *dbe,struct dso *dso,struct machine *machine) { -if (dso->db_id) +if (dso__db_id (dso))return 0 ; - dso->db_id = ++dbe->dso_last_db_id; +dso__set_db_id (dso, ++dbe->dso_last_db_id);if (dbe->export_dso)return dbe->export_dso (dbe, dso, machine);
@@ -184,7 +184,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al, err =db_export__dso (dbe, dso,maps__machine (al->maps));if (err)return err; - *dso_db_id = dso->db_id; + *dso_db_id =dso__db_id (dso);if (!al->sym) { al->sym =symbol__new (al->addr,0 ,0 ,0 ,"unknown" );
tools/perf/util/disasm.c +17 -17
@@ -1054,8 +1054,8 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, schar bf[SBUILD_ID_SIZE +15 ] =" with build id " ;char *build_id_msg =NULL ; -if (dso->has_build_id) { -build_id__sprintf (&dso->bid, bf +15 ); +if (dso__has_build_id (dso)) { +build_id__sprintf (dso__bid (dso), bf +15 ); build_id_msg = bf; } scnprintf(buf, buflen,
@@ -1077,11 +1077,11 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, sscnprintf (buf, buflen,"Problems while parsing the CPUID in the arch specific initialization." );break ;case SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE : -scnprintf (buf, buflen,"Invalid BPF file: %s." , dso->long_name); +scnprintf (buf, buflen,"Invalid BPF file: %s." ,dso__long_name (dso));break ;case SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF :scnprintf (buf, buflen,"The %s BPF file has no BTF section, compile with -g or use pahole -J." , - dso->long_name); +dso__long_name (dso));break ;default :scnprintf (buf, buflen,"Internal error: Invalid %d error code\n" , errnum);
@@ -1099,7 +1099,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filchar *pos;int len; -if (dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && +if (dso__symtab_type (dso) ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso))return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX ;
@@ -1108,7 +1108,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil__symbol__join_symfs (filename, filename_size, build_id_filename);free (build_id_filename); }else { -if (dso->has_build_id) +if (dso__has_build_id (dso))return ENOMEM ; goto fallback; }
@@ -1142,20 +1142,20 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil* cache, or is just a kallsyms file, well, lets hope that this * DSO is the same as when 'perf record' ran. */ -if (dso->kernel && dso->long_name[0 ] =='/' ) -snprintf (filename, filename_size,"%s" , dso->long_name); +if (dso__kernel (dso) &&dso__long_name (dso)[0 ] =='/' ) +snprintf (filename, filename_size,"%s" ,dso__long_name (dso));else -__symbol__join_symfs (filename, filename_size, dso->long_name); +__symbol__join_symfs (filename, filename_size,dso__long_name (dso)); -mutex_lock (&dso->lock); -if (access (filename,R_OK ) && errno ==ENOENT && dso->nsinfo) { +mutex_lock (dso__lock (dso)); +if (access (filename,R_OK ) && errno ==ENOENT &&dso__nsinfo (dso)) {char *new_name =dso__filename_with_chroot (dso, filename);if (new_name) {strlcpy (filename, new_name, filename_size);free (new_name); } } -mutex_unlock (&dso->lock); +mutex_unlock (dso__lock (dso)); }free (build_id_path);
@@ -1423,7 +1423,7 @@ static void print_capstone_detail(cs_insn *insn, char *buf, size_t len, orig_addr = addr + insn->size + op->mem.disp; addr =map__objdump_2mem (map, orig_addr); -if (map__dso (map)->kernel) { +if (dso__kernel (map__dso (map))) {/* * The kernel maps can be splitted into sections, * let's find the map first and the search the symbol.
@@ -1477,7 +1477,7 @@ static int symbol__disassemble_capstone(char *filename, struct symbol *sym,if (args->options->objdump_path)return -1 ; -nsinfo__mountns_enter (dso->nsinfo, &nsc); +nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); fd =open (filename,O_RDONLY );nsinfo__mountns_exit (&nsc);if (fd <0 )
@@ -1663,11 +1663,11 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args) map__unmap_ip(map, sym->end));pr_debug ("annotating [%p] %30s : [%p] %30s\n" , - dso, dso->long_name, sym, sym->name); + dso,dso__long_name (dso), sym, sym->name); -if (dso->binary_type ==DSO_BINARY_TYPE__BPF_PROG_INFO ) { +if (dso__binary_type (dso) ==DSO_BINARY_TYPE__BPF_PROG_INFO ) {return symbol__disassemble_bpf (sym, args); - }else if (dso->binary_type ==DSO_BINARY_TYPE__BPF_IMAGE ) { + }else if (dso__binary_type (dso) ==DSO_BINARY_TYPE__BPF_IMAGE ) {return symbol__disassemble_bpf_image (sym, args); }else if (dso__is_kcore (dso)) { kce.kcore_filename = symfs_filename;
tools/perf/util/dlfilter.c +6 -6
@@ -33,13 +33,13 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)if (al->map) {struct dso *dso =map__dso (al->map); -if (symbol_conf.show_kernel_path && dso->long_name) - d_al->dso = dso->long_name; +if (symbol_conf.show_kernel_path &&dso__long_name (dso)) + d_al->dso =dso__long_name (dso);else - d_al->dso = dso->name; - d_al->is_64_bit = dso->is_64_bit; - d_al->buildid_size = dso->bid.size; - d_al->buildid = dso->bid.data; + d_al->dso =dso__name (dso); + d_al->is_64_bit =dso__is_64_bit (dso); + d_al->buildid_size =dso__bid (dso)->size; + d_al->buildid =dso__bid (dso)->data; }else { d_al->dso =NULL ; d_al->is_64_bit =0 ;
tools/perf/util/dso.c +197 -171
879 lines not on this page · raw message
tools/perf/util/dso.h +442 -46
546 lines not on this page · raw message
tools/perf/util/dsos.c +27 -27
142 lines not on this page · raw message
tools/perf/util/event.c +4 -4
@@ -726,7 +726,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al, dso = al->map ?map__dso (al->map) :NULL ;dump_printf (" ...... dso: %s\n" , dso - ? dso->long_name + ?dso__long_name (dso) : (al->level =='H' ?"[hypervisor]" :"<not found>" ));if (thread__is_filtered (thread))
@@ -750,10 +750,10 @@ int machine__resolve(struct machine *machine, struct addr_location *al,if (al->map) {if (symbol_conf.dso_list && (!dso || !(strlist__has_entry (symbol_conf.dso_list, - dso->short_name) || - (dso->short_name != dso->long_name && +dso__short_name (dso)) || + (dso__short_name (dso) !=dso__long_name (dso) &&strlist__has_entry (symbol_conf.dso_list, - dso->long_name))))) { +dso__long_name (dso)))))) { al->filtered |= (1 <<HIST_FILTER__DSO ); }
tools/perf/util/header.c +4 -4
@@ -2308,7 +2308,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,build_id__init (&bid, bev->data, size);dso__set_build_id (dso, &bid); - dso->header_build_id =1 ; +dso__set_header_build_id (dso, true);if (dso_space !=DSO_SPACE__USER ) {struct kmod_path m = { .name =NULL , };
@@ -2316,13 +2316,13 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,if (!kmod_path__parse_name (&m, filename) && m.kmod)dso__set_module_info (dso, &m, machine); - dso->kernel = dso_space; +dso__set_kernel (dso, dso_space);free (m.name); } -build_id__sprintf (&dso->bid, sbuild_id); +build_id__sprintf (dso__bid (dso), sbuild_id);pr_debug ("build id event received for %s: %s [%zu]\n" , - dso->long_name, sbuild_id, size); +dso__long_name (dso), sbuild_id, size);dso__put (dso); }
tools/perf/util/hist.c +2 -2
@@ -2128,7 +2128,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists, struct hist_entry *he) {if (hists->dso_filter !=NULL && - (he->ms.map ==NULL ||map__dso (he->ms.map) != hists->dso_filter)) { + (he->ms.map ==NULL || !RC_CHK_EQUAL (map__dso (he->ms.map), hists->dso_filter))) { he->filtered |= (1 <<HIST_FILTER__DSO );return true; }
@@ -2808,7 +2808,7 @@ int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool sh }if (dso) printed +=scnprintf (bf + printed, size - printed, -", DSO: %s" , dso->short_name); +", DSO: %s" ,dso__short_name (dso));if (socket_id >-1 ) printed +=scnprintf (bf + printed, size - printed,", Processor Socket: %d" , socket_id);
tools/perf/util/intel-pt.c +11 -11
@@ -598,15 +598,15 @@ static struct auxtrace_cache *intel_pt_cache(struct dso *dso,struct auxtrace_cache *c;unsigned int bits; -if (dso->auxtrace_cache) -return dso->auxtrace_cache; +if (dso__auxtrace_cache (dso)) +return dso__auxtrace_cache (dso); bits =intel_pt_cache_size (dso, machine);/* Ignoring cache creation failure */ c =auxtrace_cache__new (bits,sizeof (struct intel_pt_cache_entry ),200 ); - dso->auxtrace_cache = c; +dso__set_auxtrace_cache (dso, c);return c; }
@@ -650,7 +650,7 @@ intel_pt_cache_lookup(struct dso *dso, struct machine *machine, u64 offset)if (!c)return NULL ; -return auxtrace_cache__lookup (dso->auxtrace_cache, offset); +return auxtrace_cache__lookup (dso__auxtrace_cache (dso), offset); } static void intel_pt_cache_invalidate(struct dso *dso, struct machine *machine,
@@ -661,7 +661,7 @@ static void intel_pt_cache_invalidate(struct dso *dso, struct machine *machine,if (!c)return ; -auxtrace_cache__remove (dso->auxtrace_cache, offset); +auxtrace_cache__remove (dso__auxtrace_cache (dso), offset); }static inline bool intel_pt_guest_kernel_ip (uint64_t ip)
@@ -820,8 +820,8 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn, } dso =map__dso (al.map); -if (dso->data.status ==DSO_DATA_STATUS_ERROR && -dso__data_status_seen (dso,DSO_DATA_STATUS_SEEN_ITRACE )) { +if (dso__data (dso)->status ==DSO_DATA_STATUS_ERROR && +dso__data_status_seen (dso,DSO_DATA_STATUS_SEEN_ITRACE )) { ret = -ENOENT ; goto out_ret; }
@@ -854,7 +854,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,/* Load maps to ensure dso->is_64_bit has been updated */ map__load (al.map); - x86_64 = dso->is_64_bit; + x86_64 =dso__is_64_bit (dso);while (1 ) { len = dso__data_read_offset(dso, machine,
@@ -1008,7 +1008,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data) offset =map__map_ip (al.map, ip); - res =intel_pt_match_pgd_ip (ptq->pt, ip, offset,map__dso (al.map)->long_name); + res =intel_pt_match_pgd_ip (ptq->pt, ip, offset,dso__long_name (map__dso (al.map)));addr_location__exit (&al);return res; }
@@ -3416,7 +3416,7 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event) } dso =map__dso (al.map); -if (!dso || !dso->auxtrace_cache) +if (!dso || !dso__auxtrace_cache (dso))continue ; offset =map__map_ip (al.map, addr);
@@ -3436,7 +3436,7 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event) }else {intel_pt_cache_invalidate (dso, machine, offset);intel_pt_log ("Invalidated instruction cache for %s at %#" PRIx64"\n" , - dso->long_name, addr); +dso__long_name (dso), addr); } } out:
tools/perf/util/machine.c +23 -23
131 lines not on this page · raw message
tools/perf/util/map.c +38 -39
177 lines not on this page · raw message
tools/perf/util/scripting-engines/trace-event-perl.c +3 -3
Lines of this file are not shown. View the raw message.
tools/perf/util/scripting-engines/trace-event-python.c +11 -10
Lines of this file are not shown. View the raw message.
tools/perf/util/srcline.c +34 -31
65 lines not on this page · raw message
tools/perf/util/symbol-elf.c +47 -47
94 lines not on this page · raw message
tools/perf/util/symbol.c +95 -91
186 lines not on this page · raw message
tools/perf/util/unwind-libunwind-local.c +9 -9
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Part of the diff is not shown here. View the raw message.
Ian Rogers
reviewerPATCH v3 11/12 perf dso: Reference counting related fixes
In reply to Ian RogersEnsure gets and puts are better aligned fixing reference couting checking problems.
--- tools/perf/util/machine.c | 4 +-- tools/perf/util/map.c | 1 + tools/perf/util/symbol-elf.c | 51 ++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 28 deletions(-)
tools/perf/util/machine.c +2 -2
@@ -683,7 +683,7 @@ static int machine__process_ksymbol_register(struct machine *machine, struct perf_sample *sample __maybe_unused) {struct symbol *sym; -struct dso *dso; +struct dso *dso =NULL ;struct map *map =maps__find (machine__kernel_maps (machine), event->ksymbol.addr);int err =0 ;
@@ -696,7 +696,6 @@ static int machine__process_ksymbol_register(struct machine *machine, }dso__set_kernel (dso,DSO_SPACE__KERNEL ); map =map__new2 (0 , dso); -dso__put (dso);if (!map) { err = -ENOMEM ; goto out;
@@ -735,6 +734,7 @@ static int machine__process_ksymbol_register(struct machine *machine,dso__insert_symbol (dso, sym); out:map__put (map); +dso__put (dso);return err; }
tools/perf/util/map.c +1 -0
@@ -200,6 +200,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,dso__set_build_id (dso,dso__bid (header_bid_dso));dso__set_header_build_id (dso,1 ); } +dso__put (header_bid_dso); }dso__put (dso); }
tools/perf/util/symbol-elf.c +25 -26
120 lines not on this page · raw message
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Re: [PATCH v3 11/12] perf dso: Reference counting related fixes
Quoted 1 line
Ensure gets and puts are better aligned fixing reference couting
How do you think about to avoid a typo in the last word of this text line for the final commit?
Quoted 1 line
checking problems.
Regards,
Markus
Ian Rogers
reviewerPATCH v3 12/12 perf dso: Use container_of to avoid a pointer in dso_data
In reply to Ian RogersThe dso pointer in dso_data is necessary for reference count checking to account for the dso_data forming a global list of open dso's with references to the dso. The dso pointer also allows for the indirection that reference count checking needs. Outside of reference count checking the indirection isn't needed and container_of is more efficient and saves space.
The reference count won't be increased by placing items onto the global list, matching how things were before the reference count checking change, but we assert the dso is in dsos holding it live (and that the set of open dsos is a subset of all dsos for the machine). Update the DSO data tests so that they use a dsos struct to make the invariant true.
--- tools/perf/tests/dso-data.c | 60 ++++++++++++++++++------------------- tools/perf/util/dso.c | 16 +++++++++- tools/perf/util/dso.h | 2 ++ 3 files changed, 46 insertions(+), 32 deletions(-)
tools/perf/tests/dso-data.c +29 -31
@@ -10,6 +10,7 @@#include <sys/resource.h> #include <api/fs/fs.h> #include "dso.h" +#include "dsos.h" #include "machine.h" #include "symbol.h" #include "tests.h"
@@ -123,9 +124,10 @@ static int test__dso_data(struct test_suite *test __maybe_unused, int subtest __TEST_ASSERT_VAL ("No test file" , file);memset (&machine,0 ,sizeof (machine)); +dsos__init (&machine.dsos); - dso =dso__new ((const char *)file); - + dso =dso__new (file); +TEST_ASSERT_VAL ("Failed to add dso" , !dsos__add (&machine.dsos, dso));TEST_ASSERT_VAL ("Failed to access to dso" ,dso__data_fd (dso, &machine) >=0 );
@@ -170,6 +172,7 @@ static int test__dso_data(struct test_suite *test __maybe_unused, int subtest __ }dso__put (dso); +dsos__exit (&machine.dsos);unlink (file);return 0 ; }
@@ -199,41 +202,35 @@ static long open_files_cnt(void)return nr -1 ; } -static struct dso **dsos; - -static int dsos__create (int cnt,int size) +static int dsos__create (int cnt,int size,struct dsos *dsos) {int i; - dsos =malloc (sizeof (*dsos) * cnt); -TEST_ASSERT_VAL ("failed to alloc dsos array" , dsos); +dsos__init (dsos);for (i =0 ; i < cnt; i++) { -char *file; +struct dso *dso; +char *file =test_file (size); - file =test_file (size);TEST_ASSERT_VAL ("failed to get dso file" , file); - - dsos[i] =dso__new (file); -TEST_ASSERT_VAL ("failed to get dso" , dsos[i]); + dso =dso__new (file); +TEST_ASSERT_VAL ("failed to get dso" , dso); +TEST_ASSERT_VAL ("failed to add dso" , !dsos__add (dsos, dso)); +dso__put (dso); }return 0 ; } -static void dsos__delete (int cnt) +static void dsos__delete (struct dsos *dsos) { -int i; - -for (i =0 ; i < cnt; i++) { -struct dso *dso = dsos[i]; +for (unsigned int i =0 ; i < dsos->cnt; i++) { +struct dso *dso = dsos->dsos[i];dso__data_close (dso);unlink (dso__name (dso)); -dso__put (dso); } - -free (dsos); +dsos__exit (dsos); }static int set_fd_limit (int n)
@@ -267,10 +264,10 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt/* and this is now our dso open FDs limit */ dso_cnt = limit /2 ;TEST_ASSERT_VAL ("failed to create dsos\n" , - !dsos__create (dso_cnt,TEST_FILE_SIZE )); + !dsos__create (dso_cnt,TEST_FILE_SIZE , &machine.dsos));for (i =0 ; i < (dso_cnt -1 ); i++) { -struct dso *dso = dsos[i]; +struct dso *dso = machine.dsos.dsos[i];/* * Open dsos via dso__data_fd(), it opens the data
@@ -290,17 +287,17 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt }/* verify the first one is already open */ -TEST_ASSERT_VAL ("dsos[0] is not open" ,dso__data (dsos[0 ])->fd !=-1 ); +TEST_ASSERT_VAL ("dsos[0] is not open" ,dso__data (machine.dsos.dsos[0 ])->fd !=-1 );/* open +1 dso to reach the allowed limit */ - fd =dso__data_fd (dsos[i], &machine); + fd =dso__data_fd (machine.dsos.dsos[i], &machine);TEST_ASSERT_VAL ("failed to get fd" , fd >0 );/* should force the first one to be closed */ -TEST_ASSERT_VAL ("failed to close dsos[0]" ,dso__data (dsos[0 ])->fd ==-1 ); +TEST_ASSERT_VAL ("failed to close dsos[0]" ,dso__data (machine.dsos.dsos[0 ])->fd ==-1 );/* cleanup everything */ -dsos__delete (dso_cnt); +dsos__delete (&machine.dsos);/* Make sure we did not leak any file descriptor. */ nr_end =open_files_cnt ();
@@ -325,9 +322,9 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sublong nr_end, nr =open_files_cnt (), lim =new_limit (3 );int fd, fd_extra; -#define dso_0 (dsos[0]) -#define dso_1 (dsos[1]) -#define dso_2 (dsos[2]) +#define dso_0 (machine.dsos.dsos[0]) +#define dso_1 (machine.dsos.dsos[1]) +#define dso_2 (machine.dsos.dsos[2])/* Rest the internal dso open counter limit. */ reset_fd_limit ();
@@ -347,7 +344,8 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int subTEST_ASSERT_VAL ("failed to set file limit" , !set_fd_limit ((lim))); -TEST_ASSERT_VAL ("failed to create dsos\n" , !dsos__create (3 ,TEST_FILE_SIZE )); +TEST_ASSERT_VAL ("failed to create dsos\n" , + !dsos__create (3 ,TEST_FILE_SIZE , &machine.dsos));/* open dso_0 */ fd =dso__data_fd (dso_0, &machine);
@@ -386,7 +384,7 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sub/* cleanup everything */ close (fd_extra); -dsos__delete (3 ); +dsos__delete (&machine.dsos);/* Make sure we did not leak any file descriptor. */ nr_end =open_files_cnt ();
tools/perf/util/dso.c +15 -1
@@ -497,14 +497,20 @@ static pthread_mutex_t dso__data_open_lock = PTHREAD_MUTEX_INITIALIZER;static void dso__list_add (struct dso *dso) {list_add_tail (&dso__data (dso)->open_entry, &dso__data_open); +#ifdef REFCNT_CHECKING dso__data (dso)->dso =dso__get (dso); +#endif +/* Assume the dso is part of dsos, hence the optional reference count above. */ +assert (dso__dsos (dso)); dso__data_open_cnt++; }static void dso__list_del (struct dso *dso) {list_del_init (&dso__data (dso)->open_entry); +#ifdef REFCNT_CHECKING dso__put (dso__data (dso)->dso); +#endif WARN_ONCE (dso__data_open_cnt <=0 ,"DSO data fd counter out of bounds." ); dso__data_open_cnt--;
@@ -654,9 +660,15 @@ static void close_dso(struct dso *dso)static void close_first_dso (void ) {struct dso_data *dso_data; +struct dso *dso; dso_data = list_first_entry(&dso__data_open, struct dso_data, open_entry); -close_dso (dso_data->dso); +#ifdef REFCNT_CHECKING + dso = dso_data->dso; +#else + dso = container_of(dso_data, struct dso, data); +#endif +close_dso (dso); }static rlim_t get_fd_limit (void )
@@ -1449,7 +1461,9 @@ struct dso *dso__new_id(const char *name, struct dso_id *id) data->fd =-1 ; data->status =DSO_DATA_STATUS_UNKNOWN ;INIT_LIST_HEAD (&data->open_entry); +#ifdef REFCNT_CHECKING data->dso =NULL ;/* Set when on the open_entry list. */ +#endif }return res; }
tools/perf/util/dso.h +2 -0
@@ -147,7 +147,9 @@ struct dso_cache {struct dso_data {struct rb_root cache;struct list_head open_entry; +#ifdef REFCNT_CHECKING struct dso *dso; +#endif int fd;int status;u32 status_seen;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Arnaldo Carvalho de Melo
maintainerQuoted 9 lines · Ian Rogers
12 more patches from:
https://lore.kernel.org/lkml/[email protected]/
a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking.
Quoted 7 lines
The changes migrate dsos code, the collection of dso structs, more into the
dsos.c/dsos.hfiles. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduce by half.
Got the first 5 patches, would be nice if more people could review it, I'll try and get back to is soon.
- Arnaldo
Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 9 lines · Ian Rogers
12 more patches from:
https://lore.kernel.org/lkml/[email protected]/
a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking.Quoted 7 lines
The changes migrate dsos code, the collection of dso structs, more into the
dsos.c/dsos.hfiles. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduce by half.
Quoted 2 lines
Got the first 5 patches, would be nice if more people could review it, I'll try and get back to is soon.
For the series:
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerQuoted 21 lines · Namhyung Kim
Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 16 lines · Ian Rogers
12 more patches from:
https://lore.kernel.org/lkml/[email protected]/
a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking.The changes migrate dsos code, the collection of dso structs, more into the
dsos.c/dsos.hfiles. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduce by half.
Quoted 6 lines
Quoted 2 lines
Got the first 5 patches, would be nice if more people could review it, I'll try and get back to is soon.
For the series:
Acked-by Namhyung Kim <[email protected]>
It is not applying right now, I've just merged with torvalds/master and I'm running build tests now, will push to tmp.perf-tools-next right now.
- Arnaldo
Ian Rogers
reviewerQuoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines · Namhyung Kim
Quoted 21 lines · Arnaldo Carvalho de Melo
Quoted 9 lines · Ian Rogers
12 more patches from:
https://lore.kernel.org/lkml/[email protected]/
a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking.Quoted 7 lines
The changes migrate dsos code, the collection of dso structs, more into the
dsos.c/dsos.hfiles. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduce by half.Got the first 5 patches, would be nice if more people could review it, I'll try and get back to is soon.
Quoted 6 lines
Quoted 3 lines
For the series:
Acked-by Namhyung Kim <[email protected]>It is not applying right now, I've just merged with torvalds/master and I'm running build tests now, will push to tmp.perf-tools-next right now.
Ok, do you want me to rebase on tmp.perf-tools-next?
Thanks,
Ian
Quoted 1 line
- Arnaldo