perf/core improvements and fixes
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling, I'll cherry pick some into a separate
perf/urgent pull request, like the jump-to-another-function one, after the usual round of tests, but since I've been working on then in my perf/core branch, lets flush them now.
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit ddc4becca1409541c2ebb7ecb99b5cef44cf17e4:
Merge tag 'perf-core-for-mingo-4.17-20180220' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2018-02-21 08:50:45 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-4.17-20180305
for you to fetch changes up to 6afad54d2f0ddebacfcf3b829147d7fed8dab298:
perf mmap: Discard legacy interfaces for mmap read forward (2018-03-05 10:51:10 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
- Be more robust when drawing arrows in the annotation TUI, avoiding a segfault when jump instructions have as a target addresses in functions other that the one currently being annotated. The full fix will come in the following days, when jumping to other functions will work as call instructions (Arnaldo Carvalho de Melo)
- Allow asking for the maximum allowed sample rate in 'top' and 'record', i.e. 'perf record -F max' will read the kernel.perf_event_max_sample_rate sysctl and use it (Arnaldo Carvalho de Melo)
- When the user specifies a freq above kernel.perf_event_max_sample_rate, Throttle it down to that max freq, and warn the user about it, add as well --strict-freq so that the previous behaviour of not starting the session when the desired freq can't be used can be selected (Arnaldo Carvalho de Melo)
- Find 'call' instruction target symbol at parsing time, used so far in the TUI, part of the infrastructure changes that will end up allowing for jumps to navigate to other functions, just like 'call' instructions. (Arnaldo Carvalho de Melo)
- Use xyarray dimensions to iterate fds in 'perf stat' (Andi Kleen)
- Ignore threads for which the current user hasn't permissions when enabling system-wide --per-thread (Jin Yao)
- Fix some backtrace perf test cases to use 'perf record' + 'perf script' instead, till 'perf trace' starts using ordered_events or equivalent to avoid symbol resolving artifacts due to reordering of PERF_RECORD_MMAP events (Jiri Olsa)
- Fix crash in 'perf record' pipe mode, it needs to allocate the ID array even for a single event, unlike non-pipe mode (Jiri Olsa)
- Make annoying fallback message on older kernels with newer 'perf top' binaries trying to use overwrite mode and that not being present in the older kernels (Kan Liang)
- Switch last users of old APIs to the newer perf_mmap__read_event() one, then discard those old mmap read forward APIs (Kan Liang)
- Fix the usage on the 'perf kallsyms' man page (Sangwon Hong)
- Simplify cgroup arguments when tracking multiple events (weiping zhang)
----------------------------------------------------------------
Andi Kleen (1):
perf stat: Use xyarray dimensions to iterate fds
Arnaldo Carvalho de Melo (6):
perf annotate browser: Be more robust when drawing jump arrows perf record: Allow asking for the maximum allowed sample rate perf top browser: Show sample_freq in browser title line perf top: Allow asking for the maximum allowed sample rate perf record: Throttle user defined frequencies to the maximum allowed perf annotate: Find 'call' instruction target symbol at parsing time
Jin Yao (1):
perf stat: Ignore error thread when enabling system-wide --per-thread
Jiri Olsa (3):
perf tests: Switch trace+probe_libc_inet_pton to use record perf tests: Rename trace+probe_libc_inet_pton to record+probe_libc_inet_pton perf record: Fix crash in pipe mode
Kan Liang (15):
perf top: Fix annoying fallback message on older kernels
perf kvm: Switch to new perf_mmap__read_event() interface
perf trace: Switch to new perf_mmap__read_event() interface
perf python: Switch to new perf_mmap__read_event() interface
perf test: Switch to new perf_mmap__read_event() interface for bpf perf test: Switch to new perf_mmap__read_event() interface for 'code reading' test perf test: Switch to new perf_mmap__read_event() interface for "keep tracking" test perf test: Switch to new perf_mmap__read_event() interface for mmap-basic perf test: Switch to new perf_mmap__read_event() interface for tp fields perf test: Switch to new perf_mmap__read_event() interface for perf-record perf test: Switch to new perf_mmap__read_event() interface for time-to-tsc perf test: Switch to new perf_mmap__read_event() interface for sw-clock perf test: Switch to new perf_mmap__read_event() interface for switch-tracking perf test: Switch to new perf_mmap__read_event() interface for task-exit perf mmap: Discard legacy interfaces for mmap read forward
Sangwon Hong (1):
perf kallsyms: Fix the usage on the man page
weiping zhang (1):
perf cgroup: Simplify arguments when tracking multiple events
tools/perf/Documentation/perf-kallsyms.txt | 2 +-
tools/perf/Documentation/perf-record.txt | 15 ++++++-
tools/perf/Documentation/perf-stat.txt | 6 ++-
tools/perf/Documentation/perf-top.txt | 4 +-
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 11 ++++-
tools/perf/builtin-kvm.c | 17 ++++++--
tools/perf/builtin-record.c | 18 +++++++-
tools/perf/builtin-stat.c | 25 ++++++++---
tools/perf/builtin-top.c | 6 ++-
tools/perf/builtin-trace.c | 11 ++++-
tools/perf/perf.h | 4 ++
tools/perf/tests/bpf.c | 9 +++-
tools/perf/tests/code-reading.c | 11 ++++-
tools/perf/tests/keep-tracking.c | 10 ++++-
tools/perf/tests/mmap-basic.c | 12 ++++-
tools/perf/tests/openat-syscall-tp-fields.c | 11 ++++-
tools/perf/tests/perf-record.c | 11 ++++-
...inet_pton.sh => record+probe_libc_inet_pton.sh} | 30 ++++++-------
tools/perf/tests/sw-clock.c | 12 ++++-
tools/perf/tests/switch-tracking.c | 11 ++++-
tools/perf/tests/task-exit.c | 12 ++++-
tools/perf/ui/browsers/annotate.c | 42 +++++++++++++-----
tools/perf/ui/browsers/hists.c | 10 +++--
tools/perf/util/annotate.c | 38 ++++++++--------
tools/perf/util/annotate.h | 1 +
tools/perf/util/cgroup.c | 17 +++++++-
tools/perf/util/evlist.c | 25 +----------
tools/perf/util/evlist.h | 4 --
tools/perf/util/evsel.c | 3 ++
tools/perf/util/mmap.c | 21 +--------
tools/perf/util/python.c | 12 +++--
tools/perf/util/record.c | 51 +++++++++++++++++++---
tools/perf/util/thread_map.c | 1 +
tools/perf/util/thread_map.h | 1 +
34 files changed, 328 insertions(+), 146 deletions(-)
rename tools/perf/tests/shell/{trace+probe_libc_inet_pton.sh => record+probe_libc_inet_pton.sh} (61%)Test results:
The first ones are container (docker) based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf.
The objtool and samples/bpf/ builds are disabled now that I'm switching from using the sources in a local volume to fetching them from a http server to build it inside the container, to make it easier to build in a container cluster. Those will come back later.
Several are cross builds, the ones with -x-ARCH and the android one, and those may not have all the features built, due to lack of multi-arch devel packages, available and being used so far on just a few, like debian:experimental-x-{arm64,mipsel}.
The 'perf test' one will perform a variety of tests exercising tools/perf/util/, tools/lib/{bpf,traceevent,etc}, as well as run perf commands with a variety of command line event specifications to then intercept the sys_perf_event syscall to check that the perf_event_attr fields are set up as expected, among a variety of other unit tests.
Then there is the 'make -C tools/perf build-test' ones, that build tools/perf/ with a variety of feature sets, exercising the build with an incomplete set of features as well as with a complete one. It is planned to have it run on each of the containers mentioned above, using some container orchestration infrastructure. Get in contact if interested in helping having this in place.
Ran on a Thinkpad t450s (Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz)
# dm 1 84.32 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0 2 91.48 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822 3 88.85 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0 4 95.11 alpine:edge : Ok gcc (Alpine 6.4.0) 6.4.0 5 83.60 amazonlinux:1 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) 6 94.16 amazonlinux:2 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 7 122.03 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 8 57.09 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 9 45.20 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 10 65.78 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 11 86.03 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 12 72.97 debian:7 : Ok gcc (Debian 4.7.2-5) 4.7.2 13 84.25 debian:8 : Ok gcc (Debian 4.9.2-10+deb8u1) 4.9.2 14 137.70 debian:9 : Ok gcc (Debian 6.3.0-18) 6.3.0 20170516 15 151.22 debian:experimental : Ok gcc (Debian 7.2.0-17) 7.2.1 20171205 16 85.40 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 17 83.49 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 18 77.44 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 7.2.0-11) 7.2.0 19 89.35 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 20 79.55 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) 21 97.67 fedora:21 : Ok gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) 22 84.82 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 23 86.14 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 24 88.66 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) 25 76.55 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 26 163.16 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1) 27 166.89 fedora:26 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 28 160.95 fedora:27 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 29 159.80 fedora:rawhide : Ok gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1) 30 83.86 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 6.4.0-r1 p1.3) 6.4.0 31 87.20 mageia:5 : Ok gcc (GCC) 4.9.2 32 89.17 mageia:6 : Ok gcc (Mageia 5.4.0-5.mga6) 5.4.0 33 81.88 opensuse:42.1 : Ok gcc (SUSE Linux) 4.8.5 34 80.75 opensuse:42.2 : Ok gcc (SUSE Linux) 4.8.5 35 82.94 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5 36 165.47 opensuse:tumbleweed : Ok gcc (SUSE Linux) 7.3.0 37 66.79 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 38 78.03 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 39 63.00 ubuntu:12.04.5 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 40 77.96 ubuntu:14.04.4 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 41 68.39 ubuntu:14.04.4-x-linaro-arm64 : Ok aarch64-linux-gnu-gcc (Linaro GCC 5.4-2017.05) 5.4.1 20170404 42 79.03 ubuntu:15.04 : Ok gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2 43 126.72 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609 44 68.22 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 45 66.60 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 46 67.14 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 47 67.40 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609 48 69.12 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 49 66.66 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 50 135.05 ubuntu:16.10 : Ok gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005 51 136.33 ubuntu:17.04 : Ok gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406 52 137.14 ubuntu:17.10 : Ok gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0 53 136.01 ubuntu:18.04 : Ok gcc (Ubuntu 7.2.0-16ubuntu1) 7.2.0
# uname -a Linux jouet 4.16.0-rc3-00097-gf3afe530d644 #1 SMP Wed Feb 28 10:04:12 -03 2018 x86_64 x86_64 x86_64 GNU/Linux # perf test 1: vmlinux symtab matches kallsyms : Ok 2: Detect openat syscall event : Ok 3: Detect openat syscall event on all cpus : Ok 4: Read samples using the mmap interface : Ok 5: Test data source output : Ok 6: Parse event definition strings : Ok 7: Simple expression parser : Ok 8: PERF_RECORD_* events & perf_sample fields : Ok 9: Parse perf pmu format : Ok 10: DSO data read : Ok 11: DSO data cache : Ok 12: DSO data reopen : Ok 13: Roundtrip evsel->name : Ok 14: Parse sched tracepoints fields : Ok 15: syscalls:sys_enter_openat event fields : Ok 16: Setup struct perf_event_attr : Ok 17: Match and link multiple hists : Ok 18: 'import perf' in python : Ok 19: Breakpoint overflow signal handler : Ok 20: Breakpoint overflow sampling : Ok 21: Number of exit events of a simple workload : Ok 22: Software clock events period values : Ok 23: Object code reading : Ok 24: Sample parsing : Ok 25: Use a dummy software event to keep tracking : Ok 26: Parse with no sample_id_all bit set : Ok 27: Filter hist entries : Ok 28: Lookup mmap thread : Ok 29: Share thread mg : Ok 30: Sort output of hist entries : Ok 31: Cumulate child hist entries : Ok 32: Track with sched_switch : Ok 33: Filter fds with revents mask in a fdarray : Ok 34: Add fd to a fdarray, making it autogrow : Ok 35: kmod_path__parse : Ok 36: Thread map : Ok 37: LLVM search and compile : 37.1: Basic BPF llvm compile : Ok 37.2: kbuild searching : Ok 37.3: Compile source for BPF prologue generation : Ok 37.4: Compile source for BPF relocation : Ok 38: Session topology : Ok 39: BPF filter : 39.1: Basic BPF filtering : Ok 39.2: BPF pinning : Ok 39.3: BPF prologue generation : Ok 39.4: BPF relocation checker : Ok 40: Synthesize thread map : Ok 41: Remove thread map : Ok 42: Synthesize cpu map : Ok 43: Synthesize stat config : Ok 44: Synthesize stat : Ok 45: Synthesize stat round : Ok 46: Synthesize attr update : Ok 47: Event times : Ok 48: Read backward ring buffer : Ok 49: Print cpu map : Ok 50: Probe SDT events : Ok 51: is_printable_array : Ok 52: Print bitmap : Ok 53: perf hooks : Ok 54: builtin clang support : Skip (not compiled in) 55: unit_number__scnprintf : Ok 56: x86 rdpmc : Ok 57: Convert perf time to TSC : Ok 58: DWARF unwind : Ok 59: x86 instruction decoder - new instructions : Ok 60: Use vfs_getname probe to get syscall args filenames : Ok 61: probe libc's inet_pton & backtrace it with ping : Ok 62: Check open filename arg using perf trace + vfs_getname: Ok 63: probe libc's inet_pton & backtrace it with ping : Ok 64: Add vfs_getname probe to get syscall args filenames : Ok #
$ make -C tools/perf build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_pure_O: cd . && make
make_static_O: cd . && make LDFLAGS=-static
make_tags_O: cd . && make tags
make_with_babeltrace_O: cd . && make LIBBABELTRACE=1
make_no_slang_O: cd . && make NO_SLANG=1
make_install_O: cd . && make install
make_help_O: cd . && make help
make_no_libaudit_O: cd . && make NO_LIBAUDIT=1
make_util_pmu_bison_o_O: cd . && make util/pmu-bison.o
make_no_libpython_O: cd . && make NO_LIBPYTHON=1
make_no_scripts_O: cd . && make NO_LIBPYTHON=1 NO_LIBPERL=1
make_doc_O: cd . && make doc
make_debug_O: cd . && make DEBUG=1
make_no_gtk2_O: cd . && make NO_GTK2=1
make_no_libbpf_O: cd . && make NO_LIBBPF=1
make_no_libunwind_O: cd . && make NO_LIBUNWIND=1
make_no_ui_O: cd . && make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_minimal_O: cd . && make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1
make_no_libdw_dwarf_unwind_O: cd . && make NO_LIBDW_DWARF_UNWIND=1
make_no_backtrace_O: cd . && make NO_BACKTRACE=1
make_no_demangle_O: cd . && make NO_DEMANGLE=1
make_no_libbionic_O: cd . && make NO_LIBBIONIC=1
make_no_auxtrace_O: cd . && make NO_AUXTRACE=1
make_no_libperl_O: cd . && make NO_LIBPERL=1
make_no_newt_O: cd . && make NO_NEWT=1
make_clean_all_O: cd . && make clean all
make_no_libelf_O: cd . && make NO_LIBELF=1
make_util_map_o_O: cd . && make util/map.o
make_install_prefix_slash_O: cd . && make install prefix=/tmp/krava/
make_perf_o_O: cd . && make perf.o
make_install_prefix_O: cd . && make install prefix=/tmp/krava
make_install_bin_O: cd . && make install-bin
make_no_libnuma_O: cd . && make NO_LIBNUMA=1
make_with_clangllvm_O: cd . && make LIBCLANGLLVM=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$ Arnaldo Carvalho de Melo
maintainerPATCH 1/28 perf kallsyms: Fix the usage on the man page
From: Sangwon Hong <[email protected]>
First, all man pages highlight only perf and subcommands except 'perf kallsyms', which includes the full usage. Fix it for commands to monopolize underlines.
Second, options can be ommited when executing 'perf kallsyms', so add square brackets between <option>.
--- tools/perf/Documentation/perf-kallsyms.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Documentation/perf-kallsyms.txt +1 -1
@@ -8,7 +8,7 @@ perf-kallsyms - Searches running kernel for symbols SYNOPSIS -------- [verse] -'perf kallsyms <options> symbol_name[,symbol_name...]' +'perf kallsyms' [<options>] symbol_name[,symbol_name...] DESCRIPTION -----------
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/28 perf stat: Use xyarray dimensions to iterate fds
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Now that the xyarray stores the dimensions we can use those to iterate over the FDs for a evsel.
--- tools/perf/builtin-stat.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +5 -6
@@ -508,14 +508,13 @@ static int perf_stat_synthesize_config(bool is_pipe)#define FD (e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) -static int __store_counter_ids (struct perf_evsel *counter, -struct cpu_map *cpus, -struct thread_map *threads) +static int __store_counter_ids (struct perf_evsel *counter) {int cpu, thread; -for (cpu =0 ; cpu < cpus->nr; cpu++) { -for (thread =0 ; thread < threads->nr; thread++) { +for (cpu =0 ; cpu <xyarray__max_x (counter->fd); cpu++) { +for (thread =0 ; thread <xyarray__max_y (counter->fd); + thread++) {int fd =FD (counter, cpu, thread); if (perf_evlist__id_add_fd(evsel_list, counter,
@@ -535,7 +534,7 @@ static int store_counter_ids(struct perf_evsel *counter)if (perf_evsel__alloc_id (counter, cpus->nr, threads->nr))return -ENOMEM ; -return __store_counter_ids (counter, cpus, threads); +return __store_counter_ids (counter); }static bool perf_evsel__should_store_id (struct perf_evsel *counter)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 3/28 perf cgroup: Simplify arguments when tracking multiple events
In reply to Arnaldo Carvalho de MeloFrom: weiping zhang <[email protected]>
When using -G with one cgroup and -e with multiple events, only the first event gets the correct cgroup setting, all events from the second onwards will track system-wide events.
If the user wants to track multiple events for a specific cgroup, the user must give parameters like the following:
$ perf stat -e e1 -e e2 -e e3 -G test,test,test
This patch simplify this case, just type one cgroup:
$ perf stat -e e1 -e e2 -e e3 -G test
$ mkdir -p /sys/fs/cgroup/perf_event/empty_cgroup $ perf stat -e cycles -e cache-misses -a -I 1000 -G empty_cgroup
Before:
1.001007226 <not counted> cycles empty_cgroup
1.001007226 7,506 cache-missesAfter:
1.000834097 <not counted> cycles empty_cgroup
1.000834097 <not counted> cache-misses empty_cgroup--- tools/perf/Documentation/perf-record.txt | 6 +++++- tools/perf/Documentation/perf-stat.txt | 6 +++++- tools/perf/util/cgroup.c | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -1
@@ -308,7 +308,11 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first to first event, second cgroup to second event and so on. It is possible to provide an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have corresponding events, i.e., they always refer to events defined earlier on the command -line. +line. If the user wants to track multiple events for a specific cgroup, the user can +use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'. + +If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this +command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'. -b:: --branch-any::
tools/perf/Documentation/perf-stat.txt +5 -1
@@ -118,7 +118,11 @@ can be provided. Each cgroup is applied to the corresponding event, i.e., first to first event, second cgroup to second event and so on. It is possible to provide an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have corresponding events, i.e., they always refer to events defined earlier on the command -line. +line. If the user wants to track multiple events for a specific cgroup, the user can +use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'. + +If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this +command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'. -o file:: --output file::
tools/perf/util/cgroup.c +16 -1
@@ -157,9 +157,11 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str, int unset __maybe_unused) {struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; +struct perf_evsel *counter; +struct cgroup_sel *cgrp =NULL ;const char *p, *e, *eos = str +strlen (str);char *s; -int ret; +int ret, i;if (list_empty (&evlist->entries)) {fprintf (stderr,"must define events before cgroups\n" );
@@ -188,5 +190,18 @@ int parse_cgroups(const struct option *opt __maybe_unused, const char *str,break ; str = p+1 ; } +/* for the case one cgroup combine to multiple events */ + i =0 ; +if (nr_cgroups ==1 ) { +evlist__for_each_entry (evlist, counter) { +if (i ==0 ) + cgrp = counter->cgrp; +else { + counter->cgrp = cgrp; +refcount_inc (&cgrp->refcnt); + } + i++; + } + }return 0 ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/28 perf top: Fix annoying fallback message on older kernels
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
On older (e.g. v4.4) kernels, an annoying fallback message can be observed in 'perf top':
┌─Warning:──────────────────────┐ │fall back to non-overwrite mode│ │ │ │ │ │Press any key... │ └───────────────────────────────┘
The 'perf top' utility has been changed to overwrite mode since commit ebebbf082357 ("perf top: Switch default mode to overwrite mode").
For older kernels which don't have overwrite mode support, 'perf top' will fall back to non-overwrite mode and print out the fallback message using ui__warning(), which needs user's input to close.
The fallback message is not critical for end users. Turning it to debug message which is printed when running with -vv.
--- tools/perf/builtin-top.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-top.c +1 -1
@@ -991,7 +991,7 @@ static int perf_top_overwrite_fallback(struct perf_top *top,evlist__for_each_entry (evlist, counter) counter->attr.write_backward = false; opts->overwrite = false; -ui__warning ("fall back to non-overwrite mode\n" ); +pr_debug2 ("fall back to non-overwrite mode\n" );return 1 ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/28 perf stat: Ignore error thread when enabling system-wide --per-thread
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
If we execute 'perf stat --per-thread' with non-root account (even set kernel.perf_event_paranoid = -1 yet), it reports the error:
jinyao@skl:~$ perf stat --per-thread Error: You may not have permission to collect system-wide stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN).
The current value is 2:
-1: Allow use of (almost) all events by all users
Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
Quoted 1 line
= 0: Disallow ftrace function tracepoint by users without
CAP_SYS_ADMIN
Disallow raw tracepoint access by users without CAP_SYS_ADMIN
Quoted 2 lines
= 1: Disallow CPU event access by users without
CAP_SYS_ADMIN= 2: Disallow kernel profiling by users withoutCAP_SYS_ADMIN
To make this setting permanent, edit /etc/sysctl.conf too, e.g.:
kernel.perf_event_paranoid = -1
Perhaps the ptrace rule doesn't allow to trace some processes. But anyway the global --per-thread mode had better ignore such errors and continue working on other threads.
This patch will record the index of error thread in perf_evsel__open() and remove this thread before retrying.
For example (run with non-root, kernel.perf_event_paranoid isn't set):
jinyao@skl:~$ perf stat --per-thread ^C Performance counter stats for 'system wide':
vmstat-3458 6.171984 cpu-clock:u (msec) # 0.000 CPUs utilized
perf-3670 0.515599 cpu-clock:u (msec) # 0.000 CPUs utilized
vmstat-3458 1,163,643 cycles:u # 0.189 GHz
perf-3670 40,881 cycles:u # 0.079 GHz
vmstat-3458 1,410,238 instructions:u # 1.21 insn per cycle
perf-3670 3,536 instructions:u # 0.09 insn per cycle
vmstat-3458 288,937 branches:u # 46.814 M/sec
perf-3670 936 branches:u # 1.815 M/sec
vmstat-3458 15,195 branch-misses:u # 5.26% of all branches
perf-3670 76 branch-misses:u # 8.12% of all branches12.651675247 seconds time elapsed
--- tools/perf/builtin-stat.c | 14 +++++++++++++- tools/perf/util/evsel.c | 3 +++ tools/perf/util/thread_map.c | 1 + tools/perf/util/thread_map.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +13 -1
@@ -637,7 +637,19 @@ static int __run_perf_stat(int argc, const char **argv)if (verbose >0 )ui__warning ("%s\n" , msg); goto try_again; - } + }else if (target__has_per_thread (&target) && + evsel_list->threads && + evsel_list->threads->err_thread !=-1 ) { +/* +* For global --per-thread case, skip current +* error thread. +*/ +if (!thread_map__remove (evsel_list->threads, + evsel_list->threads->err_thread)) { + evsel_list->threads->err_thread =-1 ; + goto try_again; + } + }perf_evsel__open_strerror (counter, &target, errno, msg,sizeof (msg));
tools/perf/util/evsel.c +3 -0
@@ -1915,6 +1915,9 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, goto fallback_missing_features; } out_close: +if (err) + threads->err_thread = thread; + do { while (--thread >= 0) { close(FD(evsel, cpu, thread));
tools/perf/util/thread_map.c +1 -0
@@ -32,6 +32,7 @@ static void thread_map__reset(struct thread_map *map, int start, int nr)size_t size = (nr - start) *sizeof (map->map[0 ]);memset (&map->map[start],0 , size); + map->err_thread =-1 ; }static struct thread_map *thread_map__realloc (struct thread_map *map,int nr)
tools/perf/util/thread_map.h +1 -0
@@ -14,6 +14,7 @@ struct thread_map_data {struct thread_map {refcount_t refcnt;int nr; +int err_thread;struct thread_map_data map[]; };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/28 perf annotate browser: Be more robust when drawing jump arrows
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
This first happened with a gcc function, _cpp_lex_token, that has the usual jumps:
│1159e6c: ↓ jne 115aa32 <_cpp_lex_token@@Base+0xf92>
I.e. jumps to a label inside that function (_cpp_lex_token), and those works, but also this kind:
│1159e8b: ↓ jne c469be <cpp_named_operator2name@@Base+0xa72>
I.e. jumps to another function, outside _cpp_lex_token, which are not being correctly handled generating as a side effect references to ab->offset[] entries that are set to NULL, so to make this code more robust, check that here.
A proper fix for will be put in place, looking at the function name right after the '<' token and probably treating this like a 'call' instruction.
For now just don't draw the arrow.
--- tools/perf/ui/browsers/annotate.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
tools/perf/ui/browsers/annotate.c +25 -0
@@ -328,7 +328,32 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)if (!disasm_line__is_valid_jump (cursor, sym))return ; +/* +* This first was seen with a gcc function, _cpp_lex_token, that +* has the usual jumps: +* +* │1159e6c: ↓ jne 115aa32 <_cpp_lex_token@@Base+0xf92> +* +* I.e. jumps to a label inside that function (_cpp_lex_token), and +* those works, but also this kind: +* +* │1159e8b: ↓ jne c469be <cpp_named_operator2name@@Base+0xa72> +* +* I.e. jumps to another function, outside _cpp_lex_token, which +* are not being correctly handled generating as a side effect references +* to ab->offset[] entries that are set to NULL, so to make this code +* more robust, check that here. +* +* A proper fix for will be put in place, looking at the function +* name right after the '<' token and probably treating this like a +* 'call' instruction. +*/ target = ab->offsets[cursor->ops.target.offset]; +if (target ==NULL ) { +ui_helpline__printf ("WARN: jump target inconsistency, press 'o', ab->offsets[%#x] = NULL\n" , + cursor->ops.target.offset); +return ; + } bcursor =browser_line (&cursor->al); btarget =browser_line (target);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/28 perf tests: Switch trace+probe_libc_inet_pton to use record
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
There's a problem with relying on backtrace data from 'perf trace' the way the trace+probe_libc_inet_pton does. This test inserts uprobe within ping binary and checks that it gets its sample using 'perf trace'.
It also checks it gets proper backtrace from sample and that's where the issue is.
The 'perf trace' does not sort events (by definition) so it can happen that it processes the event sample before the ping binary memory map event. This can (very rarely) happen as proved by this events dump output (from custom added debug output):
...
7680/7680: [0x7f4e29718000(0x204000) @ 0 fd:00 33611321 4230892504]: r-xp /usr/lib64/libdl-2.17.so 7680/7680: [0x7f4e29502000(0x216000) @ 0 fd:00 33617257 2606846872]: r-xp /usr/lib64/libz.so.1.2.7 (IP, 0x2): 7680/7680: 0x7f4e29c2ed60 period: 1 addr: 0
7680/7680: [0x564842ef0000(0x233000) @ 0 fd:00 83 1989280200]: r-xp /usr/bin/ping 7680/7680: [0x7f4e2aca2000(0x224000) @ 0 fd:00 33611308 1219144940]: r-xp /usr/lib64/ld-2.17.so
...
In this case 'perf trace' fails to resolve the last callchain IP (within the ping binary) because it does not know about the ping binary memory map yet and the test fails like this:
PING ::1(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.037 ms
--- ::1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.037/0.037/0.037/0.000 ms
0.000 probe_libc:inet_pton:(7f4e29c2ed60))
__GI___inet_pton (/usr/lib64/libc-2.17.so)
getaddrinfo (/usr/lib64/libc-2.17.so)
[0] ([unknown])
FAIL: expected backtrace entry 8 ".*\(.*/bin/ping.*\)$" got "[0] ([unknown])"
Switching the test to use 'perf record' and 'perf script' instead of 'perf trace'.
--- .../perf/tests/shell/trace+probe_libc_inet_pton.sh | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-)
tools/perf/tests/shell/trace+probe_libc_inet_pton.sh +15 -15
@@ -15,30 +15,28 @@ nm -g $libc 2>/dev/null | fgrep -q inet_pton || exit 254 trace_libc_inet_pton_backtrace() { idx=0 - expected[0]="PING.*bytes" - expected[1]="64 bytes from ::1.*" - expected[2]=".*ping statistics.*" - expected[3]=".*packets transmitted.*" - expected[4]="rtt min.*" - expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)" - expected[6]=".*inet_pton[[:space:]]\($libc|inlined\)$" + expected[0]="ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)" + expected[1]=".*inet_pton[[:space:]]\($libc\)$" case "$(uname -m)" in s390x) eventattr='call-graph=dwarf' - expected[7]="gaih_inet.*[[:space:]]\($libc|inlined\)$" - expected[8]="__GI_getaddrinfo[[:space:]]\($libc|inlined\)$" - expected[9]="main[[:space:]]\(.*/bin/ping.*\)$" - expected[10]="__libc_start_main[[:space:]]\($libc\)$" - expected[11]="_start[[:space:]]\(.*/bin/ping.*\)$" + expected[2]="gaih_inet.*[[:space:]]\($libc|inlined\)$" + expected[3]="__GI_getaddrinfo[[:space:]]\($libc|inlined\)$" + expected[4]="main[[:space:]]\(.*/bin/ping.*\)$" + expected[5]="__libc_start_main[[:space:]]\($libc\)$" + expected[6]="_start[[:space:]]\(.*/bin/ping.*\)$" ;; *) eventattr='max-stack=3' - expected[7]="getaddrinfo[[:space:]]\($libc\)$" - expected[8]=".*\(.*/bin/ping.*\)$" + expected[2]="getaddrinfo[[:space:]]\($libc\)$" + expected[3]=".*\(.*/bin/ping.*\)$" ;; esac - perf trace --no-syscalls -e probe_libc:inet_pton/$eventattr/ ping -6 -c 1 ::1 2>&1 | grep -v ^$ | while read line ; do + file=`mktemp -u /tmp/perf.data.XXX` + + perf record -e probe_libc:inet_pton/$eventattr/ -o $file ping -6 -c 1 ::1 > /dev/null 2>&1 + perf script -i $file | while read line ; do echo $line echo "$line" | egrep -q "${expected[$idx]}" if [ $? -ne 0 ] ; then
@@ -48,6 +46,8 @@ trace_libc_inet_pton_backtrace() { let idx+=1 [ -z "${expected[$idx]}" ] && break done + + rm -f $file } # Check for IPv6 interface existence
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/28 perf tests: Rename trace+probe_libc_inet_pton to record+probe_libc_inet_pton
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Because the test is no longer using perf trace but perf record instead.
---
.../{trace+probe_libc_inet_pton.sh => record+probe_libc_inet_pton.sh} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename tools/perf/tests/shell/{trace+probe_libc_inet_pton.sh => record+probe_libc_inet_pton.sh} (100%)tools/perf/tests/shell/record+probe_libc_inet_pton.sh renamed from tools/perf/tests/shell/trace+probe_libc_inet_pton.sh +0 -0
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 9/28 perf record: Allow asking for the maximum allowed sample rate
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Add the handy '-F max' shortcut to reading and using the kernel.perf_event_max_sample_rate value as the user supplied sampling frequency:
# perf record -F max sleep 1
info: Using a maximum frequency rate of 15,000 Hz
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (14 samples) ]
# sysctl kernel.perf_event_max_sample_rate
kernel.perf_event_max_sample_rate = 15000
# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 15000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 # perf record -F 10 sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (4 samples) ]
# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 10, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
#--- tools/perf/Documentation/perf-record.txt | 4 +++- tools/perf/builtin-record.c | 7 ++++++- tools/perf/perf.h | 2 ++ tools/perf/util/record.c | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-record.txt +3 -1
@@ -193,7 +193,9 @@ OPTIONS Child tasks do not inherit counters. -F:: --freq=:: - Profile at this frequency. + Profile at this frequency. Use 'max' to use the currently maximum + allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate + sysctl. -m:: --mmap-pages=::
tools/perf/builtin-record.c +6 -1
@@ -45,6 +45,7 @@#include <errno.h> #include <inttypes.h> +#include <locale.h> #include <poll.h> #include <unistd.h> #include <sched.h>
@@ -1542,7 +1543,9 @@ static struct option __record_options[] = {OPT_BOOLEAN (0 ,"tail-synthesize" , &record.opts.tail_synthesize,"synthesize non-sample events at the end of output" ),OPT_BOOLEAN (0 ,"overwrite" , &record.opts.overwrite,"use overwrite mode" ), -OPT_UINTEGER ('F' ,"freq" , &record.opts.user_freq,"profile at this frequency" ), +OPT_CALLBACK ('F' ,"freq" , &record.opts,"freq or 'max'" , +"profile at this frequency" , + record__parse_freq),OPT_CALLBACK ('m' ,"mmap-pages" , &record.opts,"pages[,pages]" ,"number of mmap data pages and AUX area tracing mmap pages" , record__parse_mmap_pages),
@@ -1651,6 +1654,8 @@ int cmd_record(int argc, const char **argv)struct record *rec = &record;char errbuf[BUFSIZ ]; +setlocale (LC_ALL ,"" ); +#ifndef HAVE_LIBBPF_SUPPORT # define set_nobuild (s, l, c) set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c)set_nobuild ('\0' ,"clang-path" , true);
tools/perf/perf.h +2 -0
@@ -82,4 +82,6 @@ struct record_opts {struct option ;extern const char *const *record_usage;extern struct option *record_options; + +int record__parse_freq (const struct option *opt,const char *str,int unset);#endif
tools/perf/util/record.c +23 -0
@@ -5,6 +5,7 @@#include "parse-events.h" #include <errno.h> #include <api/fs/fs.h> +#include <subcmd/parse-options.h> #include "util.h" #include "cloexec.h"
@@ -287,3 +288,25 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)perf_evlist__delete (temp_evlist);return ret; } + +int record__parse_freq (const struct option *opt,const char *str,int unset__maybe_unused ) +{ +unsigned int freq; +struct record_opts *opts = opt->value; + +if (!str) +return -EINVAL ; + +if (strcasecmp (str,"max" ) ==0 ) { +if (get_max_rate (&freq)) { +pr_err ("couldn't read /proc/sys/kernel/perf_event_max_sample_rate\n" ); +return -1 ; + } +pr_info ("info: Using a maximum frequency rate of %'d Hz\n" , freq); + }else { + freq =atoi (str); + } + + opts->user_freq = freq; +return 0 ; +}
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/28 perf top browser: Show sample_freq in browser title line
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The '--stdio' 'perf top' UI shows it, so lets remove this UI difference and show it too in '--tui', will be useful for 'perf top --tui -F max'.
--- tools/perf/ui/browsers/hists.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +7 -3
@@ -2223,7 +2223,7 @@ static int perf_evsel_browser_title(struct hist_browser *browser,u64 nr_events = hists->stats.total_period;struct perf_evsel *evsel =hists_to_evsel (hists);const char *ev_name =perf_evsel__name (evsel); -char buf[512 ]; +char buf[512 ], sample_freq_str[64 ] ="" ;size_t buflen =sizeof (buf);char ref[30 ] =" show reference callgraph, " ;bool enable_ref = false;
@@ -2255,10 +2255,14 @@ static int perf_evsel_browser_title(struct hist_browser *browser,if (symbol_conf.show_ref_callgraph &&strstr (ev_name,"call-graph=no" )) enable_ref = true; + +if (!is_report_browser (hbt)) +scnprintf (sample_freq_str,sizeof (sample_freq_str)," %d Hz," , evsel->attr.sample_freq); + nr_samples =convert_unit (nr_samples, &unit); printed =scnprintf (bf, size, -"Samples: %lu%c of event '%s',%sEvent count (approx.): %" PRIu64, - nr_samples, unit, ev_name, enable_ref ? ref :" " , nr_events); +"Samples: %lu%c of event '%s',%s%sEvent count (approx.): %" PRIu64, + nr_samples, unit, ev_name, sample_freq_str, enable_ref ? ref :" " , nr_events);if (hists->uid_filter_str)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 11/28 perf top: Allow asking for the maximum allowed sample rate
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Add the handy '-F max' shortcut, just introduced to 'perf record', to reading and using the kernel.perf_event_max_sample_rate value as the user supplied sampling frequency:
--- tools/perf/Documentation/perf-top.txt | 4 +++- tools/perf/builtin-top.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-top.txt +3 -1
@@ -55,7 +55,9 @@ Default is to monitor all CPUS. -F <freq>:: --freq=<freq>:: - Profile at this frequency. + Profile at this frequency. Use 'max' to use the currently maximum + allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate + sysctl. -i:: --inherit::
tools/perf/builtin-top.c +3 -1
@@ -1307,7 +1307,9 @@ int cmd_top(int argc, const char **argv)OPT_STRING (0 ,"sym-annotate" , &top.sym_filter,"symbol name" ,"symbol to annotate" ),OPT_BOOLEAN ('z' ,"zero" , &top.zero,"zero history across updates" ), -OPT_UINTEGER ('F' ,"freq" , &opts->user_freq,"profile at this frequency" ), +OPT_CALLBACK ('F' ,"freq" , &top.record_opts,"freq or 'max'" , +"profile at this frequency" , + record__parse_freq),OPT_INTEGER ('E' ,"entries" , &top.print_entries,"display this many functions" ), OPT_BOOLEAN('U', "hide_user_symbols", &top.hide_user_symbols,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 12/28 perf record: Throttle user defined frequencies to the maximum allowed
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
# perf record -F 200000 sleep 1
warning: Maximum frequency rate (15,000 Hz) exceeded, throttling from 200,000 Hz to 15,000 Hz.
The limit can be raised via /proc/sys/kernel/perf_event_max_sample_rate.
The kernel will lower it when perf's interrupts take too long.
Use --strict-freq to disable this throttling, refusing to record.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (15 samples) ]
# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 15000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1For those wanting that it fails if the desired frequency can't be used:
# perf record --strict-freq -F 200000 sleep 1
error: Maximum frequency rate (15,000 Hz) exceeded.
Please use -F freq option with a lower value or consider
tweaking /proc/sys/kernel/perf_event_max_sample_rate.
#--- tools/perf/Documentation/perf-record.txt | 7 ++++++- tools/perf/builtin-record.c | 2 ++ tools/perf/perf.h | 1 + tools/perf/util/record.c | 20 +++++++++++++++----- 4 files changed, 24 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-record.txt +6 -1
@@ -191,11 +191,16 @@ OPTIONS -i:: --no-inherit:: Child tasks do not inherit counters. + -F:: --freq=:: Profile at this frequency. Use 'max' to use the currently maximum allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate - sysctl. + sysctl. Will throttle down to the currently maximum allowed frequency. + See --strict-freq. + +--strict-freq:: + Fail if the specified frequency can't be used. -m:: --mmap-pages=::
tools/perf/builtin-record.c +2 -0
@@ -1543,6 +1543,8 @@ static struct option __record_options[] = {OPT_BOOLEAN (0 ,"tail-synthesize" , &record.opts.tail_synthesize,"synthesize non-sample events at the end of output" ),OPT_BOOLEAN (0 ,"overwrite" , &record.opts.overwrite,"use overwrite mode" ), +OPT_BOOLEAN (0 ,"strict-freq" , &record.opts.strict_freq, +"Fail if the specified frequency can't be used" ),OPT_CALLBACK ('F' ,"freq" , &record.opts,"freq or 'max'" ,"profile at this frequency" , record__parse_freq),
tools/perf/perf.h +1 -0
@@ -61,6 +61,7 @@ struct record_opts {bool tail_synthesize;bool overwrite;bool ignore_missing_thread; +bool strict_freq;unsigned int freq;unsigned int mmap_pages;unsigned int auxtrace_mmap_pages;
tools/perf/util/record.c +15 -5
@@ -216,11 +216,21 @@ static int record_opts__config_freq(struct record_opts *opts)* User specified frequency is over current maximum. */ if (user_freq && (max_rate < opts->freq)) { -pr_err ("Maximum frequency rate (%u) reached.\n" -"Please use -F freq option with lower value or consider\n" -"tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n" , - max_rate); -return -1 ; +if (opts->strict_freq) { +pr_err ("error: Maximum frequency rate (%'u Hz) exceeded.\n" +" Please use -F freq option with a lower value or consider\n" +" tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n" , + max_rate); +return -1 ; + }else { +pr_warning ("warning: Maximum frequency rate (%'u Hz) exceeded, throttling from %'u Hz to %'u Hz.\n" +" The limit can be raised via /proc/sys/kernel/perf_event_max_sample_rate.\n" +" The kernel will lower it when perf's interrupts take too long.\n" +" Use --strict-freq to disable this throttling, refusing to record.\n" , + max_rate, opts->freq, max_rate); + + opts->freq = max_rate; + } }/*
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 13/28 perf annotate: Find 'call' instruction target symbol at parsing time
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that we do it just once, not everytime we press enter or -> on a 'call' instruction line.
--- tools/perf/ui/browsers/annotate.c | 17 +++++------------ tools/perf/util/annotate.c | 38 +++++++++++++++++++++----------------- tools/perf/util/annotate.h | 1 + 3 files changed, 27 insertions(+), 29 deletions(-)
tools/perf/ui/browsers/annotate.c +5 -12
@@ -568,35 +568,28 @@ static bool annotate_browser__callq(struct annotate_browser *browser,struct map_symbol *ms = browser->b.priv;struct disasm_line *dl =disasm_line (browser->selection);struct annotation *notes; -struct addr_map_symbol target = { - .map = ms->map, - .addr =map__objdump_2mem (ms->map, dl->ops.target.addr), - };char title[SYM_TITLE_MAX_SIZE ];if (!ins__is_call (&dl->ins))return false; -if (map_groups__find_ams (&target) || -map__rip_2objdump (target.map, target.map->map_ip (target.map, - target.addr)) != - dl->ops.target.addr) { +if (!dl->ops.target.sym) {ui_helpline__puts ("The called function was not found." );return true; } - notes =symbol__annotation (target.sym); + notes =symbol__annotation (dl->ops.target.sym);pthread_mutex_lock (¬es->lock); -if (notes->src ==NULL &&symbol__alloc_hist (target.sym) <0 ) { +if (notes->src ==NULL &&symbol__alloc_hist (dl->ops.target.sym) <0 ) {pthread_mutex_unlock (¬es->lock);ui__warning ("Not enough memory for annotating '%s' symbol!\n" , - target.sym->name); + dl->ops.target.sym->name);return true; }pthread_mutex_unlock (¬es->lock); -symbol__tui_annotate (target.sym, target.map, evsel, hbt); +symbol__tui_annotate (dl->ops.target.sym, ms->map, evsel, hbt);sym_title (ms->sym, ms->map, title,sizeof (title));ui_browser__show_title (&browser->b, title);return true;
tools/perf/util/annotate.c +21 -17
@@ -187,6 +187,9 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2)static int call__parse (struct arch *arch,struct ins_operands *ops,struct map *map) {char *endptr, *tok, *name; +struct addr_map_symbol target = { + .map = map, + }; ops->target.addr =strtoull (ops->raw, &endptr,16 );
@@ -208,28 +211,29 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map * ops->target.name =strdup (name); *tok ='>' ; -return ops->target.name ==NULL ?-1 :0 ; +if (ops->target.name ==NULL ) +return -1 ; +find_target: + target.addr =map__objdump_2mem (map, ops->target.addr); -indirect_call: - tok =strchr (endptr,'*' ); -if (tok ==NULL ) { -struct symbol *sym =map__find_symbol (map, map->map_ip (map, ops->target.addr)); -if (sym !=NULL ) - ops->target.name =strdup (sym->name); -else - ops->target.addr =0 ; -return 0 ; - } +if (map_groups__find_ams (&target) ==0 && +map__rip_2objdump (target.map, map->map_ip (target.map, target.addr)) == ops->target.addr) + ops->target.sym = target.sym; - ops->target.addr =strtoull (tok +1 ,NULL ,16 );return 0 ; + +indirect_call: + tok =strchr (endptr,'*' ); +if (tok !=NULL ) + ops->target.addr =strtoull (tok +1 ,NULL ,16 ); + goto find_target; }static int call__scnprintf (struct ins *ins,char *bf,size_t size,struct ins_operands *ops) { -if (ops->target.name) -return scnprintf (bf, size,"%-6s %s" , ins->name, ops->target.name); +if (ops->target.sym) +return scnprintf (bf, size,"%-6s %s" , ins->name, ops->target.sym->name);if (ops->target.addr ==0 )return ins__raw_scnprintf (ins, bf, size, ops);
@@ -1283,8 +1287,8 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file, dl->ops.target.offset_avail = true; } -/* kcore has no symbols, so add the call target name */ -if (dl->ins.ops &&ins__is_call (&dl->ins) && !dl->ops.target.name) { +/* kcore has no symbols, so add the call target symbol */ +if (dl->ins.ops &&ins__is_call (&dl->ins) && !dl->ops.target.sym) {struct addr_map_symbol target = { .map = map, .addr = dl->ops.target.addr,
@@ -1292,7 +1296,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,if (!map_groups__find_ams (&target) && target.sym->start == target.al_addr) - dl->ops.target.name =strdup (target.sym->name); + dl->ops.target.sym = target.sym; }annotation_line__add (&dl->al, ¬es->src->source);
tools/perf/util/annotate.h +1 -0
@@ -24,6 +24,7 @@ struct ins_operands {struct {char *raw;char *name; +struct symbol *sym;u64 addr;s64 offset;bool offset_avail;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 14/28 perf record: Fix crash in pipe mode
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Currently we can crash perf record when running in pipe mode, like:
$ perf record ls | perf report # To display the perf.data header info, please use --header/--header-only options. # perf: Segmentation fault Error: The - file has no samples!
The callstack of the crash is:
0x0000000000515242 in perf_event__synthesize_event_update_name 3513 ev = event_update_event__new(len + 1, PERF_EVENT_UPDATE__NAME, evsel->id[0]); (gdb) bt #0 0x0000000000515242 in perf_event__synthesize_event_update_name #1 0x00000000005158a4 in perf_event__synthesize_extra_attr #2 0x0000000000443347 in record__synthesize #3 0x00000000004438e3 in __cmd_record #4 0x000000000044514e in cmd_record #5 0x00000000004cbc95 in run_builtin #6 0x00000000004cbf02 in handle_internal_command #7 0x00000000004cc054 in run_argv #8 0x00000000004cc422 in main
The reason of the crash is that the evsel does not have ids array allocated and the pipe's synthesize code tries to access it.
We don't force evsel ids allocation when we have single event, because it's not needed. However we need it when we are in pipe mode even for single event as a key for evsel update event.
Fixing this by forcing evsel ids allocation event for single event, when we are in pipe mode.
--- tools/perf/builtin-record.c | 9 +++++++++ tools/perf/perf.h | 1 + tools/perf/util/record.c | 8 ++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +9 -0
@@ -882,6 +882,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } } +/* +* If we have just single event and are sending data +* through pipe, we need to force the ids allocation, +* because we synthesize event name through the pipe +* and need the id for that. +*/ +if (data->is_pipe && rec->evlist->nr_entries ==1 ) + rec->opts.sample_id = true; +if (record__open (rec) !=0 ) { err =-1 ; goto out_child;
tools/perf/perf.h +1 -0
@@ -62,6 +62,7 @@ struct record_opts {bool overwrite;bool ignore_missing_thread;bool strict_freq; +bool sample_id;unsigned int freq;unsigned int mmap_pages;unsigned int auxtrace_mmap_pages;
tools/perf/util/record.c +6 -2
@@ -138,6 +138,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,struct perf_evsel *evsel;bool use_sample_identifier = false;bool use_comm_exec; +bool sample_id = opts->sample_id;/* * Set the evsel leader links before we configure attributes,
@@ -164,8 +165,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,* match the id. */ use_sample_identifier =perf_can_sample_identifier (); -evlist__for_each_entry (evlist, evsel) -perf_evsel__set_sample_id (evsel, use_sample_identifier); + sample_id = true; }else if (evlist->nr_entries >1 ) {struct perf_evsel *first =perf_evlist__first (evlist);
@@ -175,6 +175,10 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts, use_sample_identifier =perf_can_sample_identifier ();break ; } + sample_id = true; + } + +if (sample_id) {evlist__for_each_entry (evlist, evsel)perf_evsel__set_sample_id (evsel, use_sample_identifier); }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 15/28 perf kvm: Switch to new perf_mmap__read_event() interface
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf kvm still use the legacy interface.
Switch to the new perf_mmap__read_event() interface for perf kvm.
No functional change.
Committer notes:
Tested before and after running:
# perf kvm stat record
On a machine with a kvm guest, then used:
# perf kvm stat report
Before/after results match and look like:
# perf kvm stat record -a sleep 5 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.132 MB perf.data.guest (1828 samples) ] # perf kvm stat report
Analyze events for all VMs, all VCPUs:
VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
IO_INSTRUCTION 258 40.06% 0.08% 3.51us 122.54us 14.87us (+- 6.76%)
MSR_WRITE 178 27.64% 0.01% 0.47us 6.34us 2.18us (+- 4.80%)
EPT_MISCONFIG 148 22.98% 0.03% 3.76us 65.60us 11.22us (+- 8.14%)
HLT 47 7.30% 99.88% 181.69us 249988.06us 102061.36us (+-13.49%)
PAUSE_INSTRUCTION 5 0.78% 0.00% 0.38us 0.79us 0.47us (+-17.05%)
MSR_READ 4 0.62% 0.00% 1.14us 3.33us 2.67us (+-19.35%)
EXTERNAL_INTERRUPT 2 0.31% 0.00% 2.15us 2.17us 2.16us (+- 0.30%)
PENDING_INTERRUPT 1 0.16% 0.00% 2.56us 2.56us 2.56us (+- 0.00%)
PREEMPTION_TIMER 1 0.16% 0.00% 3.21us 3.21us 3.21us (+- 0.00%)Total Samples:644, Total events handled time:4802790.72us.
#
--- tools/perf/builtin-kvm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/perf/builtin-kvm.c +13 -4
@@ -743,16 +743,24 @@ static bool verify_vcpu(int vcpu)static s64 perf_kvm__mmap_read_idx (struct perf_kvm_stat *kvm,int idx,u64 *mmap_time) { +struct perf_evlist *evlist = kvm->evlist;union perf_event *event; +struct perf_mmap *md; +u64 end, start;u64 timestamp;s64 n =0 ;int err; *mmap_time =ULLONG_MAX ; -while ((event =perf_evlist__mmap_read (kvm->evlist, idx)) !=NULL ) { - err =perf_evlist__parse_sample_timestamp (kvm->evlist, event, ×tamp); + md = &evlist->mmap[idx]; + err =perf_mmap__read_init (md, false, &start, &end); +if (err <0 ) +return (err == -EAGAIN ) ?0 :-1 ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { + err =perf_evlist__parse_sample_timestamp (evlist, event, ×tamp);if (err) { -perf_evlist__mmap_consume (kvm->evlist, idx); +perf_mmap__consume (md, false);pr_err ("Failed to parse sample\n" );return -1 ; }
@@ -762,7 +770,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,* FIXME: Here we can't consume the event, as perf_session__queue_event will * point to it, and it'll get possibly overwritten by the kernel. */ -perf_evlist__mmap_consume (kvm->evlist, idx); +perf_mmap__consume (md, false);if (err) {pr_err ("Failed to enqueue sample: %d\n" , err);
@@ -779,6 +787,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,break ; } +perf_mmap__read_done (md);return n; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 16/28 perf trace: Switch to new perf_mmap__read_event() interface
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The 'perf trace' utility still use the legacy interface.
Switch to the new perf_mmap__read_event() interface.
No functional change.
--- tools/perf/builtin-trace.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/builtin-trace.c +9 -2
@@ -2472,8 +2472,14 @@ static int trace__run(struct trace *trace, int argc, const char **argv)for (i =0 ; i < evlist->nr_mmaps; i++) {union perf_event *event; +struct perf_mmap *md; +u64 end, start; -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {struct perf_sample sample; ++trace->nr_events;
@@ -2486,7 +2492,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)trace__handle_event (trace, event, &sample); next_event: -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false);if (interrupted) goto out_disable;
@@ -2496,6 +2502,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) draining = true; } } +perf_mmap__read_done (md); }if (trace->nr_events == before) {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 17/28 perf python: Switch to new perf_mmap__read_event() interface
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf python binding still use the legacy interface.
No functional change.
Committer notes:
Tested before and after with:
[root@jouet perf]# export PYTHONPATH=/tmp/build/perf/python
[root@jouet perf]# tools/perf/python/twatch.py
cpu: 0, pid: 1183, tid: 6293 { type: exit, pid: 1183, ppid: 1183, tid: 6293, ptid: 6293, time: 17886646588257}
cpu: 2, pid: 13820, tid: 13820 { type: fork, pid: 13820, ppid: 13820, tid: 6306, ptid: 13820, time: 17886869099529}
cpu: 1, pid: 13820, tid: 6306 { type: comm, pid: 13820, tid: 6306, comm: TaskSchedulerFo } ^CTraceback (most recent call last):
File "tools/perf/python/twatch.py", line 68, in <module>
main()
File "tools/perf/python/twatch.py", line 40, in main
evlist.poll(timeout = -1)
KeyboardInterrupt
[root@jouet perf]#
No problems found.
--- tools/perf/util/python.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/util/python.c +9 -3
@@ -983,13 +983,19 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,union perf_event *event;int sample_id_all =1 , cpu;static char *kwlist[] = {"cpu" ,"sample_id_all" ,NULL }; +struct perf_mmap *md; +u64 end, start;int err;if (!PyArg_ParseTupleAndKeywords (args, kwargs,"i|i" , kwlist, &cpu, &sample_id_all))return NULL ; - event =perf_evlist__mmap_read (evlist, cpu); + md = &evlist->mmap[cpu]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) + goto end; + + event =perf_mmap__read_event (md, false, &start, end);if (event !=NULL ) {PyObject *pyevent =pyrf_event__new (event);struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
@@ -1007,14 +1013,14 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, err =perf_evsel__parse_sample (evsel, event, &pevent->sample);/* Consume the even only after we parsed it out. */ -perf_evlist__mmap_consume (evlist, cpu); +perf_mmap__consume (md, false);if (err)return PyErr_Format (PyExc_OSError,"perf: can't parse sample, err=%d" , err);return pyevent; } - +end:Py_INCREF (Py_None);return Py_None; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 18/28 perf test: Switch to new perf_mmap__read_event() interface for bpf
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'bpf' still use the legacy interface.
No functional change.
Committer notes:
Tested with:
# perf test bpf 39: BPF filter : 39.1: Basic BPF filtering : Ok 39.2: BPF pinning : Ok 39.3: BPF prologue generation : Ok 39.4: BPF relocation checker : Ok #
--- tools/perf/tests/bpf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/tests/bpf.c +8 -1
@@ -176,13 +176,20 @@ static int do_test(struct bpf_object *obj, int (*func)(void),for (i =0 ; i < evlist->nr_mmaps; i++) {union perf_event *event; +struct perf_mmap *md; +u64 end, start; -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {const u32 type = event->header.type;if (type ==PERF_RECORD_SAMPLE ) count ++; } +perf_mmap__read_done (md); }if (count != expect) {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 19/28 perf test: Switch to new perf_mmap__read_event() interface for 'code reading' test
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'object code reading' still use the legacy interface.
No functional change.
Committer notes:
Testing:
# perf test reading 23: Object code reading: Ok #
--- tools/perf/tests/code-reading.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/tests/code-reading.c +9 -2
@@ -409,15 +409,22 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist, struct state *state) {union perf_event *event; +struct perf_mmap *md; +u64 end, start;int i, ret;for (i =0 ; i < evlist->nr_mmaps; i++) { -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { ret =process_event (machine, evlist, event, state); -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false);if (ret <0 )return ret; } +perf_mmap__read_done (md); }return 0 ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 20/28 perf test: Switch to new perf_mmap__read_event() interface for "keep tracking" test
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'keep tracking' still use the legacy interface.
No functional change.
Committer testing:
# perf test tracking 25: Use a dummy software event to keep tracking : Ok #
--- tools/perf/tests/keep-tracking.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/tests/keep-tracking.c +8 -2
@@ -27,18 +27,24 @@static int find_comm (struct perf_evlist *evlist,const char *comm) {union perf_event *event; +struct perf_mmap *md; +u64 end, start;int i, found; found =0 ;for (i =0 ; i < evlist->nr_mmaps; i++) { -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {if (event->header.type ==PERF_RECORD_COMM && (pid_t )event->comm.pid ==getpid () && (pid_t )event->comm.tid ==getpid () &&strcmp (event->comm.comm, comm) ==0 ) found +=1 ; -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); }return found; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 21/28 perf test: Switch to new perf_mmap__read_event() interface for mmap-basic
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'mmap-basic' still use the legacy interface.
No functional change.
Committer notes:
Testing it:
# perf test "mmap interface" 4: Read samples using the mmap interface : Ok #
--- tools/perf/tests/mmap-basic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/tests/mmap-basic.c +10 -2
@@ -38,6 +38,8 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse expected_nr_events[nsyscalls], i, j;struct perf_evsel *evsels[nsyscalls], *evsel;char sbuf[STRERR_BUFSIZE ]; +struct perf_mmap *md; +u64 end, start; threads =thread_map__new (-1 ,getpid (),UINT_MAX );if (threads ==NULL ) {
@@ -106,7 +108,11 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse ++foo; } -while ((event =perf_evlist__mmap_read (evlist,0 )) !=NULL ) { + md = &evlist->mmap[0 ]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) + goto out_init; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {struct perf_sample sample;if (event->header.type !=PERF_RECORD_SAMPLE ) {
@@ -129,9 +135,11 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse goto out_delete_evlist; } nr_events[evsel->idx]++; -perf_evlist__mmap_consume (evlist,0 ); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); +out_init: err =0 ;evlist__for_each_entry (evlist, evsel) {if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 22/28 perf test: Switch to new perf_mmap__read_event() interface for tp fields
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'syscalls:sys_enter_openat event fields' still use the legacy interface.
No functional change.
Committer notes:
Testing it:
# perf test sys_enter_openat 15: syscalls:sys_enter_openat event fields : Ok #
--- tools/perf/tests/openat-syscall-tp-fields.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/tests/openat-syscall-tp-fields.c +9 -2
@@ -86,8 +86,14 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestfor (i =0 ; i < evlist->nr_mmaps; i++) {union perf_event *event; +struct perf_mmap *md; +u64 end, start; -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {const u32 type = event->header.type;int tp_flags;struct perf_sample sample;
@@ -95,7 +101,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest ++nr_events;if (type !=PERF_RECORD_SAMPLE ) { -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false);continue ; }
@@ -115,6 +121,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest goto out_ok; } +perf_mmap__read_done (md); }if (nr_events == before)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 23/28 perf test: Switch to new perf_mmap__read_event() interface for perf-record
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'perf-record' still use the legacy interface.
No functional change.
Committer notes:
Testing it:
# perf test PERF_RECORD 8: PERF_RECORD_* events & perf_sample fields : Ok #
--- tools/perf/tests/perf-record.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/tests/perf-record.c +9 -2
@@ -164,8 +164,14 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusfor (i =0 ; i < evlist->nr_mmaps; i++) {union perf_event *event; +struct perf_mmap *md; +u64 end, start; -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {const u32 type = event->header.type;const char *name =perf_event__name (type);
@@ -266,8 +272,9 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus ++errs; } -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); }/*
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 24/28 perf test: Switch to new perf_mmap__read_event() interface for time-to-tsc
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'time-to-tsc' still use the legacy interface.
No functional change.
Commiter notes:
Testing it:
# perf test tsc 57: Convert perf time to TSC : Ok #
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +9 -2
@@ -60,6 +60,8 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeunion perf_event *event;u64 test_tsc, comm1_tsc, comm2_tsc;u64 test_time, comm1_time =0 , comm2_time =0 ; +struct perf_mmap *md; +u64 end, start; threads =thread_map__new (-1 ,getpid (),UINT_MAX );CHECK_NOT_NULL__ (threads);
@@ -109,7 +111,11 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeperf_evlist__disable (evlist);for (i =0 ; i < evlist->nr_mmaps; i++) { -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {struct perf_sample sample; if (event->header.type != PERF_RECORD_COMM ||
@@ -128,8 +134,9 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe comm2_time = sample.time; } next_event: -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); }if (!comm1_time || !comm2_time)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 25/28 perf test: Switch to new perf_mmap__read_event() interface for sw-clock
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'sw-clock' still use the legacy interface.
No functional change.
Committer testing:
# perf test clock 22: Software clock events period values : Ok #
--- tools/perf/tests/sw-clock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/tests/sw-clock.c +10 -2
@@ -39,6 +39,8 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) };struct cpu_map *cpus;struct thread_map *threads; +struct perf_mmap *md; +u64 end, start; attr.sample_freq =500 ;
@@ -93,7 +95,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)perf_evlist__disable (evlist); -while ((event =perf_evlist__mmap_read (evlist,0 )) !=NULL ) { + md = &evlist->mmap[0 ]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) + goto out_init; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {struct perf_sample sample;if (event->header.type !=PERF_RECORD_SAMPLE )
@@ -108,9 +114,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) total_periods += sample.period; nr_samples++; next_event: -perf_evlist__mmap_consume (evlist,0 ); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); +out_init:if ((u64 ) nr_samples == total_periods) {pr_debug ("All (%d) samples have period value of 1!\n" , nr_samples);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 26/28 perf test: Switch to new perf_mmap__read_event() interface for switch-tracking
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'switch-tracking' still use the legacy interface.
No functional change.
Committer testing:
# perf test switch 32: Track with sched_switch : Ok #
--- tools/perf/tests/switch-tracking.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/tests/switch-tracking.c +9 -2
@@ -258,16 +258,23 @@ static int process_events(struct perf_evlist *evlist,unsigned pos, cnt =0 ;LIST_HEAD (events);struct event_node *events_array, *node; +struct perf_mmap *md; +u64 end, start;int i, ret;for (i =0 ; i < evlist->nr_mmaps; i++) { -while ((event =perf_evlist__mmap_read (evlist, i)) !=NULL ) { + md = &evlist->mmap[i]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) +continue ; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { cnt +=1 ; ret =add_event (evlist, &events, event); -perf_evlist__mmap_consume (evlist, i); +perf_mmap__consume (md, false);if (ret <0 ) goto out_free_nodes; } +perf_mmap__read_done (md); } events_array =calloc (cnt,sizeof (struct event_node ));
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 27/28 perf test: Switch to new perf_mmap__read_event() interface for task-exit
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf test 'task-exit' still use the legacy interface.
No functional change.
Committer notes:
Testing it:
# perf test exit 21: Number of exit events of a simple workload : Ok #
--- tools/perf/tests/task-exit.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/tests/task-exit.c +10 -2
@@ -47,6 +47,8 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedchar sbuf[STRERR_BUFSIZE ];struct cpu_map *cpus;struct thread_map *threads; +struct perf_mmap *md; +u64 end, start;signal (SIGCHLD , sig_handler);
@@ -110,13 +112,19 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedperf_evlist__start_workload (evlist); retry: -while ((event =perf_evlist__mmap_read (evlist,0 )) !=NULL ) { + md = &evlist->mmap[0 ]; +if (perf_mmap__read_init (md, false, &start, &end) <0 ) + goto out_init; + +while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) {if (event->header.type ==PERF_RECORD_EXIT ) nr_exit++; -perf_evlist__mmap_consume (evlist,0 ); +perf_mmap__consume (md, false); } +perf_mmap__read_done (md); +out_init:if (!exited || !nr_exit) {perf_evlist__poll (evlist,-1 ); goto retry;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 28/28 perf mmap: Discard legacy interfaces for mmap read forward
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
Discards legacy interfaces perf_evlist__mmap_read_forward(), perf_evlist__mmap_read() and perf_evlist__mmap_consume().
No tools use them.
--- tools/perf/util/evlist.c | 25 +------------------------ tools/perf/util/evlist.h | 4 ---- tools/perf/util/mmap.c | 21 +-------------------- 3 files changed, 2 insertions(+), 48 deletions(-)
tools/perf/util/evlist.c +1 -24
@@ -702,29 +702,6 @@ static int perf_evlist__resume(struct perf_evlist *evlist)return perf_evlist__set_paused (evlist, false); } -union perf_event *perf_evlist__mmap_read_forward (struct perf_evlist *evlist,int idx) -{ -struct perf_mmap *md = &evlist->mmap[idx]; - -/* -* Check messup is required for forward overwritable ring buffer: -* memory pointed by md->prev can be overwritten in this case. -* No need for read-write ring buffer: kernel stop outputting when -* it hit md->prev (perf_mmap__consume()). -*/ -return perf_mmap__read_forward (md); -} - -union perf_event *perf_evlist__mmap_read (struct perf_evlist *evlist,int idx) -{ -return perf_evlist__mmap_read_forward (evlist, idx); -} - -void perf_evlist__mmap_consume (struct perf_evlist *evlist,int idx) -{ -perf_mmap__consume (&evlist->mmap[idx], false); -} -static void perf_evlist__munmap_nofree (struct perf_evlist *evlist) {int i;
@@ -761,7 +738,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist) map[i].fd =-1 ;/* * When the perf_mmap() call is made we grab one refcount, plus -* one extra to let perf_evlist__mmap_consume() get the last +* one extra to let perf_mmap__consume() get the last * events after all real references (perf_mmap__get()) are * dropped. *
tools/perf/util/evlist.h +0 -4
@@ -129,10 +129,6 @@ struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);void perf_evlist__toggle_bkw_mmap (struct perf_evlist *evlist,enum bkw_mmap_state state); -union perf_event *perf_evlist__mmap_read (struct perf_evlist *evlist,int idx); - -union perf_event *perf_evlist__mmap_read_forward (struct perf_evlist *evlist, -int idx);void perf_evlist__mmap_consume (struct perf_evlist *evlist,int idx);int perf_evlist__open (struct perf_evlist *evlist);
tools/perf/util/mmap.c +1 -20
@@ -63,25 +63,6 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,return event; } -/* -* legacy interface for mmap read. -* Don't use it. Use perf_mmap__read_event(). -*/ -union perf_event *perf_mmap__read_forward (struct perf_mmap *map) -{ -u64 head; - -/* -* Check if event was unmapped due to a POLLHUP/POLLERR. -*/ -if (!refcount_read (&map->refcnt)) -return NULL ; - - head =perf_mmap__read_head (map); - -return perf_mmap__read (map, &map->prev, head); -} -/* * Read event from ring buffer one by one. * Return one event for each call.
@@ -191,7 +172,7 @@ void perf_mmap__munmap(struct perf_mmap *map)int perf_mmap__mmap (struct perf_mmap *map,struct mmap_params *mp,int fd) {/* -* The last one will be done at perf_evlist__mmap_consume(), so that we +* The last one will be done at perf_mmap__consume(), so that we * make sure we don't prevent tools from consuming every last event in * the ring buffer. *
Signature · 1 line
2.14.3
Quoted 143 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling, I'll cherry pick some into a separate
perf/urgent pull request, like the jump-to-another-function one, after the usual round of tests, but since I've been working on then in my perf/core branch, lets flush them now.- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
ddc4becca1409541c2ebb7ecb99b5cef44cf17e4:Merge tag 'perf-core-for-mingo-4.17-20180220' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/core (2018-02-21 08:50:45 +0100)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-4.17-20180305for you to fetch changes up to
6afad54d2f0ddebacfcf3b829147d7fed8dab298:perf mmap: Discard legacy interfaces for mmap read forward (2018-03-05 10:51:10 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:- Be more robust when drawing arrows in the annotation TUI, avoiding a segfault when jump instructions have as a target addresses in functions other that the one currently being annotated. The full fix will come in the following days, when jumping to other functions will work as call instructions (Arnaldo Carvalho de Melo)
- Allow asking for the maximum allowed sample rate in 'top' and 'record', i.e. 'perf record -F max' will read the kernel.perf_event_max_sample_rate sysctl and use it (Arnaldo Carvalho de Melo)
- When the user specifies a freq above kernel.perf_event_max_sample_rate, Throttle it down to that max freq, and warn the user about it, add as well --strict-freq so that the previous behaviour of not starting the session when the desired freq can't be used can be selected (Arnaldo Carvalho de Melo)
- Find 'call' instruction target symbol at parsing time, used so far in the TUI, part of the infrastructure changes that will end up allowing for jumps to navigate to other functions, just like 'call' instructions. (Arnaldo Carvalho de Melo)
- Use xyarray dimensions to iterate fds in 'perf stat' (Andi Kleen)
- Ignore threads for which the current user hasn't permissions when enabling system-wide --per-thread (Jin Yao)
- Fix some backtrace perf test cases to use 'perf record' + 'perf script' instead, till 'perf trace' starts using
ordered_eventsor equivalent to avoid symbol resolving artifacts due to reordering ofPERF_RECORD_MMAPevents (Jiri Olsa)- Fix crash in 'perf record' pipe mode, it needs to allocate the ID array even for a single event, unlike non-pipe mode (Jiri Olsa)
- Make annoying fallback message on older kernels with newer 'perf top' binaries trying to use overwrite mode and that not being present in the older kernels (Kan Liang)
- Switch last users of old APIs to the newer
perf_mmap__read_event()one, then discard those old mmap read forward APIs (Kan Liang)- Fix the usage on the 'perf kallsyms' man page (Sangwon Hong)
- Simplify cgroup arguments when tracking multiple events (weiping zhang)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Andi Kleen (1):
perf stat: Use xyarray dimensions to iterate fdsArnaldo Carvalho de Melo (6):
perf annotate browser: Be more robust when drawing jump arrows perf record: Allow asking for the maximum allowed sample rate perf top browser: Showsample_freqin browser title line perf top: Allow asking for the maximum allowed sample rate perf record: Throttle user defined frequencies to the maximum allowed perf annotate: Find 'call' instruction target symbol at parsing timeJin Yao (1):
perf stat: Ignore error thread when enabling system-wide --per-threadJiri Olsa (3):
perf tests: Switch trace+probe_libc_inet_pton to use record perf tests: Rename trace+probe_libc_inet_pton to record+probe_libc_inet_pton perf record: Fix crash in pipe modeKan Liang (15):
perf top: Fix annoying fallback message on older kernels
perf kvm: Switch to newperf_mmap__read_event()interface
perf trace: Switch to newperf_mmap__read_event()interface
perf python: Switch to newperf_mmap__read_event()interface
perf test: Switch to newperf_mmap__read_event()interface for bpf perf test: Switch to newperf_mmap__read_event()interface for 'code reading' test perf test: Switch to newperf_mmap__read_event()interface for "keep tracking" test perf test: Switch to newperf_mmap__read_event()interface for mmap-basic perf test: Switch to newperf_mmap__read_event()interface for tp fields perf test: Switch to newperf_mmap__read_event()interface for perf-record perf test: Switch to newperf_mmap__read_event()interface for time-to-tsc perf test: Switch to newperf_mmap__read_event()interface for sw-clock perf test: Switch to newperf_mmap__read_event()interface for switch-tracking perf test: Switch to newperf_mmap__read_event()interface for task-exit perf mmap: Discard legacy interfaces for mmap read forwardSangwon Hong (1):
perf kallsyms: Fix the usage on the man pageweiping zhang (1):
perf cgroup: Simplify arguments when tracking multiple eventstools/perf/Documentation/perf-kallsyms.txt | 2 +- tools/perf/Documentation/perf-record.txt | 15 ++++++- tools/perf/Documentation/perf-stat.txt | 6 ++- tools/perf/Documentation/perf-top.txt | 4 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 11 ++++- tools/perf/builtin-kvm.c | 17 ++++++-- tools/perf/builtin-record.c | 18 +++++++- tools/perf/builtin-stat.c | 25 ++++++++--- tools/perf/builtin-top.c | 6 ++- tools/perf/builtin-trace.c | 11 ++++- tools/perf/perf.h | 4 ++ tools/perf/tests/bpf.c | 9 +++- tools/perf/tests/code-reading.c | 11 ++++- tools/perf/tests/keep-tracking.c | 10 ++++- tools/perf/tests/mmap-basic.c | 12 ++++- tools/perf/tests/openat-syscall-tp-fields.c | 11 ++++- tools/perf/tests/perf-record.c | 11 ++++- ...inet_pton.sh => record+probe_libc_inet_pton.sh} | 30 ++++++------- tools/perf/tests/sw-clock.c | 12 ++++- tools/perf/tests/switch-tracking.c | 11 ++++- tools/perf/tests/task-exit.c | 12 ++++- tools/perf/ui/browsers/annotate.c | 42 +++++++++++++----- tools/perf/ui/browsers/hists.c | 10 +++-- tools/perf/util/annotate.c | 38 ++++++++-------- tools/perf/util/annotate.h | 1 + tools/perf/util/cgroup.c | 17 +++++++- tools/perf/util/evlist.c | 25 +---------- tools/perf/util/evlist.h | 4 --
Quoted 8 lines
tools/perf/util/evsel.c | 3 ++
tools/perf/util/mmap.c | 21 +--------
tools/perf/util/python.c | 12 +++--
tools/perf/util/record.c | 51 +++++++++++++++++++---
tools/perf/util/thread_map.c | 1 +
tools/perf/util/thread_map.h | 1 +
34 files changed, 328 insertions(+), 146 deletions(-)
rename tools/perf/tests/shell/{trace+probe_libc_inet_pton.sh => record+probe_libc_inet_pton.sh} (61%)Pulled, thanks a lot Arnaldo!
Ingo