perf tools: Share struct map after clone
Subsystems (2)
Jiri Olsa
reviewerv2 cover perf tools: Share struct map after clone
hi,
Andi reported that maps cloning is eating lot of memory and it's probably unnecessary, because they keep the same data.
This 'maps sharing' seems to save lot of heap for reports with many forks/cloned mmaps (over 60% in example below).
Profile kernel build:
$ perf record make -j 40
Get heap profile (tools/perf directory):
$ <install gperftools> $ make TCMALLOC=1 $ HEAPPROFILE=/tmp/heapprof ./perf report -i perf.data --stdio > out $ pprof ./perf /tmp/heapprof.000*
Before:
(pprof) top
Total: 2335.5 MB
1735.1 74.3% 74.3% 1735.1 74.3% memdup
402.0 17.2% 91.5% 402.0 17.2% zalloc
140.2 6.0% 97.5% 145.8 6.2% map__new
33.6 1.4% 98.9% 33.6 1.4% symbol__new
12.4 0.5% 99.5% 12.4 0.5% alloc_event
6.2 0.3% 99.7% 6.2 0.3% nsinfo__new
5.5 0.2% 100.0% 5.5 0.2% nsinfo__copy
0.3 0.0% 100.0% 0.3 0.0% dso__new
0.1 0.0% 100.0% 0.1 0.0% do_read_string
0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocateAfter:
(pprof) top
Total: 784.5 MB
385.8 49.2% 49.2% 385.8 49.2% memdup
285.8 36.4% 85.6% 285.8 36.4% zalloc
80.4 10.3% 95.9% 83.7 10.7% map__new
19.1 2.4% 98.3% 19.1 2.4% symbol__new
6.2 0.8% 99.1% 6.2 0.8% alloc_event
3.6 0.5% 99.6% 3.6 0.5% nsinfo__new
3.2 0.4% 100.0% 3.2 0.4% nsinfo__copy
0.2 0.0% 100.0% 0.2 0.0% dso__new
0.0 0.0% 100.0% 0.0 0.0% do_read_string
0.0 0.0% 100.0% 0.0 0.0% elf_fillv2 changes:
- rebased to Arnaldo's perf/core
- patch 1 already taken
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_shared
thanks,
jirka
---
Jiri Olsa (2):
perf tools: Separate shareable part of 'struct map' into 'struct map_shared' perf tools: Make 'struct map_shared' truly shared
tools/perf/arch/arm/tests/dwarf-unwind.c | 2 +- tools/perf/arch/arm64/tests/dwarf-unwind.c | 2 +- tools/perf/arch/powerpc/tests/dwarf-unwind.c | 2 +- tools/perf/arch/powerpc/util/skip-callchain-idx.c | 4 +-- tools/perf/arch/powerpc/util/sym-handling.c | 4 +-- tools/perf/arch/s390/annotate/instructions.c | 2 +- tools/perf/arch/x86/tests/dwarf-unwind.c | 2 +- tools/perf/arch/x86/util/event.c | 6 ++-- tools/perf/builtin-annotate.c | 8 +++--- tools/perf/builtin-inject.c | 10 ++++--- tools/perf/builtin-kallsyms.c | 7 +++-- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-mem.c | 6 ++-- tools/perf/builtin-report.c | 19 +++++++------ tools/perf/builtin-script.c | 16 +++++------ tools/perf/builtin-top.c | 15 +++++----- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 34 ++++++++++++----------- tools/perf/tests/hists_common.c | 4 +-- tools/perf/tests/hists_cumulate.c | 4 +-- tools/perf/tests/hists_filter.c | 4 +-- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/map_groups.c | 22 +++++++-------- tools/perf/tests/mmap-thread-lookup.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 36 ++++++++++++------------ tools/perf/ui/browsers/annotate.c | 4 +-- tools/perf/ui/browsers/hists.c | 10 +++---- tools/perf/ui/browsers/map.c | 4 +-- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 34 +++++++++++------------ tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf-event.c | 8 +++--- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 6 ++-- tools/perf/util/db-export.c | 4 +-- tools/perf/util/dso.c | 2 +- tools/perf/util/event.c | 6 ++-- tools/perf/util/evsel_fprintf.c | 2 +- tools/perf/util/hist.c | 10 +++---- tools/perf/util/intel-pt.c | 42 ++++++++++++++++------------ tools/perf/util/machine.c | 76 +++++++++++++++++++++++++------------------------- tools/perf/util/map.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------- tools/perf/util/map.h | 32 +++++++++++++-------- tools/perf/util/probe-event.c | 32 ++++++++++----------- tools/perf/util/scripting-engines/trace-event-perl.c | 8 +++--- tools/perf/util/scripting-engines/trace-event-python.c | 12 ++++---- tools/perf/util/sort.c | 58 ++++++++++++++++++++------------------ tools/perf/util/symbol-elf.c | 28 +++++++++---------- tools/perf/util/symbol.c | 80 ++++++++++++++++++++++++++--------------------------- tools/perf/util/symbol_fprintf.c | 2 +- tools/perf/util/synthetic-events.c | 14 +++++----- tools/perf/util/thread.c | 14 +++++----- tools/perf/util/unwind-libdw.c | 16 +++++++---- tools/perf/util/unwind-libunwind-local.c | 37 +++++++++++++------------ tools/perf/util/unwind-libunwind.c | 4 +-- tools/perf/util/vdso.c | 2 +- 56 files changed, 540 insertions(+), 456 deletions(-)
Jiri Olsa
reviewerPATCH v2 1/2 perf tools: Separate shareable part of 'struct map' into 'struct map_shared'
This is preparation for truly sharing the 'struct map_shared'. So far it's statically added inside 'struct map', so there's no functional change expected other than compilation fail.
--- tools/perf/arch/arm/tests/dwarf-unwind.c | 2 +- tools/perf/arch/arm64/tests/dwarf-unwind.c | 2 +- tools/perf/arch/powerpc/tests/dwarf-unwind.c | 2 +- .../arch/powerpc/util/skip-callchain-idx.c | 4 +- tools/perf/arch/powerpc/util/sym-handling.c | 4 +- tools/perf/arch/s390/annotate/instructions.c | 2 +- tools/perf/arch/x86/tests/dwarf-unwind.c | 2 +- tools/perf/arch/x86/util/event.c | 6 +- tools/perf/builtin-annotate.c | 8 +- tools/perf/builtin-inject.c | 10 +- tools/perf/builtin-kallsyms.c | 7 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-mem.c | 6 +- tools/perf/builtin-report.c | 19 +- tools/perf/builtin-script.c | 16 +- tools/perf/builtin-top.c | 15 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 34 ++-- tools/perf/tests/hists_common.c | 4 +- tools/perf/tests/hists_cumulate.c | 4 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/map_groups.c | 22 +-- tools/perf/tests/mmap-thread-lookup.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 36 ++-- tools/perf/ui/browsers/annotate.c | 4 +- tools/perf/ui/browsers/hists.c | 10 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 34 ++-- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf-event.c | 8 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/callchain.c | 6 +- tools/perf/util/db-export.c | 4 +- tools/perf/util/dso.c | 2 +- tools/perf/util/event.c | 6 +- tools/perf/util/evsel_fprintf.c | 2 +- tools/perf/util/hist.c | 10 +- tools/perf/util/intel-pt.c | 42 +++-- tools/perf/util/machine.c | 76 ++++---- tools/perf/util/map.c | 168 ++++++++++-------- tools/perf/util/map.h | 29 +-- tools/perf/util/probe-event.c | 32 ++-- .../util/scripting-engines/trace-event-perl.c | 8 +- .../scripting-engines/trace-event-python.c | 12 +- tools/perf/util/sort.c | 58 +++--- tools/perf/util/symbol-elf.c | 28 +-- tools/perf/util/symbol.c | 78 ++++---- tools/perf/util/symbol_fprintf.c | 2 +- tools/perf/util/synthetic-events.c | 14 +- tools/perf/util/thread.c | 14 +- tools/perf/util/unwind-libdw.c | 16 +- tools/perf/util/unwind-libunwind-local.c | 37 ++-- tools/perf/util/unwind-libunwind.c | 4 +- tools/perf/util/vdso.c | 2 +- 56 files changed, 489 insertions(+), 444 deletions(-)
tools/perf/arch/arm/tests/dwarf-unwind.c +1 -1
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,return -1 ; } - stack_size = map->end - sp; + stack_size =map_sh (map)->end - sp; stack_size = stack_size >STACK_SIZE ?STACK_SIZE : stack_size;memcpy (buf, (void *) sp, stack_size);
tools/perf/arch/arm64/tests/dwarf-unwind.c +1 -1
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,return -1 ; } - stack_size = map->end - sp; + stack_size =map_sh (map)->end - sp; stack_size = stack_size >STACK_SIZE ?STACK_SIZE : stack_size;memcpy (buf, (void *) sp, stack_size);
tools/perf/arch/powerpc/tests/dwarf-unwind.c +1 -1
@@ -34,7 +34,7 @@ static int sample_ustack(struct perf_sample *sample,return -1 ; } - stack_size = map->end - sp; + stack_size =map_sh (map)->end - sp; stack_size = stack_size >STACK_SIZE ?STACK_SIZE : stack_size;memcpy (buf, (void *) sp, stack_size);
tools/perf/arch/powerpc/util/skip-callchain-idx.c +2 -2
@@ -255,14 +255,14 @@ int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain)thread__find_symbol (thread,PERF_RECORD_MISC_USER , ip, &al);if (al.map) - dso = al.map->dso; + dso =map_sh (al.map)->dso;if (!dso) {pr_debug ("%" PRIx64" dso is NULL\n" , ip);return skip_slot; } - rc =check_return_addr (dso, al.map->start, ip); + rc =check_return_addr (dso,map_sh (al.map)->start, ip);pr_debug ("[DSO %s, sym %s, ip 0x%" PRIx64"] rc %d\n" , dso->long_name, al.sym->name, ip, rc);
tools/perf/arch/powerpc/util/sym-handling.c +2 -2
@@ -114,7 +114,7 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev, lep_offset =PPC64_LOCAL_ENTRY_OFFSET (sym->arch_sym); -if (map->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS ) +if (map_sh (map)->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS ) tev->point.offset +=PPC64LE_LEP_OFFSET ;else if (lep_offset) {if (pev->uprobes)
@@ -141,7 +141,7 @@ void arch__post_process_probe_trace_events(struct perf_probe_event *pev,for (i =0 ; i < ntevs; i++) { tev = &pev->tevs[i];map__for_each_symbol (map, sym, tmp) { -if (map->unmap_ip (map, sym->start) == tev->point.address) { +if (map_sh (map)->unmap_ip (map, sym->start) == tev->point.address) {arch__fix_tev_from_maps (pev, tev, map, sym);break ; }
tools/perf/arch/s390/annotate/instructions.c +1 -1
@@ -39,7 +39,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops, target.addr =map__objdump_2mem (map, ops->target.addr);if (map_groups__find_ams (&target) ==0 && -map__rip_2objdump (target.map, map->map_ip (target.map, target.addr)) == ops->target.addr) +map__rip_2objdump (target.map,map_sh (map)->map_ip (target.map, target.addr)) == ops->target.addr) ops->target.sym = target.sym;return 0 ;
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
@@ -34,7 +34,7 @@ static int sample_ustack(struct perf_sample *sample,return -1 ; } - stack_size = map->end - sp; + stack_size =map_sh (map)->end - sp; stack_size = stack_size >STACK_SIZE ?STACK_SIZE : stack_size;memcpy (buf, (void *) sp, stack_size);
tools/perf/arch/x86/util/event.c +3 -3
@@ -57,9 +57,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, event->mmap.header.size = size; - event->mmap.start = pos->start; - event->mmap.len = pos->end - pos->start; - event->mmap.pgoff = pos->pgoff; + event->mmap.start =map_sh (pos)->start; + event->mmap.len =map_sh (pos)->end -map_sh (pos)->start; + event->mmap.pgoff =map_sh (pos)->pgoff; event->mmap.pid = machine->pid;strlcpy (event->mmap.filename, kmap->name,PATH_MAX );
tools/perf/builtin-annotate.c +4 -4
@@ -199,7 +199,7 @@ static int process_branch_callback(struct evsel *evsel,return 0 ;if (a.map !=NULL ) - a.map->dso->hit =1 ; +map_sh (a.map)->dso->hit =1 ;hist__account_cycles (sample->branch_stack, al, sample, false);
@@ -233,9 +233,9 @@ static int perf_evsel__add_sample(struct evsel *evsel,*/ if (al->sym !=NULL ) {rb_erase_cached (&al->sym->rb_node, - &al->map->dso->symbols); + &map_sh (al->map)->dso->symbols);symbol__delete (al->sym); -dso__reset_find_symbol_cache (al->map->dso); +dso__reset_find_symbol_cache (map_sh (al->map)->dso); }return 0 ; }
@@ -317,7 +317,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 || he->ms.map->dso->annotate_warned) +if (he->ms.sym ==NULL ||map_sh (he->ms.map)->dso->annotate_warned) goto find_next; if (ann->sym_hist_filter &&
tools/perf/builtin-inject.c +6 -4
@@ -440,10 +440,12 @@ static int perf_event__inject_buildid(struct perf_tool *tool, }if (thread__find_map (thread, sample->cpumode, sample->ip, &al)) { -if (!al.map->dso->hit) { - al.map->dso->hit =1 ; +struct map_shared *sh =map_sh (al.map); + +if (!sh->dso->hit) { + sh->dso->hit =1 ;if (map__load (al.map) >=0 ) { -dso__inject_build_id (al.map->dso, tool, machine); +dso__inject_build_id (sh->dso, tool, machine);/* * If this fails, too bad, let the other side * account this as unresolved.
@@ -452,7 +454,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,#ifdef HAVE_LIBELF_SUPPORT pr_warning ("no symbols found in %s, maybe " "install a debug package?\n" , - al.map->dso->long_name); + sh->dso->long_name);#endif } }
tools/perf/builtin-kallsyms.c +5 -2
@@ -28,6 +28,7 @@ static int __cmd_kallsyms(int argc, const char **argv)for (i =0 ; i < argc; ++i) {struct map *map; +struct map_shared *sh;struct symbol *symbol =machine__find_kernel_symbol_by_name (machine, argv[i], &map);if (symbol ==NULL ) {
@@ -35,9 +36,11 @@ static int __cmd_kallsyms(int argc, const char **argv)continue ; } + sh =map_sh (map); +printf ("%s: %s %s %#" PRIx64"-%#" PRIx64" (%#" PRIx64"-%#" PRIx64")\n" , - symbol->name, map->dso->short_name, map->dso->long_name, - map->unmap_ip (map, symbol->start), map->unmap_ip (map, symbol->end), + symbol->name, sh->dso->short_name, sh->dso->long_name, + sh->unmap_ip (map, symbol->start), sh->unmap_ip (map, symbol->end), symbol->start, symbol->end); }
tools/perf/builtin-kmem.c +1 -1
@@ -1016,7 +1016,7 @@ static void __print_slab_result(struct rb_root *root,if (sym !=NULL )snprintf (buf,sizeof (buf),"%s+%" PRIx64"" , sym->name, - addr - map->unmap_ip (map, sym->start)); + addr -map_sh (map)->unmap_ip (map, sym->start));else snprintf (buf,sizeof (buf),"%#" PRIx64"" , addr);printf (" %-34s |" , buf);
tools/perf/builtin-mem.c +3 -3
@@ -169,7 +169,7 @@ dump_raw_samples(struct perf_tool *tool, goto out_put;if (al.map !=NULL ) - al.map->dso->hit =1 ; +map_sh (al.map)->dso->hit =1 ;if (mem->phys_addr) {if (symbol_conf.field_sep) {
@@ -197,7 +197,7 @@ dump_raw_samples(struct perf_tool *tool, symbol_conf.field_sep, sample->data_src, symbol_conf.field_sep, - al.map ? (al.map->dso ? al.map->dso->long_name :"???" ) :"???" , + al.map ? (map_sh (al.map)->dso ?map_sh (al.map)->dso->long_name :"???" ) :"???" , al.sym ? al.sym->name : "???"); }else {if (symbol_conf.field_sep) {
@@ -222,7 +222,7 @@ dump_raw_samples(struct perf_tool *tool, symbol_conf.field_sep, sample->data_src, symbol_conf.field_sep, - al.map ? (al.map->dso ? al.map->dso->long_name :"???" ) :"???" , + al.map ? (map_sh (al.map)->dso ?map_sh (al.map)->dso->long_name :"???" ) :"???" , al.sym ? al.sym->name : "???"); } out_put:
tools/perf/builtin-report.c +10 -9
@@ -288,7 +288,7 @@ static int process_sample_event(struct perf_tool *tool, }if (al.map !=NULL ) - al.map->dso->hit =1 ; +map_sh (al.map)->dso->hit =1 ;if (ui__has_annotation () || rep->symbol_ipc) { hist__account_cycles(sample->branch_stack, &al, sample,
@@ -531,7 +531,7 @@ static void report__warn_kptr_restrict(const struct report *rep)return ;if (kernel_map ==NULL || - (kernel_map->dso->hit && + (map_sh (kernel_map)->dso->hit && (kernel_kmap->ref_reloc_sym ==NULL || kernel_kmap->ref_reloc_sym->addr ==0 ))) { const char *desc =
@@ -731,15 +731,16 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)for (nd =rb_first (&maps->entries); nd; nd =rb_next (nd)) { struct map *map = rb_entry(nd, struct map, rb_node); +struct map_shared *sh =map_sh (map); printed +=fprintf (fp,"%*s %" PRIx64"-%" PRIx64" %c%c%c%c %08" PRIx64" %" PRIu64" %s\n" , - indent,"" , map->start, map->end, - map->prot &PROT_READ ?'r' :'-' , - map->prot &PROT_WRITE ?'w' :'-' , - map->prot &PROT_EXEC ?'x' :'-' , - map->flags &MAP_SHARED ?'s' :'p' , - map->pgoff, - map->ino, map->dso->name); + indent,"" , sh->start, sh->end, + sh->prot &PROT_READ ?'r' :'-' , + sh->prot &PROT_WRITE ?'w' :'-' , + sh->prot &PROT_EXEC ?'x' :'-' , + sh->flags &MAP_SHARED ?'s' :'p' , + sh->pgoff, + sh->ino, sh->dso->name); }return printed;
tools/perf/builtin-script.c +8 -8
@@ -842,11 +842,11 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, to = br->entries[i].to;if (thread__find_map_fb (thread, sample->cpumode, from, &alf) && - !alf.map->dso->adjust_symbols) + !map_sh (alf.map)->dso->adjust_symbols) from =map__map_ip (alf.map, from);if (thread__find_map_fb (thread, sample->cpumode, to, &alt) && - !alt.map->dso->adjust_symbols) + !map_sh (alt.map)->dso->adjust_symbols) to =map__map_ip (alt.map, to); printed +=fprintf (fp," 0x%" PRIx64, from);
@@ -909,11 +909,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,return 0 ; } -if (!thread__find_map (thread, *cpumode, start, &al) || !al.map->dso) { +if (!thread__find_map (thread, *cpumode, start, &al) || !map_sh (al.map)->dso) {pr_debug ("\tcannot resolve %" PRIx64"-%" PRIx64"\n" , start, end);return 0 ; } -if (al.map->dso->data.status ==DSO_DATA_STATUS_ERROR ) { +if (map_sh (al.map)->dso->data.status ==DSO_DATA_STATUS_ERROR ) {pr_debug ("\tcannot resolve %" PRIx64"-%" PRIx64"\n" , start, end);return 0 ; }
@@ -921,11 +921,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,/* Load maps to ensure dso->is_64_bit has been updated */ map__load (al.map); - offset = al.map->map_ip (al.map, start); - len =dso__data_read_offset (al.map->dso, machine, offset, (u8 *)buffer, + offset =map_sh (al.map)->map_ip (al.map, start); + len =dso__data_read_offset (map_sh (al.map)->dso, machine, offset, (u8 *)buffer, end - start +MAXINSN ); - *is64bit = al.map->dso->is_64_bit; + *is64bit =map_sh (al.map)->dso->is_64_bit;if (len <=0 )pr_debug ("\tcannot fetch code for block at %" PRIx64"-%" PRIx64"\n" , start, end);
@@ -992,7 +992,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,if (al.addr < al.sym->end) off = al.addr - al.sym->start;else - off = al.addr - al.map->start - al.sym->start; + off = al.addr -map_sh (al.map)->start - al.sym->start; printed +=fprintf (fp,"\t%s" , al.sym->name);if (off) printed +=fprintf (fp,"%+d" , off);
tools/perf/builtin-top.c +8 -7
@@ -124,8 +124,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)/* * We can't annotate with just /proc/kallsyms */ -if (map->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && - !dso__is_kcore (map->dso)) { +if (map_sh (map)->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && + !dso__is_kcore (map_sh (map)->dso)) {pr_err ("Can't annotate %s: No vmlinux file was found in the " "path\n" , sym->name);sleep (1 );
@@ -164,6 +164,7 @@ static void __zero_source_counters(struct hist_entry *he)static void ui__warn_map_erange (struct map *map,struct symbol *sym,u64 ip) { +struct map_shared *sh =map_sh (map);struct utsname uts;int err =uname (&uts);
@@ -177,8 +178,8 @@ 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, map->dso->long_name,dso__symtab_origin (map->dso), - map->start, map->end, sym->start, sym->end, + ip, sh->dso->long_name,dso__symtab_origin (sh->dso), + sh->start, sh->end, sym->start, sym->end, sym->binding ==STB_GLOBAL ?'g' : sym->binding ==STB_LOCAL ?'l' :'w' , sym->name, err ? "[unknown]" : uts.machine,
@@ -186,7 +187,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)if (use_browser <=0 )sleep (5 ); - map->erange_warned = true; + sh->erange_warned = true; } static void perf_top__record_precise_ip(struct perf_top *top,
@@ -219,7 +220,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,*/ pthread_mutex_unlock (&he->hists->lock); -if (err == -ERANGE && !he->ms.map->erange_warned) +if (err == -ERANGE && !map_sh (he->ms.map)->erange_warned)ui__warn_map_erange (he->ms.map, sym, ip);else if (err == -ENOMEM ) { pr_err("Not enough memory for annotating '%s' symbol!\n",
@@ -798,7 +799,7 @@ static void perf_event__process_sample(struct perf_tool *tool, __map__is_kernel(al.map) && map__has_symbols(al.map)) {if (symbol_conf.vmlinux_name) {char serr[256 ]; -dso__strerror_load (al.map->dso, serr,sizeof (serr)); +dso__strerror_load (map_sh (al.map)->dso, serr,sizeof (serr));ui__warning ("The %s file can't be used: %s\n%s" , symbol_conf.vmlinux_name, serr, msg); }else {
tools/perf/builtin-trace.c +1 -1
@@ -2680,7 +2680,7 @@ static void print_location(FILE *f, struct perf_sample *sample, {if ((verbose >0 || print_dso) && al->map) -fprintf (f,"%s@" , al->map->dso->long_name); +fprintf (f,"%s@" ,map_sh (al->map)->dso->long_name);if ((verbose >0 || print_sym) && al->sym) fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/tests/code-reading.c +18 -16
@@ -236,6 +236,7 @@ static void dump_buf(unsigned char *buf, size_t len)static int read_object_code (u64 addr,size_t len,u8 cpumode,struct thread *thread,struct state *state) { +struct map_shared *sh;struct addr_location al;unsigned char buf1[BUFSZ ];unsigned char buf2[BUFSZ ];
@@ -248,7 +249,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,pr_debug ("Reading object code for memory address: %#" PRIx64"\n" , addr); -if (!thread__find_map (thread, cpumode, addr, &al) || !al.map->dso) { +if (!thread__find_map (thread, cpumode, addr, &al) || !map_sh (al.map)->dso) {if (cpumode ==PERF_RECORD_MISC_HYPERVISOR ) {pr_debug ("Hypervisor address can not be resolved - skipping\n" );return 0 ;
@@ -258,10 +259,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,return -1 ; } -pr_debug ("File is: %s\n" , al.map->dso->long_name); + sh =map_sh (al.map); +pr_debug ("File is: %s\n" , sh->dso->long_name); -if (al.map->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && - !dso__is_kcore (al.map->dso)) { +if (sh->dso->symtab_type ==DSO_BINARY_TYPE__KALLSYMS && + !dso__is_kcore (sh->dso)) {pr_debug ("Unexpected kernel address - skipping\n" );return 0 ; }
@@ -272,11 +274,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, len =BUFSZ ;/* Do not go off the map */ -if (addr + len > al.map->end) - len = al.map->end - addr; +if (addr + len > sh->end) + len = sh->end - addr;/* Read the object code using perf */ - ret_len =dso__data_read_offset (al.map->dso, thread->mg->machine, + ret_len =dso__data_read_offset (sh->dso, thread->mg->machine, al.addr, buf1, len);if (ret_len != len) {pr_debug ("dso__data_read_offset failed\n" );
@@ -291,11 +293,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,return -1 ;/* objdump struggles with kcore - try each map only once */ -if (dso__is_kcore (al.map->dso)) { +if (dso__is_kcore (sh->dso)) {size_t d;for (d =0 ; d < state->done_cnt; d++) { -if (state->done[d] == al.map->start) { +if (state->done[d] == sh->start) {pr_debug ("kcore map tested already" );pr_debug (" - skipping\n" );return 0 ;
@@ -305,12 +307,12 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,pr_debug ("Too many kcore maps - skipping\n" );return 0 ; } - state->done[state->done_cnt++] = al.map->start; + state->done[state->done_cnt++] = sh->start; } - objdump_name = al.map->dso->long_name; -if (dso__needs_decompress (al.map->dso)) { -if (dso__decompress_kmodule_path (al.map->dso, objdump_name, + objdump_name = sh->dso->long_name; +if (dso__needs_decompress (sh->dso)) { +if (dso__decompress_kmodule_path (sh->dso, objdump_name, decomp_name,sizeof (decomp_name)) <0 ) {pr_debug ("decompression failed\n" );
@@ -338,7 +340,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, len -= ret;if (len) {pr_debug ("Reducing len to %zu\n" , len); - }else if (dso__is_kcore (al.map->dso)) { + }else if (dso__is_kcore (sh->dso)) {/* * objdump cannot handle very large segments * that may be found in kcore.
@@ -596,8 +598,8 @@ static int do_test_code_reading(bool try_kcore)pr_debug ("map__load failed\n" ); goto out_err; } - have_vmlinux =dso__is_vmlinux (map->dso); - have_kcore =dso__is_kcore (map->dso); + have_vmlinux =dso__is_vmlinux (map_sh (map)->dso); + have_kcore =dso__is_kcore (map_sh (map)->dso);/* 2nd time through we just try kcore */ if (try_kcore && !have_kcore)
tools/perf/tests/hists_common.c +2 -2
@@ -181,7 +181,7 @@ void print_hists_in(struct hists *hists)if (!he->filtered) {pr_info ("%2d: entry: %-8s [%-8s] %20s: period = %" PRIu64"\n" , i,thread__comm_str (he->thread), - he->ms.map->dso->short_name, +map_sh (he->ms.map)->dso->short_name, he->ms.sym->name, he->stat.period); }
@@ -208,7 +208,7 @@ void print_hists_out(struct hists *hists)if (!he->filtered) {pr_info ("%2d: entry: %8s:%5d [%-8s] %20s: period = %" PRIu64"/%" PRIu64"\n" , i,thread__comm_str (he->thread), he->thread->tid, - he->ms.map->dso->short_name, +map_sh (he->ms.map)->dso->short_name, he->ms.sym->name, he->stat.period, he->stat_acc ? he->stat_acc->period :0 ); }
tools/perf/tests/hists_cumulate.c +2 -2
@@ -150,12 +150,12 @@ static void del_hist_entries(struct hists *hists)typedef int (*test_fn_t )(struct evsel *,struct machine *);#define COMM (he) (thread__comm_str(he->thread)) -#define DSO (he) (he->ms.map->dso->short_name) +#define DSO (he) (map_sh(he->ms.map)->dso->short_name)#define SYM (he) (he->ms.sym->name)#define CPU (he) (he->cpu)#define PID (he) (he->thread->tid)#define DEPTH (he) (he->callchain->max_depth) -#define CDSO (cl) (cl->ms.map->dso->short_name) +#define CDSO (cl) (map_sh(cl->ms.map)->dso->short_name)#define CSYM (cl) (cl->ms.sym->name)struct result {
tools/perf/tests/hists_filter.c +2 -2
@@ -194,7 +194,7 @@ int test__hists_filter(struct test *test __maybe_unused, int subtest __maybe_unuhists__filter_by_thread (hists);/* now applying dso filter for 'kernel' */ - hists->dso_filter = fake_samples[0 ].map->dso; + hists->dso_filter =map_sh (fake_samples[0 ].map)->dso;hists__filter_by_dso (hists);if (verbose >2 ) {
@@ -288,7 +288,7 @@ int test__hists_filter(struct test *test __maybe_unused, int subtest __maybe_unu/* now applying all filters at once. */ hists->thread_filter = fake_samples[1 ].thread; - hists->dso_filter = fake_samples[1 ].map->dso; + hists->dso_filter =map_sh (fake_samples[1 ].map)->dso;hists__filter_by_thread (hists);hists__filter_by_dso (hists);
tools/perf/tests/hists_output.c +1 -1
@@ -116,7 +116,7 @@ static void del_hist_entries(struct hists *hists)typedef int (*test_fn_t )(struct evsel *,struct machine *);#define COMM (he) (thread__comm_str(he->thread)) -#define DSO (he) (he->ms.map->dso->short_name) +#define DSO (he) (map_sh(he->ms.map)->dso->short_name)#define SYM (he) (he->ms.sym->name)#define CPU (he) (he->cpu)#define PID (he) (he->thread->tid)
tools/perf/tests/map_groups.c +11 -11
@@ -20,9 +20,9 @@ static int check_maps(struct map_def *merged, unsigned int size, struct map_grou map =map_groups__first (mg);while (map) { -TEST_ASSERT_VAL ("wrong map start" , map->start == merged[i].start); -TEST_ASSERT_VAL ("wrong map end" , map->end == merged[i].end); -TEST_ASSERT_VAL ("wrong map name" , !strcmp (map->dso->name, merged[i].name)); +TEST_ASSERT_VAL ("wrong map start" ,map_sh (map)->start == merged[i].start); +TEST_ASSERT_VAL ("wrong map end" ,map_sh (map)->end == merged[i].end); +TEST_ASSERT_VAL ("wrong map name" , !strcmp (map_sh (map)->dso->name, merged[i].name));TEST_ASSERT_VAL ("wrong map refcnt" ,refcount_read (&map->refcnt) ==2 ); i++;
@@ -73,8 +73,8 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb map =dso__new_map (bpf_progs[i].name);TEST_ASSERT_VAL ("failed to create map" , map); - map->start = bpf_progs[i].start; - map->end = bpf_progs[i].end; +map_sh (map)->start = bpf_progs[i].start; +map_sh (map)->end = bpf_progs[i].end;map_groups__insert (&mg, map);map__put (map); }
@@ -89,16 +89,16 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __maybTEST_ASSERT_VAL ("failed to create map" , map_kcore3);/* kcore1 map overlaps over all bpf maps */ - map_kcore1->start =100 ; - map_kcore1->end =1000 ; +map_sh (map_kcore1)->start =100 ; +map_sh (map_kcore1)->end =1000 ;/* kcore2 map hides behind bpf_prog_2 */ - map_kcore2->start =550 ; - map_kcore2->end =570 ; +map_sh (map_kcore2)->start =550 ; +map_sh (map_kcore2)->end =570 ;/* kcore3 map hides behind bpf_prog_3, kcore1 and adds new map */ - map_kcore3->start =880 ; - map_kcore3->end =1100 ; +map_sh (map_kcore3)->start =880 ; +map_sh (map_kcore3)->end =1100 ; ret =map_groups__merge_in (&mg, map_kcore1);TEST_ASSERT_VAL ("failed to merge map" , !ret);
tools/perf/tests/mmap-thread-lookup.c +1 -1
@@ -202,7 +202,7 @@ static int mmap_events(synth_cb synth)break ; } -pr_debug ("map %p, addr %" PRIx64"\n" , al.map, al.map->start); +pr_debug ("map %p, addr %" PRIx64"\n" , al.map,map_sh (al.map)->start); }machine__delete_threads (machine);
tools/perf/tests/vmlinux-kallsyms.c +18 -18
@@ -12,7 +12,7 @@#include "debug.h" #include "machine.h" -#define UM (x) kallsyms_map->unmap_ip(kallsyms_map, (x)) +#define UM (x) map_sh(kallsyms_map)->unmap_ip(kallsyms_map, (x))int test__vmlinux_matches_kallsyms (struct test *test__maybe_unused ,int subtest__maybe_unused ) {
@@ -117,8 +117,8 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtestif (sym->start == sym->end)continue ; - mem_start = vmlinux_map->unmap_ip (vmlinux_map, sym->start); - mem_end = vmlinux_map->unmap_ip (vmlinux_map, sym->end); + mem_start =map_sh (vmlinux_map)->unmap_ip (vmlinux_map, sym->start); + mem_end =map_sh (vmlinux_map)->unmap_ip (vmlinux_map, sym->end); first_pair =machine__find_kernel_symbol (&kallsyms, mem_start,NULL ); pair = first_pair;
@@ -163,7 +163,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtestcontinue ; } - }else if (mem_start == kallsyms.vmlinux_map->end) { + }else if (mem_start ==map_sh (kallsyms.vmlinux_map)->end) {/* * Ignore aliases to _etext, i.e. to the end of the kernel text area, * such as __indirect_thunk_end.
@@ -191,11 +191,11 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest* both cases. */ pair =map_groups__find_by_name (&kallsyms.kmaps, - (map->dso->kernel ? - map->dso->short_name : - map->dso->name)); + (map_sh (map)->dso->kernel ? +map_sh (map)->dso->short_name : +map_sh (map)->dso->name));if (pair) { - pair->priv =1 ; +map_sh (pair)->priv =1 ; }else {if (!header_printed) {pr_info ("WARN: Maps only in vmlinux:\n" );
@@ -210,26 +210,26 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtestfor (map =maps__first (maps); map; map =map__next (map)) {struct map *pair; - mem_start = vmlinux_map->unmap_ip (vmlinux_map, map->start); - mem_end = vmlinux_map->unmap_ip (vmlinux_map, map->end); + mem_start =map_sh (vmlinux_map)->unmap_ip (vmlinux_map,map_sh (map)->start); + mem_end =map_sh (vmlinux_map)->unmap_ip (vmlinux_map,map_sh (map)->end); pair =map_groups__find (&kallsyms.kmaps, mem_start); -if (pair ==NULL || pair->priv) +if (pair ==NULL ||map_sh (pair)->priv)continue ; -if (pair->start == mem_start) { +if (map_sh (pair)->start == mem_start) {if (!header_printed) {pr_info ("WARN: Maps in vmlinux with a different name in kallsyms:\n" ); header_printed = true; }pr_info ("WARN: %" PRIx64"-%" PRIx64" %" PRIx64" %s in kallsyms as" , - map->start, map->end, map->pgoff, map->dso->name); -if (mem_end != pair->end) +map_sh (map)->start,map_sh (map)->end,map_sh (map)->pgoff,map_sh (map)->dso->name); +if (mem_end !=map_sh (pair)->end)pr_info (":\nWARN: *%" PRIx64"-%" PRIx64" %" PRIx64, - pair->start, pair->end, pair->pgoff); -pr_info (" %s\n" , pair->dso->name); - pair->priv =1 ; +map_sh (pair)->start,map_sh (pair)->end,map_sh (pair)->pgoff); +pr_info (" %s\n" ,map_sh (pair)->dso->name); +map_sh (pair)->priv =1 ; } }
@@ -238,7 +238,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest maps =machine__kernel_maps (&kallsyms);for (map =maps__first (maps); map; map =map__next (map)) { -if (!map->priv) { +if (!map_sh (map)->priv) {if (!header_printed) {pr_info ("WARN: Maps only in kallsyms:\n" ); header_printed = true;
tools/perf/ui/browsers/annotate.c +2 -2
@@ -393,7 +393,7 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)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->long_name, +return snprintf (title, sz,"%s %s [Percent: %s]" , sym->name,map_sh (map)->dso->long_name,percent_type_str (percent_type)); }
@@ -915,7 +915,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,if (sym ==NULL )return -1 ; -if (map->dso->annotate_warned) +if (map_sh (map)->dso->annotate_warned)return -1 ; err =symbol__annotate2 (sym, map, evsel, opts, &browser.arch);
tools/perf/ui/browsers/hists.c +5 -5
@@ -2402,7 +2402,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused, struct popup_action *act, char **optstr, struct map *map, struct symbol *sym) { - if (sym == NULL || map->dso->annotate_warned) + if (sym == NULL || map_sh(map)->dso->annotate_warned) return 0; if (asprintf(optstr, "Annotate %s", sym->name) < 0)
@@ -2491,8 +2491,8 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act)ui_helpline__pop (); }else {ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"" , -__map__is_kernel (map) ?"the Kernel" : map->dso->short_name); - browser->hists->dso_filter = map->dso; +__map__is_kernel (map) ?"the Kernel" :map_sh (map)->dso->short_name); + browser->hists->dso_filter =map_sh (map)->dso;perf_hpp__set_elide (HISTC_DSO , true);pstack__push (browser->pstack, &browser->hists->dso_filter); }
@@ -2511,7 +2511,7 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,if (asprintf (optstr,"Zoom %s %s DSO" , browser->hists->dso_filter ?"out of" :"into" , -__map__is_kernel (map) ?"the Kernel" : map->dso->short_name) <0 ) +__map__is_kernel (map) ?"the Kernel" :map_sh (map)->dso->short_name) <0 )return 0 ; act->ms.map = map;
@@ -2939,7 +2939,7 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,if (browser->selection ==NULL || browser->selection->sym ==NULL || - browser->selection->map->dso->annotate_warned) +map_sh (browser->selection->map)->dso->annotate_warned)continue ; actions->ms.map = browser->selection->map;
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, browser->map->dso->long_name, +if (ui_browser__show (&browser->b,map_sh (browser->map)->dso->long_name,"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->symbols, + .entries = &map_sh (map)->dso->symbols, .refresh = ui_browser__rb_tree_refresh, .seek = ui_browser__rb_tree_seek, .write = map_browser__write,
tools/perf/ui/gtk/annotate.c +1 -1
@@ -170,7 +170,7 @@ static int symbol__gtk_annotate(struct symbol *sym, struct map *map,GtkWidget *tab_label;int err; -if (map->dso->annotate_warned) +if (map_sh (map)->dso->annotate_warned)return -1 ; err =symbol__annotate (sym, map, evsel,0 , &annotation__default_options,NULL );
tools/perf/util/annotate.c +17 -17
@@ -272,7 +272,7 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s target.addr =map__objdump_2mem (map, ops->target.addr);if (map_groups__find_ams (&target) ==0 && -map__rip_2objdump (target.map, map->map_ip (target.map, target.addr)) == ops->target.addr) +map__rip_2objdump (target.map,map_sh (map)->map_ip (target.map, target.addr)) == ops->target.addr) ops->target.sym = target.sym;return 0 ;
@@ -368,8 +368,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s } target.addr =map__objdump_2mem (map, ops->target.addr); - start = map->unmap_ip (map, sym->start), - end = map->unmap_ip (map, sym->end); + start =map_sh (map)->unmap_ip (map, sym->start), + end =map_sh (map)->unmap_ip (map, sym->end); ops->target.outside = target.addr < start || target.addr > end;
@@ -392,7 +392,7 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s* the symbol searching and disassembly should be done. */ if (map_groups__find_ams (&target) ==0 && -map__rip_2objdump (target.map, map->map_ip (target.map, target.addr)) == ops->target.addr) +map__rip_2objdump (target.map,map_sh (map)->map_ip (target.map, target.addr)) == ops->target.addr) ops->target.sym = target.sym;if (!ops->target.outside) {
@@ -872,7 +872,7 @@ static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,unsigned offset;struct sym_hist *h; -pr_debug3 ("%s: addr=%#" PRIx64"\n" , __func__, map->unmap_ip (map, addr)); +pr_debug3 ("%s: addr=%#" PRIx64"\n" , __func__,map_sh (map)->unmap_ip (map, addr));if ((addr < sym->start || addr >= sym->end) && (addr != sym->end || sym->start != sym->end)) {
@@ -999,13 +999,13 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,if (start && (start->sym == ams->sym || (ams->sym && - start->addr == ams->sym->start + ams->map->start))) + start->addr == ams->sym->start +map_sh (ams->map)->start))) saddr = start->al_addr;if (saddr ==0 )pr_debug2 ("BB with bad start: addr %" PRIx64" start %" PRIx64" sym %" PRIx64" saddr %" PRIx64"\n" , ams->addr, start ? start->addr :0 , - ams->sym ? ams->sym->start + ams->map->start :0 , + ams->sym ? ams->sym->start +map_sh (ams->map)->start :0 , saddr); err =symbol__account_cycles (ams->al_addr, saddr, ams->sym, cycles);if (err)
@@ -1586,7 +1586,7 @@ static void delete_last_nop(struct symbol *sym)int symbol__strerror_disassemble (struct symbol *sym__maybe_unused ,struct map *map,int errnum,char *buf,size_t buflen) { -struct dso *dso = map->dso; +struct dso *dso =map_sh (map)->dso;BUG_ON (buflen ==0 );
@@ -1706,7 +1706,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,disassembler_ftype disassemble;struct map *map = args->ms.map;struct disassemble_info info; -struct dso *dso = map->dso; +struct dso *dso =map_sh (map)->dso;int pc =0 , count, sub_id;struct btf *btf =NULL ;char tpath[PATH_MAX ];
@@ -1908,7 +1908,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) {struct annotation_options *opts = args->options;struct map *map = args->ms.map; -struct dso *dso = map->dso; +struct dso *dso =map_sh (map)->dso;char *command;FILE *file;char symfs_filename[PATH_MAX ];
@@ -1934,8 +1934,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)return err;pr_debug ("%s: filename=%s, sym=%s, start=%#" PRIx64", end=%#" PRIx64"\n" , __func__, - symfs_filename, sym->name, map->unmap_ip (map, sym->start), - map->unmap_ip (map, sym->end)); + symfs_filename, sym->name,map_sh (map)->unmap_ip (map, sym->start), +map_sh (map)->unmap_ip (map, sym->end));pr_debug ("annotating [%p] %30s : [%p] %30s\n" , dso, dso->long_name, sym, sym->name);
@@ -2339,7 +2339,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,struct evsel *evsel, struct annotation_options *opts) { - struct dso *dso = map->dso; + struct dso *dso = map_sh(map)->dso;char *filename;const char *d_filename;const char *evsel_name =perf_evsel__name (evsel);
@@ -2522,7 +2522,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel, }fprintf (fp,"%s() %s\nEvent: %s\n\n" , - ms->sym->name, ms->map->dso->long_name, ev_name); + ms->sym->name,map_sh (ms->map)->dso->long_name, ev_name);symbol__annotate_fprintf2 (ms->sym, fp, opts);fclose (fp);
@@ -2734,7 +2734,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,if (percent_max <=0.5 )continue ; - al->path =get_srcline (map->dso, notes->start + al->offset,NULL , + al->path =get_srcline (map_sh (map)->dso, notes->start + al->offset,NULL , false, true, notes->start + al->offset);insert_source_line (&tmp_root, al, opts); }
@@ -2755,7 +2755,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,struct evsel *evsel, struct annotation_options *opts) { - struct dso *dso = map->dso; + struct dso *dso = map_sh(map)->dso;struct rb_root source_line =RB_ROOT ;struct hists *hists =evsel__hists (evsel);char buf[1024 ];
@@ -2783,7 +2783,7 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,struct evsel *evsel, struct annotation_options *opts) { - struct dso *dso = map->dso; + struct dso *dso = map_sh(map)->dso;struct rb_root source_line =RB_ROOT ;if (symbol__annotate (sym, map, evsel,0 , opts,NULL ) <0 )
tools/perf/util/auxtrace.c +1 -1
@@ -1929,7 +1929,7 @@ static struct dso *load_dso(const char *name)if (map__load (map) <0 )pr_err ("File '%s' not found or has no symbols.\n" , name); - dso =dso__get (map->dso); + dso =dso__get (map_sh (map)->dso);map__put (map);
tools/perf/util/bpf-event.c +4 -4
@@ -57,10 +57,10 @@ static int machine__process_bpf_event_load(struct machine *machine, map =map_groups__find (&machine->kmaps, addr);if (map) { - map->dso->binary_type =DSO_BINARY_TYPE__BPF_PROG_INFO ; - map->dso->bpf_prog.id = id; - map->dso->bpf_prog.sub_id = i; - map->dso->bpf_prog.env = env; +map_sh (map)->dso->binary_type =DSO_BINARY_TYPE__BPF_PROG_INFO ; +map_sh (map)->dso->bpf_prog.id = id; +map_sh (map)->dso->bpf_prog.sub_id = i; +map_sh (map)->dso->bpf_prog.env = env; } }return 0 ;
tools/perf/util/build-id.c +1 -1
@@ -53,7 +53,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, }if (thread__find_map (thread, sample->cpumode, sample->ip, &al)) - al.map->dso->hit =1 ; +map_sh (al.map)->dso->hit =1 ;thread__put (thread);return 0 ;
tools/perf/util/callchain.c +3 -3
@@ -695,8 +695,8 @@ static enum match_result match_chain_strings(const char *left,static enum match_result match_chain_dso_addresses (struct map *left_map,u64 left_ip,struct map *right_map,u64 right_ip) { -struct dso *left_dso = left_map ? left_map->dso :NULL ; -struct dso *right_dso = right_map ? right_map->dso :NULL ; +struct dso *left_dso = left_map ?map_sh (left_map)->dso :NULL ; +struct dso *right_dso = right_map ?map_sh (right_map)->dso :NULL ;if (left_dso != right_dso)return left_dso < right_dso ?MATCH_LT :MATCH_GT ;
@@ -1167,7 +1167,7 @@ char *callchain_list__sym_name(struct callchain_list *cl,if (show_dso)scnprintf (bf + printed, bfsize - printed," %s" , cl->ms.map ? - cl->ms.map->dso->short_name : +map_sh (cl->ms.map)->dso->short_name :"unknown" );return bf;
tools/perf/util/db-export.c +2 -2
@@ -179,7 +179,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,int err;if (al->map) { -struct dso *dso = al->map->dso; +struct dso *dso =map_sh (al->map)->dso; err =db_export__dso (dbe, dso, al->machine);if (err)
@@ -255,7 +255,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe, al.addr = node->ip;if (al.map && !al.sym) - al.sym =dso__find_symbol (al.map->dso, al.addr); + al.sym =dso__find_symbol (map_sh (al.map)->dso, al.addr);db_ids_from_al (dbe, &al, &dso_db_id, &sym_db_id, &offset);
tools/perf/util/dso.c +1 -1
@@ -1061,7 +1061,7 @@ ssize_t dso__data_read_addr(struct dso *dso, struct map *map, struct machine *machine, u64 addr, u8 *data, ssize_t size) { - u64 offset = map->map_ip(map, addr); + u64 offset = map_sh(map)->map_ip(map, addr);return dso__data_read_offset (dso, machine, offset, data, size); }
tools/perf/util/event.c +3 -3
@@ -508,7 +508,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,*/ if (load_map)map__load (al->map); - al->addr = al->map->map_ip (al->map, al->addr); + al->addr =map_sh (al->map)->map_ip (al->map, al->addr); }return al->map;
@@ -566,7 +566,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,dump_printf (" ... thread: %s:%d\n" ,thread__comm_str (thread), thread->tid);thread__find_map (thread, sample->cpumode, sample->ip, al);dump_printf (" ...... dso: %s\n" , - al->map ? al->map->dso->long_name : + al->map ?map_sh (al->map)->dso->long_name : al->level =='H' ?"[hypervisor]" :"<not found>" );if (thread__is_filtered (thread))
@@ -585,7 +585,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al, }if (al->map) { -struct dso *dso = al->map->dso; +struct dso *dso =map_sh (al->map)->dso; if (symbol_conf.dso_list && (!dso || !(strlist__has_entry(symbol_conf.dso_list,
tools/perf/util/evsel_fprintf.c +1 -1
@@ -143,7 +143,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, printed +=fprintf (fp,"%c%16" PRIx64, s, node->ip);if (node->map) - addr = node->map->map_ip (node->map, node->ip); + addr =map_sh (node->map)->map_ip (node->map, node->ip);if (print_sym) { printed +=fprintf (fp," " );
tools/perf/util/hist.c +5 -5
@@ -101,7 +101,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)hists__set_col_len (hists,HISTC_THREAD , len +8 );if (h->ms.map) { - len =dso__name_len (h->ms.map->dso); + len =dso__name_len (map_sh (h->ms.map)->dso);hists__new_col_len (hists,HISTC_DSO , len); }
@@ -115,7 +115,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) symlen +=BITS_PER_LONG /4 +2 +3 ;hists__new_col_len (hists,HISTC_SYMBOL_FROM , symlen); - symlen =dso__name_len (h->branch_info->from.map->dso); + symlen =dso__name_len (map_sh (h->branch_info->from.map)->dso);hists__new_col_len (hists,HISTC_DSO_FROM , symlen); }else { symlen = unresolved_col_width +4 +2 ;
@@ -129,7 +129,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) symlen +=BITS_PER_LONG /4 +2 +3 ;hists__new_col_len (hists,HISTC_SYMBOL_TO , symlen); - symlen =dso__name_len (h->branch_info->to.map->dso); + symlen =dso__name_len (map_sh (h->branch_info->to.map)->dso);hists__new_col_len (hists,HISTC_DSO_TO , symlen); }else { symlen = unresolved_col_width +4 +2 ;
@@ -173,7 +173,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) }if (h->mem_info->daddr.map) { - symlen =dso__name_len (h->mem_info->daddr.map->dso); + symlen =dso__name_len (map_sh (h->mem_info->daddr.map)->dso);hists__new_col_len (hists,HISTC_MEM_DADDR_DSO , symlen); }else {
@@ -2041,7 +2041,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists, struct hist_entry *he) {if (hists->dso_filter !=NULL && - (he->ms.map ==NULL || he->ms.map->dso != hists->dso_filter)) { + (he->ms.map ==NULL ||map_sh (he->ms.map)->dso != hists->dso_filter)) { he->filtered |= (1 <<HIST_FILTER__DSO );return true; }
tools/perf/util/intel-pt.c +24 -18
120 lines not on this page · raw message
tools/perf/util/machine.c +38 -38
220 lines not on this page · raw message
tools/perf/util/map.c +90 -78
436 lines not on this page · raw message
tools/perf/util/map.h +18 -11
@@ -17,13 +17,9 @@ struct ref_reloc_sym;struct map_groups ;struct machine ;struct evsel ; +struct map ; -struct map { -union { -struct rb_node rb_node; -struct list_head node; - }; -struct rb_node rb_node_name; +struct map_shared {u64 start;u64 end;bool erange_warned;
@@ -42,10 +38,21 @@ struct map {u64 (*unmap_ip)(struct map *,u64 );struct dso *dso; +}; + +struct map { +union { +struct rb_node rb_node; +struct list_head node; + }; +struct rb_node rb_node_name; +struct map_shared shared;struct map_groups *groups; -refcount_t refcnt; +refcount_t refcnt; }; +#define map_sh (__m) (&((__m)->shared)) +struct kmap ;struct kmap *__map__kmap (struct map *map);
@@ -54,12 +61,12 @@ struct map_groups *map__kmaps(struct map *map);static inline u64 map__map_ip (struct map *map,u64 ip) { -return ip - map->start + map->pgoff; +return ip -map_sh (map)->start +map_sh (map)->pgoff; }static inline u64 map__unmap_ip (struct map *map,u64 ip) { -return ip + map->start - map->pgoff; +return ip +map_sh (map)->start -map_sh (map)->pgoff; }static inline u64 identity__map_ip (struct map *map__maybe_unused ,u64 ip)
@@ -69,7 +76,7 @@ static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)static inline size_t map__size (const struct map *map) { -return map->end - map->start; +return map_sh (map)->end -map_sh (map)->start; }/* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
@@ -89,7 +96,7 @@ struct thread;* Note: caller must ensure map->dso is not NULL (map is loaded). */ #define map__for_each_symbol (map, pos, n) \ - dso__for_each_symbol(map->dso, pos, n) + dso__for_each_symbol(map_sh(map)->dso, pos, n)/* map__for_each_symbol_with_name - iterate over the symbols in the given map * that have the given name
tools/perf/util/probe-event.c +16 -16
@@ -132,9 +132,9 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr, sym =machine__find_kernel_symbol_by_name (host_machine, name, &map);if (!sym)return -ENOENT ; - *addr = map->unmap_ip (map, sym->start) - - ((reloc) ?0 : map->reloc) - - ((reladdr) ? map->start :0 ); + *addr =map_sh (map)->unmap_ip (map, sym->start) - + ((reloc) ?0 :map_sh (map)->reloc) - + ((reladdr) ?map_sh (map)->start :0 ); }return 0 ; }
@@ -155,9 +155,9 @@ static struct map *kernel_get_module_map(const char *module)for (pos =maps__first (maps); pos; pos =map__next (pos)) {/* short_name is "[module]" */ -if (strncmp (pos->dso->short_name +1 , module, - pos->dso->short_name_len -2 ) ==0 && - module[pos->dso->short_name_len -2 ] =='\0' ) { +if (strncmp (map_sh (pos)->dso->short_name +1 , module, +map_sh (pos)->dso->short_name_len -2 ) ==0 && + module[map_sh (pos)->dso->short_name_len -2 ] =='\0' ) {return map__get (pos); } }
@@ -171,8 +171,8 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)struct map *map; map =dso__new_map (target); -if (map && map->dso) - map->dso->nsinfo =nsinfo__get (nsi); +if (map &&map_sh (map)->dso) +map_sh (map)->dso->nsinfo =nsinfo__get (nsi);return map; }else {return kernel_get_module_map (target);
@@ -323,7 +323,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)snprintf (module_name,sizeof (module_name),"[%s]" , module); map =map_groups__find_by_name (&host_machine->kmaps, module_name);if (map) { - dso = map->dso; + dso =map_sh (map)->dso; goto found; }pr_debug ("Failed to find module %s.\n" , module);
@@ -331,7 +331,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso) } map =machine__kernel_map (host_machine); - dso = map->dso; + dso =map_sh (map)->dso; vmlinux_name = symbol_conf.vmlinux_name; dso->load_errno =0 ;
@@ -373,7 +373,7 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,if (uprobes) address = sym->start;else - address = map->unmap_ip (map, sym->start) - map->reloc; + address =map_sh (map)->unmap_ip (map, sym->start) -map_sh (map)->reloc;break ; }if (!address) {
@@ -2123,7 +2123,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp, goto out; pp->retprobe = tp->retprobe; - pp->offset = addr - map->unmap_ip (map, sym->start); + pp->offset = addr -map_sh (map)->unmap_ip (map, sym->start); pp->function =strdup (sym->name); ret = pp->function ?0 : -ENOMEM ;
@@ -2958,7 +2958,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, goto err_out; }/* Add one probe point */ - tp->address = map->unmap_ip (map, sym->start) + pp->offset; + tp->address =map_sh (map)->unmap_ip (map, sym->start) + pp->offset;/* Check the kprobe (not in module) is within .text */ if (!pev->uprobes && !pev->target &&
@@ -3528,13 +3528,13 @@ int show_available_funcs(const char *target, struct nsinfo *nsi, (target) ? : "kernel"); goto end; } -if (!dso__sorted_by_name (map->dso)) -dso__sort_by_name (map->dso); +if (!dso__sorted_by_name (map_sh (map)->dso)) +dso__sort_by_name (map_sh (map)->dso);/* Show all (filtered) symbols */ setup_pager (); -for (nd =rb_first_cached (&map->dso->symbol_names); nd; +for (nd =rb_first_cached (&map_sh (map)->dso->symbol_names); nd; nd =rb_next (nd)) { struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
tools/perf/util/scripting-engines/trace-event-perl.c +4 -4
@@ -315,11 +315,11 @@ static SV *perl_process_callchain(struct perf_sample *sample,if (node->map) {struct map *map = node->map;const char *dsoname ="[unknown]" ; -if (map && map->dso) { -if (symbol_conf.show_kernel_path && map->dso->long_name) - dsoname = map->dso->long_name; +if (map &&map_sh (map)->dso) { +if (symbol_conf.show_kernel_path &&map_sh (map)->dso->long_name) + dsoname =map_sh (map)->dso->long_name;else - dsoname = map->dso->name; + dsoname =map_sh (map)->dso->name; }if (!hv_stores (elem,"dso" ,newSVpv (dsoname,0 ))) {hv_undef (elem);
tools/perf/util/scripting-engines/trace-event-python.c +6 -6
@@ -381,11 +381,11 @@ static const char *get_dsoname(struct map *map) {const char *dsoname ="[unknown]" ; -if (map && map->dso) { -if (symbol_conf.show_kernel_path && map->dso->long_name) - dsoname = map->dso->long_name; +if (map &&map_sh (map)->dso) { +if (symbol_conf.show_kernel_path &&map_sh (map)->dso->long_name) + dsoname =map_sh (map)->dso->long_name;else - dsoname = map->dso->name; + dsoname =map_sh (map)->dso->name; }return dsoname;
@@ -525,7 +525,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al)if (al->addr < sym->end) offset = al->addr - sym->start;else - offset = al->addr - al->map->start - sym->start; + offset = al->addr -map_sh (al->map)->start - sym->start;return offset; }
@@ -769,7 +769,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, _PyUnicode_FromString(thread__comm_str(al->thread)));if (al->map) {pydict_set_item_string_decref (dict,"dso" , -_PyUnicode_FromString (al->map->dso->name)); +_PyUnicode_FromString (map_sh (al->map)->dso->name)); }if (al->sym) { pydict_set_item_string_decref(dict, "symbol",
tools/perf/util/sort.c +31 -27
139 lines not on this page · raw message
tools/perf/util/symbol-elf.c +14 -14
@@ -868,11 +868,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,*/ if (*remap_kernel && dso->kernel) { *remap_kernel = false; - map->start = shdr->sh_addr +ref_reloc (kmap); - map->end = map->start + shdr->sh_size; - map->pgoff = shdr->sh_offset; - map->map_ip = map__map_ip; - map->unmap_ip = map__unmap_ip; +map_sh (map)->start = shdr->sh_addr +ref_reloc (kmap); +map_sh (map)->end =map_sh (map)->start + shdr->sh_size; +map_sh (map)->pgoff = shdr->sh_offset; +map_sh (map)->map_ip = map__map_ip; +map_sh (map)->unmap_ip = map__unmap_ip;/* Ensure maps are correctly ordered */ if (kmaps) {map__get (map);
@@ -889,7 +889,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,*/ if (*remap_kernel && kmodule) { *remap_kernel = false; - map->pgoff = shdr->sh_offset; +map_sh (map)->pgoff = shdr->sh_offset; } *curr_mapp = map;
@@ -907,7 +907,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,u64 start = sym->st_value;if (kmodule) - start += map->start + shdr->sh_offset; + start +=map_sh (map)->start + shdr->sh_offset; curr_dso =dso__new (dso_name);if (curr_dso ==NULL )
@@ -921,11 +921,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,return -1 ;if (adjust_kernel_syms) { - curr_map->start = shdr->sh_addr +ref_reloc (kmap); - curr_map->end = curr_map->start + shdr->sh_size; - curr_map->pgoff = shdr->sh_offset; +map_sh (curr_map)->start = shdr->sh_addr +ref_reloc (kmap); +map_sh (curr_map)->end =map_sh (curr_map)->start + shdr->sh_size; +map_sh (curr_map)->pgoff = shdr->sh_offset; }else { - curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; +map_sh (curr_map)->map_ip =map_sh (curr_map)->unmap_ip = identity__map_ip; } curr_dso->symtab_type = dso->symtab_type;map_groups__insert (kmaps, curr_map);
@@ -941,7 +941,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, *curr_mapp = curr_map; *curr_dsop = curr_dso; }else - *curr_dsop = curr_map->dso; + *curr_dsop =map_sh (curr_map)->dso;return 0 ; }
@@ -1041,7 +1041,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,if (strcmp (elf_name, kmap->ref_reloc_sym->name))continue ; kmap->ref_reloc_sym->unrelocated_addr = sym.st_value; - map->reloc = kmap->ref_reloc_sym->addr - +map_sh (map)->reloc = kmap->ref_reloc_sym->addr - kmap->ref_reloc_sym->unrelocated_addr;break ; }
@@ -1052,7 +1052,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,* attempted to prelink vdso to its virtual address. */ if (dso__is_vdso (dso)) - map->reloc = map->start - dso->text_offset; +map_sh (map)->reloc =map_sh (map)->start - dso->text_offset; dso->adjust_symbols = runtime_ss->adjust_symbols ||ref_reloc (kmap);/*
tools/perf/util/symbol.c +39 -39
216 lines not on this page · raw message
tools/perf/util/symbol_fprintf.c +1 -1
@@ -30,7 +30,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,if (al->addr < sym->end) offset = al->addr - sym->start;else - offset = al->addr - al->map->start - sym->start; + offset = al->addr -map_sh (al->map)->start - sym->start; length +=fprintf (fp,"+0x%lx" , offset); }return length;
tools/perf/util/synthetic-events.c +7 -7
@@ -444,18 +444,18 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_tif (!__map__is_kmodule (pos))continue ; - size =PERF_ALIGN (pos->dso->long_name_len +1 ,sizeof (u64)); + size =PERF_ALIGN (map_sh (pos)->dso->long_name_len +1 ,sizeof (u64)); event->mmap.header.type =PERF_RECORD_MMAP ; event->mmap.header.size = (sizeof (event->mmap) - (sizeof (event->mmap.filename) - size));memset (event->mmap.filename + size,0 , machine->id_hdr_size); event->mmap.header.size += machine->id_hdr_size; - event->mmap.start = pos->start; - event->mmap.len = pos->end - pos->start; + event->mmap.start =map_sh (pos)->start; + event->mmap.len =map_sh (pos)->end -map_sh (pos)->start; event->mmap.pid = machine->pid; -memcpy (event->mmap.filename, pos->dso->long_name, - pos->dso->long_name_len +1 ); +memcpy (event->mmap.filename,map_sh (pos)->dso->long_name, +map_sh (pos)->dso->long_name_len +1 );if (perf_tool__process_synth_event (tool, event, machine, process) !=0 ) { rc =-1 ;break ;
@@ -856,8 +856,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool, event->mmap.header.size = (sizeof (event->mmap) - (sizeof (event->mmap.filename) - size) + machine->id_hdr_size); event->mmap.pgoff = kmap->ref_reloc_sym->addr; - event->mmap.start = map->start; - event->mmap.len = map->end - event->mmap.start; + event->mmap.start =map_sh (map)->start; + event->mmap.len =map_sh (map)->end - event->mmap.start; event->mmap.pid = machine->pid; err =perf_tool__process_synth_event (tool, event, machine, process);
tools/perf/util/thread.c +7 -7
@@ -443,14 +443,14 @@ int thread__memcpy(struct thread *thread, struct machine *machine,if (machine__kernel_ip (machine, ip)) cpumode =PERF_RECORD_MISC_KERNEL ; -if (!thread__find_map (thread, cpumode, ip, &al) || !al.map->dso || - al.map->dso->data.status ==DSO_DATA_STATUS_ERROR || +if (!thread__find_map (thread, cpumode, ip, &al) || !map_sh (al.map)->dso || +map_sh (al.map)->dso->data.status ==DSO_DATA_STATUS_ERROR ||map__load (al.map) <0 ) -return -1 ; +return -1 ; - offset = al.map->map_ip (al.map, ip); -if (is64bit) - *is64bit = al.map->dso->is_64_bit; + offset =map_sh (al.map)->map_ip (al.map, ip); +if (is64bit) + *is64bit =map_sh (al.map)->dso->is_64_bit; -return dso__data_read_offset (al.map->dso, machine, offset, buf, len); +return dso__data_read_offset (map_sh (al.map)->dso, machine, offset, buf, len); }
tools/perf/util/unwind-libdw.c +10 -6
@@ -31,6 +31,8 @@ static int __report_module(struct addr_location *al, u64 ip, {Dwfl_Module *mod;struct dso *dso =NULL ; +struct map_shared *sh; +/* * Some callers will use al->sym, so we can't just use the * cheaper thread__find_map() here.
@@ -38,23 +40,25 @@ static int __report_module(struct addr_location *al, u64 ip,thread__find_symbol (ui->thread,PERF_RECORD_MISC_USER , ip, al);if (al->map) - dso = al->map->dso; + dso =map_sh (al->map)->dso;if (!dso)return 0 ; + sh =map_sh (al->map); + mod =dwfl_addrmodule (ui->dwfl, ip);if (mod) {Dwarf_Addr s;dwfl_module_info (mod,NULL , &s,NULL ,NULL ,NULL ,NULL ,NULL ); -if (s != al->map->start - al->map->pgoff) +if (s != sh->start - sh->pgoff) mod =0 ; }if (!mod) mod =dwfl_report_elf (ui->dwfl, dso->short_name, - (dso->symsrc_filename ? dso->symsrc_filename : dso->long_name),-1 , al->map->start - al->map->pgoff, + (dso->symsrc_filename ? dso->symsrc_filename : dso->long_name),-1 , sh->start - sh->pgoff, false);return mod &&dwfl_addrmodule (ui->dwfl, ip) == mod ?0 :-1 ;
@@ -87,7 +91,7 @@ static int entry(u64 ip, struct unwind_info *ui)pr_debug ("unwind: %s:ip = 0x%" PRIx64" (0x%" PRIx64")\n" , al.sym ? al.sym->name :"''" , ip, - al.map ? al.map->map_ip (al.map, ip) : (u64 )0 ); + al.map ?map_sh (al.map)->map_ip (al.map, ip) : (u64 )0 );return 0 ; }
@@ -112,10 +116,10 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,return -1 ; } -if (!al.map->dso) +if (!map_sh (al.map)->dso)return -1 ; - size =dso__data_read_addr (al.map->dso, al.map, ui->machine, + size =dso__data_read_addr (map_sh (al.map)->dso, al.map, ui->machine, addr, (u8 *) data,sizeof (*data));return !(size ==sizeof (*data));
tools/perf/util/unwind-libunwind-local.c +20 -17
@@ -376,25 +376,28 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi, {struct unwind_info *ui = arg;struct map *map; +struct map_shared *sh;unw_dyn_info_t di;u64 table_data, segbase, fde_count;int ret = -EINVAL ; map =find_map (ip, ui); -if (!map || !map->dso) +if (!map || !map_sh (map)->dso)return -EINVAL ; -pr_debug ("unwind: find_proc_info dso %s\n" , map->dso->name); + sh =map_sh (map); + +pr_debug ("unwind: find_proc_info dso %s\n" , sh->dso->name);/* Check the .eh_frame section for unwinding info */ -if (!read_unwind_spec_eh_frame (map->dso, ui->machine, +if (!read_unwind_spec_eh_frame (sh->dso, ui->machine, &table_data, &segbase, &fde_count)) {memset (&di,0 ,sizeof (di)); di.format =UNW_INFO_FORMAT_REMOTE_TABLE ; - di.start_ip = map->start; - di.end_ip = map->end; - di.u.rti.segbase = map->start + segbase - map->pgoff; - di.u.rti.table_data = map->start + table_data - map->pgoff; + di.start_ip = sh->start; + di.end_ip = sh->end; + di.u.rti.segbase = sh->start + segbase - sh->pgoff; + di.u.rti.table_data = sh->start + table_data - sh->pgoff; di.u.rti.table_len = fde_count *sizeof (struct table_entry ) /sizeof (unw_word_t); ret = dwarf_search_unwind_table(as, ip, &di, pi,
@@ -404,20 +407,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,#ifndef NO_LIBUNWIND_DEBUG_FRAME /* Check the .debug_frame section for unwinding info */ if (ret <0 && - !read_unwind_spec_debug_frame (map->dso, ui->machine, &segbase)) { -int fd =dso__data_get_fd (map->dso, ui->machine); -int is_exec =elf_is_exec (fd, map->dso->name); -unw_word_t base = is_exec ?0 : map->start; + !read_unwind_spec_debug_frame (sh->dso, ui->machine, &segbase)) { +int fd =dso__data_get_fd (sh->dso, ui->machine); +int is_exec =elf_is_exec (fd, sh->dso->name); +unw_word_t base = is_exec ?0 : sh->start;const char *symfile;if (fd >=0 ) -dso__data_put_fd (map->dso); +dso__data_put_fd (sh->dso); - symfile = map->dso->symsrc_filename ?: map->dso->name; + symfile = sh->dso->symsrc_filename ?: sh->dso->name;memset (&di,0 ,sizeof (di));if (dwarf_find_debug_frame (0 , &di, ip, base, symfile, - map->start, map->end)) + sh->start, sh->end))return dwarf_search_unwind_table (as, ip, &di, pi, need_unwind_info, arg); }
@@ -473,10 +476,10 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,return -1 ; } -if (!map->dso) +if (!map_sh (map)->dso)return -1 ; - size =dso__data_read_addr (map->dso, map, ui->machine, + size =dso__data_read_addr (map_sh (map)->dso, map, ui->machine, addr, (u8 *) data,sizeof (*data));return !(size ==sizeof (*data));
@@ -582,7 +585,7 @@ static int entry(u64 ip, struct thread *thread,pr_debug ("unwind: %s:ip = 0x%" PRIx64" (0x%" PRIx64")\n" , al.sym ? al.sym->name :"''" , ip, - al.map ? al.map->map_ip (al.map, ip) : (u64 )0 ); + al.map ?map_sh (al.map)->map_ip (al.map, ip) : (u64 )0 );return cb (&e, arg); }
tools/perf/util/unwind-libunwind.c +2 -2
@@ -31,7 +31,7 @@ int unwind__prepare_access(struct map_groups *mg, struct map *map,if (mg->addr_space) {pr_debug ("unwind: thread map already set, dso=%s\n" , - map->dso->name); +map_sh (map)->dso->name);if (initialized) *initialized = true;return 0 ;
@@ -41,7 +41,7 @@ int unwind__prepare_access(struct map_groups *mg, struct map *map,if (!mg->machine->env || !mg->machine->env->arch) goto out_register; - dso_type =dso__type (map->dso, mg->machine); + dso_type =dso__type (map_sh (map)->dso, mg->machine);if (dso_type ==DSO__TYPE_UNKNOWN )return 0 ;
tools/perf/util/vdso.c +1 -1
@@ -145,7 +145,7 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,struct map *map =map_groups__first (thread->mg);for (; map ; map =map_groups__next (map)) { -struct dso *dso = map->dso; +struct dso *dso =map_sh (map)->dso;if (!dso || dso->long_name[0 ] !='/' )continue ; dso_type =dso__type (dso, machine);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH v2 2/2 perf tools: Make 'struct map_shared' truly shared
In reply to Jiri OlsaAndi reported that maps cloning is eating lot of memory and it's probably unnecessary, because they keep the same data.
Changing 'struct map_shared' to be a pointer inside 'struct map', so it can be shared on fork. Changing the map__clone function to actually share 'struct map_shared' for cloned maps.
The 'struct map_shared' carries its own refcnt counter, which is incremented when it's assigned to new 'struct map' and decremented when 'struct map' gets deleted in map__delete (its refcnt is 0).
This 'maps sharing' seems to save lot of heap for reports with many forks/cloned mmaps (over 60% in example below).
Profile kernel build:
$ perf record make -j 40
Get heap profile (tools/perf directory):
$ <install gperftools> $ make TCMALLOC=1 $ HEAPPROFILE=/tmp/heapprof ./perf report -i perf.data --stdio > out $ pprof ./perf /tmp/heapprof.000*
Before:
(pprof) top
Total: 2335.5 MB
1735.1 74.3% 74.3% 1735.1 74.3% memdup
402.0 17.2% 91.5% 402.0 17.2% zalloc
140.2 6.0% 97.5% 145.8 6.2% map__new
33.6 1.4% 98.9% 33.6 1.4% symbol__new
12.4 0.5% 99.5% 12.4 0.5% alloc_event
6.2 0.3% 99.7% 6.2 0.3% nsinfo__new
5.5 0.2% 100.0% 5.5 0.2% nsinfo__copy
0.3 0.0% 100.0% 0.3 0.0% dso__new
0.1 0.0% 100.0% 0.1 0.0% do_read_string
0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocateAfter:
(pprof) top
Total: 758.5 MB
385.7 50.8% 50.8% 385.7 50.8% memdup
248.4 32.7% 83.6% 248.4 32.7% zalloc
91.2 12.0% 95.6% 94.8 12.5% map__new
19.3 2.5% 98.2% 19.3 2.5% symbol__new
6.2 0.8% 99.0% 6.2 0.8% alloc_event
3.9 0.5% 99.5% 3.9 0.5% nsinfo__new
3.5 0.5% 100.0% 3.5 0.5% nsinfo__copy
0.2 0.0% 100.0% 0.2 0.0% dso__new
0.0 0.0% 100.0% 0.0 0.0% do_read_string
0.0 0.0% 100.0% 0.0 0.0% elf_fillThe perf report output is the same.
--- tools/perf/util/map.c | 62 ++++++++++++++++++++++++++++++++-------- tools/perf/util/map.h | 7 +++-- tools/perf/util/symbol.c | 2 +- 3 files changed, 55 insertions(+), 16 deletions(-)
tools/perf/util/map.c +50 -12
@@ -145,6 +145,7 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso) map->groups =NULL ; sh->erange_warned = false;refcount_set (&map->refcnt,1 ); +refcount_set (&sh->refcnt,1 ); } struct map *map__new(struct machine *machine, u64 start, u64 len,
@@ -153,14 +154,16 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, struct thread *thread) {struct map *map =malloc (sizeof (*map)); +struct map_shared *sh =malloc (sizeof (*sh));struct nsinfo *nsi =NULL ;struct nsinfo *nnsi; -if (map !=NULL ) { +if (map !=NULL && sh !=NULL ) {char newfilename[PATH_MAX ];struct dso *dso;int anon, no_dso, vdso, android; -struct map_shared *sh =map_sh (map); + + map->shared = sh; android =is_android_lib (filename); anon =is_anon_memory (filename, flags);
@@ -220,11 +223,12 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, } dso->nsinfo = nsi;dso__put (dso); +return map; } -return map; out_delete:nsinfo__put (nsi);free (map); +free (sh);return NULL ; }
@@ -235,13 +239,19 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,*/ struct map *map__new2 (u64 start,struct dso *dso) { +struct map_shared *sh =zalloc (sizeof (*sh));struct map *map =calloc (1 , (sizeof (*map) + (dso->kernel ?sizeof (struct kmap ) :0 ))); -if (map !=NULL ) { + +if (map !=NULL && sh !=NULL ) { + map->shared = sh;/* * ->end will be filled after we load all the symbols */ map__init (map, start,0 ,0 , dso); + }else { +zfree (&map); +free (sh); }return map;
@@ -289,15 +299,29 @@ bool map__has_symbols(const struct map *map)return dso__has_symbols (map_sh (map)->dso); } -static void map__exit (struct map *map) +static void map_shared__delete (struct map_shared *sh) { -BUG_ON (!RB_EMPTY_NODE (&map->rb_node)); -dso__zput (map_sh (map)->dso); +dso__put (sh->dso); +free (sh); +} + +static struct map_shared *map_shared__get (struct map_shared *sh) +{ +if (sh) +refcount_inc (&sh->refcnt); +return sh; +} + +static void map_shared__put (struct map_shared *sh) +{ +if (sh &&refcount_dec_and_test (&sh->refcnt)) +map_shared__delete (sh); }void map__delete (struct map *map) { -map__exit (map); +BUG_ON (!RB_EMPTY_NODE (&map->rb_node)); +map_shared__put (map->shared);free (map); }
@@ -390,12 +414,26 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)return dso__find_symbol_by_name (map_sh (map)->dso, name); } -struct map *map__clone (struct map *from) +struct map *map__clone (struct map *from,bool share) {struct map *map =memdup (from,sizeof (*map)); +struct map_shared *sh;if (map !=NULL ) {refcount_set (&map->refcnt,1 ); + +if (share) { + sh =map_shared__get (map->shared); + }else { + sh =memdup (map->shared,sizeof (*sh)); +if (!sh) { +free (map); +return NULL ; + } + map->shared = sh; +refcount_set (&sh->refcnt,1 ); + } +RB_CLEAR_NODE (&map->rb_node);dso__get (map_sh (map)->dso); map->groups =NULL ;
@@ -840,7 +878,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp* overlapped by the new map: */ if (map_sh (map)->start >map_sh (pos)->start) { -struct map *before =map__clone (pos); +struct map *before =map__clone (pos, false);if (before ==NULL ) { err = -ENOMEM ;
@@ -855,7 +893,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp }if (map_sh (map)->end <map_sh (pos)->end) { -struct map *after =map__clone (pos); +struct map *after =map__clone (pos, false);if (after ==NULL ) { err = -ENOMEM ;
@@ -902,7 +940,7 @@ int map_groups__clone(struct thread *thread, struct map_groups *parent)down_read (&maps->lock);for (map =maps__first (maps); map; map =map__next (map)) { -struct map *new =map__clone (map); +struct map *new =map__clone (map, true);if (new ==NULL ) goto out_unlock;
tools/perf/util/map.h +4 -3
@@ -38,6 +38,7 @@ struct map_shared {u64 (*unmap_ip)(struct map *,u64 );struct dso *dso; +refcount_t refcnt; };struct map {
@@ -46,12 +47,12 @@ struct map {struct list_head node; };struct rb_node rb_node_name; -struct map_shared shared; +struct map_shared *shared;struct map_groups *groups;refcount_t refcnt; }; -#define map_sh (__m) (&((__m)->shared)) +#define map_sh (__m) ((__m)->shared)struct kmap ;
@@ -123,7 +124,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, char *filename, struct thread *thread);struct map *map__new2 (u64 start,struct dso *dso);void map__delete (struct map *map); -struct map *map__clone (struct map *map); +struct map *map__clone (struct map *map,bool share);static inline struct map *map__get (struct map *map) {
tools/perf/util/symbol.c +1 -1
@@ -1213,7 +1213,7 @@ int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map)* |new.............| -> |new..| |new..| * |old....| -> |old....| */ -struct map *m =map__clone (new_map); +struct map *m =map__clone (new_map, false);if (!m)return -ENOMEM ;
Signature · 1 line
2.21.0
Quoted 48 lines · Jiri Olsa
hi,
Andi reported that maps cloning is eating lot of memory and it's probably unnecessary, because they keep the same data.This 'maps sharing' seems to save lot of heap for reports with many forks/cloned mmaps (over 60% in example below).
Profile kernel build:
$ perf record make -j 40Get heap profile (
tools/perfdirectory):$ <install gperftools> $ make TCMALLOC=1 $ HEAPPROFILE=/tmp/heapprof ./perf report -i perf.data --stdio > out $ pprof ./perf /tmp/heapprof.000*Before:
(pprof) top
Total: 2335.5 MB1735.1 74.3% 74.3% 1735.1 74.3% memdup 402.0 17.2% 91.5% 402.0 17.2% zalloc 140.2 6.0% 97.5% 145.8 6.2% map__new 33.6 1.4% 98.9% 33.6 1.4% symbol__new 12.4 0.5% 99.5% 12.4 0.5% alloc_event 6.2 0.3% 99.7% 6.2 0.3% nsinfo__new 5.5 0.2% 100.0% 5.5 0.2% nsinfo__copy 0.3 0.0% 100.0% 0.3 0.0% dso__new 0.1 0.0% 100.0% 0.1 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocateAfter:
(pprof) top
Total: 784.5 MB385.8 49.2% 49.2% 385.8 49.2% memdup 285.8 36.4% 85.6% 285.8 36.4% zalloc 80.4 10.3% 95.9% 83.7 10.7% map__new 19.1 2.4% 98.3% 19.1 2.4% symbol__new 6.2 0.8% 99.1% 6.2 0.8% alloc_event 3.6 0.5% 99.6% 3.6 0.5% nsinfo__new 3.2 0.4% 100.0% 3.2 0.4% nsinfo__copy 0.2 0.0% 100.0% 0.2 0.0% dso__new 0.0 0.0% 100.0% 0.0 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% elf_fill
Quoted 7 lines
v2 changes:
- rebased to Arnaldo's perf/core
- patch 1 already takenAlso available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_shared
I rebased to latest perf/core and pushed the branch out
jirka
Quoted 53 lines · Jiri Olsa
Quoted 52 lines · Jiri Olsa
hi,
Andi reported that maps cloning is eating lot of memory and it's probably unnecessary, because they keep the same data.This 'maps sharing' seems to save lot of heap for reports with many forks/cloned mmaps (over 60% in example below).
Profile kernel build:
$ perf record make -j 40Get heap profile (
tools/perfdirectory):$ <install gperftools> $ make TCMALLOC=1 $ HEAPPROFILE=/tmp/heapprof ./perf report -i perf.data --stdio > out $ pprof ./perf /tmp/heapprof.000*Before:
(pprof) top
Total: 2335.5 MB1735.1 74.3% 74.3% 1735.1 74.3% memdup 402.0 17.2% 91.5% 402.0 17.2% zalloc 140.2 6.0% 97.5% 145.8 6.2% map__new 33.6 1.4% 98.9% 33.6 1.4% symbol__new 12.4 0.5% 99.5% 12.4 0.5% alloc_event 6.2 0.3% 99.7% 6.2 0.3% nsinfo__new 5.5 0.2% 100.0% 5.5 0.2% nsinfo__copy 0.3 0.0% 100.0% 0.3 0.0% dso__new 0.1 0.0% 100.0% 0.1 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocateAfter:
(pprof) top
Total: 784.5 MB385.8 49.2% 49.2% 385.8 49.2% memdup 285.8 36.4% 85.6% 285.8 36.4% zalloc 80.4 10.3% 95.9% 83.7 10.7% map__new 19.1 2.4% 98.3% 19.1 2.4% symbol__new 6.2 0.8% 99.1% 6.2 0.8% alloc_event 3.6 0.5% 99.6% 3.6 0.5% nsinfo__new 3.2 0.4% 100.0% 3.2 0.4% nsinfo__copy 0.2 0.0% 100.0% 0.2 0.0% dso__new 0.0 0.0% 100.0% 0.0 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% elf_fillv2 changes:
- rebased to Arnaldo's perf/core
- patch 1 already taken
Quoted 5 lines
Quoted 3 lines
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_sharedI rebased to latest perf/core and pushed the branch out
rebased and pushed out
jirka
Quoted 54 lines · Jiri Olsa
Quoted 53 lines · Jiri Olsa
Quoted 52 lines · Jiri Olsa
hi,
Andi reported that maps cloning is eating lot of memory and it's probably unnecessary, because they keep the same data.This 'maps sharing' seems to save lot of heap for reports with many forks/cloned mmaps (over 60% in example below).
Profile kernel build:
$ perf record make -j 40Get heap profile (
tools/perfdirectory):$ <install gperftools> $ make TCMALLOC=1 $ HEAPPROFILE=/tmp/heapprof ./perf report -i perf.data --stdio > out $ pprof ./perf /tmp/heapprof.000*Before:
(pprof) top
Total: 2335.5 MB1735.1 74.3% 74.3% 1735.1 74.3% memdup 402.0 17.2% 91.5% 402.0 17.2% zalloc 140.2 6.0% 97.5% 145.8 6.2% map__new 33.6 1.4% 98.9% 33.6 1.4% symbol__new 12.4 0.5% 99.5% 12.4 0.5% alloc_event 6.2 0.3% 99.7% 6.2 0.3% nsinfo__new 5.5 0.2% 100.0% 5.5 0.2% nsinfo__copy 0.3 0.0% 100.0% 0.3 0.0% dso__new 0.1 0.0% 100.0% 0.1 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocateAfter:
(pprof) top
Total: 784.5 MB385.8 49.2% 49.2% 385.8 49.2% memdup 285.8 36.4% 85.6% 285.8 36.4% zalloc 80.4 10.3% 95.9% 83.7 10.7% map__new 19.1 2.4% 98.3% 19.1 2.4% symbol__new 6.2 0.8% 99.1% 6.2 0.8% alloc_event 3.6 0.5% 99.6% 3.6 0.5% nsinfo__new 3.2 0.4% 100.0% 3.2 0.4% nsinfo__copy 0.2 0.0% 100.0% 0.2 0.0% dso__new 0.0 0.0% 100.0% 0.0 0.0% do_read_string 0.0 0.0% 100.0% 0.0 0.0% elf_fillv2 changes:
- rebased to Arnaldo's perf/core
- patch 1 already taken
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_sharedI rebased to latest perf/core and pushed the branch out
rebased and pushed out
heya,
I lost track of this.. what's the status, are you going with your version, or is this one still in? I don't see any of them in latest code..
thanks,
jirka
Em Mon, Nov 18, 2019 at 01:14:00PM +0100, Jiri Olsa escreveu:
Quoted 6 lines · Jiri Olsa
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_shared
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I rebased to latest perf/core and pushed the branch out
rebased and pushed out
heya,
I lost track of this.. what's the status, are you going with your version, or is this one still in? I don't see any of them in latest code..
So, I'm still working on and off on this, current status is at:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=perf/map_share
Its just one patch more than perf/core, the one that does the sharing.
The thing is, as I'm going over all the fields in 'struct map', it seems that we'll end up with just one cacheline per instance, as there are things there that are not strictly related to a map, but to a map_group (unmap_ip/map_ip), or to a dso (maj, min, ino, ino_generation), and some need less than what is allocated to them.
Current status is:
[root@quaco ~]# pahole -C map ~acme/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));[root@quaco ~]#
This is with the tentative move of maj/min/ino/ino_generation to 'struct dso', but that needs more work to match the sort order that touches it "dcacheline", i.e. a map that comes with the same backing DSO but different values for those fields is not the same DSO, right?
Right now with moving the maj/min/etc to dso, in the map_share patch we get the structure used to keep shared entries in the rb_tree at 40 bytes, under one cacheline, while the full 'struct map' is 32 bytes more than one cacheline, so still good for sharing:
[acme@quaco perf]$ pahole -C map_node ~/bin/perf
struct map_node {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
refcount_t refcnt; /* 24 4 */
_Bool is_node:1; /* 28: 0 1 */
/* XXX 7 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
struct map * map; /* 32 8 */
/* size: 40, cachelines: 1, members: 4 */
/* sum members: 36, holes: 1, sum holes: 3 */
/* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 7 bits */
/* forced alignments: 1 */
/* last cacheline: 40 bytes */
} __attribute__((__aligned__(8)));
[acme@quaco perf]$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
refcount_t refcnt; /* 24 4 */
_Bool is_node:1; /* 28: 0 1 */
_Bool erange_warned:1; /* 28: 1 1 */
_Bool priv:1; /* 28: 2 1 */
/* XXX 5 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u64 start; /* 32 8 */
u64 end; /* 40 8 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
u32 flags; /* 88 4 */
u32 prot; /* 92 4 */
/* size: 96, cachelines: 2, members: 14 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 3 bits, bit holes: 1, sum bit holes: 5 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));[acme@quaco perf]$
So give me some more time, please :-)
The sharing map is this one, without the maj/map/ move to 'struct dso':
- Arnaldo
Quoted 123 lines · Arnaldo Carvalho de Melo
Em Mon, Nov 18, 2019 at 01:14:00PM +0100, Jiri Olsa escreveu:
Quoted 6 lines · Jiri Olsa
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/map_sharedQuoted 8 lines
Quoted 3 lines
Quoted 1 line
I rebased to latest perf/core and pushed the branch out
rebased and pushed out
heya,
I lost track of this.. what's the status, are you going with your version, or is this one still in? I don't see any of them in latest code..So, I'm still working on and off on this, current status is at:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=perf/map_share
Its just one patch more than perf/core, the one that does the sharing.
The thing is, as I'm going over all the fields in 'struct map', it seems that we'll end up with just one cacheline per instance, as there are things there that are not strictly related to a map, but to a
map_group(unmap_ip/map_ip), or to a dso (maj, min, ino,ino_generation), and some need less than what is allocated to them.Current status is:
[root@quaco ~]# pahole -C map ~acme/bin/perf
struct map { union { struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */ struct list_head node; /* 0 16 */ } __attribute__((__aligned__(8))); /* 0 24 */ u64 start; /* 24 8 */ u64 end; /* 32 8 */ _Bool erange_warned:1; /* 40: 0 1 */ _Bool priv:1; /* 40: 1 1 */ /* XXX 6 bits hole, try to pack */ /* XXX 3 bytes hole, try to pack */ u32 prot; /* 44 4 */ u64 pgoff; /* 48 8 */ u64 reloc; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ u64 (*map_ip)(struct map *, u64); /* 64 8 */ u64 (*unmap_ip)(struct map *, u64); /* 72 8 */ struct dso * dso; /* 80 8 */ refcount_t refcnt; /* 88 4 */ u32 flags; /* 92 4 */ /* size: 96, cachelines: 2, members: 13 */ /* sum members: 92, holes: 1, sum holes: 3 */ /* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */ /* forced alignments: 1 */ /* last cacheline: 32 bytes */ } __attribute__((__aligned__(8)));[root@quaco ~]#
This is with the tentative move of maj/min/ino/ino_generation to 'struct dso', but that needs more work to match the sort order that touches it "dcacheline", i.e. a map that comes with the same backing DSO but different values for those fields is not the same DSO, right?
Right now with moving the maj/min/etc to dso, in the
map_sharepatch we get the structure used to keep shared entries in therb_treeat 40 bytes, under one cacheline, while the full 'struct map' is 32 bytes more than one cacheline, so still good for sharing:[acme@quaco perf]$ pahole -C
map_node~/bin/perfstruct map_node { union { struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */ struct list_head node; /* 0 16 */ } __attribute__((__aligned__(8))); /* 0 24 */ refcount_t refcnt; /* 24 4 */ _Bool is_node:1; /* 28: 0 1 */ /* XXX 7 bits hole, try to pack */ /* XXX 3 bytes hole, try to pack */ struct map * map; /* 32 8 */ /* size: 40, cachelines: 1, members: 4 */ /* sum members: 36, holes: 1, sum holes: 3 */ /* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 7 bits */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); [acme@quaco perf]$ pahole -C map ~/bin/perf struct map { union { struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */ struct list_head node; /* 0 16 */ } __attribute__((__aligned__(8))); /* 0 24 */ refcount_t refcnt; /* 24 4 */ _Bool is_node:1; /* 28: 0 1 */ _Bool erange_warned:1; /* 28: 1 1 */ _Bool priv:1; /* 28: 2 1 */ /* XXX 5 bits hole, try to pack */ /* XXX 3 bytes hole, try to pack */ u64 start; /* 32 8 */ u64 end; /* 40 8 */ u64 pgoff; /* 48 8 */ u64 reloc; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ u64 (*map_ip)(struct map *, u64); /* 64 8 */ u64 (*unmap_ip)(struct map *, u64); /* 72 8 */ struct dso * dso; /* 80 8 */ u32 flags; /* 88 4 */ u32 prot; /* 92 4 */ /* size: 96, cachelines: 2, members: 14 */ /* sum members: 92, holes: 1, sum holes: 3 */ /* sum bitfield members: 3 bits, bit holes: 1, sum bit holes: 5 bits */ /* forced alignments: 1 */ /* last cacheline: 32 bytes */ } __attribute__((__aligned__(8)));
Quoted 3 lines
[acme@quaco perf]$
So give me some more time, please :-)
sure ;-) I just did not want to loose track of this
thanks,
jirka