tools/perf: Update rbtree implementation and optimize users
cover tools/perf: Update rbtree implementation and optimize users
Hi,
The following optimizes the rb_first() lookups in perf tooling such that we can avoid walking down the tree finding the first element. Tree traversals (and overall computing the first node in the tree) is a surprisingly common operation.
The first patch adds the updated implementation of rbtrees, including the cached interfaces, taken from the kernel. The rest of the patches make use of this for the users I thought might care the most.
With these patches I am able to build and use perf without anything going wrong (but needs more testing no doubt, as changes while redundant can be a little tricky depending on if the user get smart about the trees). I'm sorry if some patches seem too big, I've tried to split them the best I could.
Applies on today's -tip tree. Please consider for v4.16.
Thanks!
Davidlohr Bueso (7):
tools/perf: Update rbtree implementation
perf machine: Use cached rbtrees
perf callchain: Use cached rbtrees
perf util: Use cached rbtree for rblists
perf symbols: Use cached rbtrees
perf hist: Use cached rbtrees
perf sched: Use cached rbtrees
tools/include/linux/rbtree.h | 50 ++++++++- tools/include/linux/rbtree_augmented.h | 60 ++++++++-- tools/lib/rbtree.c | 171 ++++++++++++++++++++-------- tools/perf/builtin-annotate.c | 4 +- tools/perf/builtin-c2c.c | 6 +- tools/perf/builtin-diff.c | 10 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 45 ++++---- tools/perf/builtin-top.c | 6 +- tools/perf/tests/hists_common.c | 8 +- tools/perf/tests/hists_cumulate.c | 19 ++-- tools/perf/tests/hists_link.c | 8 +- tools/perf/tests/hists_output.c | 32 +++--- tools/perf/tests/vmlinux-kallsyms.c | 3 +- tools/perf/ui/browsers/hists.c | 16 +-- tools/perf/ui/gtk/hists.c | 6 +- tools/perf/ui/stdio/hist.c | 3 +- tools/perf/util/build-id.c | 12 +- tools/perf/util/dso.c | 7 +- tools/perf/util/dso.h | 6 +- tools/perf/util/hist.c | 198 ++++++++++++++++++--------------- tools/perf/util/hist.h | 10 +- tools/perf/util/intlist.h | 2 +- tools/perf/util/machine.c | 52 +++++---- tools/perf/util/machine.h | 4 +- tools/perf/util/map.c | 8 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/probe-event.c | 3 +- tools/perf/util/rblist.c | 30 +++-- tools/perf/util/rblist.h | 2 +- tools/perf/util/sort.h | 4 +- tools/perf/util/srcline.c | 21 ++-- tools/perf/util/srcline.h | 6 +- tools/perf/util/stat-shadow.c | 2 +- tools/perf/util/strlist.h | 2 +- tools/perf/util/symbol.c | 85 +++++++------- tools/perf/util/symbol.h | 12 +- tools/perf/util/symbol_fprintf.c | 3 +- 38 files changed, 570 insertions(+), 350 deletions(-)
Signature · 1 line
2.13.6
PATCH 1/7 tools/perf: Update rbtree implementation
There have been a number of changes in the kernel's rbrtee implementation, including loose lockless searching guarantees and rb_root_cached, which later patches will use as an optimization.
--- tools/include/linux/rbtree.h | 50 ++++++++-- tools/include/linux/rbtree_augmented.h | 60 +++++++++--- tools/lib/rbtree.c | 171 ++++++++++++++++++++++++--------- 3 files changed, 219 insertions(+), 62 deletions(-)
tools/include/linux/rbtree.h +44 -6
@@ -43,13 +43,28 @@ struct rb_root {struct rb_node *rb_node; }; +/* +* Leftmost-cached rbtrees. +* +* We do not cache the rightmost node based on footprint +* size vs number of potential users that could benefit +* from O(1) rb_last(). Just not worth it, users that want +* this feature can always implement the logic explicitly. +* Furthermore, users that want to cache both pointers may +* find it a bit asymmetric, but that's ok. +*/ +struct rb_root_cached { +struct rb_root rb_root; +struct rb_node *rb_leftmost; +};#define rb_parent (r) ((struct rb_node *)((r)->__rb_parent_color & ~3))#define RB_ROOT (struct rb_root) { NULL, } +#define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }#define rb_entry (ptr, type, member) container_of(ptr, type, member) -#define RB_EMPTY_ROOT (root) ((root)->rb_node == NULL) +#define RB_EMPTY_ROOT (root) (READ_ONCE((root)->rb_node) == NULL)/* 'empty' nodes are nodes that are known not to be inserted in an rbtree */ #define RB_EMPTY_NODE (node) \
@@ -68,6 +83,12 @@ extern struct rb_node *rb_prev(const struct rb_node *);extern struct rb_node *rb_first (const struct rb_root *);extern struct rb_node *rb_last (const struct rb_root *); +extern void rb_insert_color_cached (struct rb_node *, +struct rb_root_cached *,bool ); +extern void rb_erase_cached (struct rb_node *node,struct rb_root_cached *); +/* Same as rb_first(), but O(1) */ +#define rb_first_cached (root) (root)->rb_leftmost +/* Postorder iteration - always visit the parent after its children */ extern struct rb_node *rb_first_postorder (const struct rb_root *);extern struct rb_node *rb_next_postorder (const struct rb_node *);
@@ -90,12 +111,29 @@ static inline void rb_link_node(struct rb_node *node, struct rb_node *parent, ____ptr ?rb_entry (____ptr, type, member) :NULL ; \ }) - -/* -* Handy for checking that we are not deleting an entry that is -* already in a list, found in block/{blk-throttle,cfq-iosched}.c, -* probably should be moved to lib/rbtree.c... +/** +* rbtree_postorder_for_each_entry_safe - iterate in post-order over rb_root of +* given type allowing the backing memory of @pos to be invalidated +* +* @pos: the 'type *' to use as a loop cursor. +* @n: another 'type *' to use as temporary storage +* @root: 'rb_root *' of the rbtree. +* @field: the name of the rb_node field within 'type'. +* +* rbtree_postorder_for_each_entry_safe() provides a similar guarantee as +* list_for_each_entry_safe() and allows the iteration to continue independent +* of changes to @pos by the body of the loop. +* +* Note, however, that it cannot handle other modifications that re-order the +* rbtree it is iterating over. This includes calling rb_erase() on @pos, as +* rb_erase() may rebalance the tree, causing us to miss some nodes. */ +#define rbtree_postorder_for_each_entry_safe (pos, n, root, field) \ + for (pos = rb_entry_safe(rb_first_postorder(root), typeof(*pos), field); \ + pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \ + typeof(*pos), field); 1; }); \ + pos = n) +static inline void rb_erase_init (struct rb_node *n,struct rb_root *root) {rb_erase (n, root);
tools/include/linux/rbtree_augmented.h +48 -12
132 lines not on this page · raw message
tools/lib/rbtree.c +127 -44
318 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 2/7 perf machine: Use cached rbtrees
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something required for nearly every operation dealing with machine->guests and threads->entries.
The conversion is straightforward, however, it's worth noticing that the rb_erase_init() calls have been replaced by rb_erase_cached() which has no _init() flavor, however, the node is explicitly cleared next anyway, which was redundant until now.
--- tools/perf/util/build-id.c | 12 +++++++---- tools/perf/util/machine.c | 52 ++++++++++++++++++++++++++-------------------- tools/perf/util/machine.h | 4 ++-- 3 files changed, 40 insertions(+), 28 deletions(-)
tools/perf/util/build-id.c +8 -4
@@ -367,7 +367,8 @@ int perf_session__write_buildid_table(struct perf_session *session,if (err)return err; -for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { +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__write_buildid_table (pos, fd);if (err)
@@ -400,7 +401,8 @@ int dsos__hit_all(struct perf_session *session)if (err)return err; -for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { +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);
@@ -855,7 +857,8 @@ int perf_session__cache_build_ids(struct perf_session *session) ret =machine__cache_build_ids (&session->machines.host); -for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&session->machines.guests); + nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); ret |=machine__cache_build_ids (pos); }
@@ -872,7 +875,8 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)struct rb_node *nd;bool ret =machine__read_build_ids (&session->machines.host, with_hits); -for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&session->machines.guests); + nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); ret |=machine__read_build_ids (pos, with_hits); }
tools/perf/util/machine.c +30 -22
187 lines not on this page · raw message
tools/perf/util/machine.h +2 -2
@@ -29,7 +29,7 @@ struct vdso_info;#define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)struct threads { -struct rb_root entries; +struct rb_root_cached entries;struct rw_semaphore lock;unsigned int nr;struct list_head dead;
@@ -126,7 +126,7 @@ typedef void (*machine__process_t)(struct machine *machine, void *data);struct machines {struct machine host; -struct rb_root guests; +struct rb_root_cached guests; };void machines__init (struct machines *machines);
Signature · 1 line
2.13.6
kernel test robot
build bot[lkp-robot] [perf machine] 8edf8850d5: stderr./usr/src/linux-perf-x86_64-rhel-#/tools/perf/util/rb_resort.h:#:#:error:passing_argument#of'threads_sorted__new'from_incompatible_pointer_type[-Werror=incompatible-pointer-types]
FYI, we noticed the following commit (built with gcc-7):
FYI, we noticed the following commit (built with gcc-7):
commit: 8edf8850d51e911a35b5d7aad4f8604db11abc66 ("perf machine: Use cached rbtrees")
url: https://github.com/0day-ci/linux/commits/Davidlohr-Bueso/tools-perf-Update-rbtree-implementation-and-optimize-users/20171128-120320
in testcase: perf-sanity-tests
with following parameters:
on test machine: qemu-system-x86_64 -enable-kvm -cpu kvm64,+ssse3 -smp 2 -m 8G
caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):
[ 68.830934] /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/perf/util/rb_resort.h:148:28: error: passing argument 1 of 'threads_sorted__new' from incompatible pointer type [-Werror=incompatible-pointer-types]
To reproduce:
git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email
Thanks,
Xiaolong
#!/bin/sh
export_top_env()
{
export suite='perf-sanity-tests'
export testcase='perf-sanity-tests'
export category='functional'
export job_origin='/lkp/lkp/src/allot/rand/vm-lkp-nex04-8G/perf-sanity-tests.yaml'
export testbox='vm-lkp-nex04-8G-7'
export tbox_group='vm-lkp-nex04-8G'
export kconfig='x86_64-rhel-7.2'
export compiler='gcc-7'
export queue='bisect'
export branch='linux-devel/devel-hourly-2017113020'
export commit='8edf8850d51e911a35b5d7aad4f8604db11abc66'
export submit_id='5a20989b0b9a932e0b23ef08'
export job_file='/lkp/scheduled/vm-lkp-nex04-8G-7/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-8edf8850d51e911a35b5d7aad4f8604db11abc66-20171201-11787-559318-0.yaml'
export id='068eb217604f9cb2c499ea3bf76c9c6f7712efeb'
export model='qemu-system-x86_64 -enable-kvm -cpu kvm64,+ssse3'
export nr_vm=10
export nr_cpu=2
export memory='8G'
export hdd_partitions='/dev/vda'
export need_linux_perf=true
export need_kconfig='CONFIG_KVM_GUEST=y'
export ssh_base_port=23250
export rootfs='debian-x86_64-2016-08-31.cgz'
export enqueue_time='2017-12-01 07:47:40 +0800'
export _id='5a20989b0b9a932e0b23ef08'
export _rt='/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66'
export user='lkp'
export result_root='/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/0'
export LKP_SERVER='inn'
export max_uptime=3600
export initrd='/osimage/debian/debian-x86_64-2016-08-31.cgz'
export bootloader_append='root=/dev/ram0user=lkp job=/lkp/scheduled/vm-lkp-nex04-8G-7/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-8edf8850d51e911a35b5d7aad4f8604db11abc66-20171201-11787-559318-0.yaml ARCH=x86_64
kconfig=x86_64-rhel-7.2
branch=linux-devel/devel-hourly-2017113020
commit=8edf8850d51e911a35b5d7aad4f8604db11abc66 BOOT_IMAGE=/pkg/linux/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/vmlinuz-4.14.0-01278-g8edf885
max_uptime=3600 RESULT_ROOT=/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/0 LKP_SERVER=inn
debug
apic=debugsysrq_always_enabled
rcupdate.rcu_cpu_stall_timeout=100
net.ifnames=0
printk.devkmsg=on
panic=-1
softlockup_panic=1
nmi_watchdog=panic
oops=panic
load_ramdisk=2
prompt_ramdisk=0
drbd.minor_count=8
systemd.log_level=errignore_loglevel
console=tty0
earlyprintk=ttyS0,115200
console=ttyS0,115200
vga=normal
rw'
export modules_initrd='/pkg/linux/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/modules.cgz'
export bm_initrd='/osimage/deps/debian-x86_64-2016-08-31.cgz/lkp_2017-08-01.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/rsync-rootfs_2016-11-15.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/run-ipconfig_2016-11-15.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/perf-sanity-tests_2017-09-25.cgz,/osimage/pkg/debian-x86_64-2016-08-31.cgz/perf-x86_64-a8c964eacb21_2017-10-01.cgz'
export linux_perf_initrd='/pkg/linux/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/linux-perf.cgz'
export lkp_initrd='/lkp/lkp/lkp-x86_64.cgz'
export site='inn'
export LKP_CGI_PORT=80
export LKP_CIFS_PORT=139
export kernel='/pkg/linux/x86_64-rhel-7.2/gcc-7/8edf8850d51e911a35b5d7aad4f8604db11abc66/vmlinuz-4.14.0-01278-g8edf885'
export dequeue_time='2017-12-01 08:09:44 +0800'
export job_initrd='/lkp/scheduled/vm-lkp-nex04-8G-7/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-8edf8850d51e911a35b5d7aad4f8604db11abc66-20171201-11787-559318-0.cgz'
[ -n "$LKP_SRC" ] ||
export LKP_SRC=/lkp/${user:-lkp}/src
}run_job()
{
echo $$ > $TMP/run-job.pid
. $LKP_SRC/lib/http.sh
. $LKP_SRC/lib/job.sh
. $LKP_SRC/lib/env.sh
export_top_env
run_monitor $LKP_SRC/monitors/wrapper kmsg
run_monitor $LKP_SRC/monitors/wrapper heartbeat
run_monitor $LKP_SRC/monitors/wrapper oom-killer
run_monitor $LKP_SRC/monitors/plain/watchdog
run_test $LKP_SRC/tests/wrapper perf-sanity-tests
}extract_stats()
{
$LKP_SRC/stats/wrapper perf-sanity-tests
$LKP_SRC/stats/wrapper kmsg
$LKP_SRC/stats/wrapper time perf-sanity-tests.time $LKP_SRC/stats/wrapper time $LKP_SRC/stats/wrapper dmesg $LKP_SRC/stats/wrapper kmsg $LKP_SRC/stats/wrapper stderr $LKP_SRC/stats/wrapper last_state
}
"$@"
2017-12-01 08:11:10 make LLVM_CONFIG=/usr/bin/llvm-config-3.9 LIBCLANGLLVM=1 ARCH= -C /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/perf make: Entering directory '/usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/perf' BUILD: Doing 'make [33m-j2[m' parallel build HOSTCC fixdep.o HOSTLD fixdep-in.o LINK fixdep
Auto-detecting system features:
... dwarf: [ [32mon[m ] ... dwarf_getlocations: [ [32mon[m ] ... glibc: [ [32mon[m ] ... gtk2: [ [31mOFF[m ] ... libaudit: [ [32mon[m ] ... libbfd: [ [32mon[m ] ... libelf: [ [32mon[m ] ... libnuma: [ [32mon[m ] ... numa_num_possible_cpus: [ [32mon[m ]
... libperl: [ [31mOFF[m ]
... libpython: [ [32mon[m ]
... libslang: [ [31mOFF[m ]
... libcrypto: [ [31mOFF[m ]
... libunwind: [ [32mon[m ] ... libdw-dwarf-unwind: [ [32mon[m ] ... zlib: [ [32mon[m ] ... lzma: [ [32mon[m ] ... get_cpuid: [ [32mon[m ] ... bpf: [ [32mon[m ]
GEN common-cmds.h CC fd/array.o CC event-parse.o LD fd/libapi-in.o CC fs/fs.o CC fs/tracing_path.o LD fs/libapi-in.o CC cpu.o CC debug.o CC str_error_r.o LD libapi-in.o AR libapi.a CC event-plugin.o CC trace-seq.o CC exec-cmd.o CC parse-filter.o CC help.o CC parse-utils.o CC kbuffer-parse.o LD libtraceevent-in.o LINK libtraceevent.a CC libbpf.o CC pager.o CC parse-options.o CC bpf.o LD libbpf-in.o LINK libbpf.a HOSTCC pmu-events/json.o HOSTCC pmu-events/jsmn.o HOSTCC pmu-events/jevents.o HOSTLD pmu-events/jevents-in.o CC plugin_jbd2.o LD plugin_jbd2-in.o CC plugin_hrtimer.o LD plugin_hrtimer-in.o CC plugin_kmem.o CC run-command.o LD plugin_kmem-in.o CC plugin_kvm.o LD plugin_kvm-in.o CC plugin_mac80211.o LD plugin_mac80211-in.o CC sigchain.o CC plugin_sched_switch.o LD plugin_sched_switch-in.o CC plugin_function.o LD plugin_function-in.o CC subcmd-config.o CC plugin_xen.o LD libsubcmd-in.o AR libsubcmd.a CC plugin_scsi.o LD plugin_xen-in.o GEN perf-archive CC plugin_cfg80211.o LD plugin_scsi-in.o LD plugin_cfg80211-in.o GEN perf-with-kcore LINK plugin_jbd2.so CC util/annotate.o LINK plugin_hrtimer.so LINK plugin_kmem.so LINK plugin_kvm.so LINK plugin_mac80211.so LINK plugin_sched_switch.so LINK plugin_function.so LINK plugin_xen.so LINK plugin_scsi.so LINK plugin_cfg80211.so CC arch/common.o CC arch/x86/util/header.o CC arch/x86/util/tsc.o CC arch/x86/util/pmu.o CC arch/x86/util/kvm-stat.o CC util/block-range.o CC arch/x86/util/perf_regs.o CC arch/x86/util/group.o CC arch/x86/util/dwarf-regs.o CC util/build-id.o CC arch/x86/util/unwind-libunwind.o CC arch/x86/util/auxtrace.o CC arch/x86/util/intel-pt.o CC util/config.o CC arch/x86/util/intel-bts.o CC util/ctype.o CC util/db-export.o LD arch/x86/util/libperf-in.o CC arch/x86/tests/regs_load.o CC arch/x86/tests/dwarf-unwind.o CC arch/x86/tests/arch-tests.o CC util/env.o CC arch/x86/tests/rdpmc.o CC util/event.o CC arch/x86/tests/perf-time-to-tsc.o CC arch/x86/tests/insn-x86.o LD arch/x86/tests/libperf-in.o LD arch/x86/libperf-in.o LD arch/libperf-in.o CC builtin-bench.o CC builtin-annotate.o CC util/evlist.o CC builtin-config.o CC builtin-diff.o CC util/evsel.o CC builtin-evlist.o CC builtin-ftrace.o CC builtin-help.o CC builtin-sched.o CC util/evsel_fprintf.o CC util/find_bit.o CC util/kallsyms.o CC util/levenshtein.o CC util/llvm-utils.o CC builtin-buildid-list.o CC util/mmap.o CC builtin-buildid-cache.o CC util/memswap.o CC builtin-kallsyms.o BISON util/parse-events-bison.c CC util/perf_regs.o CC builtin-list.o CC util/path.o CC util/print_binary.o CC builtin-record.o CC util/rbtree.o CC util/libstring.o CC util/bitmap.o CC util/hweight.o CC builtin-report.o CC util/smt.o CC util/quote.o CC util/strbuf.o CC util/string.o CC util/strlist.o CC builtin-stat.o CC util/strfilter.o CC util/top.o CC util/usage.o CC util/dso.o CC builtin-timechart.o CC util/symbol.o CC builtin-top.o CC util/symbol_fprintf.o CC builtin-script.o CC util/color.o CC util/metricgroup.o CC util/header.o CC builtin-kmem.o CC builtin-lock.o CC util/callchain.o CC builtin-kvm.o CC builtin-inject.o CC builtin-mem.o CC util/values.o CC builtin-data.o CC util/debug.o CC builtin-version.o CC builtin-c2c.o CC util/machine.o CC builtin-trace.o CC util/map.o CC util/pstack.o CC util/session.o /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/build/Makefile.build:96: recipe for target 'builtin-trace.o' failed Makefile.perf:495: recipe for target 'perf-in.o' failed CC util/syscalltbl.o CC util/ordered-events.o CC ui/setup.o CC ui/helpline.o CC util/namespaces.o CC ui/progress.o CC ui/util.o CC util/comm.o CC ui/hist.o CC util/thread.o CC util/thread_map.o CC util/trace-event-parse.o CC util/parse-events-bison.o CC ui/stdio/hist.o BISON util/pmu-bison.c CC util/trace-event-read.o CC util/trace-event-info.o LD ui/libperf-in.o CC scripts/python/Perf-Trace-Util/Context.o LD scripts/python/Perf-Trace-Util/libperf-in.o LD scripts/libperf-in.o CC trace/beauty/clone.o CC util/trace-event-scripting.o CC trace/beauty/fcntl.o CC util/trace-event.o CC trace/beauty/ioctl.o CC trace/beauty/kcmp.o CC util/svghelper.o CC trace/beauty/pkey_alloc.o CC trace/beauty/prctl.o CC trace/beauty/statx.o LD trace/beauty/libperf-in.o CC util/sort.o CC util/hist.o CC util/util.o CC util/xyarray.o CC util/cpumap.o CC util/cgroup.o CC util/target.o CC util/rblist.o CC util/intlist.o CC util/vdso.o CC util/counts.o CC util/stat.o CC util/stat-shadow.o CC util/record.o CC util/srcline.o CC util/data.o CC util/tsc.o CC util/cloexec.o CC util/call-path.o CC util/rwsem.o CC util/thread-stack.o CC util/auxtrace.o CC util/intel-pt-decoder/intel-pt-pkt-decoder.o GEN util/intel-pt-decoder/inat-tables.c CC util/intel-pt-decoder/intel-pt-log.o CC util/intel-pt-decoder/intel-pt-decoder.o CC util/scripting-engines/trace-event-python.o LD util/scripting-engines/libperf-in.o CXX util/c++/clang.o CC util/intel-pt-decoder/intel-pt-insn-decoder.o LD util/intel-pt-decoder/libperf-in.o CC util/intel-pt.o CC util/intel-bts.o CC util/parse-branch-options.o CC util/dump-insn.o CC util/parse-regs-options.o CC util/term.o CC util/help-unknown-cmd.o CC util/mem-events.o CC util/vsprintf.o CC util/drv_configs.o CC util/units.o CC util/time-utils.o BISON util/expr-bison.c CC util/branch.o CC util/bpf-loader.o CC util/bpf-prologue.o CC util/symbol-elf.o CC util/probe-file.o
/usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/build/Makefile.build:100: recipe for target 'util/c++/clang.o' failed /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/build/Makefile.build:139: recipe for target 'c++' failed /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/build/Makefile.build:139: recipe for target 'util' failed Makefile.perf:619: recipe for target 'libperf-in.o' failed
Makefile.perf:209: recipe for target 'sub-make' failed
Makefile:69: recipe for target 'all' failed
make: Leaving directory '/usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/perf'
Re: [lkp-robot] [perf machine] 8edf8850d5: stderr./usr/src/linux-perf-x86_64-rhel-#/tools/perf/util/rb_resort.h:#:#:error:passing_argument#of'threads_sorted__new'from_incompatible_pointer_type[-Werror=incompatible-pointer-types]
Quoted 1 line · kernel test robot
[ 68.830934] /usr/src/linux-perf-x86_64-rhel-7.2-8edf8850d51e911a35b5d7aad4f8604db11abc66/tools/perf/util/rb_resort.h:148:28: error: passing argument 1 of 'threads_sorted__new' from incompatible pointer type [-Werror=incompatible-pointer-types]
I didn't have libaudit so I wasn't building builtin-trace, which obviously needs fixed.
Arnaldo, dunno if you're taking this series, but please let me know if you want a v2 or you can fold the below fix into this patch.
Thanks,
Davidlohr
tools/perf/util/rb_resort.h +2 -2
@@ -140,12 +140,12 @@ struct __name##_sorted *__name = __name##_sorted__new/* For 'struct intlist' */ #define DECLARE_RESORT_RB_INTLIST (__name, __ilist) \ - DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries, \ + DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries.rb_root, \ __ilist->rblist.nr_entries)/* For 'struct machine->threads' */ #define DECLARE_RESORT_RB_MACHINE_THREADS (__name, __machine, hash_bucket) \ - DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries, \ + DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries.rb_root,\ __machine->threads[hash_bucket].nr)#endif /* _PERF_RESORT_RB_H_ */
PATCH 3/7 perf callchain: Use cached rbtrees
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something required for nearly every srcline callchain node deletion (srcline__tree_delete()).
--- tools/perf/util/dso.c | 2 +- tools/perf/util/dso.h | 2 +- tools/perf/util/srcline.c | 21 ++++++++++++--------- tools/perf/util/srcline.h | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-)
tools/perf/util/dso.c +1 -1
@@ -1204,7 +1204,7 @@ struct dso *dso__new(const char *name) dso->symbols[i] = dso->symbol_names[i] =RB_ROOT ; dso->data.cache =RB_ROOT ; dso->inlined_nodes =RB_ROOT ; - dso->srclines =RB_ROOT ; + dso->srclines =RB_ROOT_CACHED ; dso->data.fd =-1 ; dso->data.status =DSO_DATA_STATUS_UNKNOWN ; dso->symtab_type =DSO_BINARY_TYPE__NOT_FOUND ;
tools/perf/util/dso.h +1 -1
@@ -143,7 +143,7 @@ struct dso {struct rb_root symbols[MAP__NR_TYPES ];struct rb_root symbol_names[MAP__NR_TYPES ];struct rb_root inlined_nodes; -struct rb_root srclines; +struct rb_root_cached srclines;struct {u64 addr;struct symbol *symbol;
tools/perf/util/srcline.c +12 -9
@@ -561,11 +561,12 @@ struct srcline_node {struct rb_node rb_node; }; -void srcline__tree_insert (struct rb_root *tree,u64 addr,char *srcline) +void srcline__tree_insert (struct rb_root_cached *tree,u64 addr,char *srcline) { -struct rb_node **p = &tree->rb_node; +struct rb_node **p = &tree->rb_root.rb_node;struct rb_node *parent =NULL ;struct srcline_node *i, *node; +bool leftmost = true; node =zalloc (sizeof (struct srcline_node ));if (!node) {
@@ -581,16 +582,18 @@ void srcline__tree_insert(struct rb_root *tree, u64 addr, char *srcline) i = rb_entry(parent, struct srcline_node, rb_node);if (addr < i->addr) p = &(*p)->rb_left; -else +else { p = &(*p)->rb_right; + leftmost = false; + } }rb_link_node (&node->rb_node, parent, p); -rb_insert_color (&node->rb_node, tree); +rb_insert_color_cached (&node->rb_node, tree, leftmost); } -char *srcline__tree_find (struct rb_root *tree,u64 addr) +char *srcline__tree_find (struct rb_root_cached *tree,u64 addr) { -struct rb_node *n = tree->rb_node; +struct rb_node *n = tree->rb_root.rb_node;while (n) { struct srcline_node *i = rb_entry(n, struct srcline_node,
@@ -607,15 +610,15 @@ char *srcline__tree_find(struct rb_root *tree, u64 addr)return NULL ; } -void srcline__tree_delete (struct rb_root *tree) +void srcline__tree_delete (struct rb_root_cached *tree) {struct srcline_node *pos; -struct rb_node *next =rb_first (tree); +struct rb_node *next =rb_first_cached (tree);while (next) { pos = rb_entry(next, struct srcline_node, rb_node); next =rb_next (&pos->rb_node); -rb_erase (&pos->rb_node, tree); +rb_erase_cached (&pos->rb_node, tree);free_srcline (pos->srcline);zfree (&pos); }
tools/perf/util/srcline.h +3 -3
@@ -17,11 +17,11 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,void free_srcline (char *srcline);/* insert the srcline into the DSO, which will take ownership */ -void srcline__tree_insert (struct rb_root *tree,u64 addr,char *srcline); +void srcline__tree_insert (struct rb_root_cached *tree,u64 addr,char *srcline);/* find previously inserted srcline */ -char *srcline__tree_find (struct rb_root *tree,u64 addr); +char *srcline__tree_find (struct rb_root_cached *tree,u64 addr);/* delete all srclines within the tree */ -void srcline__tree_delete (struct rb_root *tree); +void srcline__tree_delete (struct rb_root_cached *tree);#define SRCLINE_UNKNOWN ((char *) "??:0")
Signature · 1 line
2.13.6
PATCH 4/7 perf util: Use cached rbtree for rblists
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something required for any of the strlist or intlist traversals (XXX_for_each_entry()). There are a number of users in perf of these (particularly strlists), including probes, and buildid.
--- tools/perf/util/intlist.h | 2 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/rblist.c | 30 ++++++++++++++++++------------ tools/perf/util/rblist.h | 2 +- tools/perf/util/stat-shadow.c | 2 +- tools/perf/util/strlist.h | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-)
tools/perf/util/intlist.h +1 -1
@@ -45,7 +45,7 @@ static inline unsigned int intlist__nr_entries(const struct intlist *ilist)/* For intlist iteration */ static inline struct int_node *intlist__first (struct intlist *ilist) { -struct rb_node *rn =rb_first (&ilist->rblist.entries); +struct rb_node *rn =rb_first_cached (&ilist->rblist.entries); return rn ? rb_entry(rn, struct int_node, rb_node) : NULL; }static inline struct int_node *intlist__next (struct int_node *in)
tools/perf/util/metricgroup.c +1 -1
@@ -350,7 +350,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,else if (metrics && !raw)printf ("\nMetrics:\n\n" ); -for (node =rb_first (&groups.entries); node; node = next) { +for (node =rb_first_cached (&groups.entries); node; node = next) { struct mep *me = container_of(node, struct mep, nd);if (metricgroups)
tools/perf/util/rblist.c +18 -12
@@ -13,8 +13,9 @@int rblist__add_node (struct rblist *rblist,const void *new_entry) { -struct rb_node **p = &rblist->entries.rb_node; +struct rb_node **p = &rblist->entries.rb_root.rb_node;struct rb_node *parent =NULL , *new_node; +bool leftmost = true;while (*p !=NULL ) {int rc;
@@ -24,9 +25,10 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry) rc = rblist->node_cmp (parent, new_entry);if (rc >0 ) p = &(*p)->rb_left; -else if (rc <0 ) +else if (rc <0 ) { p = &(*p)->rb_right; -else + leftmost = false; + }else return -EEXIST ; }
@@ -35,7 +37,7 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry)return -ENOMEM ;rb_link_node (new_node, parent, p); -rb_insert_color (new_node, &rblist->entries); +rb_insert_color_cached (new_node, &rblist->entries, leftmost); ++rblist->nr_entries;return 0 ;
@@ -43,7 +45,7 @@ int rblist__add_node(struct rblist *rblist, const void *new_entry)void rblist__remove_node (struct rblist *rblist,struct rb_node *rb_node) { -rb_erase (rb_node, &rblist->entries); +rb_erase_cached (rb_node, &rblist->entries); --rblist->nr_entries; rblist->node_delete (rblist, rb_node); }
@@ -52,8 +54,9 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, const void *entry, bool create) { -struct rb_node **p = &rblist->entries.rb_node; +struct rb_node **p = &rblist->entries.rb_root.rb_node;struct rb_node *parent =NULL , *new_node =NULL ; +bool leftmost = true;while (*p !=NULL ) {int rc;
@@ -63,9 +66,10 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, rc = rblist->node_cmp (parent, entry);if (rc >0 ) p = &(*p)->rb_left; -else if (rc <0 ) +else if (rc <0 ) { p = &(*p)->rb_right; -else + leftmost = false; + }else return parent; }
@@ -73,7 +77,8 @@ static struct rb_node *__rblist__findnew(struct rblist *rblist, new_node = rblist->node_new (rblist, entry);if (new_node) {rb_link_node (new_node, parent, p); -rb_insert_color (new_node, &rblist->entries); +rb_insert_color_cached (new_node, + &rblist->entries, leftmost); ++rblist->nr_entries; } }
@@ -94,7 +99,7 @@ struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry)void rblist__init (struct rblist *rblist) {if (rblist !=NULL ) { - rblist->entries =RB_ROOT ; + rblist->entries =RB_ROOT_CACHED ; rblist->nr_entries =0 ; }
@@ -104,7 +109,7 @@ void rblist__init(struct rblist *rblist)void rblist__delete (struct rblist *rblist) {if (rblist !=NULL ) { -struct rb_node *pos, *next =rb_first (&rblist->entries); +struct rb_node *pos, *next =rb_first_cached (&rblist->entries);while (next) { pos = next;
@@ -119,7 +124,8 @@ struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx) {struct rb_node *node; -for (node =rb_first (&rblist->entries); node; node =rb_next (node)) { +for (node =rb_first_cached (&rblist->entries); + node; node =rb_next (node)) {if (!idx--)return node; }
tools/perf/util/rblist.h +1 -1
@@ -20,7 +20,7 @@*/ struct rblist { -struct rb_root entries; +struct rb_root_cached entries;unsigned int nr_entries;int (*node_cmp)(struct rb_node *rbn,const void *entry);
tools/perf/util/stat-shadow.c +1 -1
@@ -164,7 +164,7 @@ void perf_stat__reset_shadow_stats(void)memset (runtime_smi_num_stats,0 ,sizeof (runtime_smi_num_stats));memset (runtime_aperf_stats,0 ,sizeof (runtime_aperf_stats)); - next =rb_first (&runtime_saved_values.entries); + next =rb_first_cached (&runtime_saved_values.entries);while (next) { pos = next; next =rb_next (pos);
tools/perf/util/strlist.h +1 -1
@@ -57,7 +57,7 @@ static inline unsigned int strlist__nr_entries(const struct strlist *slist)/* For strlist iteration */ static inline struct str_node *strlist__first (struct strlist *slist) { -struct rb_node *rn =rb_first (&slist->rblist.entries); +struct rb_node *rn =rb_first_cached (&slist->rblist.entries); return rn ? rb_entry(rn, struct str_node, rb_node) : NULL; }static inline struct str_node *strlist__next (struct str_node *sn)
Signature · 1 line
2.13.6
kernel test robot
build bot[lkp-robot] [perf util] f7a7a64385: stderr.builtin-trace.c:#:#:note:in_expansion_of_macro'DECLARE_RESORT_RB_INTLIST'
FYI, we noticed the following commit (built with gcc-7):
FYI, we noticed the following commit (built with gcc-7):
commit: f7a7a64385657f44638b40f09dcae8f7fe02879a ("perf util: Use cached rbtree for rblists")
url: https://github.com/0day-ci/linux/commits/Davidlohr-Bueso/tools-perf-Update-rbtree-implementation-and-optimize-users/20171128-120320
in testcase: perf-sanity-tests
with following parameters:
on test machine: qemu-system-x86_64 -enable-kvm -cpu kvm64,+ssse3 -smp 2 -m 8G
caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):
[ 56.941979] DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries, \ [ 56.941982] [ 56.944797] ^ [ 56.944799] [ 56.955333] builtin-trace.c:2695:2: note: in expansion of macro 'DECLARE_RESORT_RB_INTLIST' [ 56.955336] [ 56.959650] DECLARE_RESORT_RB_INTLIST(syscall_stats, ttrace->syscall_stats); [ 56.959652] [ 56.962706] ^~~~~~~~~~~~~~~~~~~~~~~~~ [ 56.962708] [ 56.973237] builtin-trace.c:2675:18: note: expected 'struct rb_root *' but argument is of type 'struct rb_root_cached *' [ 56.973240] [ 56.984371] DEFINE_RESORT_RB(syscall_stats, a->msecs > b->msecs, [ 56.984374]
To reproduce:
git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email
Thanks,
Xiaolong
#!/bin/sh
export_top_env()
{
export suite='perf-sanity-tests'
export testcase='perf-sanity-tests'
export category='functional'
export job_origin='/lkp/lkp/src/allot/rand/vm-lkp-nex04-8G/perf-sanity-tests.yaml'
export testbox='vm-lkp-nex04-8G-2'
export tbox_group='vm-lkp-nex04-8G'
export kconfig='x86_64-rhel-7.2'
export compiler='gcc-7'
export queue='bisect'
export branch='linux-devel/devel-hourly-2017113020'
export commit='f7a7a64385657f44638b40f09dcae8f7fe02879a'
export submit_id='5a20917b0b9a933eccbe8f7e'
export job_file='/lkp/scheduled/vm-lkp-nex04-8G-2/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-f7a7a64385657f44638b40f09dcae8f7fe02879a-20171201-81612-1www3df-0.yaml'
export id='23959748adb1545e2443f957ee4371a619a687f3'
export model='qemu-system-x86_64 -enable-kvm -cpu kvm64,+ssse3'
export nr_vm=10
export nr_cpu=2
export memory='8G'
export hdd_partitions='/dev/vda'
export need_linux_perf=true
export need_kconfig='CONFIG_KVM_GUEST=y'
export ssh_base_port=23250
export rootfs='debian-x86_64-2016-08-31.cgz'
export enqueue_time='2017-12-01 07:17:16 +0800'
export _id='5a20917b0b9a933eccbe8f7e'
export _rt='/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a'
export user='lkp'
export result_root='/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/0'
export LKP_SERVER='inn'
export max_uptime=3600
export initrd='/osimage/debian/debian-x86_64-2016-08-31.cgz'
export bootloader_append='root=/dev/ram0user=lkp job=/lkp/scheduled/vm-lkp-nex04-8G-2/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-f7a7a64385657f44638b40f09dcae8f7fe02879a-20171201-81612-1www3df-0.yaml ARCH=x86_64
kconfig=x86_64-rhel-7.2
branch=linux-devel/devel-hourly-2017113020
commit=f7a7a64385657f44638b40f09dcae8f7fe02879a BOOT_IMAGE=/pkg/linux/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/vmlinuz-4.14.0-01280-gf7a7a64
max_uptime=3600 RESULT_ROOT=/result/perf-sanity-tests/defaults/vm-lkp-nex04-8G/debian-x86_64-2016-08-31.cgz/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/0 LKP_SERVER=inn
debug
apic=debugsysrq_always_enabled
rcupdate.rcu_cpu_stall_timeout=100
net.ifnames=0
printk.devkmsg=on
panic=-1
softlockup_panic=1
nmi_watchdog=panic
oops=panic
load_ramdisk=2
prompt_ramdisk=0
drbd.minor_count=8
systemd.log_level=errignore_loglevel
console=tty0
earlyprintk=ttyS0,115200
console=ttyS0,115200
vga=normal
rw'
export modules_initrd='/pkg/linux/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/modules.cgz'
export bm_initrd='/osimage/deps/debian-x86_64-2016-08-31.cgz/lkp_2017-08-01.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/rsync-rootfs_2016-11-15.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/run-ipconfig_2016-11-15.cgz,/osimage/deps/debian-x86_64-2016-08-31.cgz/perf-sanity-tests_2017-09-25.cgz,/osimage/pkg/debian-x86_64-2016-08-31.cgz/perf-x86_64-a8c964eacb21_2017-10-01.cgz'
export linux_perf_initrd='/pkg/linux/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/linux-perf.cgz'
export lkp_initrd='/lkp/lkp/lkp-x86_64.cgz'
export site='inn'
export LKP_CGI_PORT=80
export LKP_CIFS_PORT=139
export kernel='/pkg/linux/x86_64-rhel-7.2/gcc-7/f7a7a64385657f44638b40f09dcae8f7fe02879a/vmlinuz-4.14.0-01280-gf7a7a64'
export dequeue_time='2017-12-01 07:41:31 +0800'
export job_initrd='/lkp/scheduled/vm-lkp-nex04-8G-2/perf-sanity-tests-defaults-debian-x86_64-2016-08-31.cgz-f7a7a64385657f44638b40f09dcae8f7fe02879a-20171201-81612-1www3df-0.cgz'
[ -n "$LKP_SRC" ] ||
export LKP_SRC=/lkp/${user:-lkp}/src
}run_job()
{
echo $$ > $TMP/run-job.pid
. $LKP_SRC/lib/http.sh
. $LKP_SRC/lib/job.sh
. $LKP_SRC/lib/env.sh
export_top_env
run_monitor $LKP_SRC/monitors/wrapper kmsg
run_monitor $LKP_SRC/monitors/wrapper heartbeat
run_monitor $LKP_SRC/monitors/wrapper oom-killer
run_monitor $LKP_SRC/monitors/plain/watchdog
run_test $LKP_SRC/tests/wrapper perf-sanity-tests
}extract_stats()
{
$LKP_SRC/stats/wrapper perf-sanity-tests
$LKP_SRC/stats/wrapper kmsg
$LKP_SRC/stats/wrapper time perf-sanity-tests.time $LKP_SRC/stats/wrapper time $LKP_SRC/stats/wrapper dmesg $LKP_SRC/stats/wrapper kmsg $LKP_SRC/stats/wrapper stderr $LKP_SRC/stats/wrapper last_state
}
"$@"
2017-12-01 07:42:15 make LLVM_CONFIG=/usr/bin/llvm-config-3.9 LIBCLANGLLVM=1 ARCH= -C /usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/perf make: Entering directory '/usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/perf' BUILD: Doing 'make [33m-j2[m' parallel build HOSTCC fixdep.o HOSTLD fixdep-in.o LINK fixdep
Auto-detecting system features:
... dwarf: [ [32mon[m ] ... dwarf_getlocations: [ [32mon[m ] ... glibc: [ [32mon[m ] ... gtk2: [ [31mOFF[m ] ... libaudit: [ [32mon[m ] ... libbfd: [ [32mon[m ] ... libelf: [ [32mon[m ] ... libnuma: [ [32mon[m ] ... numa_num_possible_cpus: [ [32mon[m ]
... libperl: [ [31mOFF[m ]
... libpython: [ [32mon[m ]
... libslang: [ [31mOFF[m ]
... libcrypto: [ [31mOFF[m ]
... libunwind: [ [32mon[m ] ... libdw-dwarf-unwind: [ [32mon[m ] ... zlib: [ [32mon[m ] ... lzma: [ [32mon[m ] ... get_cpuid: [ [32mon[m ] ... bpf: [ [32mon[m ]
GEN common-cmds.h CC fd/array.o CC event-parse.o LD fd/libapi-in.o CC fs/fs.o CC fs/tracing_path.o LD fs/libapi-in.o CC cpu.o CC debug.o CC str_error_r.o LD libapi-in.o AR libapi.a CC exec-cmd.o CC help.o CC event-plugin.o CC trace-seq.o CC parse-filter.o CC pager.o CC parse-utils.o CC parse-options.o CC kbuffer-parse.o LD libtraceevent-in.o LINK libtraceevent.a CC libbpf.o CC bpf.o LD libbpf-in.o LINK libbpf.a HOSTCC pmu-events/json.o HOSTCC pmu-events/jsmn.o HOSTCC pmu-events/jevents.o CC run-command.o HOSTLD pmu-events/jevents-in.o CC plugin_jbd2.o CC sigchain.o LD plugin_jbd2-in.o CC plugin_hrtimer.o LD plugin_hrtimer-in.o CC plugin_kmem.o CC subcmd-config.o LD plugin_kmem-in.o LD libsubcmd-in.o CC plugin_kvm.o AR libsubcmd.a GEN perf-archive GEN perf-with-kcore CC util/annotate.o LD plugin_kvm-in.o CC plugin_mac80211.o LD plugin_mac80211-in.o CC plugin_sched_switch.o LD plugin_sched_switch-in.o CC plugin_function.o LD plugin_function-in.o CC plugin_xen.o LD plugin_xen-in.o CC plugin_scsi.o LD plugin_scsi-in.o CC plugin_cfg80211.o LD plugin_cfg80211-in.o LINK plugin_jbd2.so LINK plugin_hrtimer.so LINK plugin_kmem.so LINK plugin_kvm.so LINK plugin_mac80211.so LINK plugin_sched_switch.so LINK plugin_function.so LINK plugin_xen.so LINK plugin_scsi.so LINK plugin_cfg80211.so CC builtin-bench.o CC builtin-annotate.o CC builtin-config.o CC util/block-range.o CC builtin-diff.o CC util/build-id.o CC util/config.o CC builtin-evlist.o CC builtin-ftrace.o CC util/ctype.o CC util/db-export.o CC builtin-help.o CC builtin-sched.o CC util/env.o CC util/event.o CC util/evlist.o CC builtin-buildid-list.o CC builtin-buildid-cache.o CC builtin-kallsyms.o CC util/evsel.o CC builtin-list.o CC builtin-record.o CC builtin-report.o CC util/evsel_fprintf.o CC builtin-stat.o CC util/find_bit.o CC util/kallsyms.o CC util/levenshtein.o CC util/llvm-utils.o CC util/mmap.o CC util/memswap.o BISON util/parse-events-bison.c CC util/perf_regs.o CC util/path.o CC builtin-timechart.o CC util/print_binary.o CC util/rbtree.o CC util/libstring.o CC util/bitmap.o CC util/hweight.o CC util/smt.o CC util/quote.o CC util/strbuf.o CC builtin-top.o CC util/string.o CC util/strlist.o CC util/strfilter.o CC builtin-script.o CC util/top.o CC util/usage.o CC util/dso.o CC util/symbol.o CC builtin-kmem.o CC util/symbol_fprintf.o CC util/color.o CC builtin-lock.o CC util/metricgroup.o CC util/header.o CC builtin-kvm.o CC builtin-inject.o CC builtin-mem.o CC builtin-data.o CC builtin-version.o CC builtin-c2c.o CC util/callchain.o CC builtin-trace.o CC util/values.o CC util/debug.o CC util/machine.o /usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/build/Makefile.build:96: recipe for target 'builtin-trace.o' failed Makefile.perf:495: recipe for target 'perf-in.o' failed CC util/map.o CC arch/common.o CC arch/x86/util/header.o CC util/pstack.o CC arch/x86/util/tsc.o CC util/session.o CC arch/x86/util/pmu.o CC arch/x86/util/kvm-stat.o CC arch/x86/util/perf_regs.o CC arch/x86/util/group.o CC arch/x86/util/dwarf-regs.o CC arch/x86/util/unwind-libunwind.o CC arch/x86/util/auxtrace.o CC util/syscalltbl.o CC arch/x86/util/intel-pt.o CC util/ordered-events.o CC util/namespaces.o CC arch/x86/util/intel-bts.o CC util/comm.o CC util/thread.o LD arch/x86/util/libperf-in.o CC arch/x86/tests/regs_load.o CC arch/x86/tests/dwarf-unwind.o CC arch/x86/tests/arch-tests.o CC util/thread_map.o CC arch/x86/tests/rdpmc.o CC arch/x86/tests/perf-time-to-tsc.o CC util/trace-event-parse.o CC arch/x86/tests/insn-x86.o CC util/parse-events-bison.o LD arch/x86/tests/libperf-in.o LD arch/x86/libperf-in.o LD arch/libperf-in.o CC ui/setup.o CC ui/helpline.o BISON util/pmu-bison.c CC util/trace-event-read.o CC ui/progress.o CC ui/util.o CC util/trace-event-info.o CC ui/hist.o CC util/trace-event-scripting.o CC util/trace-event.o CC util/svghelper.o CC util/sort.o CC ui/stdio/hist.o LD ui/libperf-in.o CC util/hist.o CC util/util.o CC scripts/python/Perf-Trace-Util/Context.o LD scripts/python/Perf-Trace-Util/libperf-in.o LD scripts/libperf-in.o CC trace/beauty/clone.o CC trace/beauty/fcntl.o CC trace/beauty/ioctl.o CC trace/beauty/kcmp.o CC trace/beauty/pkey_alloc.o CC trace/beauty/prctl.o CC trace/beauty/statx.o CC util/xyarray.o LD trace/beauty/libperf-in.o CC util/cpumap.o CC util/cgroup.o CC util/target.o CC util/rblist.o CC util/intlist.o CC util/vdso.o CC util/counts.o CC util/stat.o CC util/stat-shadow.o CC util/record.o CC util/srcline.o CC util/data.o CC util/tsc.o CC util/cloexec.o CC util/call-path.o CC util/rwsem.o CC util/thread-stack.o CC util/auxtrace.o CC util/intel-pt-decoder/intel-pt-pkt-decoder.o GEN util/intel-pt-decoder/inat-tables.c CC util/intel-pt-decoder/intel-pt-log.o CC util/intel-pt-decoder/intel-pt-decoder.o CC util/scripting-engines/trace-event-python.o LD util/scripting-engines/libperf-in.o CXX util/c++/clang.o CC util/intel-pt-decoder/intel-pt-insn-decoder.o LD util/intel-pt-decoder/libperf-in.o CC util/intel-pt.o CC util/intel-bts.o CC util/parse-branch-options.o CC util/dump-insn.o CC util/parse-regs-options.o CC util/term.o CC util/help-unknown-cmd.o CC util/mem-events.o CC util/vsprintf.o CC util/drv_configs.o CC util/units.o CC util/time-utils.o BISON util/expr-bison.c CC util/branch.o CC util/bpf-loader.o CC util/bpf-prologue.o CC util/symbol-elf.o CC util/probe-file.o CC util/probe-event.o
/usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/build/Makefile.build:100: recipe for target 'util/c++/clang.o' failed /usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/build/Makefile.build:139: recipe for target 'c++' failed /usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/build/Makefile.build:139: recipe for target 'util' failed Makefile.perf:619: recipe for target 'libperf-in.o' failed
Makefile.perf:209: recipe for target 'sub-make' failed
Makefile:69: recipe for target 'all' failed
make: Leaving directory '/usr/src/linux-perf-x86_64-rhel-7.2-f7a7a64385657f44638b40f09dcae8f7fe02879a/tools/perf'
PATCH 5/7 perf symbols: Use cached rbtrees
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node).
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 4 +- tools/perf/tests/vmlinux-kallsyms.c | 3 +- tools/perf/util/dso.c | 5 ++- tools/perf/util/dso.h | 4 +- tools/perf/util/map.c | 8 ++-- tools/perf/util/probe-event.c | 3 +- tools/perf/util/symbol.c | 85 ++++++++++++++++++++----------------- tools/perf/util/symbol.h | 12 +++--- tools/perf/util/symbol_fprintf.c | 3 +- 11 files changed, 71 insertions(+), 60 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -164,7 +164,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,* the DSO? */ if (al->sym !=NULL ) { -rb_erase (&al->sym->rb_node, +rb_erase_cached (&al->sym->rb_node, &al->map->dso->symbols[al->map->type]);symbol__delete (al->sym);dso__reset_find_symbol_cache (al->map->dso);
tools/perf/builtin-report.c +1 -1
@@ -454,7 +454,7 @@ static void report__warn_kptr_restrict(const struct report *rep)if (kernel_map) {const struct dso *kdso = kernel_map->dso; -if (!RB_EMPTY_ROOT (&kdso->symbols[MAP__FUNCTION ])) { +if (!RB_EMPTY_ROOT (&kdso->symbols[MAP__FUNCTION ].rb_root)) { desc ="If some relocation was applied (e.g. " "kexec) symbols may be misresolved." ; }
tools/perf/builtin-top.c +2 -2
@@ -740,7 +740,7 @@ static void perf_event__process_sample(struct perf_tool *tool,"Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n" "Check /proc/sys/kernel/kptr_restrict.\n\n" "Kernel%s samples will not be resolved.\n" , - al.map && !RB_EMPTY_ROOT (&al.map->dso->symbols[MAP__FUNCTION ]) ? + al.map && !RB_EMPTY_ROOT (&al.map->dso->symbols[MAP__FUNCTION ].rb_root) ? " modules" : "");if (use_browser <=0 )sleep (5 );
@@ -763,7 +763,7 @@ static void perf_event__process_sample(struct perf_tool *tool,*/ if (!machine->kptr_restrict_warned && !top->vmlinux_warned && al.map == machine->vmlinux_maps[MAP__FUNCTION ] && -RB_EMPTY_ROOT (&al.map->dso->symbols[MAP__FUNCTION ])) { +RB_EMPTY_ROOT (&al.map->dso->symbols[MAP__FUNCTION ].rb_root)) {if (symbol_conf.vmlinux_name) {char serr[256 ];dso__strerror_load (al.map->dso, serr,sizeof (serr));
tools/perf/tests/vmlinux-kallsyms.c +2 -1
@@ -108,7 +108,8 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest* in the kallsyms dso. For the ones that are in both, check its names and * end addresses too. */ -for (nd =rb_first (&vmlinux_map->dso->symbols[type]); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&vmlinux_map->dso->symbols[type]); + nd; nd =rb_next (nd)) {struct symbol *pair, *first_pair; sym = rb_entry(nd, struct symbol, rb_node);
tools/perf/util/dso.c +3 -2
@@ -1201,7 +1201,8 @@ struct dso *dso__new(const char *name)dso__set_long_name (dso, dso->name, false);dso__set_short_name (dso, dso->name, false);for (i =0 ; i <MAP__NR_TYPES ; ++i) - dso->symbols[i] = dso->symbol_names[i] =RB_ROOT ; + dso->symbols[i] = dso->symbol_names[i] =RB_ROOT_CACHED ; + dso->data.cache =RB_ROOT ; dso->inlined_nodes =RB_ROOT ; dso->srclines =RB_ROOT_CACHED ;
@@ -1478,7 +1479,7 @@ size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp) dso__loaded(dso, type) ? "" : "NOT "); ret +=dso__fprintf_buildid (dso, fp); ret +=fprintf (fp,")\n" ); -for (nd =rb_first (&dso->symbols[type]); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&dso->symbols[type]); nd; nd =rb_next (nd)) { struct symbol *pos = rb_entry(nd, struct symbol, rb_node); ret +=symbol__fprintf (pos, fp); }
tools/perf/util/dso.h +2 -2
@@ -140,8 +140,8 @@ struct dso {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 rb_root symbols[MAP__NR_TYPES ]; -struct rb_root symbol_names[MAP__NR_TYPES ]; +struct rb_root_cached symbols[MAP__NR_TYPES ]; +struct rb_root_cached symbol_names[MAP__NR_TYPES ];struct rb_root inlined_nodes;struct rb_root_cached srclines;struct {
tools/perf/util/map.c +4 -4
@@ -279,8 +279,8 @@ void map__put(struct map *map)void map__fixup_start (struct map *map) { -struct rb_root *symbols = &map->dso->symbols[map->type]; -struct rb_node *nd =rb_first (symbols); +struct rb_root_cached *symbols = &map->dso->symbols[map->type]; +struct rb_node *nd =rb_first_cached (symbols);if (nd !=NULL ) { struct symbol *sym = rb_entry(nd, struct symbol, rb_node); map->start = sym->start;
@@ -289,8 +289,8 @@ void map__fixup_start(struct map *map)void map__fixup_end (struct map *map) { -struct rb_root *symbols = &map->dso->symbols[map->type]; -struct rb_node *nd =rb_last (symbols); +struct rb_root_cached *symbols = &map->dso->symbols[map->type]; +struct rb_node *nd =rb_last (&symbols->rb_root);if (nd !=NULL ) { struct symbol *sym = rb_entry(nd, struct symbol, rb_node); map->end = sym->end;
tools/perf/util/probe-event.c +2 -1
@@ -3473,7 +3473,8 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,/* Show all (filtered) symbols */ setup_pager (); -for (nd =rb_first (&map->dso->symbol_names[map->type]); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&map->dso->symbol_names[map->type]); + nd; nd =rb_next (nd)) { struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);if (strfilter__compare (_filter, pos->sym.name))
tools/perf/util/symbol.c +46 -39
243 lines not on this page · raw message
tools/perf/util/symbol.h +6 -6
@@ -66,7 +66,7 @@ struct symbol { };void symbol__delete (struct symbol *sym); -void symbols__delete (struct rb_root *symbols); +void symbols__delete (struct rb_root_cached *symbols);/* symbols__for_each_entry - iterate over symbols (rb_root) *
@@ -75,7 +75,7 @@ void symbols__delete(struct rb_root *symbols);* @nd: the 'struct rb_node *' to use as a temporary storage */ #define symbols__for_each_entry (symbols, pos, nd) \ - for (nd = rb_first(symbols); \ + for (nd = rb_first_cached(symbols); \ nd && (pos = rb_entry(nd, struct symbol, rb_node)); \ nd = rb_next(nd))
@@ -312,10 +312,10 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,char *dso__demangle_sym (struct dso *dso,int kmodule,const char *elf_name); -void __symbols__insert (struct rb_root *symbols,struct symbol *sym,bool kernel); -void symbols__insert (struct rb_root *symbols,struct symbol *sym); -void symbols__fixup_duplicate (struct rb_root *symbols); -void symbols__fixup_end (struct rb_root *symbols); +void __symbols__insert (struct rb_root_cached *symbols,struct symbol *sym,bool kernel); +void symbols__insert (struct rb_root_cached *symbols,struct symbol *sym); +void symbols__fixup_duplicate (struct rb_root_cached *symbols); +void symbols__fixup_end (struct rb_root_cached *symbols);void __map_groups__fixup_end (struct map_groups *mg,enum map_type type);typedef int (*mapfn_t )(u64 start,u64 len,u64 pgoff,void *data);
tools/perf/util/symbol_fprintf.c +2 -1
@@ -64,7 +64,8 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso,struct rb_node *nd;struct symbol_name_rb_node *pos; -for (nd =rb_first (&dso->symbol_names[type]); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&dso->symbol_names[type]); + nd; nd =rb_next (nd)) { pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);fprintf (fp,"%s\n" , pos->sym.name); }
Signature · 1 line
2.13.6
PATCH 6/7 perf hist: Use cached rbtrees
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something heavily required for histograms. Specifically, the following are converted to rb_root_cached, and users accordingly:
hist::entries_in_arrayhist::entries_inhist::entrieshist::entries_collapsedhist_entry::hroot_inhist_entry::hroot_out
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-c2c.c | 6 +- tools/perf/builtin-diff.c | 10 +- tools/perf/builtin-top.c | 2 +- tools/perf/tests/hists_common.c | 8 +- tools/perf/tests/hists_cumulate.c | 19 ++-- tools/perf/tests/hists_link.c | 8 +- tools/perf/tests/hists_output.c | 32 +++--- tools/perf/ui/browsers/hists.c | 16 +-- tools/perf/ui/gtk/hists.c | 6 +- tools/perf/ui/stdio/hist.c | 3 +- tools/perf/util/hist.c | 198 +++++++++++++++++++++----------------- tools/perf/util/hist.h | 10 +- tools/perf/util/sort.h | 4 +- 14 files changed, 175 insertions(+), 149 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -228,7 +228,7 @@ static void hists__find_annotations(struct hists *hists,struct perf_evsel *evsel, struct perf_annotate *ann) { - struct rb_node *nd = rb_first(&hists->entries), *next; + struct rb_node *nd = rb_first_cached(&hists->entries), *next;int key =K_RIGHT ;while (nd) {
tools/perf/builtin-c2c.c +3 -3
@@ -1968,7 +1968,7 @@ static int resort_hitm_cb(struct hist_entry *he)static int hists__iterate_cb (struct hists *hists,hists__resort_cb_t cb) { -struct rb_node *next =rb_first (&hists->entries); +struct rb_node *next =rb_first_cached (&hists->entries);int ret =0 ;while (next) {
@@ -2095,7 +2095,7 @@ static void print_pareto(FILE *out)if (WARN_ONCE (ret,"failed to setup sort entries\n" ))return ; - nd =rb_first (&c2c.hists.hists.entries); + nd =rb_first_cached (&c2c.hists.hists.entries);for (; nd; nd =rb_next (nd)) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
@@ -2163,7 +2163,7 @@ static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)static void c2c_browser__update_nr_entries (struct hist_browser *hb) {u64 nr_entries =0 ; -struct rb_node *nd =rb_first (&hb->hists->entries); +struct rb_node *nd =rb_first_cached (&hb->hists->entries);while (nd) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
tools/perf/builtin-diff.c +5 -5
@@ -429,7 +429,7 @@ get_pair_fmt(struct hist_entry *he, struct diff_hpp_fmt *dfmt)static void hists__baseline_only (struct hists *hists) { -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *next;if (hists__has (hists, need_collapse))
@@ -437,13 +437,13 @@ static void hists__baseline_only(struct hists *hists)else root = hists->entries_in; - next =rb_first (root); + next =rb_first_cached (root);while (next !=NULL ) { struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in); next =rb_next (&he->rb_node_in);if (!hist_entry__next_pair (he)) { -rb_erase (&he->rb_node_in, root); +rb_erase_cached (&he->rb_node_in, root);hist_entry__delete (he); } }
@@ -451,7 +451,7 @@ static void hists__baseline_only(struct hists *hists)static void hists__precompute (struct hists *hists) { -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *next;if (hists__has (hists, need_collapse))
@@ -459,7 +459,7 @@ static void hists__precompute(struct hists *hists)else root = hists->entries_in; - next =rb_first (root); + next =rb_first_cached (root);while (next !=NULL ) {struct hist_entry *he, *pair;struct data__file *d;
tools/perf/builtin-top.c +1 -1
@@ -373,7 +373,7 @@ static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)if (p) *p =0 ; - next =rb_first (&hists->entries); + next =rb_first_cached (&hists->entries);while (next) { n = rb_entry(next, struct hist_entry, rb_node);if (n->ms.sym && !strcmp (buf, n->ms.sym->name)) {
tools/perf/tests/hists_common.c +4 -4
@@ -161,7 +161,7 @@ struct machine *setup_fake_machine(struct machines *machines)void print_hists_in (struct hists *hists) {int i =0 ; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node;if (hists__has (hists, need_collapse))
@@ -170,7 +170,7 @@ void print_hists_in(struct hists *hists) root = hists->entries_in;pr_info ("----- %s --------\n" , __func__); - node =rb_first (root); + node =rb_first_cached (root);while (node) {struct hist_entry *he;
@@ -191,13 +191,13 @@ void print_hists_in(struct hists *hists)void print_hists_out (struct hists *hists) {int i =0 ; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; root = &hists->entries;pr_info ("----- %s --------\n" , __func__); - node =rb_first (root); + node =rb_first_cached (root);while (node) {struct hist_entry *he;
tools/perf/tests/hists_cumulate.c +10 -9
@@ -125,8 +125,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)static void del_hist_entries (struct hists *hists) {struct hist_entry *he; -struct rb_root *root_in; -struct rb_root *root_out; +struct rb_root_cached *root_in; +struct rb_root_cached *root_out;struct rb_node *node;if (hists__has (hists, need_collapse))
@@ -136,12 +136,12 @@ static void del_hist_entries(struct hists *hists) root_out = &hists->entries; -while (!RB_EMPTY_ROOT (root_out)) { - node =rb_first (root_out); +while (!RB_EMPTY_ROOT (&root_out->rb_root)) { + node =rb_first_cached (root_out); he = rb_entry(node, struct hist_entry, rb_node); -rb_erase (node, root_out); -rb_erase (&he->rb_node_in, root_in); +rb_erase_cached (node, root_out); +rb_erase_cached (&he->rb_node_in, root_in);hist_entry__delete (he); } }
@@ -179,7 +179,8 @@ static int do_test(struct hists *hists, struct result *expected, size_t nr_expecchar buf[32 ];size_t i, c;struct hist_entry *he; -struct rb_root *root; +struct rb_root *root;/* for callchain entry test */ +struct rb_root_cached *root_cached;struct rb_node *node;struct callchain_node *cnode;struct callchain_list *clist;
@@ -198,8 +199,8 @@ static int do_test(struct hists *hists, struct result *expected, size_t nr_expecprint_hists_out (hists); } - root = &hists->entries; -for (node =rb_first (root), i =0 ; + root_cached = &hists->entries; +for (node =rb_first_cached (root_cached), i =0 ; node && (he = rb_entry(node, struct hist_entry, rb_node)); node =rb_next (node), i++) {scnprintf (buf,sizeof (buf),"Invalid hist entry #%zd" , i);
tools/perf/tests/hists_link.c +4 -4
@@ -142,7 +142,7 @@ static int find_sample(struct sample *samples, size_t nr_samples,static int __validate_match (struct hists *hists) {size_t count =0 ; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node;/*
@@ -153,7 +153,7 @@ static int __validate_match(struct hists *hists)else root = hists->entries_in; - node =rb_first (root); + node =rb_first_cached (root);while (node) {struct hist_entry *he;
@@ -192,7 +192,7 @@ static int __validate_link(struct hists *hists, int idx)size_t count =0 ;size_t count_pair =0 ;size_t count_dummy =0 ; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node;/*
@@ -205,7 +205,7 @@ static int __validate_link(struct hists *hists, int idx)else root = hists->entries_in; - node =rb_first (root); + node =rb_first_cached (root);while (node) {struct hist_entry *he;
tools/perf/tests/hists_output.c +16 -16
@@ -91,8 +91,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)static void del_hist_entries (struct hists *hists) {struct hist_entry *he; -struct rb_root *root_in; -struct rb_root *root_out; +struct rb_root_cached *root_in; +struct rb_root_cached *root_out;struct rb_node *node;if (hists__has (hists, need_collapse))
@@ -102,12 +102,12 @@ static void del_hist_entries(struct hists *hists) root_out = &hists->entries; -while (!RB_EMPTY_ROOT (root_out)) { - node =rb_first (root_out); +while (!RB_EMPTY_ROOT (&root_out->rb_root)) { + node =rb_first_cached (root_out); he = rb_entry(node, struct hist_entry, rb_node); -rb_erase (node, root_out); -rb_erase (&he->rb_node_in, root_in); +rb_erase_cached (node, root_out); +rb_erase_cached (&he->rb_node_in, root_in);hist_entry__delete (he); } }
@@ -126,7 +126,7 @@ static int test1(struct perf_evsel *evsel, struct machine *machine)int err;struct hists *hists =evsel__hists (evsel);struct hist_entry *he; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; field_order =NULL ;
@@ -162,7 +162,7 @@ static int test1(struct perf_evsel *evsel, struct machine *machine) } root = &hists->entries; - node =rb_first (root); + node =rb_first_cached (root); he = rb_entry(node, struct hist_entry, rb_node); TEST_ASSERT_VAL("Invalid hist entry", !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
@@ -228,7 +228,7 @@ static int test2(struct perf_evsel *evsel, struct machine *machine)int err;struct hists *hists =evsel__hists (evsel);struct hist_entry *he; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; field_order ="overhead,cpu" ;
@@ -262,7 +262,7 @@ static int test2(struct perf_evsel *evsel, struct machine *machine) } root = &hists->entries; - node =rb_first (root); + node =rb_first_cached (root); he = rb_entry(node, struct hist_entry, rb_node);TEST_ASSERT_VAL ("Invalid hist entry" ,CPU (he) ==1 &&PID (he) ==100 && he->stat.period ==300 );
@@ -284,7 +284,7 @@ static int test3(struct perf_evsel *evsel, struct machine *machine)int err;struct hists *hists =evsel__hists (evsel);struct hist_entry *he; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; field_order ="comm,overhead,dso" ;
@@ -316,7 +316,7 @@ static int test3(struct perf_evsel *evsel, struct machine *machine) } root = &hists->entries; - node =rb_first (root); + node =rb_first_cached (root); he = rb_entry(node, struct hist_entry, rb_node); TEST_ASSERT_VAL("Invalid hist entry", !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
@@ -358,7 +358,7 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)int err;struct hists *hists =evsel__hists (evsel);struct hist_entry *he; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; field_order ="dso,sym,comm,overhead,dso" ;
@@ -394,7 +394,7 @@ static int test4(struct perf_evsel *evsel, struct machine *machine) } root = &hists->entries; - node =rb_first (root); + node =rb_first_cached (root); he = rb_entry(node, struct hist_entry, rb_node); TEST_ASSERT_VAL("Invalid hist entry", !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") &&
@@ -460,7 +460,7 @@ static int test5(struct perf_evsel *evsel, struct machine *machine)int err;struct hists *hists =evsel__hists (evsel);struct hist_entry *he; -struct rb_root *root; +struct rb_root_cached *root;struct rb_node *node; field_order ="cpu,pid,comm,dso,sym" ;
@@ -497,7 +497,7 @@ static int test5(struct perf_evsel *evsel, struct machine *machine) } root = &hists->entries; - node =rb_first (root); + node =rb_first_cached (root); he = rb_entry(node, struct hist_entry, rb_node); TEST_ASSERT_VAL("Invalid hist entry",
tools/perf/ui/browsers/hists.c +8 -8
@@ -50,7 +50,7 @@ static int hist_browser__get_folding(struct hist_browser *browser)struct hists *hists = browser->hists;int unfolded_rows =0 ; -for (nd =rb_first (&hists->entries); +for (nd =rb_first_cached (&hists->entries); (nd =hists__filter_entries (nd, browser->min_pcnt)) !=NULL ; nd =rb_hierarchy_next (nd)) { struct hist_entry *he =
@@ -264,7 +264,7 @@ static int hierarchy_count_rows(struct hist_browser *hb, struct hist_entry *he,if (he->has_no_entry)return 1 ; - node =rb_first (&he->hroot_out); + node =rb_first_cached (&he->hroot_out);while (node) {float percent;
@@ -369,7 +369,7 @@ static void hist_entry__init_have_children(struct hist_entry *he) he->has_children = !RB_EMPTY_ROOT (&he->sorted_chain);callchain__init_have_children (&he->sorted_chain); }else { - he->has_children = !RB_EMPTY_ROOT (&he->hroot_out); + he->has_children = !RB_EMPTY_ROOT (&he->hroot_out.rb_root); } he->init_have_children = true;
@@ -505,7 +505,7 @@ static int hierarchy_set_folding(struct hist_browser *hb, struct hist_entry *he,struct hist_entry *child;int n =0 ; -for (nd =rb_first (&he->hroot_out); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&he->hroot_out); nd; nd =rb_next (nd)) { child = rb_entry(nd, struct hist_entry, rb_node); percent =hist_entry__get_percent_limit (child);if (!child->filtered && percent >= hb->min_pcnt)
@@ -563,7 +563,7 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold)struct rb_node *nd;struct hist_entry *he; - nd =rb_first (&browser->hists->entries); + nd =rb_first_cached (&browser->hists->entries);while (nd) { he = rb_entry(nd, struct hist_entry, rb_node);
@@ -1731,7 +1731,7 @@ static void ui_browser__hists_init_top(struct ui_browser *browser)struct hist_browser *hb; hb = container_of(browser, struct hist_browser, b); - browser->top =rb_first (&hb->hists->entries); + browser->top =rb_first_cached (&hb->hists->entries); } }
@@ -2700,7 +2700,7 @@ add_socket_opt(struct hist_browser *browser, struct popup_action *act,static void hist_browser__update_nr_entries (struct hist_browser *hb) {u64 nr_entries =0 ; -struct rb_node *nd =rb_first (&hb->hists->entries); +struct rb_node *nd =rb_first_cached (&hb->hists->entries);if (hb->min_pcnt ==0 && !symbol_conf.report_hierarchy) { hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries;
@@ -2720,7 +2720,7 @@ static void hist_browser__update_percent_limit(struct hist_browser *hb, double percent) {struct hist_entry *he; -struct rb_node *nd =rb_first (&hb->hists->entries); +struct rb_node *nd =rb_first_cached (&hb->hists->entries);u64 total =hists__total_period (hb->hists);u64 min_callchain_hits = total * (percent /100 );
tools/perf/ui/gtk/hists.c +3 -3
@@ -353,7 +353,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,g_object_unref (GTK_TREE_MODEL (store)); -for (nd =rb_first (&hists->entries); nd; nd =rb_next (nd)) { +for (nd =rb_first_cached (&hists->entries); nd; nd =rb_next (nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);GtkTreeIter iter;u64 total =hists__total_period (h->hists);
@@ -400,7 +400,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, } static void perf_gtk__add_hierarchy_entries(struct hists *hists, - struct rb_root *root, + struct rb_root_cached *root, GtkTreeStore *store, GtkTreeIter *parent, struct perf_hpp *hpp,
@@ -414,7 +414,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,u64 total =hists__total_period (hists);int size; -for (node =rb_first (root); node; node =rb_next (node)) { +for (node =rb_first_cached (root); node; node =rb_next (node)) {GtkTreeIter iter;float percent;char *bf;
tools/perf/ui/stdio/hist.c +2 -1
@@ -788,7 +788,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, indent =hists__overhead_width (hists) +4 ; -for (nd =rb_first (&hists->entries); nd; nd =__rb_hierarchy_next (nd,HMD_FORCE_CHILD )) { +for (nd =rb_first_cached (&hists->entries); + nd; nd =__rb_hierarchy_next (nd,HMD_FORCE_CHILD )) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);float percent;
tools/perf/util/hist.c +111 -87
613 lines not on this page · raw message
tools/perf/util/hist.h +5 -5
@@ -68,10 +68,10 @@ struct thread;struct dso ;struct hists { -struct rb_root entries_in_array[2 ]; -struct rb_root *entries_in; -struct rb_root entries; -struct rb_root entries_collapsed; +struct rb_root_cached entries_in_array[2 ]; +struct rb_root_cached *entries_in; +struct rb_root_cached entries; +struct rb_root_cached entries_collapsed;u64 nr_entries;u64 nr_non_filtered_entries;u64 callchain_period;
@@ -223,7 +223,7 @@ static inline struct hists *evsel__hists(struct perf_evsel *evsel)int hists__init (void );int __hists__init (struct hists *hists,struct perf_hpp_list *hpp_list); -struct rb_root *hists__get_rotate_entries_in (struct hists *hists); +struct rb_root_cached *hists__get_rotate_entries_in (struct hists *hists);struct perf_hpp {char *buf;
tools/perf/util/sort.h +2 -2
@@ -143,8 +143,8 @@ struct hist_entry {union {/* this is for hierarchical entry structure */ struct { -struct rb_root hroot_in; -struct rb_root hroot_out; +struct rb_root_cached hroot_in; +struct rb_root_cached hroot_out; };/* non-leaf entries */ struct rb_root sorted_chain;/* leaf entry has callchains */ };
Signature · 1 line
2.13.6
PATCH 7/7 perf sched: Use cached rbtrees
In reply to Davidlohr BuesoAt the cost of an extra pointer, we can avoid the O(logN) cost of finding the first element in the tree (smallest node), which is something heavily required for perf-sched.
--- tools/perf/builtin-sched.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-)
tools/perf/builtin-sched.c +25 -20
@@ -213,7 +213,7 @@ struct perf_sched {u64 all_runtime;u64 all_count;u64 cpu_last_switched[MAX_CPUS ]; -struct rb_root atom_root, sorted_atom_root, merged_atom_root; +struct rb_root_cached atom_root, sorted_atom_root, merged_atom_root;struct list_head sort_list, cmp_pid;bool force;bool skip_merge;
@@ -267,7 +267,7 @@ struct evsel_runtime {struct idle_thread_runtime {struct thread_runtime tr;struct thread *last_thread; -struct rb_root sorted_root; +struct rb_root_cached sorted_root;struct callchain_root callchain;struct callchain_cursor cursor; };
@@ -915,10 +915,10 @@ thread_lat_cmp(struct list_head *list, struct work_atoms *l, struct work_atoms * }static struct work_atoms * -thread_atoms_search (struct rb_root *root,struct thread *thread, +thread_atoms_search (struct rb_root_cached *root,struct thread *thread,struct list_head *sort_list) { -struct rb_node *node = root->rb_node; +struct rb_node *node = root->rb_root.rb_node;struct work_atoms key = { .thread = thread };while (node) {
@@ -941,10 +941,11 @@ thread_atoms_search(struct rb_root *root, struct thread *thread, }static void -__thread_latency_insert (struct rb_root *root,struct work_atoms *data, +__thread_latency_insert (struct rb_root_cached *root,struct work_atoms *data,struct list_head *sort_list) { -struct rb_node **new = &(root->rb_node), *parent =NULL ; +struct rb_node **new = &(root->rb_root.rb_node), *parent =NULL ; +bool leftmost = true;while (*new) {struct work_atoms *this;
@@ -957,12 +958,14 @@ __thread_latency_insert(struct rb_root *root, struct work_atoms *data,if (cmp >0 ) new = &((*new)->rb_left); -else +else { new = &((*new)->rb_right); + leftmost = false; + } }rb_link_node (&data->node, parent, new); -rb_insert_color (&data->node, root); +rb_insert_color_cached (&data->node, root, leftmost); }static int thread_atoms_insert (struct perf_sched *sched,struct thread *thread)
@@ -1412,15 +1415,15 @@ static int sort_dimension__add(const char *tok, struct list_head *list)static void perf_sched__sort_lat (struct perf_sched *sched) {struct rb_node *node; -struct rb_root *root = &sched->atom_root; +struct rb_root_cached *root = &sched->atom_root; again:for (;;) {struct work_atoms *data; - node =rb_first (root); + node =rb_first_cached (root);if (!node)break ; -rb_erase (node, root); +rb_erase_cached (node, root); data = rb_entry(node, struct work_atoms, node);__thread_latency_insert (&sched->sorted_atom_root, data, &sched->sort_list); }
@@ -2712,12 +2715,12 @@ static size_t callchain__fprintf_folded(FILE *fp, struct callchain_node *node)return ret; } -static size_t timehist_print_idlehist_callchain (struct rb_root *root) +static size_t timehist_print_idlehist_callchain (struct rb_root_cached *root) {size_t ret =0 ;FILE *fp = stdout;struct callchain_node *chain; -struct rb_node *rb_node =rb_first (root); +struct rb_node *rb_node =rb_first_cached (root);printf (" %16s %8s %s\n" ,"Idle time (msec)" ,"Count" ,"Callchains" ); printf(" %.16s %.8s %.50s\n", graph_dotted_line, graph_dotted_line,
@@ -2818,7 +2821,7 @@ static void timehist_print_summary(struct perf_sched *sched,if (itr ==NULL )continue ; - callchain_param.sort (&itr->sorted_root, &itr->callchain, + callchain_param.sort (&itr->sorted_root.rb_root, &itr->callchain,0 , &callchain_param);printf (" CPU %2d:" , i);
@@ -3025,11 +3028,12 @@ static void print_bad_events(struct perf_sched *sched) } } -static void __merge_work_atoms (struct rb_root *root,struct work_atoms *data) +static void __merge_work_atoms (struct rb_root_cached *root,struct work_atoms *data) { -struct rb_node **new = &(root->rb_node), *parent =NULL ; +struct rb_node **new = &(root->rb_root.rb_node), *parent =NULL ;struct work_atoms *this;const char *comm =thread__comm_str (data->thread), *this_comm; +bool leftmost = true;while (*new) {int cmp;
@@ -3043,6 +3047,7 @@ static void __merge_work_atoms(struct rb_root *root, struct work_atoms *data) new = &((*new)->rb_left); }else if (cmp <0 ) { new = &((*new)->rb_right); + leftmost = false; }else { this->num_merged++; this->total_runtime += data->total_runtime;
@@ -3060,7 +3065,7 @@ static void __merge_work_atoms(struct rb_root *root, struct work_atoms *data) data->num_merged++;rb_link_node (&data->node, parent, new); -rb_insert_color (&data->node, root); +rb_insert_color_cached (&data->node, root, leftmost); }static void perf_sched__merge_lat (struct perf_sched *sched)
@@ -3071,8 +3076,8 @@ static void perf_sched__merge_lat(struct perf_sched *sched)if (sched->skip_merge)return ; -while ((node =rb_first (&sched->atom_root))) { -rb_erase (node, &sched->atom_root); +while ((node =rb_first_cached (&sched->atom_root))) { +rb_erase_cached (node, &sched->atom_root); data = rb_entry(node, struct work_atoms, node);__merge_work_atoms (&sched->merged_atom_root, data); }
@@ -3094,7 +3099,7 @@ static int perf_sched__lat(struct perf_sched *sched)printf (" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n" );printf (" -----------------------------------------------------------------------------------------------------------------\n" ); - next =rb_first (&sched->sorted_atom_root); + next =rb_first_cached (&sched->sorted_atom_root);while (next) {struct work_atoms *work_list;
Signature · 1 line
2.13.6
Quoted 1 line
Applies on today's -tip tree. Please consider for v4.16.
No numbers on the improvements?
-Andi
Quoted 3 lines · Andi Kleen
Quoted 1 line
Applies on today's -tip tree. Please consider for v4.16.
No numbers on the improvements?
I have not done performance tests perse for perf, but ultimately it will depend a lot on the workload and size of the tree. I had previously measured, on a Xeon E5-2450 @ 2.10GHz, the cost of an rb_first() was ~60 cycles for 100 nodes, and ~75 cycles with 1000 nodes. fwiw.
Thanks,
Davidlohr
Arnaldo Carvalho de Melo
maintainerEm Mon, Nov 27, 2017 at 08:14:57AM -0800, Davidlohr Bueso escreveu:
Quoted 11 lines · Andi Kleen
Quoted 4 lines
Quoted 2 lines
Applies on today's -tip tree. Please consider for v4.16.
No numbers on the improvements?
I have not done performance tests perse for perf, but ultimately it will depend a lot on the workload and size of the tree. I had previously measured, on a Xeon E5-2450 @ 2.10GHz, the cost of an
rb_first()was ~60 cycles for 100 nodes, and ~75 cycles with 1000 nodes. fwiw.
I'll try to do some before/after perf stat runs to compare output and to see the overall diff in cycles, etc.
- Arnaldo