perf/core improvements and fixes
Subsystems (3)
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit 3f986eefc89c528bf2d398a6dc3637b743a7139e:
Merge branch 'perf/urgent' into perf/core, to resolve conflict (2018-03-07 09:23:12 +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-20180308
for you to fetch changes up to 2427b432e63b4b911100f717c48289195b7a7d62:
perf tools: Update quipper information (2018-03-08 11:30:54 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
- Support to display the IPC/Cycle in 'annotate' TUI, for systems where this info can be obtained, like Intel's >= Skylake (Jin Yao)
- Support wildcards on PMU name in dynamic PMU events (Agustin Vega-Frias)
- Display pmu name when printing unmerged events in stat (Agustin Vega-Frias)
- Auto-merge PMU events created by prefix or glob match (Agustin Vega-Frias)
- Fix s390 'call' operations target function annotation (Thomas Richter)
- Handle s390 PC relative load and store instruction in the augmented 'annotate', code, used so far in the TUI modes of 'perf report' and 'perf annotate' (Thomas Richter)
- Provide libtraceevent with a kernel symbol resolver, so that symbols in tracepoint fields can be resolved when showing them in tools such as 'perf report' (Wang YanQing)
- Refactor the cgroups code to look more like other code in tools/perf, using cgroup__{put,get} for refcount operations instead of its open-coded equivalent, breaking larger functions, etc (Arnaldo Carvalho de Melo)
- Implement support for the -G/--cgroup target in 'perf trace', allowing strace like tracing (plus other events, backtraces, etc) for cgroups (Arnaldo Carvalho de Melo)
- Update thread shortname in 'perf sched map' when the thread's COMM changes (Changbin Du)
- refcount 'struct mem_info', for better sharing it over several users, avoid duplicating structs and fixing crashes related to use after free (Jiri Olsa)
- Display perf.data version, offsets in 'perf report --header' (Jiri Olsa)
- Record the machine's memory topology information in a perf.data feature section, to be used by tools such as 'perf c2c' (Jiri Olsa)
- Fix output of forced groups in the header for 'perf report' --stdio and --tui (Jiri Olsa)
- Better support llvm, clang, cxx make tests in the build process (Jiri Olsa)
- Streamline the 'struct perf_mmap' methods, storing some info in the struct instead of passing it via various methods, shortening its signatures (Kan Liang)
- Update the quipper perf.data parser library site information (Stephane Eranian)
- Correct perf's man pages title markers for asciidoctor (Takashi Iwai)
- Intel PT fixes and refactorings paving the way for implementing support for AUX area sampling (Adrian Hunter)
----------------------------------------------------------------
Adrian Hunter (13):
perf record: Combine some auxtrace initialization into a single function perf auxtrace: Add missing parameters from kernel-doc comments perf auxtrace: Rename some buffer-queuing functions
perf auxtrace: Make auxtrace_queues__add_buffer() return buffer_ptr perf intel-pt: Fix overlap detection to identify consecutive buffers correctly perf intel-pt: Fix sync_switch
perf intel-pt: Fix error recovery from missing TIP packet
perf intel-pt: Fix timestamp following overflow
perf intel-pt/bts: In auxtrace_record__init_intel() evlist is never NULL perf intel-pt: Get rid of intel_pt_use_buffer_pid_tid()
perf intel-pt: Tidy old_buffer handling in intel_pt_get_trace() perf intel-pt: Remove a check for sampling mode
perf intel-pt: Adjust overlap-checking to support sampling mode
Agustin Vega-Frias (3):
perf pmu: Support wildcards on pmu name in dynamic pmu events perf pmu: Display pmu name when printing unmerged events in stat perf pmu: Auto-merge PMU events created by prefix or glob match
Arnaldo Carvalho de Melo (11):
perf cgroup: Remove misplaced __maybe_unused
perf cgroup: Rename 'struct cgroup_sel' to 'struct cgroup' perf cgroup: Introduce cgroup__delete()
perf cgroup: Rename close_cgroup() to cgroup__put() perf cgroup: Introduce cgroup__get()
perf cgroup: Introduce find_cgroup() method
perf cgroup: Introduce cgroup__new() out of open coded equivalent perf cgroup: Add evlist__findnew_cgroup()
perf cgroup: Add evlist__add_default_cgroup()
perf cgroup: Make the cgroup name be const char *
perf trace: Support setting cgroups as targets
Changbin Du (2):
perf sched: Move thread::shortname to thread_runtime perf sched map: Re-annotate shortname if thread comm changed
Jin Yao (1):
perf annotate: Support to display the IPC/Cycle in TUI mode
Jiri Olsa (11):
perf report: Fix the output for stdio events list
perf report: Display perf.data header info
perf record: Move machine variable down the function perf record: Remove progname from struct record
perf tools: Add refcnt into struct mem_info
perf c2c: Use mem_info refcnt logic
perf tools: Add MEM_TOPOLOGY feature to perf data file perf tools: Update tags with .cpp files
perf build: Add llvm/clang/cxx make tests into FEATURE_TESTS_EXTRA perf build: Add llvm/clang make targets to FILES
perf build: Force llvm/clang test compile output to .make.output
Kan Liang (8):
perf evlist: Store 'overwrite' in struct perf_mmap perf mmap: Store mmap scope in struct perf_mmap() perf mmap: Use the stored scope data in perf_mmap__push() perf mmap: Use the stored data in perf_mmap__read_event() perf mmap: Use stored 'overwrite' in perf_mmap__consume() perf mmap: Simplify perf_mmap__consume()
perf mmap: Simplify perf_mmap__read_event() perf mmap: Simplify perf_mmap__read_init()
Stephane Eranian (1):
perf tools: Update quipper information
Takashi Iwai (1):
perf tools: Correct title markers for asciidoctor
Thomas Richter (2):
perf annotate: Fix s390 target function disassembly perf annotate: Handle s390 PC relative load and store instruction.
Wang YanQing (1):
perf report: Provide libtraceevent with a kernel symbol resolver
tools/build/Makefile.feature | 6 +- tools/build/feature/Makefile | 14 +- tools/include/linux/bitmap.h | 2 +- tools/perf/Documentation/perf-data.txt | 2 +- tools/perf/Documentation/perf-ftrace.txt | 2 +- tools/perf/Documentation/perf-kallsyms.txt | 2 +- tools/perf/Documentation/perf-list.txt | 8 +- tools/perf/Documentation/perf-sched.txt | 2 +- tools/perf/Documentation/perf-script-perl.txt | 2 +- tools/perf/Documentation/perf-stat.txt | 17 ++ tools/perf/Documentation/perf-trace.txt | 25 ++ tools/perf/Documentation/perf.data-file-format.txt | 7 +- tools/perf/Makefile.perf | 6 +- tools/perf/arch/s390/annotate/instructions.c | 116 +++++++- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 7 +- tools/perf/arch/x86/util/auxtrace.c | 14 +- tools/perf/builtin-annotate.c | 88 +++++- tools/perf/builtin-c2c.c | 24 +- tools/perf/builtin-kvm.c | 9 +- tools/perf/builtin-record.c | 45 +-- tools/perf/builtin-report.c | 26 +- tools/perf/builtin-sched.c | 133 ++++++--- tools/perf/builtin-stat.c | 29 +- tools/perf/builtin-top.c | 7 +- tools/perf/builtin-trace.c | 57 +++- tools/perf/tests/backward-ring-buffer.c | 5 +- tools/perf/tests/bpf.c | 5 +- tools/perf/tests/code-reading.c | 7 +- tools/perf/tests/keep-tracking.c | 7 +- tools/perf/tests/mmap-basic.c | 7 +- tools/perf/tests/openat-syscall-tp-fields.c | 7 +- tools/perf/tests/perf-record.c | 7 +- tools/perf/tests/sw-clock.c | 7 +- tools/perf/tests/switch-tracking.c | 7 +- tools/perf/tests/task-exit.c | 7 +- tools/perf/ui/browsers/hists.c | 5 +- tools/perf/util/annotate.c | 2 +- tools/perf/util/auxtrace.c | 37 ++- tools/perf/util/auxtrace.h | 2 + tools/perf/util/cgroup.c | 111 +++++--- tools/perf/util/cgroup.h | 13 +- tools/perf/util/env.h | 9 + tools/perf/util/evlist.c | 8 +- tools/perf/util/evsel.c | 23 +- tools/perf/util/evsel.h | 6 +- tools/perf/util/header.c | 312 ++++++++++++++++++++- tools/perf/util/header.h | 1 + tools/perf/util/hist.c | 4 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 64 ++--- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 +- tools/perf/util/intel-pt.c | 110 ++++---- tools/perf/util/machine.c | 2 +- tools/perf/util/mmap.c | 63 ++--- tools/perf/util/mmap.h | 16 +- tools/perf/util/parse-events.c | 21 +- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.l | 2 +- tools/perf/util/parse-events.y | 18 +- tools/perf/util/python.c | 7 +- tools/perf/util/symbol.c | 22 ++ tools/perf/util/symbol.h | 19 +- tools/perf/util/thread.h | 1 - 62 files changed, 1197 insertions(+), 401 deletions(-)
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.
# dm 1 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0 2 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822 3 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0 1 alpine:3.7 : Ok gcc (Alpine 6.4.0) 6.4.0 5 alpine:edge : Ok gcc (Alpine 6.4.0) 6.4.0 6 amazonlinux:1 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) 7 amazonlinux:2 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 8 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 9 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 10 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 11 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 12 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 13 debian:7 : Ok gcc (Debian 4.7.2-5) 4.7.2 14 debian:8 : Ok gcc (Debian 4.9.2-10+deb8u1) 4.9.2 15 debian:9 : Ok gcc (Debian 6.3.0-18) 6.3.0 20170516 16 debian:experimental : Ok gcc (Debian 7.2.0-17) 7.2.1 20171205 17 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 18 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 19 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 7.2.0-11) 7.2.0 20 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 21 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) 22 fedora:21 : Ok gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) 23 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 24 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 25 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) 26 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 27 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1) 28 fedora:26 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 29 fedora:27 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 30 fedora:rawhide : Ok gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1) 31 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 6.4.0-r1 p1.3) 6.4.0 32 mageia:5 : Ok gcc (GCC) 4.9.2 33 mageia:6 : Ok gcc (Mageia 5.4.0-5.mga6) 5.4.0 34 opensuse:42.1 : Ok gcc (SUSE Linux) 4.8.5 35 opensuse:42.2 : Ok gcc (SUSE Linux) 4.8.5 36 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5 37 opensuse:tumbleweed : Ok gcc (SUSE Linux) 7.3.0 38 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 39 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 40 ubuntu:12.04.5 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 41 ubuntu:14.04.4 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 42 ubuntu:14.04.4-x-linaro-arm64 : Ok aarch64-linux-gnu-gcc (Linaro GCC 5.4-2017.05) 5.4.1 20170404 43 ubuntu:15.04 : Ok gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2 44 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609 45 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 46 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 47 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 48 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609 49 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 50 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 51 ubuntu:16.10 : Ok gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005 52 ubuntu:17.04 : Ok gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406 53 ubuntu:17.10 : Ok gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0 54 ubuntu:18.04 : Ok gcc (Ubuntu 7.2.0-16ubuntu1) 7.2.0
# uname -a Linux jouet 4.16.0-rc4 #1 SMP Mon Mar 5 12:18:05 -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 : FAILED! 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_no_auxtrace_O: make NO_AUXTRACE=1
make_no_libelf_O: make NO_LIBELF=1
make_doc_O: make doc
make_tags_O: make tags
make_with_babeltrace_O: make LIBBABELTRACE=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_no_libpython_O: make NO_LIBPYTHON=1
make_minimal_O: 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_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_install_prefix_O: make install prefix=/tmp/krava
make_pure_O: make
make_clean_all_O: make clean all
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_with_clangllvm_O: make LIBCLANGLLVM=1
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_libbionic_O: make NO_LIBBIONIC=1
make_no_libnuma_O: make NO_LIBNUMA=1
make_debug_O: make DEBUG=1
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_no_libunwind_O: make NO_LIBUNWIND=1
make_install_O: make install
make_help_O: make help
make_util_map_o_O: make util/map.o
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_no_demangle_O: make NO_DEMANGLE=1
make_install_bin_O: make install-bin
make_perf_o_O: make perf.o
make_no_gtk2_O: make NO_GTK2=1
make_no_newt_O: make NO_NEWT=1
make_no_slang_O: make NO_SLANG=1
make_no_libaudit_O: make NO_LIBAUDIT=1
make_no_libbpf_O: make NO_LIBBPF=1
make_static_O: make LDFLAGS=-static
make_no_libperl_O: make NO_LIBPERL=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/54 perf cgroup: Remove misplaced __maybe_unused
From: Arnaldo Carvalho de Melo <[email protected]>
The 'opt' parameter in parse_cgroups() _is_ used. The original patch used '__used' that was even more confusing :-)
--- tools/perf/util/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cgroup.c +1 -1
@@ -153,7 +153,7 @@ void close_cgroup(struct cgroup_sel *cgrp) } } -int parse_cgroups (const struct option *opt__maybe_unused ,const char *str, +int parse_cgroups (const struct option *opt,const char *str,int unset__maybe_unused ) {struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/54 perf cgroup: Rename 'struct cgroup_sel' to 'struct cgroup'
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
That name isn't used, is shorter, lets switch to it.
--- tools/perf/util/cgroup.c | 6 +++--- tools/perf/util/cgroup.h | 5 +++-- tools/perf/util/evsel.h | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/cgroup.c +3 -3
@@ -93,7 +93,7 @@ static int open_cgroup(char *name)static int add_cgroup (struct perf_evlist *evlist,char *str) {struct perf_evsel *counter; -struct cgroup_sel *cgrp =NULL ; +struct cgroup *cgrp =NULL ;int n;/* * check if cgrp is already defined, if so we reuse it
@@ -144,7 +144,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)return 0 ; } -void close_cgroup (struct cgroup_sel *cgrp) +void close_cgroup (struct cgroup *cgrp) {if (cgrp &&refcount_dec_and_test (&cgrp->refcnt)) {close (cgrp->fd);
@@ -158,7 +158,7 @@ int parse_cgroups(const struct option *opt, const char *str, {struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;struct perf_evsel *counter; -struct cgroup_sel *cgrp =NULL ; +struct cgroup *cgrp =NULL ;const char *p, *e, *eos = str +strlen (str);char *s;int ret, i;
tools/perf/util/cgroup.h +3 -2
@@ -6,7 +6,7 @@struct option ; -struct cgroup_sel { +struct cgroup {char *name;int fd;refcount_t refcnt;
@@ -14,7 +14,8 @@ struct cgroup_sel {extern int nr_cgroups;/* number of explicit cgroups defined */ -void close_cgroup (struct cgroup_sel *cgrp); +void close_cgroup (struct cgroup *cgrp); +int parse_cgroups (const struct option *opt,const char *str,int unset);#endif /* __CGROUP_H__ */
tools/perf/util/evsel.h +2 -2
@@ -30,7 +30,7 @@ struct perf_sample_id {u64 period; }; -struct cgroup_sel ; +struct cgroup ;/* * The 'struct perf_evsel_config_term' is used to pass event
@@ -107,7 +107,7 @@ struct perf_evsel {struct perf_stat_evsel *stats;void *priv;u64 db_id; -struct cgroup_sel *cgrp; +struct cgroup *cgrp;void *handler;struct cpu_map *cpus;struct cpu_map *own_cpus;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 3/54 perf cgroup: Introduce cgroup__delete()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Just to make this code look more like other places in tools/perf.
--- tools/perf/util/cgroup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/cgroup.c +8 -3
@@ -144,12 +144,17 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)return 0 ; } +static void cgroup__delete (struct cgroup *cgroup) +{ +close (cgroup->fd); +zfree (&cgroup->name); +free (cgroup); +} +void close_cgroup (struct cgroup *cgrp) {if (cgrp &&refcount_dec_and_test (&cgrp->refcnt)) { -close (cgrp->fd); -zfree (&cgrp->name); -free (cgrp); +cgroup__delete (cgrp); } }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/54 perf cgroup: Rename close_cgroup() to cgroup__put()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It is not really closing the cgroup, but instead dropping a reference count and if it hits zero, then calling delete, which will, among other cleanup shores, close the cgroup fd.
So it is really dropping a reference to that cgroup, and the method name for that is "put", so rename close_cgroup() to cgroup__put() to follow this naming convention.
--- tools/perf/util/cgroup.c | 5 ++--- tools/perf/util/cgroup.h | 3 ++- tools/perf/util/evsel.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/cgroup.c +2 -3
@@ -135,9 +135,8 @@ static int add_cgroup(struct perf_evlist *evlist, char *str) goto found; n++; } -if (refcount_dec_and_test (&cgrp->refcnt)) -free (cgrp); +cgroup__put (cgrp);return -1 ; found: counter->cgrp = cgrp;
@@ -151,7 +150,7 @@ static void cgroup__delete(struct cgroup *cgroup)free (cgroup); } -void close_cgroup (struct cgroup *cgrp) +void cgroup__put (struct cgroup *cgrp) {if (cgrp &&refcount_dec_and_test (&cgrp->refcnt)) {cgroup__delete (cgrp);
tools/perf/util/cgroup.h +2 -1
@@ -14,7 +14,8 @@ struct cgroup {extern int nr_cgroups;/* number of explicit cgroups defined */ -void close_cgroup (struct cgroup *cgrp); + +void cgroup__put (struct cgroup *cgroup);int parse_cgroups (const struct option *opt,const char *str,int unset);
tools/perf/util/evsel.c +1 -1
@@ -1233,7 +1233,7 @@ void perf_evsel__exit(struct perf_evsel *evsel)perf_evsel__free_fd (evsel);perf_evsel__free_id (evsel);perf_evsel__free_config_terms (evsel); -close_cgroup (evsel->cgrp); +cgroup__put (evsel->cgrp);cpu_map__put (evsel->cpus);cpu_map__put (evsel->own_cpus);thread_map__put (evsel->threads);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/54 perf cgroup: Introduce cgroup__get()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The refcount operation counterpart to cgroup__put(), use it when reusing a cgroup.
--- tools/perf/util/cgroup.c | 16 ++++++++++------ tools/perf/util/cgroup.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-)
tools/perf/util/cgroup.c +10 -6
@@ -99,15 +99,12 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)* check if cgrp is already defined, if so we reuse it */ evlist__for_each_entry (evlist, counter) { - cgrp = counter->cgrp; -if (!cgrp) +if (!counter->cgrp)continue ; -if (!strcmp (cgrp->name, str)) { -refcount_inc (&cgrp->refcnt); +if (!strcmp (counter->cgrp->name, str)) { + cgrp =cgroup__get (counter->cgrp);break ; } - - cgrp =NULL ; }if (!cgrp) {
@@ -157,6 +154,13 @@ void cgroup__put(struct cgroup *cgrp) } } +struct cgroup *cgroup__get (struct cgroup *cgroup) +{ +if (cgroup) +refcount_inc (&cgroup->refcnt); +return cgroup; +} +int parse_cgroups (const struct option *opt,const char *str,int unset__maybe_unused ) {
tools/perf/util/cgroup.h +1 -0
@@ -15,6 +15,7 @@ struct cgroup {extern int nr_cgroups;/* number of explicit cgroups defined */ +struct cgroup *cgroup__get (struct cgroup *cgroup);void cgroup__put (struct cgroup *cgroup);int parse_cgroups (const struct option *opt,const char *str,int unset);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/54 perf cgroup: Introduce find_cgroup() method
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To break down complexity in add_cgroup().
--- tools/perf/util/cgroup.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/cgroup.c +10 -2
@@ -90,11 +90,10 @@ static int open_cgroup(char *name)return fd; } -static int add_cgroup (struct perf_evlist *evlist,char *str) +static struct cgroup *evlist__find_cgroup (struct perf_evlist *evlist,char *str) {struct perf_evsel *counter;struct cgroup *cgrp =NULL ; -int n;/* * check if cgrp is already defined, if so we reuse it */
@@ -107,6 +106,15 @@ static int add_cgroup(struct perf_evlist *evlist, char *str) } } +return cgrp; +} + +static int add_cgroup (struct perf_evlist *evlist,char *str) +{ +struct perf_evsel *counter; +struct cgroup *cgrp =evlist__find_cgroup (evlist, str); +int n; +if (!cgrp) { cgrp =zalloc (sizeof (*cgrp));if (!cgrp)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/54 perf cgroup: Introduce cgroup__new() out of open coded equivalent
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To follow the namespacing convention in tools/perf.
--- tools/perf/util/cgroup.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
tools/perf/util/cgroup.c +20 -10
@@ -109,6 +109,25 @@ static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char *str)return cgrp; } +static struct cgroup *cgroup__new (char *name) +{ +struct cgroup *cgroup =zalloc (sizeof (*cgroup)); + +if (cgroup !=NULL ) { + cgroup->name = name; +refcount_set (&cgroup->refcnt,1 ); + + cgroup->fd =open_cgroup (name); +if (cgroup->fd ==-1 ) + goto out_err; + } + +return cgroup; +out_err: +free (cgroup); +return NULL ; +} +static int add_cgroup (struct perf_evlist *evlist,char *str) {struct perf_evsel *counter;
@@ -116,18 +135,9 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)int n;if (!cgrp) { - cgrp =zalloc (sizeof (*cgrp)); + cgrp =cgroup__new (str);if (!cgrp)return -1 ; - - cgrp->name = str; -refcount_set (&cgrp->refcnt,1 ); - - cgrp->fd =open_cgroup (str); -if (cgrp->fd ==-1 ) { -free (cgrp); -return -1 ; - } }/*
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/54 perf sched: Move thread::shortname to thread_runtime
In reply to Arnaldo Carvalho de MeloFrom: Changbin Du <[email protected]>
The thread::shortname only used by sched command, so move it to sched private structure.
--- tools/perf/builtin-sched.c | 95 +++++++++++++++++++++++++++------------------- tools/perf/util/thread.h | 1 - 2 files changed, 55 insertions(+), 41 deletions(-)
tools/perf/builtin-sched.c +55 -40
@@ -254,6 +254,8 @@ struct thread_runtime {u64 total_delay_time;int last_state; + +char shortname[3 ];u64 migrations; };
@@ -897,6 +899,37 @@ struct sort_dimension {struct list_head list; }; +/* +* handle runtime stats saved per thread +*/ +static struct thread_runtime *thread__init_runtime (struct thread *thread) +{ +struct thread_runtime *r; + + r =zalloc (sizeof (struct thread_runtime )); +if (!r) +return NULL ; + +init_stats (&r->run_stats); +thread__set_priv (thread, r); + +return r; +} + +static struct thread_runtime *thread__get_runtime (struct thread *thread) +{ +struct thread_runtime *tr; + + tr =thread__priv (thread); +if (tr ==NULL ) { + tr =thread__init_runtime (thread); +if (tr ==NULL ) +pr_debug ("Failed to malloc memory for runtime data.\n" ); + } + +return tr; +} +static int thread_lat_cmp (struct list_head *list,struct work_atoms *l,struct work_atoms *r) {
@@ -1480,6 +1513,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, {const u32 next_pid =perf_evsel__intval (evsel, sample,"next_pid" );struct thread *sched_in; +struct thread_runtime *tr;int new_shortname;u64 timestamp0, timestamp = sample->time;s64 delta;
@@ -1519,22 +1553,28 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,if (sched_in ==NULL )return -1 ; + tr =thread__get_runtime (sched_in); +if (tr ==NULL ) { +thread__put (sched_in); +return -1 ; + } + sched->curr_thread[this_cpu] =thread__get (sched_in);printf (" " ); new_shortname =0 ; -if (!sched_in->shortname[0 ]) { +if (!tr->shortname[0 ]) {if (!strcmp (thread__comm_str (sched_in),"swapper" )) {/* * Don't allocate a letter-number for swapper:0 * as a shortname. Instead, we use '.' for it. */ - sched_in->shortname[0 ] ='.' ; - sched_in->shortname[1 ] =' ' ; + tr->shortname[0 ] ='.' ; + tr->shortname[1 ] =' ' ; }else { - sched_in->shortname[0 ] = sched->next_shortname1; - sched_in->shortname[1 ] = sched->next_shortname2; + tr->shortname[0 ] = sched->next_shortname1; + tr->shortname[1 ] = sched->next_shortname2;if (sched->next_shortname1 <'Z' ) { sched->next_shortname1++;
@@ -1552,6 +1592,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,for (i =0 ; i < cpus_nr; i++) {int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;struct thread *curr_thread = sched->curr_thread[cpu]; +struct thread_runtime *curr_tr;const char *pid_color = color;const char *cpu_color = color;
@@ -1569,9 +1610,14 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,else color_fprintf (stdout, cpu_color,"*" ); -if (sched->curr_thread[cpu]) -color_fprintf (stdout, pid_color,"%2s " , sched->curr_thread[cpu]->shortname); -else +if (sched->curr_thread[cpu]) { + curr_tr =thread__get_runtime (sched->curr_thread[cpu]); +if (curr_tr ==NULL ) { +thread__put (sched_in); +return -1 ; + } +color_fprintf (stdout, pid_color,"%2s " , curr_tr->shortname); + }else color_fprintf (stdout, color," " ); }
@@ -1587,7 +1633,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, pid_color =COLOR_PIDS ;color_fprintf (stdout, pid_color,"%s => %s:%d" , - sched_in->shortname,thread__comm_str (sched_in), sched_in->tid); + tr->shortname,thread__comm_str (sched_in), sched_in->tid); }if (sched->map.comp && new_cpu)
@@ -2200,37 +2246,6 @@ static void save_idle_callchain(struct idle_thread_runtime *itr,callchain_cursor__copy (&itr->cursor, &callchain_cursor); } -/* -* handle runtime stats saved per thread -*/ -static struct thread_runtime *thread__init_runtime (struct thread *thread) -{ -struct thread_runtime *r; - - r =zalloc (sizeof (struct thread_runtime )); -if (!r) -return NULL ; - -init_stats (&r->run_stats); -thread__set_priv (thread, r); - -return r; -} - -static struct thread_runtime *thread__get_runtime (struct thread *thread) -{ -struct thread_runtime *tr; - - tr =thread__priv (thread); -if (tr ==NULL ) { - tr =thread__init_runtime (thread); -if (tr ==NULL ) -pr_debug ("Failed to malloc memory for runtime data.\n" ); - } - -return tr; -} - static struct thread *timehist_get_thread(struct perf_sched *sched, struct perf_sample *sample, struct machine *machine,
tools/perf/util/thread.h +0 -1
@@ -26,7 +26,6 @@ struct thread {pid_t ppid;int cpu;refcount_t refcnt; -char shortname[3 ];bool comm_set;int comm_len;bool dead;/* if set thread has exited */
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 9/54 perf sched map: Re-annotate shortname if thread comm changed
In reply to Arnaldo Carvalho de MeloFrom: Changbin Du <[email protected]>
This is to show the real name of thread that created via fork-exec. See below example for shortname *A0*.
$ sudo ./perf sched map
*A0 80393.050639 secs A0 => perf:22368
*. A0 80393.050748 secs . => swapper:0
. *. 80393.050887 secs
*B0 . . 80393.052735 secs B0 => rcu_sched:8
*. . . 80393.052743 secs
. *C0 . 80393.056264 secs C0 => kworker/2:1H:287
. *A0 . 80393.056270 secs
. *D0 . 80393.056769 secs D0 => ksoftirqd/2:22
- . *A0 . 80393.056804 secs
+ . *A0 . 80393.056804 secs A0 => pi:22368
. *. . 80393.056854 secs
*B0 . . 80393.060727 secs
...--- tools/perf/builtin-sched.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
tools/perf/builtin-sched.c +36 -2
@@ -256,6 +256,8 @@ struct thread_runtime {int last_state;char shortname[3 ]; +bool comm_changed; +u64 migrations; };
@@ -1626,7 +1628,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,timestamp__scnprintf_usec (timestamp, stimestamp,sizeof (stimestamp));color_fprintf (stdout, color," %12s secs " , stimestamp); -if (new_shortname || (verbose >0 && sched_in->tid)) { +if (new_shortname || tr->comm_changed || (verbose >0 && sched_in->tid)) {const char *pid_color = color;if (thread__has_color (sched_in))
@@ -1634,6 +1636,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,color_fprintf (stdout, pid_color,"%s => %s:%d" , tr->shortname,thread__comm_str (sched_in), sched_in->tid); + tr->comm_changed = false; }if (sched->map.comp && new_cpu)
@@ -1737,6 +1740,37 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __maybe_return err; } +static int perf_sched__process_comm (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_sample *sample, +struct machine *machine) +{ +struct thread *thread; +struct thread_runtime *tr; +int err; + + err =perf_event__process_comm (tool, event, sample, machine); +if (err) +return err; + + thread =machine__find_thread (machine, sample->pid, sample->tid); +if (!thread) { +pr_err ("Internal error: can't find thread\n" ); +return -1 ; + } + + tr =thread__get_runtime (thread); +if (tr ==NULL ) { +thread__put (thread); +return -1 ; + } + + tr->comm_changed = true; +thread__put (thread); + +return 0 ; +} +static int perf_sched__read_events (struct perf_sched *sched) {const struct perf_evsel_str_handler handlers[] = {
@@ -3306,7 +3340,7 @@ int cmd_sched(int argc, const char **argv)struct perf_sched sched = { .tool = { .sample = perf_sched__process_tracepoint_sample, - .comm = perf_event__process_comm, + .comm = perf_sched__process_comm, .namespaces = perf_event__process_namespaces, .lost = perf_event__process_lost, .fork = perf_sched__process_fork_event,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/54 perf record: Combine some auxtrace initialization into a single function
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
In preparation for adding AUX area sampling support, combine some auxtrace initialization into a single function.
--- tools/perf/builtin-record.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
tools/perf/builtin-record.c +24 -12
@@ -274,6 +274,24 @@ static void record__read_auxtrace_snapshot(struct record *rec) } } +static int record__auxtrace_init (struct record *rec) +{ +int err; + +if (!rec->itr) { + rec->itr =auxtrace_record__init (rec->evlist, &err); +if (err) +return err; + } + + err =auxtrace_parse_snapshot_options (rec->itr, &rec->opts, + rec->opts.auxtrace_snapshot_opts); +if (err) +return err; + +return auxtrace_parse_filters (rec->evlist); +} +#else static inline
@@ -294,6 +312,11 @@ int auxtrace_record__snapshot_start(struct auxtrace_record *itr __maybe_unused)return 0 ; } +static int record__auxtrace_init (struct record *rec__maybe_unused ) +{ +return 0 ; +} +#endif static int record__mmap_evlist(struct record *rec,
@@ -1727,17 +1750,6 @@ int cmd_record(int argc, const char **argv)alarm (rec->switch_output.time); } -if (!rec->itr) { - rec->itr =auxtrace_record__init (rec->evlist, &err); -if (err) - goto out; - } - - err =auxtrace_parse_snapshot_options (rec->itr, &rec->opts, - rec->opts.auxtrace_snapshot_opts); -if (err) - goto out; -/* * Allow aliases to facilitate the lookup of symbols for address * filters. Refer to auxtrace_parse_filters().
@@ -1746,7 +1758,7 @@ int cmd_record(int argc, const char **argv)symbol__init (NULL ); - err =auxtrace_parse_filters (rec->evlist); + err =record__auxtrace_init (rec);if (err) goto out;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 11/54 perf cgroup: Add evlist__findnew_cgroup()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Similar to machine__findnew_thread(), etc, i.e. try to find, get a refcount if found and return it, otherwise return a new cgroup object.
--- tools/perf/util/cgroup.c | 17 ++++++++++------- tools/perf/util/cgroup.h | 4 ++++ 2 files changed, 14 insertions(+), 7 deletions(-)
tools/perf/util/cgroup.c +10 -7
@@ -128,18 +128,21 @@ static struct cgroup *cgroup__new(char *name)return NULL ; } +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name) +{ +struct cgroup *cgroup =evlist__find_cgroup (evlist, name); + +return cgroup ?:cgroup__new (name); +} +static int add_cgroup (struct perf_evlist *evlist,char *str) {struct perf_evsel *counter; -struct cgroup *cgrp =evlist__find_cgroup (evlist, str); +struct cgroup *cgrp =evlist__findnew_cgroup (evlist, str);int n; -if (!cgrp) { - cgrp =cgroup__new (str); -if (!cgrp) -return -1 ; - } - +if (!cgrp) +return -1 ;/* * find corresponding event * if add cgroup N, then need to find event N
tools/perf/util/cgroup.h +4 -0
@@ -18,6 +18,10 @@ extern int nr_cgroups; /* number of explicit cgroups defined */struct cgroup *cgroup__get (struct cgroup *cgroup);void cgroup__put (struct cgroup *cgroup); +struct perf_evlist ; + +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name); +int parse_cgroups (const struct option *opt,const char *str,int unset);#endif /* __CGROUP_H__ */
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 12/54 perf cgroup: Add evlist__add_default_cgroup()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that tools like 'perf trace' can allow the user to set a cgroup to be used for all the evsels still without a crgroup setup by parse_cgroups(), such as the one to use for the syscalls, vfs_getname and other events involved in strace like syscall tracing.
--- tools/perf/util/cgroup.c | 14 ++++++++++++++ tools/perf/util/cgroup.h | 2 ++ 2 files changed, 16 insertions(+)
tools/perf/util/cgroup.c +14 -0
@@ -182,6 +182,20 @@ struct cgroup *cgroup__get(struct cgroup *cgroup)return cgroup; } +static void evsel__set_default_cgroup (struct perf_evsel *evsel,struct cgroup *cgroup) +{ +if (evsel->cgrp ==NULL ) + evsel->cgrp =cgroup__get (cgroup); +} + +void evlist__set_default_cgroup (struct perf_evlist *evlist,struct cgroup *cgroup) +{ +struct perf_evsel *evsel; + +evlist__for_each_entry (evlist, evsel) +evsel__set_default_cgroup (evsel, cgroup); +} +int parse_cgroups (const struct option *opt,const char *str,int unset__maybe_unused ) {
tools/perf/util/cgroup.h +2 -0
@@ -22,6 +22,8 @@ struct perf_evlist;struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name); +void evlist__set_default_cgroup (struct perf_evlist *evlist,struct cgroup *cgroup); +int parse_cgroups (const struct option *opt,const char *str,int unset);#endif /* __CGROUP_H__ */
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 13/54 perf cgroup: Make the cgroup name be const char *
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The usual thing is for a constructor to allocate space for its members, not to require that the caller pass a pre-allocated 'name' and then, at its destructor, to free something not allocated by it.
Fix it by making cgroup__new() to receive a const char pointer, then allocate cgroup->name that then can continue to be freed at cgroup__delete(), balancing the alloc/free operations inside the cgroup struct methods.
This eases calling evlist__findnew_cgroup() from the custom 'perf trace' cgroup parser, that will only call parse_cgroups() when the '-G cgroup' is passed on the command line after '-e event' entries, when it'll behave just like 'perf stat' and 'perf record', i.e. the previous parse_cgroup() users that mandate that -G only can come after a -e.
--- tools/perf/util/cgroup.c | 24 ++++++++++++++---------- tools/perf/util/cgroup.h | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-)
tools/perf/util/cgroup.c +14 -10
@@ -71,7 +71,7 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen)return -1 ; } -static int open_cgroup (char *name) +static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];char mnt[PATH_MAX +1 ];
@@ -90,7 +90,7 @@ static int open_cgroup(char *name)return fd; } -static struct cgroup *evlist__find_cgroup (struct perf_evlist *evlist,char *str) +static struct cgroup *evlist__find_cgroup (struct perf_evlist *evlist,const char *str) {struct perf_evsel *counter;struct cgroup *cgrp =NULL ;
@@ -109,33 +109,38 @@ static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char *str)return cgrp; } -static struct cgroup *cgroup__new (char *name) +static struct cgroup *cgroup__new (const char *name) {struct cgroup *cgroup =zalloc (sizeof (*cgroup));if (cgroup !=NULL ) { - cgroup->name = name;refcount_set (&cgroup->refcnt,1 ); + cgroup->name =strdup (name); +if (!cgroup->name) + goto out_err; cgroup->fd =open_cgroup (name);if (cgroup->fd ==-1 ) - goto out_err; + goto out_free_name; }return cgroup; + +out_free_name: +free (cgroup->name); out_err:free (cgroup);return NULL ; } -struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name) +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,const char *name) {struct cgroup *cgroup =evlist__find_cgroup (evlist, name);return cgroup ?:cgroup__new (name); } -static int add_cgroup (struct perf_evlist *evlist,char *str) +static int add_cgroup (struct perf_evlist *evlist,const char *str) {struct perf_evsel *counter;struct cgroup *cgrp =evlist__findnew_cgroup (evlist, str);
@@ -222,10 +227,9 @@ int parse_cgroups(const struct option *opt, const char *str,if (!s)return -1 ; ret =add_cgroup (evlist, s); -if (ret) { -free (s); +free (s); +if (ret)return -1 ; - } }/* nr_cgroups is increased een for empty cgroups */ nr_cgroups++;
tools/perf/util/cgroup.h +1 -1
@@ -20,7 +20,7 @@ void cgroup__put(struct cgroup *cgroup);struct perf_evlist ; -struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name); +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,const char *name);void evlist__set_default_cgroup (struct perf_evlist *evlist,struct cgroup *cgroup);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 14/54 perf trace: Support setting cgroups as targets
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
One can set a cgroup as a default cgroup to be used by all events or set cgroups with the 'perf stat' and 'perf record' behaviour, i.e. '-G A' will be the cgroup for events defined so far in the command line.
Here in my main machine, with a kvm instance running a rhel6 guinea pig I have:
# ls -la /sys/fs/cgroup/perf_event/ | grep drw drwxr-xr-x. 14 root root 360 Mar 6 12:04 .. drwxr-xr-x. 3 root root 0 Mar 6 15:05 machine.slice #
So I can go ahead and use that cgroup hierarchy, say lets see what syscalls are being emitted by threads in that 'machine.slice' hierarchy that are taking more than 100ms:
# perf trace --duration 100 -G machine.slice
0.188 (249.850 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
250.274 (249.743 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
500.224 (249.755 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
750.097 (249.934 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
1000.244 (249.780 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
1250.197 (249.796 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
1500.124 (249.859 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
1750.076 (172.900 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
902.570 (1021.116 ms): qemu-system-x8/23667 ppoll(ufds: 0x558151e03180, nfds: 74, tsp: 0x7ffc00cd0900, sigsetsize: 8) = 1
1923.825 (305.133 ms): qemu-system-x8/23667 ppoll(ufds: 0x558151e03180, nfds: 74, tsp: 0x7ffc00cd0900, sigsetsize: 8) = 1
2000.172 (229.002 ms): CPU 0/KVM/23744 ioctl(fd: 16<anon_inode:kvm-vcpu:0>, cmd: KVM_RUN) = 0
^C #If we look inside that cgroup hierarchy we get:
# ls -la /sys/fs/cgroup/perf_event/machine.slice/ | grep drw drwxr-xr-x. 3 root root 0 Mar 6 15:05 . drwxr-xr-x. 2 root root 0 Mar 6 16:16 machine-qemu\x2d2\x2drhel6.sandy.scope #
There is just one, but lets say there were more and we would want to see 5 seconds worth of syscall summary for the threads in that cgroup:
# perf trace --summary -G machine.slice/machine-qemu\\x2d2\\x2drhel6.sandy.scope/ -a sleep 5
Summary of events:
qemu-system-x86 (23667), 143858 events, 24.2%
syscall calls total min avg max stddev
(msec) (msec) (msec) (msec) (%)
--------------- -------- --------- --------- --------- --------- ------
ppoll 28492 4348.631 0.000 0.153 11.616 1.05%
futex 19661 140.801 0.001 0.007 2.993 3.20%
read 18440 68.084 0.001 0.004 1.653 4.33%
ioctl 5387 24.768 0.002 0.005 0.134 1.62%
CPU 0/KVM (23744), 449455 events, 75.8%
syscall calls total min avg max stddev
(msec) (msec) (msec) (msec) (%)
--------------- -------- --------- --------- --------- --------- ------
ioctl 148364 3401.812 0.000 0.023 11.801 1.15%
futex 36131 404.127 0.001 0.011 7.377 2.63%
writev 29452 339.688 0.003 0.012 1.740 1.36%
write 11315 45.992 0.001 0.004 0.105 1.10%#
See the documentation about how to set more than one cgroup for different events in the same command line.
--- tools/perf/Documentation/perf-trace.txt | 25 +++++++++++++++++ tools/perf/builtin-trace.c | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
tools/perf/Documentation/perf-trace.txt +25 -0
@@ -63,6 +63,31 @@ filter out the startup phase of the program, which is often very different. --uid=:: Record events in threads owned by uid. Name or number. +-G:: +--cgroup:: + Record events in threads in a cgroup. + + Look for cgroups to set at the /sys/fs/cgroup/perf_event directory, then + remove the /sys/fs/cgroup/perf_event/ part and try: + + perf trace -G A -e sched:*switch + + Will set all raw_syscalls:sys_{enter,exit}, pgfault, vfs_getname, etc + _and_ sched:sched_switch to the 'A' cgroup, while: + + perf trace -e sched:*switch -G A + + will only set the sched:sched_switch event to the 'A' cgroup, all the + other events (raw_syscalls:sys_{enter,exit}, etc are left "without" + a cgroup (on the root cgroup, sys wide, etc). + + Multiple cgroups: + + perf trace -G A -e sched:*switch -G B + + the syscall ones go to the 'A' cgroup, the sched:sched_switch goes + to the 'B' cgroup. + --filter-pids=:: Filter out events for these pids and for 'trace' itself (comma separated list).
tools/perf/builtin-trace.c +50 -0
92 lines not on this page · raw message
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 15/54 perf auxtrace: Add missing parameters from kernel-doc comments
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add missing parameters from kernel-doc comments.
--- tools/perf/util/auxtrace.h | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/auxtrace.h +2 -0
@@ -130,6 +130,7 @@ struct auxtrace_index {/** * struct auxtrace - session callbacks to allow AUX area data decoding. * @process_event: lets the decoder see all session events +* @process_auxtrace_event: process a PERF_RECORD_AUXTRACE event * @flush_events: process any remaining data * @free_events: free resources associated with event processing * @free: free resources associated with the session
@@ -301,6 +302,7 @@ struct auxtrace_mmap_params {* @parse_snapshot_options: parse snapshot options * @reference: provide a 64-bit reference number for auxtrace_event * @read_finish: called after reading from an auxtrace mmap +* @alignment: alignment (if any) for AUX area data */ struct auxtrace_record { int (*recording_options)(struct auxtrace_record *itr,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 16/54 perf auxtrace: Rename some buffer-queuing functions
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Rename some buffer-queuing functions in preparation for supporting AUX area sampling buffers.
--- tools/perf/util/auxtrace.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
tools/perf/util/auxtrace.c +10 -10
@@ -233,9 +233,9 @@ static void *auxtrace_copy_data(u64 size, struct perf_session *session)return p; } -static int auxtrace_queues__add_buffer (struct auxtrace_queues *queues, -unsigned int idx, -struct auxtrace_buffer *buffer) +static int auxtrace_queues__queue_buffer (struct auxtrace_queues *queues, +unsigned int idx, +struct auxtrace_buffer *buffer) {struct auxtrace_queue *queue;int err;
@@ -286,7 +286,7 @@ static int auxtrace_queues__split_buffer(struct auxtrace_queues *queues,return -ENOMEM ; b->size =BUFFER_LIMIT_FOR_32_BIT ; b->consecutive = consecutive; - err =auxtrace_queues__add_buffer (queues, idx, b); + err =auxtrace_queues__queue_buffer (queues, idx, b);if (err) {auxtrace_buffer__free (b);return err;
@@ -302,10 +302,10 @@ static int auxtrace_queues__split_buffer(struct auxtrace_queues *queues,return 0 ; } -static int auxtrace_queues__add_event_buffer (struct auxtrace_queues *queues, -struct perf_session *session, -unsigned int idx, -struct auxtrace_buffer *buffer) +static int auxtrace_queues__add_buffer (struct auxtrace_queues *queues, +struct perf_session *session, +unsigned int idx, +struct auxtrace_buffer *buffer) {if (session->one_mmap) { buffer->data = buffer->data_offset - session->one_mmap_offset +
@@ -324,7 +324,7 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,return err; } -return auxtrace_queues__add_buffer (queues, idx, buffer); +return auxtrace_queues__queue_buffer (queues, idx, buffer); }static bool filter_cpu (struct perf_session *session,int cpu)
@@ -359,7 +359,7 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues, buffer->size = event->auxtrace.size; idx = event->auxtrace.idx; - err =auxtrace_queues__add_event_buffer (queues, session, idx, buffer); + err =auxtrace_queues__add_buffer (queues, session, idx, buffer);if (err) goto out_err;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 17/54 perf auxtrace: Make auxtrace_queues__add_buffer() return buffer_ptr
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
In preparation for supporting AUX area sampling buffers, auxtrace_queues__add_buffer() needs to be more generic. To that end, make it return buffer_ptr instead of the caller.
--- tools/perf/util/auxtrace.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
tools/perf/util/auxtrace.c +15 -8
@@ -305,8 +305,11 @@ static int auxtrace_queues__split_buffer(struct auxtrace_queues *queues,static int auxtrace_queues__add_buffer (struct auxtrace_queues *queues,struct perf_session *session,unsigned int idx, -struct auxtrace_buffer *buffer) +struct auxtrace_buffer *buffer, +struct auxtrace_buffer **buffer_ptr) { +int err; +if (session->one_mmap) { buffer->data = buffer->data_offset - session->one_mmap_offset + session->one_mmap_addr;
@@ -317,14 +320,20 @@ static int auxtrace_queues__add_buffer(struct auxtrace_queues *queues, buffer->data_needs_freeing = true; }else if (BITS_PER_LONG ==32 && buffer->size >BUFFER_LIMIT_FOR_32_BIT ) { -int err; - err =auxtrace_queues__split_buffer (queues, idx, buffer);if (err)return err; } -return auxtrace_queues__queue_buffer (queues, idx, buffer); + err =auxtrace_queues__queue_buffer (queues, idx, buffer); +if (err) +return err; + +/* FIXME: Doesn't work for split buffer */ +if (buffer_ptr) + *buffer_ptr = buffer; + +return 0 ; }static bool filter_cpu (struct perf_session *session,int cpu)
@@ -359,13 +368,11 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues, buffer->size = event->auxtrace.size; idx = event->auxtrace.idx; - err =auxtrace_queues__add_buffer (queues, session, idx, buffer); + err =auxtrace_queues__add_buffer (queues, session, idx, buffer, + buffer_ptr);if (err) goto out_err; -if (buffer_ptr) - *buffer_ptr = buffer; -return 0 ; out_err:
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 18/54 perf tools: Correct title markers for asciidoctor
In reply to Arnaldo Carvalho de MeloFrom: Takashi Iwai <[email protected]>
I've tested to process the perf man pages with asciidoctor that is picker than asciidoc, and it revealed minor syntax errors in some documents. Namely, the title markers aren't aligned with the previous line, hence asciidoctor didn't recognize as titles.
This patch corrects these markers to be processed properly.
--- tools/perf/Documentation/perf-data.txt | 2 +- tools/perf/Documentation/perf-ftrace.txt | 2 +- tools/perf/Documentation/perf-kallsyms.txt | 2 +- tools/perf/Documentation/perf-sched.txt | 2 +- tools/perf/Documentation/perf-script-perl.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-data.txt +1 -1
@@ -1,5 +1,5 @@ perf-data(1) -============== +============ NAME ----
tools/perf/Documentation/perf-ftrace.txt +1 -1
@@ -1,5 +1,5 @@ perf-ftrace(1) -============= +============== NAME ----
tools/perf/Documentation/perf-kallsyms.txt +1 -1
@@ -1,5 +1,5 @@ perf-kallsyms(1) -============== +================ NAME ----
tools/perf/Documentation/perf-sched.txt +1 -1
@@ -1,5 +1,5 @@ perf-sched(1) -============== +============= NAME ----
tools/perf/Documentation/perf-script-perl.txt +1 -1
@@ -1,5 +1,5 @@ perf-script-perl(1) -================== +=================== NAME ----
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 19/54 perf pmu: Support wildcards on pmu name in dynamic pmu events
In reply to Arnaldo Carvalho de MeloFrom: Agustin Vega-Frias <[email protected]>
Starting on v4.12 event parsing code for dynamic pmu events already supports prefix-based matching of multiple pmus when creating dynamic events. E.g., in a system with the following dynamic pmus:
mypmu_0
mypmu_1
mypmu_2
mypmu_4passing mypmu/<config>/ as an event spec will result in the creation of the event in all of the pmus. This change expands this matching through the use of fnmatch so glob-like expressions can be used to create events in multiple pmus. E.g., in the system described above if a user only wants to create the event in mypmu_0 and mypmu_1, mypmu_[01]/<config>/ can be passed.
--- tools/perf/Documentation/perf-list.txt | 8 +++++++- tools/perf/Documentation/perf-stat.txt | 13 +++++++++++++ tools/perf/util/parse-events.l | 2 +- tools/perf/util/parse-events.y | 14 ++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-list.txt +7 -1
@@ -141,7 +141,13 @@ on the first memory controller on socket 0 of a Intel Xeon system Each memory controller has its own PMU. Measuring the complete system bandwidth would require specifying all imc PMUs (see perf list output), -and adding the values together. +and adding the values together. To simplify creation of multiple events, +prefix and glob matching is supported in the PMU name, and the prefix +'uncore_' is also ignored when performing the match. So the command above +can be expanded to all memory controllers by using the syntaxes: + + perf stat -C 0 -a imc/cas_count_read/,imc/cas_count_write/ -I 1000 ... + perf stat -C 0 -a *imc*/cas_count_read/,*imc*/cas_count_write/ -I 1000 ... This example measures the combined core power every second
tools/perf/Documentation/perf-stat.txt +13 -0
@@ -49,6 +49,13 @@ report:: parameters are defined by corresponding entries in /sys/bus/event_source/devices/<pmu>/format/* + Note that the last two syntaxes support prefix and glob matching in + the PMU name to simplify creation of events accross multiple instances + of the same type of PMU in large systems (e.g. memory controller PMUs). + Multiple PMU instances are typical for uncore PMUs, so the prefix + 'uncore_' is also ignored when performing this match. + + -i:: --no-inherit:: child tasks do not inherit counters
@@ -260,6 +267,12 @@ taskset. --no-merge:: Do not merge results from same PMUs. +When multiple events are created from a single event alias, stat will, +by default, aggregate the event counts and show the result in a single +row. This option disables that behavior and shows the individual events +and counts. Aliases are listed immediately after the Kernel PMU events +by perf list. + --smi-cost:: Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
tools/perf/util/parse-events.l +1 -1
@@ -175,7 +175,7 @@ bpf_source [^,{}]+\.c[a-zA-Z0-9._]* num_dec [0-9]+ num_hex 0x[a-fA-F0-9]+ num_raw_hex [a-fA-F0-9]+ -name [a-zA-Z_*?][a-zA-Z0-9_*?.]* +name [a-zA-Z_*?\[\]][a-zA-Z0-9_*?.\[\]]* name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? /* If you add a modifier you need to update check_modifier() */
tools/perf/util/parse-events.y +12 -2
@@ -8,6 +8,7 @@ #define YYDEBUG 1 +#include <fnmatch.h> #include <linux/compiler.h> #include <linux/list.h> #include <linux/types.h>
@@ -234,6 +235,10 @@ PE_NAME opt_event_config if (parse_events_add_pmu(_parse_state, list, $1, $2)) { struct perf_pmu *pmu = NULL; int ok = 0; + char *pattern; + + if (asprintf(&pattern, "%s*", $1) < 0) + YYABORT; while ((pmu = perf_pmu__scan(pmu)) != NULL) { char *name = pmu->name;
@@ -241,14 +246,19 @@ PE_NAME opt_event_config if (!strncmp(name, "uncore_", 7) && strncmp($1, "uncore_", 7)) name += 7; - if (!strncmp($1, name, strlen($1))) { - if (parse_events_copy_term_list(orig_terms, &terms)) + if (!fnmatch(pattern, name, 0)) { + if (parse_events_copy_term_list(orig_terms, &terms)) { + free(pattern); YYABORT; + } if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms)) ok++; parse_events_terms__delete(terms); } } + + free(pattern); + if (!ok) YYABORT; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 20/54 perf pmu: Display pmu name when printing unmerged events in stat
In reply to Arnaldo Carvalho de MeloFrom: Agustin Vega-Frias <[email protected]>
To simplify creation of events accross multiple instances of the same type of PMU stat supports two methods for creating multiple events from a single event specification:
1. A prefix or glob can be used in the PMU name.
2. Aliases, which are listed immediately after the Kernel PMU events by perf list, are used.
When the --no-merge option is passed and these events are displayed individually the PMU name is lost and it's not possible to see which count corresponds to which pmu:
$ perf stat -a -e l3cache/read-miss/ --no-merge ls > /dev/null
Performance counter stats for 'system wide':
67 l3cache/read-miss/
67 l3cache/read-miss/
63 l3cache/read-miss/
60 l3cache/read-miss/
0.001675706 seconds time elapsed
$ perf stat -a -e l3cache_read_miss --no-merge ls > /dev/null
Performance counter stats for 'system wide':
12 l3cache_read_miss
17 l3cache_read_miss
10 l3cache_read_miss
8 l3cache_read_miss
0.001661305 seconds time elapsedThis change adds the original pmu name to the event. For dynamic pmu events the pmu name is restored in the event name:
$ perf stat -a -e l3cache/read-miss/ --no-merge ls > /dev/null
Performance counter stats for 'system wide':
63 l3cache_0_3/read-miss/
74 l3cache_0_1/read-miss/
64 l3cache_0_2/read-miss/
74 l3cache_0_0/read-miss/
0.001675706 seconds time elapsedFor alias events the name is added after the event name:
$ perf stat -a -e l3cache_read_miss --no-merge ls > /dev/null
Performance counter stats for 'system wide':
10 l3cache_read_miss [l3cache_0_3]
12 l3cache_read_miss [l3cache_0_1]
10 l3cache_read_miss [l3cache_0_2]
17 l3cache_read_miss [l3cache_0_0]
0.001661305 seconds time elapsed--- tools/perf/builtin-stat.c | 29 ++++++++++++++++++++++++++++- tools/perf/util/evsel.c | 1 + tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 8 +++++++- 4 files changed, 37 insertions(+), 2 deletions(-)
tools/perf/builtin-stat.c +28 -1
@@ -1251,6 +1251,31 @@ static void aggr_update_shadow(void) } } +static void uniquify_event_name (struct perf_evsel *counter) +{ +char *new_name; +char *config; + +if (!counter->pmu_name || !strncmp (counter->name, counter->pmu_name, +strlen (counter->pmu_name))) +return ; + + config =strchr (counter->name,'/' ); +if (config) { +if (asprintf (&new_name, +"%s%s" , counter->pmu_name, config) >0 ) { +free (counter->name); + counter->name = new_name; + } + }else { +if (asprintf (&new_name, +"%s [%s]" , counter->name, counter->pmu_name) >0 ) { +free (counter->name); + counter->name = new_name; + } + } +} + static void collect_all_aliases(struct perf_evsel *counter, void (*cb)(struct perf_evsel *counter, void *data, bool first),
@@ -1279,7 +1304,9 @@ static bool collect_data(struct perf_evsel *counter,if (counter->merged_stat)return false;cb (counter, data, true); -if (!no_merge && counter->auto_merge_stats) +if (no_merge) +uniquify_event_name (counter); +else if (counter->auto_merge_stats)collect_all_aliases (counter, cb, data);return true; }
tools/perf/util/evsel.c +1 -0
@@ -244,6 +244,7 @@ void perf_evsel__init(struct perf_evsel *evsel, evsel->metric_name =NULL ; evsel->metric_events =NULL ; evsel->collect_stat = false; + evsel->pmu_name =NULL ; }struct perf_evsel *perf_evsel__new_idx (struct perf_event_attr *attr,int idx)
tools/perf/util/evsel.h +1 -0
@@ -142,6 +142,7 @@ struct perf_evsel {struct perf_evsel **metric_events;bool collect_stat;bool weak_group; +const char *pmu_name; };union u64_swap {
tools/perf/util/parse-events.c +7 -1
@@ -1247,7 +1247,12 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,if (!head_config) { attr.type = pmu->type; evsel =__add_event (list, &parse_state->idx, &attr,NULL , pmu,NULL , auto_merge_stats); -return evsel ?0 : -ENOMEM ; +if (evsel) { + evsel->pmu_name = name; +return 0 ; + }else { +return -ENOMEM ; + } }if (perf_pmu__check_alias (pmu, head_config, &info))
@@ -1276,6 +1281,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, evsel->snapshot = info.snapshot; evsel->metric_expr = info.metric_expr; evsel->metric_name = info.metric_name; + evsel->pmu_name = name; }return evsel ?0 : -ENOMEM ;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 21/54 perf pmu: Auto-merge PMU events created by prefix or glob match
In reply to Arnaldo Carvalho de MeloFrom: Agustin Vega-Frias <[email protected]>
Auto-merge for these events was disabled when auto-merging of non-alias events was disabled in commit 63ce844 (perf stat: Only auto-merge events that are PMU aliases).
Non-merging of legacy events is preserved:
$ perf stat -ag -e cache-misses,cache-misses sleep 1
Performance counter stats for 'system wide':
86,323 cache-misses
86,323 cache-misses
1.002623307 seconds time elapsedBut prefix or glob matching auto-merges the events created:
$ perf stat -a -e l3cache/read-miss/ sleep 1
Performance counter stats for 'system wide':
328 l3cache/read-miss/
1.002627008 seconds time elapsed
$ perf stat -a -e l3cache_0_[01]/read-miss/ sleep 1
Performance counter stats for 'system wide':
172 l3cache/read-miss/
1.002627008 seconds time elapsedAs with events created with aliases, auto-merging can be suppressed with the --no-merge option:
$ perf stat -a -e l3cache/read-miss/ --no-merge sleep 1
Performance counter stats for 'system wide':
67 l3cache/read-miss/
67 l3cache/read-miss/
63 l3cache/read-miss/
60 l3cache/read-miss/
1.002622192 seconds time elapsed
--- tools/perf/Documentation/perf-stat.txt | 14 +++++++++----- tools/perf/util/parse-events.c | 13 +++---------- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.y | 4 ++-- 4 files changed, 15 insertions(+), 18 deletions(-)
tools/perf/Documentation/perf-stat.txt +9 -5
@@ -267,11 +267,15 @@ taskset. --no-merge:: Do not merge results from same PMUs. -When multiple events are created from a single event alias, stat will, -by default, aggregate the event counts and show the result in a single -row. This option disables that behavior and shows the individual events -and counts. Aliases are listed immediately after the Kernel PMU events -by perf list. +When multiple events are created from a single event specification, +stat will, by default, aggregate the event counts and show the result +in a single row. This option disables that behavior and shows +the individual events and counts. + +Multiple events are created from a single event specification when: +1. Prefix or glob matching is used for the PMU name. +2. Aliases, which are listed immediately after the Kernel PMU events + by perf list, are used. --smi-cost:: Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
tools/perf/util/parse-events.c +3 -10
@@ -1217,7 +1217,7 @@ int parse_events_add_numeric(struct parse_events_state *parse_state, get_config_name(head_config), &config_terms); } -static int __parse_events_add_pmu (struct parse_events_state *parse_state, +int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,char *name,struct list_head *head_config,bool auto_merge_stats) {
@@ -1287,13 +1287,6 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,return evsel ?0 : -ENOMEM ; } -int parse_events_add_pmu (struct parse_events_state *parse_state, -struct list_head *list,char *name, -struct list_head *head_config) -{ -return __parse_events_add_pmu (parse_state, list, name, head_config, false); -} -int parse_events_multi_pmu_add (struct parse_events_state *parse_state,char *str,struct list_head **listp) {
@@ -1323,8 +1316,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,return -1 ;list_add_tail (&term->list, head); -if (!__parse_events_add_pmu (parse_state, list, - pmu->name, head, true)) { +if (!parse_events_add_pmu (parse_state, list, + pmu->name, head, true)) {pr_debug ("%s -> %s/%s/\n" , str, pmu->name, alias->str); ok++;
tools/perf/util/parse-events.h +1 -1
@@ -167,7 +167,7 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx, void *ptr, char *type, u64 len);int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,char *name, -struct list_head *head_config); +struct list_head *head_config,bool auto_merge_stats); int parse_events_multi_pmu_add(struct parse_events_state *parse_state, char *str,
tools/perf/util/parse-events.y +2 -2
@@ -232,7 +232,7 @@ PE_NAME opt_event_config YYABORT; ALLOC_LIST(list); - if (parse_events_add_pmu(_parse_state, list, $1, $2)) { + if (parse_events_add_pmu(_parse_state, list, $1, $2, false)) { struct perf_pmu *pmu = NULL; int ok = 0; char *pattern;
@@ -251,7 +251,7 @@ PE_NAME opt_event_config free(pattern); YYABORT; } - if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms)) + if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true)) ok++; parse_events_terms__delete(terms); }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 22/54 perf evlist: Store 'overwrite' in struct perf_mmap
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
It has been determined that the map is for overwrite mode (evlist->overwrite_mmap) or non-overwrite mode (evlist->mmap) when calling perf_evlist__alloc_mmap().
Store the information in struct perf_mmap, which will be used later to simplify the perf_mmap__read*() interfaces.
--- tools/perf/util/evlist.c | 8 +++++--- tools/perf/util/mmap.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +5 -3
@@ -722,7 +722,8 @@ void perf_evlist__munmap(struct perf_evlist *evlist)zfree (&evlist->overwrite_mmap); } -static struct perf_mmap *perf_evlist__alloc_mmap (struct perf_evlist *evlist) +static struct perf_mmap *perf_evlist__alloc_mmap (struct perf_evlist *evlist, +bool overwrite) {int i;struct perf_mmap *map;
@@ -736,6 +737,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist)for (i =0 ; i < evlist->nr_mmaps; i++) { map[i].fd =-1 ; + map[i].overwrite = overwrite;/* * When the perf_mmap() call is made we grab one refcount, plus * one extra to let perf_mmap__consume() get the last
@@ -779,7 +781,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, maps = evlist->overwrite_mmap;if (!maps) { - maps =perf_evlist__alloc_mmap (evlist); + maps =perf_evlist__alloc_mmap (evlist, true);if (!maps)return -1 ; evlist->overwrite_mmap = maps;
@@ -1029,7 +1031,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,struct mmap_params mp;if (!evlist->mmap) - evlist->mmap =perf_evlist__alloc_mmap (evlist); + evlist->mmap =perf_evlist__alloc_mmap (evlist, false);if (!evlist->mmap)return -ENOMEM ;
tools/perf/util/mmap.h +1 -0
@@ -20,6 +20,7 @@ struct perf_mmap {int fd;refcount_t refcnt;u64 prev; +bool overwrite;struct auxtrace_mmap auxtrace_mmap;char event_copy[PERF_SAMPLE_MAX_SIZE ]__aligned(8) ; };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 23/54 perf mmap: Store mmap scope in struct perf_mmap()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
There is too much boilerplate in the perf_mmap__read*() interfaces.
The 'start' and 'end' variables should be stored in struct perf_mmap at initialization. They will be used later.
The old 'startp' and 'endp' pointers are used by perf_mmap__read_event() now. They cannot be removed. So the old 'startp/endp' and new 'md->start/md->end' will exist simultaneously now. The old one will be removed later.
--- tools/perf/util/mmap.c | 12 ++++++++---- tools/perf/util/mmap.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-)
tools/perf/util/mmap.c +8 -4
@@ -250,13 +250,15 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite, *startp = overwrite ? head : old; *endp = overwrite ? old : head; + md->start = md->overwrite ? head : old; + md->end = md->overwrite ? old : head; -if (*startp == *endp) +if (md->start == md->end)return -EAGAIN ; - size = *endp - *startp; + size = md->end - md->start;if (size > (unsigned long )(md->mask) +1 ) { -if (!overwrite) { +if (!md->overwrite) {WARN_ONCE (1 ,"failed to keep up with mmap data. (warn only once)\n" ); md->prev = head;
@@ -268,8 +270,10 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,* Backward ring buffer is full. We still have a chance to read * most of data from it. */ -if (overwrite_rb_find_range (data, md->mask, head, startp, endp)) +if (overwrite_rb_find_range (data, md->mask, head, &md->start, &md->end))return -EINVAL ; + *startp = md->start; + *endp = md->end; }return 0 ;
tools/perf/util/mmap.h +2 -0
@@ -20,6 +20,8 @@ struct perf_mmap {int fd;refcount_t refcnt;u64 prev; +u64 start; +u64 end;bool overwrite;struct auxtrace_mmap auxtrace_mmap;char event_copy[PERF_SAMPLE_MAX_SIZE ]__aligned(8) ;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 24/54 perf mmap: Use the stored scope data in perf_mmap__push()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
Using the 'start' and 'end' which are stored in struct perf_mmap to replace the temporary 'start' and 'end'.
The temporary variables will be discarded later.
It doesn't need to pass 'overwrite' to perf_mmap__push(). It's stored in struct perf_mmap.
--- tools/perf/builtin-record.c | 2 +- tools/perf/util/mmap.c | 24 ++++++++++++------------ tools/perf/util/mmap.h | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -533,7 +533,7 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evlistruct auxtrace_mmap *mm = &maps[i].auxtrace_mmap;if (maps[i].base) { -if (perf_mmap__push (&maps[i], overwrite, rec, record__pushfn) !=0 ) { +if (perf_mmap__push (&maps[i], rec, record__pushfn) !=0 ) { rc =-1 ; goto out; }
tools/perf/util/mmap.c +12 -12
@@ -279,8 +279,8 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,return 0 ; } -int perf_mmap__push (struct perf_mmap *md,bool overwrite, -void *to,int push (void *to,void *buf,size_t size)) +int perf_mmap__push (struct perf_mmap *md,void *to, +int push (void *to,void *buf,size_t size)) {u64 head =perf_mmap__read_head (md);u64 end, start;
@@ -289,16 +289,16 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite,void *buf;int rc =0 ; - rc =perf_mmap__read_init (md, overwrite, &start, &end); + rc =perf_mmap__read_init (md, md->overwrite, &start, &end);if (rc <0 )return (rc == -EAGAIN ) ?0 :-1 ; - size = end - start; + size = md->end - md->start; -if ((start & md->mask) + size != (end & md->mask)) { - buf = &data[start & md->mask]; - size = md->mask +1 - (start & md->mask); - start += size; +if ((md->start & md->mask) + size != (md->end & md->mask)) { + buf = &data[md->start & md->mask]; + size = md->mask +1 - (md->start & md->mask); + md->start += size;if (push (to, buf, size) <0 ) { rc =-1 ;
@@ -306,9 +306,9 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite, } } - buf = &data[start & md->mask]; - size = end - start; - start += size; + buf = &data[md->start & md->mask]; + size = md->end - md->start; + md->start += size;if (push (to, buf, size) <0 ) { rc =-1 ;
@@ -316,7 +316,7 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite, } md->prev = head; -perf_mmap__consume (md, overwrite); +perf_mmap__consume (md, md->overwrite); out:return rc; }
tools/perf/util/mmap.h +2 -2
@@ -93,8 +93,8 @@ union perf_event *perf_mmap__read_event(struct perf_mmap *map,bool overwrite, u64 *startp, u64 end); -int perf_mmap__push (struct perf_mmap *md,bool backward, -void *to,int push (void *to,void *buf,size_t size)); +int perf_mmap__push (struct perf_mmap *md,void *to, +int push (void *to,void *buf,size_t size));size_t perf_mmap__mmap_len (struct perf_mmap *map);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 25/54 perf mmap: Use the stored data in perf_mmap__read_event()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
Using the 'start', 'end' and 'overwrite' which are stored in struct perf_mmap to replace the parameters of perf_mmap__read_event(). The parameters will be discarded later.
No functional change.
--- tools/perf/util/mmap.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
tools/perf/util/mmap.c +8 -10
@@ -76,8 +76,9 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,* perf_mmap__read_done() */ union perf_event *perf_mmap__read_event (struct perf_mmap *map, -bool overwrite, -u64 *startp,u64 end) +bool overwrite__maybe_unused , +u64 *startp__maybe_unused , +u64 end__maybe_unused ) {union perf_event *event;
@@ -87,17 +88,14 @@ union perf_event *perf_mmap__read_event(struct perf_mmap *map,if (!refcount_read (&map->refcnt))return NULL ; -if (startp ==NULL ) -return NULL ; -/* non-overwirte doesn't pause the ringbuffer */ -if (!overwrite) - end =perf_mmap__read_head (map); +if (!map->overwrite) + map->end =perf_mmap__read_head (map); - event =perf_mmap__read (map, startp, end); + event =perf_mmap__read (map, &map->start, map->end); -if (!overwrite) - map->prev = *startp; +if (!map->overwrite) + map->prev = map->start;return event; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 26/54 perf mmap: Use stored 'overwrite' in perf_mmap__consume()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The 'overwrite' is set at allocation. It will not be changed. Using it to replace the parameter of perf_mmap__consume(). The parameters will be discarded later.
No functional change.
--- tools/perf/util/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/mmap.c +2 -2
@@ -118,9 +118,9 @@ void perf_mmap__put(struct perf_mmap *map)perf_mmap__munmap (map); } -void perf_mmap__consume (struct perf_mmap *map,bool overwrite) +void perf_mmap__consume (struct perf_mmap *map,bool overwrite__maybe_unused ) { -if (!overwrite) { +if (!map->overwrite) {u64 old = map->prev;perf_mmap__write_tail (map, old);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 27/54 perf mmap: Simplify perf_mmap__consume()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
It isn't necessary to pass the 'overwrite' argument to perf_mmap__consume(). Discard it.
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +- tools/perf/builtin-kvm.c | 4 ++-- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/util/mmap.c | 6 +++--- tools/perf/util/mmap.h | 2 +- tools/perf/util/python.c | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -134,7 +134,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe comm2_time = sample.time; } next_event: -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md); }
tools/perf/builtin-kvm.c +2 -2
@@ -760,7 +760,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { err =perf_evlist__parse_sample_timestamp (evlist, event, ×tamp);if (err) { -perf_mmap__consume (md, false); +perf_mmap__consume (md);pr_err ("Failed to parse sample\n" );return -1 ; }
@@ -770,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_mmap__consume (md, false); +perf_mmap__consume (md);if (err) {pr_err ("Failed to enqueue sample: %d\n" , err);
tools/perf/builtin-top.c +1 -1
@@ -879,7 +879,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) }else ++session->evlist->stats.nr_unknown_events; next_event: -perf_mmap__consume (md, opts->overwrite); +perf_mmap__consume (md); }perf_mmap__read_done (md);
tools/perf/builtin-trace.c +1 -1
@@ -2522,7 +2522,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)trace__handle_event (trace, event, &sample); next_event: -perf_mmap__consume (md, false); +perf_mmap__consume (md);if (interrupted) goto out_disable;
tools/perf/tests/code-reading.c +1 -1
@@ -420,7 +420,7 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist,while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { ret =process_event (machine, evlist, event, state); -perf_mmap__consume (md, false); +perf_mmap__consume (md);if (ret <0 )return ret; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -42,7 +42,7 @@ static int find_comm(struct perf_evlist *evlist, const char *comm) (pid_t)event->comm.tid == getpid() && strcmp(event->comm.comm, comm) == 0) found +=1 ; -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md); }
tools/perf/tests/mmap-basic.c +1 -1
@@ -135,7 +135,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse goto out_delete_evlist; } nr_events[evsel->idx]++; -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md);
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -101,7 +101,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest ++nr_events;if (type !=PERF_RECORD_SAMPLE ) { -perf_mmap__consume (md, false); +perf_mmap__consume (md);continue ; }
tools/perf/tests/perf-record.c +1 -1
@@ -272,7 +272,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus ++errs; } -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md); }
tools/perf/tests/sw-clock.c +1 -1
@@ -114,7 +114,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) total_periods += sample.period; nr_samples++; next_event: -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md);
tools/perf/tests/switch-tracking.c +1 -1
@@ -270,7 +270,7 @@ static int process_events(struct perf_evlist *evlist,while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { cnt +=1 ; ret =add_event (evlist, &events, event); -perf_mmap__consume (md, false); +perf_mmap__consume (md);if (ret <0 ) goto out_free_nodes; }
tools/perf/tests/task-exit.c +1 -1
@@ -120,7 +120,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedif (event->header.type ==PERF_RECORD_EXIT ) nr_exit++; -perf_mmap__consume (md, false); +perf_mmap__consume (md); }perf_mmap__read_done (md);
tools/perf/util/mmap.c +3 -3
@@ -118,7 +118,7 @@ void perf_mmap__put(struct perf_mmap *map)perf_mmap__munmap (map); } -void perf_mmap__consume (struct perf_mmap *map,bool overwrite__maybe_unused ) +void perf_mmap__consume (struct perf_mmap *map) {if (!map->overwrite) {u64 old = map->prev;
@@ -260,7 +260,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,WARN_ONCE (1 ,"failed to keep up with mmap data. (warn only once)\n" ); md->prev = head; -perf_mmap__consume (md, overwrite); +perf_mmap__consume (md);return -EAGAIN ; }
@@ -314,7 +314,7 @@ int perf_mmap__push(struct perf_mmap *md, void *to, } md->prev = head; -perf_mmap__consume (md, md->overwrite); +perf_mmap__consume (md); out:return rc; }
tools/perf/util/mmap.h +1 -1
@@ -66,7 +66,7 @@ void perf_mmap__munmap(struct perf_mmap *map);void perf_mmap__get (struct perf_mmap *map);void perf_mmap__put (struct perf_mmap *map); -void perf_mmap__consume (struct perf_mmap *map,bool overwrite); +void perf_mmap__consume (struct perf_mmap *map);static inline u64 perf_mmap__read_head (struct perf_mmap *mm) {
tools/perf/util/python.c +1 -1
@@ -1013,7 +1013,7 @@ 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_mmap__consume (md, false); +perf_mmap__consume (md);if (err) return PyErr_Format(PyExc_OSError,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 28/54 perf mmap: Simplify perf_mmap__read_event()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
It isn't necessary to pass the 'overwrite', 'start' and 'end' argument to perf_mmap__read_event(). Discard them.
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/backward-ring-buffer.c | 2 +- tools/perf/tests/bpf.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/util/mmap.c | 5 +---- tools/perf/util/mmap.h | 4 +--- tools/perf/util/python.c | 2 +- 17 files changed, 17 insertions(+), 22 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -115,7 +115,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeif (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {struct perf_sample sample; if (event->header.type != PERF_RECORD_COMM ||
tools/perf/builtin-kvm.c +1 -1
@@ -757,7 +757,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,if (err <0 )return (err == -EAGAIN ) ?0 :-1 ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) { err =perf_evlist__parse_sample_timestamp (evlist, event, ×tamp);if (err) {perf_mmap__consume (md);
tools/perf/builtin-top.c +1 -1
@@ -824,7 +824,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)if (perf_mmap__read_init (md, opts->overwrite, &start, &end) <0 )return ; -while ((event =perf_mmap__read_event (md, opts->overwrite, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) { ret =perf_evlist__parse_sample (evlist, event, &sample);if (ret) {pr_err ("Can't parse sample, err = %d\n" , ret);
tools/perf/builtin-trace.c +1 -1
@@ -2509,7 +2509,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {struct perf_sample sample; ++trace->nr_events;
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -36,7 +36,7 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,u64 start, end;perf_mmap__read_init (map, true, &start, &end); -while ((event =perf_mmap__read_event (map, true, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (map)) !=NULL ) {const u32 type = event->header.type;switch (type) {
tools/perf/tests/bpf.c +1 -1
@@ -183,7 +183,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),if (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {const u32 type = event->header.type;if (type ==PERF_RECORD_SAMPLE )
tools/perf/tests/code-reading.c +1 -1
@@ -418,7 +418,7 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist,if (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) { ret =process_event (machine, evlist, event, state);perf_mmap__consume (md);if (ret <0 )
tools/perf/tests/keep-tracking.c +1 -1
@@ -36,7 +36,7 @@ static int find_comm(struct perf_evlist *evlist, const char *comm) 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 ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) { if (event->header.type == PERF_RECORD_COMM && (pid_t)event->comm.pid == getpid() && (pid_t)event->comm.tid == getpid() &&
tools/perf/tests/mmap-basic.c +1 -1
@@ -112,7 +112,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuseif (perf_mmap__read_init (md, false, &start, &end) <0 ) goto out_init; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {struct perf_sample sample;if (event->header.type !=PERF_RECORD_SAMPLE ) {
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -93,7 +93,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestif (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {const u32 type = event->header.type;int tp_flags;struct perf_sample sample;
tools/perf/tests/perf-record.c +1 -1
@@ -171,7 +171,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusif (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {const u32 type = event->header.type;const char *name =perf_event__name (type);
tools/perf/tests/sw-clock.c +1 -1
@@ -99,7 +99,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)if (perf_mmap__read_init (md, false, &start, &end) <0 ) goto out_init; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {struct perf_sample sample;if (event->header.type !=PERF_RECORD_SAMPLE )
tools/perf/tests/switch-tracking.c +1 -1
@@ -267,7 +267,7 @@ static int process_events(struct perf_evlist *evlist,if (perf_mmap__read_init (md, false, &start, &end) <0 )continue ; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) { cnt +=1 ; ret =add_event (evlist, &events, event);perf_mmap__consume (md);
tools/perf/tests/task-exit.c +1 -1
@@ -116,7 +116,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedif (perf_mmap__read_init (md, false, &start, &end) <0 ) goto out_init; -while ((event =perf_mmap__read_event (md, false, &start, end)) !=NULL ) { +while ((event =perf_mmap__read_event (md)) !=NULL ) {if (event->header.type ==PERF_RECORD_EXIT ) nr_exit++;
tools/perf/util/mmap.c +1 -4
@@ -75,10 +75,7 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,* } * perf_mmap__read_done() */ -union perf_event *perf_mmap__read_event (struct perf_mmap *map, -bool overwrite__maybe_unused , -u64 *startp__maybe_unused , -u64 end__maybe_unused ) +union perf_event *perf_mmap__read_event (struct perf_mmap *map) {union perf_event *event;
tools/perf/util/mmap.h +1 -3
@@ -89,9 +89,7 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)union perf_event *perf_mmap__read_forward (struct perf_mmap *map); -union perf_event *perf_mmap__read_event (struct perf_mmap *map, -bool overwrite, -u64 *startp,u64 end); +union perf_event *perf_mmap__read_event (struct perf_mmap *map);int perf_mmap__push (struct perf_mmap *md,void *to,int push (void *to,void *buf,size_t size));
tools/perf/util/python.c +1 -1
@@ -995,7 +995,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,if (perf_mmap__read_init (md, false, &start, &end) <0 ) goto end; - event =perf_mmap__read_event (md, false, &start, end); + event =perf_mmap__read_event (md);if (event !=NULL ) {PyObject *pyevent =pyrf_event__new (event);struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 29/54 perf mmap: Simplify perf_mmap__read_init()
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
It isn't necessary to pass the 'start', 'end' and 'overwrite' arguments to perf_mmap__read_init(). The data is stored in the struct perf_mmap.
Discard the parameters.
--- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 3 +-- tools/perf/builtin-kvm.c | 3 +-- tools/perf/builtin-top.c | 3 +-- tools/perf/builtin-trace.c | 3 +-- tools/perf/tests/backward-ring-buffer.c | 3 +-- tools/perf/tests/bpf.c | 3 +-- tools/perf/tests/code-reading.c | 3 +-- tools/perf/tests/keep-tracking.c | 3 +-- tools/perf/tests/mmap-basic.c | 3 +-- tools/perf/tests/openat-syscall-tp-fields.c | 3 +-- tools/perf/tests/perf-record.c | 3 +-- tools/perf/tests/sw-clock.c | 3 +-- tools/perf/tests/switch-tracking.c | 3 +-- tools/perf/tests/task-exit.c | 3 +-- tools/perf/util/mmap.c | 10 ++-------- tools/perf/util/mmap.h | 3 +-- tools/perf/util/python.c | 3 +-- 17 files changed, 18 insertions(+), 40 deletions(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -2
@@ -61,7 +61,6 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeu64 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);
@@ -112,7 +111,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybefor (i =0 ; i < evlist->nr_mmaps; i++) { md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/builtin-kvm.c +1 -2
@@ -746,14 +746,13 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,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 ; md = &evlist->mmap[idx]; - err =perf_mmap__read_init (md, false, &start, &end); + err =perf_mmap__read_init (md);if (err <0 )return (err == -EAGAIN ) ?0 :-1 ;
tools/perf/builtin-top.c +1 -2
@@ -817,11 +817,10 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)struct perf_session *session = top->session;union perf_event *event;struct machine *machine; -u64 end, start;int ret; md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx]; -if (perf_mmap__read_init (md, opts->overwrite, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )return ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/builtin-trace.c +1 -2
@@ -2503,10 +2503,9 @@ 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; md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/backward-ring-buffer.c +1 -2
@@ -33,9 +33,8 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,for (i =0 ; i < evlist->nr_mmaps; i++) {struct perf_mmap *map = &evlist->overwrite_mmap[i];union perf_event *event; -u64 start, end; -perf_mmap__read_init (map, true, &start, &end); +perf_mmap__read_init (map);while ((event =perf_mmap__read_event (map)) !=NULL ) {const u32 type = event->header.type;
tools/perf/tests/bpf.c +1 -2
@@ -177,10 +177,9 @@ 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; md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/code-reading.c +1 -2
@@ -410,12 +410,11 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist, {union perf_event *event;struct perf_mmap *md; -u64 end, start;int i, ret;for (i =0 ; i < evlist->nr_mmaps; i++) { md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/keep-tracking.c +1 -2
@@ -28,13 +28,12 @@ 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++) { md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) { if (event->header.type == PERF_RECORD_COMM &&
tools/perf/tests/mmap-basic.c +1 -2
@@ -39,7 +39,6 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unusestruct 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 ) {
@@ -109,7 +108,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse } md = &evlist->mmap[0 ]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 ) goto out_init;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/openat-syscall-tp-fields.c +1 -2
@@ -87,10 +87,9 @@ 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; md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/perf-record.c +1 -2
@@ -165,10 +165,9 @@ 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; md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/sw-clock.c +1 -2
@@ -40,7 +40,6 @@ 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 ;
@@ -96,7 +95,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)perf_evlist__disable (evlist); md = &evlist->mmap[0 ]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 ) goto out_init;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/switch-tracking.c +1 -2
@@ -259,12 +259,11 @@ static int process_events(struct perf_evlist *evlist,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++) { md = &evlist->mmap[i]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 )continue ;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/tests/task-exit.c +1 -2
@@ -48,7 +48,6 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedstruct cpu_map *cpus;struct thread_map *threads;struct perf_mmap *md; -u64 end, start;signal (SIGCHLD , sig_handler);
@@ -113,7 +112,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused retry: md = &evlist->mmap[0 ]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 ) goto out_init;while ((event =perf_mmap__read_event (md)) !=NULL ) {
tools/perf/util/mmap.c +2 -8
@@ -235,16 +235,13 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u6/* * Report the start and end of the available data in ringbuffer */ -int perf_mmap__read_init (struct perf_mmap *md,bool overwrite, -u64 *startp,u64 *endp) +int perf_mmap__read_init (struct perf_mmap *md) {u64 head =perf_mmap__read_head (md);u64 old = md->prev;unsigned char *data = md->base + page_size;unsigned long size; - *startp = overwrite ? head : old; - *endp = overwrite ? old : head; md->start = md->overwrite ? head : old; md->end = md->overwrite ? old : head;
@@ -267,8 +264,6 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,*/ if (overwrite_rb_find_range (data, md->mask, head, &md->start, &md->end))return -EINVAL ; - *startp = md->start; - *endp = md->end; }return 0 ;
@@ -278,13 +273,12 @@ int perf_mmap__push(struct perf_mmap *md, void *to, int push(void *to, void *buf, size_t size)) {u64 head =perf_mmap__read_head (md); -u64 end, start;unsigned char *data = md->base + page_size;unsigned long size;void *buf;int rc =0 ; - rc =perf_mmap__read_init (md, md->overwrite, &start, &end); + rc =perf_mmap__read_init (md);if (rc <0 )return (rc == -EAGAIN ) ?0 :-1 ;
tools/perf/util/mmap.h +1 -2
@@ -96,7 +96,6 @@ int perf_mmap__push(struct perf_mmap *md, void *to,size_t perf_mmap__mmap_len (struct perf_mmap *map); -int perf_mmap__read_init (struct perf_mmap *md,bool overwrite, -u64 *startp,u64 *endp); +int perf_mmap__read_init (struct perf_mmap *md);void perf_mmap__read_done (struct perf_mmap *map);#endif /*__PERF_MMAP_H */
tools/perf/util/python.c +1 -2
@@ -984,7 +984,6 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,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,
@@ -992,7 +991,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,return NULL ; md = &evlist->mmap[cpu]; -if (perf_mmap__read_init (md, false, &start, &end) <0 ) +if (perf_mmap__read_init (md) <0 ) goto end; event =perf_mmap__read_event (md);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 30/54 perf intel-pt: Fix overlap detection to identify consecutive buffers correctly
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Overlap detection was not not updating the buffer's 'consecutive' flag. Marking buffers consecutive has the advantage that decoding begins from the start of the buffer instead of the first PSB. Fix overlap detection to identify consecutive buffers correctly.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 62 ++++++++++------------ .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 +- tools/perf/util/intel-pt.c | 5 +- 3 files changed, 34 insertions(+), 35 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +29 -33
@@ -2390,14 +2390,6 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)return &decoder->state; } -static bool intel_pt_at_psb (unsigned char *buf,size_t len) -{ -if (len <INTEL_PT_PSB_LEN ) -return false; -return memmem (buf,INTEL_PT_PSB_LEN ,INTEL_PT_PSB_STR , -INTEL_PT_PSB_LEN ); -} -/** * intel_pt_next_psb - move buffer pointer to the start of the next PSB packet. * @buf: pointer to buffer pointer
@@ -2486,6 +2478,7 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)* @buf: buffer * @len: size of buffer * @tsc: TSC value returned +* @rem: returns remaining size when TSC is found * * Find a TSC packet in @buf and return the TSC value. This function assumes * that @buf starts at a PSB and that PSB+ will contain TSC and so stops if a
@@ -2493,7 +2486,8 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)* * Return: %true if TSC is found, false otherwise. */ -static bool intel_pt_next_tsc (unsigned char *buf,size_t len,uint64_t *tsc) +static bool intel_pt_next_tsc (unsigned char *buf,size_t len,uint64_t *tsc, +size_t *rem) {struct intel_pt_pkt packet;int ret;
@@ -2504,6 +2498,7 @@ static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc)return false;if (packet.type ==INTEL_PT_TSC ) { *tsc = packet.payload; + *rem = len;return true; }if (packet.type ==INTEL_PT_PSBEND )
@@ -2554,6 +2549,8 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)* @len_a: size of first buffer * @buf_b: second buffer * @len_b: size of second buffer +* @consecutive: returns true if there is data in buf_b that is consecutive +* to buf_a * * If the trace contains TSC we can look at the last TSC of @buf_a and the * first TSC of @buf_b in order to determine if the buffers overlap, and then
@@ -2566,33 +2563,41 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)static unsigned char *intel_pt_find_overlap_tsc (unsigned char *buf_a,size_t len_a,unsigned char *buf_b, -size_t len_b) +size_t len_b,bool *consecutive) {uint64_t tsc_a, tsc_b;unsigned char *p; -size_t len; +size_t len, rem_a, rem_b; p =intel_pt_last_psb (buf_a, len_a);if (!p)return buf_b;/* No PSB in buf_a => no overlap */ len = len_a - (p - buf_a); -if (!intel_pt_next_tsc (p, len, &tsc_a)) { +if (!intel_pt_next_tsc (p, len, &tsc_a, &rem_a)) {/* The last PSB+ in buf_a is incomplete, so go back one more */ len_a -= len; p =intel_pt_last_psb (buf_a, len_a);if (!p)return buf_b;/* No full PSB+ => assume no overlap */ len = len_a - (p - buf_a); -if (!intel_pt_next_tsc (p, len, &tsc_a)) +if (!intel_pt_next_tsc (p, len, &tsc_a, &rem_a))return buf_b;/* No TSC in buf_a => assume no overlap */ }while (1 ) {/* Ignore PSB+ with no TSC */ -if (intel_pt_next_tsc (buf_b, len_b, &tsc_b) && -intel_pt_tsc_cmp (tsc_a, tsc_b) <0 ) -return buf_b;/* tsc_a < tsc_b => no overlap */ +if (intel_pt_next_tsc (buf_b, len_b, &tsc_b, &rem_b)) { +int cmp =intel_pt_tsc_cmp (tsc_a, tsc_b); + +/* Same TSC, so buffers are consecutive */ +if (!cmp && rem_b >= rem_a) { + *consecutive = true; +return buf_b + len_b - (rem_b - rem_a); + } +if (cmp <0 ) +return buf_b;/* tsc_a < tsc_b => no overlap */ + }if (!intel_pt_step_psb (&buf_b, &len_b))return buf_b + len_b;/* No PSB in buf_b => no data */
@@ -2606,6 +2611,8 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,* @buf_b: second buffer * @len_b: size of second buffer * @have_tsc: can use TSC packets to detect overlap +* @consecutive: returns true if there is data in buf_b that is consecutive +* to buf_a * * When trace samples or snapshots are recorded there is the possibility that * the data overlaps. Note that, for the purposes of decoding, data is only
@@ -2616,7 +2623,7 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,*/ unsigned char *intel_pt_find_overlap (unsigned char *buf_a,size_t len_a,unsigned char *buf_b,size_t len_b, -bool have_tsc) +bool have_tsc,bool *consecutive) {unsigned char *found;
@@ -2628,7 +2635,8 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,return buf_b;/* No overlap */ if (have_tsc) { - found =intel_pt_find_overlap_tsc (buf_a, len_a, buf_b, len_b); + found =intel_pt_find_overlap_tsc (buf_a, len_a, buf_b, len_b, + consecutive);if (found)return found; }
@@ -2643,28 +2651,16 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a, }/* Now len_b >= len_a */ -if (len_b > len_a) { -/* The leftover buffer 'b' must start at a PSB */ -while (!intel_pt_at_psb (buf_b + len_a, len_b - len_a)) { -if (!intel_pt_step_psb (&buf_a, &len_a)) -return buf_b;/* No overlap */ - } - } -while (1 ) {/* Potential overlap so check the bytes */ found =memmem (buf_a, len_a, buf_b, len_a); -if (found) +if (found) { + *consecutive = true;return buf_b + len_a; + }/* Try again at next PSB in buffer 'a' */ if (!intel_pt_step_psb (&buf_a, &len_a))return buf_b;/* No overlap */ - -/* The leftover buffer 'b' must start at a PSB */ -while (!intel_pt_at_psb (buf_b + len_a, len_b - len_a)) { -if (!intel_pt_step_psb (&buf_a, &len_a)) -return buf_b;/* No overlap */ - } } }
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +1 -1
@@ -117,7 +117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);unsigned char *intel_pt_find_overlap (unsigned char *buf_a,size_t len_a,unsigned char *buf_b,size_t len_b, -bool have_tsc); +bool have_tsc,bool *consecutive);int intel_pt__strerror (int code,char *buf,size_t buflen);
tools/perf/util/intel-pt.c +4 -1
@@ -207,14 +207,17 @@ static void intel_pt_dump_event(struct intel_pt *pt, unsigned char *buf,static int intel_pt_do_fix_overlap (struct intel_pt *pt,struct auxtrace_buffer *a,struct auxtrace_buffer *b) { +bool consecutive = false;void *start; start =intel_pt_find_overlap (a->data, a->size, b->data, b->size, - pt->have_tsc); + pt->have_tsc, &consecutive);if (!start)return -EINVAL ; b->use_size = b->data + b->size - start; b->use_data = start; +if (b->use_size && consecutive) + b->consecutive = true;return 0 ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 31/54 perf intel-pt: Fix sync_switch
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
sync_switch is a facility to synchronize decoding more closely with the point in the kernel when the context actually switched.
The flag when sync_switch is enabled was global to the decoding, whereas it is really specific to the CPU.
The trace data for different CPUs is put on different queues, so add sync_switch to the intel_pt_queue structure and use that in preference to the global setting in the intel_pt structure.
That fixes problems decoding one CPU's trace because sync_switch was disabled on a different CPU's queue.
--- tools/perf/util/intel-pt.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
tools/perf/util/intel-pt.c +25 -7
@@ -143,6 +143,7 @@ struct intel_pt_queue {bool stop;bool step_through_buffers;bool use_buffer_pid_tid; +bool sync_switch;pid_t pid, tid;int cpu;int switch_state;
@@ -963,10 +964,12 @@ static int intel_pt_setup_queue(struct intel_pt *pt,if (pt->timeless_decoding || !pt->have_sched_switch) ptq->use_buffer_pid_tid = true; } + + ptq->sync_switch = pt->sync_switch; }if (!ptq->on_heap && - (!pt->sync_switch || + (!ptq->sync_switch || ptq->switch_state !=INTEL_PT_SS_EXPECTING_SWITCH_EVENT )) {const struct intel_pt_state *state;int ret;
@@ -1549,7 +1552,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)if (pt->synth_opts.last_branch)intel_pt_update_last_branch_rb (ptq); -if (!pt->sync_switch) +if (!ptq->sync_switch)return 0 ;if (intel_pt_is_switch_ip (ptq, state->to_ip)) {
@@ -1630,6 +1633,21 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)return switch_ip; } +static void intel_pt_enable_sync_switch (struct intel_pt *pt) +{ +unsigned int i; + + pt->sync_switch = true; + +for (i =0 ; i < pt->queues.nr_queues; i++) { +struct auxtrace_queue *queue = &pt->queues.queue_array[i]; +struct intel_pt_queue *ptq = queue->priv; + +if (ptq) + ptq->sync_switch = true; + } +} +static int intel_pt_run_decoder (struct intel_pt_queue *ptq,u64 *timestamp) {const struct intel_pt_state *state = ptq->state;
@@ -1646,7 +1664,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)if (pt->switch_ip) {intel_pt_log ("switch_ip: %" PRIx64" ptss_ip: %" PRIx64"\n" , pt->switch_ip, pt->ptss_ip); - pt->sync_switch = true; +intel_pt_enable_sync_switch (pt); } } }
@@ -1662,9 +1680,9 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)if (state->err) {if (state->err ==INTEL_PT_ERR_NODATA )return 1 ; -if (pt->sync_switch && +if (ptq->sync_switch && state->from_ip >= pt->kernel_start) { - pt->sync_switch = false; + ptq->sync_switch = false;intel_pt_next_tid (pt, ptq); }if (pt->synth_opts.errors) {
@@ -1690,7 +1708,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) state->timestamp, state->est_timestamp); ptq->timestamp = state->est_timestamp;/* Use estimated TSC in unknown switch state */ - }else if (pt->sync_switch && + }else if (ptq->sync_switch && ptq->switch_state ==INTEL_PT_SS_UNKNOWN &&intel_pt_is_switch_ip (ptq, state->to_ip) && ptq->next_tid ==-1 ) {
@@ -1837,7 +1855,7 @@ static int intel_pt_sync_switch(struct intel_pt *pt, int cpu, pid_t tid,return 1 ; ptq =intel_pt_cpu_to_ptq (pt, cpu); -if (!ptq) +if (!ptq || !ptq->sync_switch)return 1 ;switch (ptq->switch_state) {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 32/54 perf intel-pt: Fix error recovery from missing TIP packet
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
When a TIP packet is expected but there is a different packet, it is an error. However the unexpected packet might be something important like a TSC packet, so after the error, it is necessary to continue from there, rather than the next packet. That is achieved by setting pkt_step to zero.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -1616,6 +1616,7 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)case INTEL_PT_PWRX :intel_pt_log ("ERROR: Missing TIP after FUP\n" ); decoder->pkt_state =INTEL_PT_STATE_ERR3 ; + decoder->pkt_step =0 ;return -ENOENT ;case INTEL_PT_OVF :
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 33/54 perf intel-pt: Fix timestamp following overflow
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
timestamp_insn_cnt is used to estimate the timestamp based on the number of instructions since the last known timestamp.
If the estimate is not accurate enough decoding might not be correctly synchronized with side-band events causing more trace errors.
However there are always timestamps following an overflow, so the estimate is not needed and can indeed result in more errors.
Suppress the estimate by setting timestamp_insn_cnt to zero.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -1378,6 +1378,7 @@ static int intel_pt_overflow(struct intel_pt_decoder *decoder)intel_pt_clear_tx_flags (decoder); decoder->have_tma = false; decoder->cbr =0 ; + decoder->timestamp_insn_cnt =0 ; decoder->pkt_state =INTEL_PT_STATE_ERR_RESYNC ; decoder->overflow = true;return -EOVERFLOW ;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 34/54 perf intel-pt/bts: In auxtrace_record__init_intel() evlist is never NULL
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Tidy auxtrace_record__init_intel() slightly by recognizing that evlist is never NULL.
--- tools/perf/arch/x86/util/auxtrace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
tools/perf/arch/x86/util/auxtrace.c +5 -9
@@ -37,15 +37,11 @@ struct auxtrace_record *auxtrace_record__init_intel(struct perf_evlist *evlist, intel_pt_pmu =perf_pmu__find (INTEL_PT_PMU_NAME ); intel_bts_pmu =perf_pmu__find (INTEL_BTS_PMU_NAME ); -if (evlist) { -evlist__for_each_entry (evlist, evsel) { -if (intel_pt_pmu && - evsel->attr.type == intel_pt_pmu->type) - found_pt = true; -if (intel_bts_pmu && - evsel->attr.type == intel_bts_pmu->type) - found_bts = true; - } +evlist__for_each_entry (evlist, evsel) { +if (intel_pt_pmu && evsel->attr.type == intel_pt_pmu->type) + found_pt = true; +if (intel_bts_pmu && evsel->attr.type == intel_bts_pmu->type) + found_bts = true; }if (found_pt && found_bts) {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 35/54 perf intel-pt: Get rid of intel_pt_use_buffer_pid_tid()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
With the new way sampling support will be implemented, intel_pt_use_buffer_pid_tid() will not be needed. Get rid of it.
--- tools/perf/util/intel-pt.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-)
tools/perf/util/intel-pt.c +3 -36
@@ -222,32 +222,6 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *return 0 ; } -static void intel_pt_use_buffer_pid_tid (struct intel_pt_queue *ptq, -struct auxtrace_queue *queue, -struct auxtrace_buffer *buffer) -{ -if (queue->cpu ==-1 && buffer->cpu !=-1 ) - ptq->cpu = buffer->cpu; - - ptq->pid = buffer->pid; - ptq->tid = buffer->tid; - -intel_pt_log ("queue %u cpu %d pid %d tid %d\n" , - ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); - -thread__zput (ptq->thread); - -if (ptq->tid !=-1 ) { -if (ptq->pid !=-1 ) - ptq->thread =machine__findnew_thread (ptq->pt->machine, - ptq->pid, - ptq->tid); -else - ptq->thread =machine__find_thread (ptq->pt->machine,-1 , - ptq->tid); - } -} -/* This function assumes data is processed sequentially only */ static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) {
@@ -311,10 +285,6 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) b->consecutive = true; } -if (ptq->use_buffer_pid_tid && (ptq->pid != buffer->pid || - ptq->tid != buffer->tid)) -intel_pt_use_buffer_pid_tid (ptq, queue, buffer); -if (ptq->step_through_buffers) ptq->stop = true;
@@ -958,12 +928,9 @@ static int intel_pt_setup_queue(struct intel_pt *pt, ptq->cpu = queue->cpu; ptq->tid = queue->tid; -if (pt->sampling_mode) { -if (pt->timeless_decoding) - ptq->step_through_buffers = true; -if (pt->timeless_decoding || !pt->have_sched_switch) - ptq->use_buffer_pid_tid = true; - } +if (pt->sampling_mode && !pt->snapshot_mode && + pt->timeless_decoding) + ptq->step_through_buffers = true; ptq->sync_switch = pt->sync_switch; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 36/54 perf intel-pt: Tidy old_buffer handling in intel_pt_get_trace()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
intel_pt_get_trace() fixes overlaps between the current buffer and the previous buffer ('old_buffer').
However the previous buffer might not have had usable data (no PSB) so the comparison must be made against the previous buffer that had usable data.
Tidy that by keeping a pointer for that purpose in struct intel_pt_queue.
--- tools/perf/util/intel-pt.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
tools/perf/util/intel-pt.c +11 -13
@@ -132,6 +132,7 @@ struct intel_pt_queue {struct intel_pt *pt;unsigned int queue_nr;struct auxtrace_buffer *buffer; +struct auxtrace_buffer *old_buffer;void *decoder;const struct intel_pt_state *state;struct ip_callchain *chain;
@@ -226,7 +227,8 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) {struct intel_pt_queue *ptq = data; -struct auxtrace_buffer *buffer = ptq->buffer, *old_buffer = buffer; +struct auxtrace_buffer *buffer = ptq->buffer; +struct auxtrace_buffer *old_buffer = ptq->old_buffer;struct auxtrace_queue *queue;if (ptq->stop) {
@@ -235,7 +237,7 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) } queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; -next: + buffer =auxtrace_buffer__next (queue, buffer);if (!buffer) {if (old_buffer)
@@ -267,16 +269,6 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) } b->ref_timestamp = buffer->reference; -/* -* If in snapshot mode and the buffer has no usable data, get next -* buffer and again check overlap against old_buffer. -*/ -if (ptq->pt->snapshot_mode && !b->len) - goto next; - -if (old_buffer) -auxtrace_buffer__drop_data (old_buffer); -if (!old_buffer || ptq->pt->sampling_mode || (ptq->pt->snapshot_mode && !buffer->consecutive)) { b->consecutive = false;
@@ -288,8 +280,14 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)if (ptq->step_through_buffers) ptq->stop = true; -if (!b->len) +if (b->len) { +if (old_buffer) +auxtrace_buffer__drop_data (old_buffer); + ptq->old_buffer = buffer; + }else { +auxtrace_buffer__drop_data (buffer);return intel_pt_get_trace (b, data); + }return 0 ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 37/54 perf intel-pt: Remove a check for sampling mode
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Intel PT code already has some preparation for AUX area sampling mode.
However the implementation has changed from the first proposal and one of the side-effects is that it will not be impossible to support snapshot mode and sampling mode at the same time.
Although there are no plans to support it, let validation (not yet implemented) control whether it is allowed rather than low-level functions.
--- tools/perf/util/intel-pt.c | 3 --- 1 file changed, 3 deletions(-)
tools/perf/util/intel-pt.c +0 -3
@@ -2061,9 +2061,6 @@ static int intel_pt_process_auxtrace_event(struct perf_session *session, struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, auxtrace); -if (pt->sampling_mode) -return 0 ; -if (!pt->data_queued) {struct auxtrace_buffer *buffer;off_t data_offset;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 38/54 perf intel-pt: Adjust overlap-checking to support sampling mode
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Adjust overlap-checking to support sampling mode.
--- tools/perf/util/intel-pt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt.c +4 -3
@@ -230,6 +230,7 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)struct auxtrace_buffer *buffer = ptq->buffer;struct auxtrace_buffer *old_buffer = ptq->old_buffer;struct auxtrace_queue *queue; +bool might_overlap;if (ptq->stop) { b->len =0 ;
@@ -256,7 +257,8 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)return -ENOMEM ; } -if (ptq->pt->snapshot_mode && !buffer->consecutive && old_buffer && + might_overlap = ptq->pt->snapshot_mode || ptq->pt->sampling_mode; +if (might_overlap && !buffer->consecutive && old_buffer &&intel_pt_do_fix_overlap (ptq->pt, old_buffer, buffer))return -ENOMEM ;
@@ -269,8 +271,7 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) } b->ref_timestamp = buffer->reference; -if (!old_buffer || ptq->pt->sampling_mode || (ptq->pt->snapshot_mode && - !buffer->consecutive)) { +if (!old_buffer || (might_overlap && !buffer->consecutive)) { b->consecutive = false; b->trace_nr = buffer->buffer_nr +1 ; }else {
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 39/54 perf annotate: Fix s390 target function disassembly
In reply to Arnaldo Carvalho de MeloFrom: Thomas Richter <[email protected]>
'perf annotate' displays function call assembler instructions with a right arrow. Hitting enter on this line/instruction causes the browser to disassemble this target function and show it on the screen. On s390 this results in an error message 'The called function was not found.'
The function call assembly line parsing does not handle the s390 bras and brasl instructions. Function call__parse expects the target as first operand:
callq e9140 <__fxstat>
S390 has a register number as first operand:
brasl %r14,41d60 <abort>
Therefore the target addresses on s390 are always zero which is an invalid address.
Introduce a s390 specific call parsing function which skips the first operand on s390.
--- tools/perf/arch/s390/annotate/instructions.c | 53 +++++++++++++++++++++++++++- tools/perf/util/annotate.c | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-)
tools/perf/arch/s390/annotate/instructions.c +52 -1
@@ -1,6 +1,57 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> +static int s390_call__parse (struct arch *arch,struct ins_operands *ops, +struct map *map) +{ +char *endptr, *tok, *name; +struct addr_map_symbol target = { + .map = map, + }; + + tok =strchr (ops->raw,',' ); +if (!tok) +return -1 ; + + ops->target.addr =strtoull (tok +1 , &endptr,16 ); + + name =strchr (endptr,'<' ); +if (name ==NULL ) +return -1 ; + + name++; + +if (arch->objdump.skip_functions_char && +strchr (name, arch->objdump.skip_functions_char)) +return -1 ; + + tok =strchr (name,'>' ); +if (tok ==NULL ) +return -1 ; + + *tok ='\0' ; + ops->target.name =strdup (name); + *tok ='>' ; + +if (ops->target.name ==NULL ) +return -1 ; + target.addr =map__objdump_2mem (map, ops->target.addr); + +if (map_groups__find_ams (&target) ==0 && +map__rip_2objdump (target.map, map->map_ip (target.map, target.addr)) == ops->target.addr) + ops->target.sym = target.sym; + +return 0 ; +} + +static int call__scnprintf (struct ins *ins,char *bf,size_t size, +struct ins_operands *ops); + +static struct ins_ops s390_call_ops = { + .parse = s390_call__parse, + .scnprintf = call__scnprintf, +}; +static struct ins_ops *s390__associate_ins_ops (struct arch *arch,const char *name) {struct ins_ops *ops =NULL ;
@@ -14,7 +65,7 @@ static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *naif (!strcmp (name,"bras" ) || !strcmp (name,"brasl" ) || !strcmp (name,"basr" )) - ops = &call_ops; + ops = &s390_call_ops;if (!strcmp (name,"br" )) ops = &ret_ops;
tools/perf/util/annotate.c +1 -1
@@ -248,7 +248,7 @@ static struct ins_ops call_ops = {bool ins__is_call (const struct ins *ins) { -return ins->ops == &call_ops; +return ins->ops == &call_ops || ins->ops == &s390_call_ops; }static int jump__parse (struct arch *arch__maybe_unused ,struct ins_operands *ops,struct map *map__maybe_unused )
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 40/54 perf report: Fix the output for stdio events list
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Changing the output header for reporting forced groups via --groups option on non grouped events, like:
$ perf record -e 'cycles,instructions' $ perf report --stdio --group
Before:
# Samples: 24 of event 'anon group { cycles:u, instructions:u }'
After:
# Samples: 24 of events 'cycles:u, instructions:u'
--- tools/perf/builtin-report.c | 17 ++++++++++++++--- tools/perf/ui/browsers/hists.c | 5 +++-- tools/perf/util/evsel.c | 20 ++++++++++++++++---- tools/perf/util/evsel.h | 1 + 4 files changed, 34 insertions(+), 9 deletions(-)
tools/perf/builtin-report.c +14 -3
@@ -400,8 +400,10 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report nr_samples =convert_unit (nr_samples, &unit); ret =fprintf (fp,"# Samples: %lu%c" , nr_samples, unit); -if (evname !=NULL ) - ret +=fprintf (fp," of event '%s'" , evname); +if (evname !=NULL ) { + ret +=fprintf (fp," of event%s '%s'" , + evsel->nr_members >1 ?"s" :"" , evname); + }if (rep->time_str) ret +=fprintf (fp," (time slices: %s)" , rep->time_str);
@@ -1175,8 +1177,17 @@ int cmd_report(int argc, const char **argv) has_br_stack =perf_header__has_feat (&session->header,HEADER_BRANCH_STACK ); -if (group_set && !session->evlist->nr_groups) +/* +* Events in data file are not collect in groups, but we still want +* the group display. Set the artificial group and set the leader's +* forced_leader flag to notify the display code. +*/ +if (group_set && !session->evlist->nr_groups) { +struct perf_evsel *leader =perf_evlist__first (session->evlist); +perf_evlist__set_leader (session->evlist); + leader->forced_leader = true; + }if (itrace_synth_opts.last_branch) has_br_stack = true;
tools/perf/ui/browsers/hists.c +3 -2
@@ -2261,8 +2261,9 @@ static int perf_evsel_browser_title(struct hist_browser *browser, nr_samples =convert_unit (nr_samples, &unit); printed =scnprintf (bf, size, -"Samples: %lu%c of event '%s',%s%sEvent count (approx.): %" PRIu64, - nr_samples, unit, ev_name, sample_freq_str, enable_ref ? ref :" " , nr_events); +"Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64, + nr_samples, unit, evsel->nr_members >1 ?"s" :"" , + ev_name, sample_freq_str, enable_ref ? ref :" " , nr_events);if (hists->uid_filter_str)
tools/perf/util/evsel.c +16 -4
@@ -622,22 +622,34 @@ const char *perf_evsel__group_name(struct perf_evsel *evsel)return evsel->group_name ?:"anon group" ; } +/* +* Returns the group details for the specified leader, +* with following rules. +* +* For record -e '{cycles,instructions}' +* 'anon group { cycles:u, instructions:u }' +* +* For record -e 'cycles,instructions' and report --group +* 'cycles:u, instructions:u' +*/ int perf_evsel__group_desc (struct perf_evsel *evsel,char *buf,size_t size) { -int ret; +int ret =0 ;struct perf_evsel *pos;const char *group_name =perf_evsel__group_name (evsel); - ret =scnprintf (buf, size,"%s" , group_name); +if (!evsel->forced_leader) + ret =scnprintf (buf, size,"%s { " , group_name); - ret +=scnprintf (buf + ret, size - ret," { %s" , + ret +=scnprintf (buf + ret, size - ret,"%s" ,perf_evsel__name (evsel));for_each_group_member (pos, evsel) ret +=scnprintf (buf + ret, size - ret,", %s" ,perf_evsel__name (pos)); - ret +=scnprintf (buf + ret, size - ret," }" ); +if (!evsel->forced_leader) + ret +=scnprintf (buf + ret, size - ret," }" );return ret; }
tools/perf/util/evsel.h +1 -0
@@ -125,6 +125,7 @@ struct perf_evsel {bool per_pkg;bool precise_max;bool ignore_missing_thread; +bool forced_leader;/* parse modifier helper */ int exclude_GH;int nr_members;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 41/54 perf report: Display perf.data header info
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Display more header info from perf.data file, following values:
$ perf report -i perf.data --header-only ... # header version : 1 # data offset : 424 # data size : 3364280 # feat offset : 3364704
It's handy for debuging.
--- tools/perf/util/header.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/header.c +6 -1
@@ -2318,7 +2318,12 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)if (ret ==-1 )return -1 ; -fprintf (fp,"# captured on: %s" ,ctime (&st.st_ctime)); +fprintf (fp,"# captured on : %s" ,ctime (&st.st_ctime)); + +fprintf (fp,"# header version : %u\n" , header->version); +fprintf (fp,"# data offset : %" PRIu64"\n" , header->data_offset); +fprintf (fp,"# data size : %" PRIu64"\n" , header->data_size); +fprintf (fp,"# feat offset : %" PRIu64"\n" , header->feat_offset);perf_header__process_sections (header, fd, &hd, perf_file_section__fprintf_info);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 42/54 perf record: Move machine variable down the function
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It's used far more down to be declared on the top of the __cmd_record.
--- tools/perf/builtin-record.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/builtin-record.c +1 -3
@@ -854,7 +854,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)int status =0 ;unsigned long waking =0 ;const bool forks = argc >0 ; -struct machine *machine;struct perf_tool *tool = &rec->tool;struct record_opts *opts = &rec->opts;struct perf_data *data = &rec->data;
@@ -959,8 +958,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } - machine = &session->machines.host; - err =record__synthesize (rec, false);if (err <0 ) goto out_child;
@@ -988,6 +985,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)* Let the child rip */ if (forks) { +struct machine *machine = &session->machines.host;union perf_event *event;pid_t tgid;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 43/54 perf record: Remove progname from struct record
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It's no longer used.
--- tools/perf/builtin-record.c | 3 --- 1 file changed, 3 deletions(-)
tools/perf/builtin-record.c +0 -3
@@ -71,7 +71,6 @@ struct record {struct auxtrace_record *itr;struct perf_evlist *evlist;struct perf_session *session; -const char *progname;int realtime_prio;bool no_buildid;bool no_buildid_set;
@@ -861,8 +860,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)bool disabled = false, draining = false;int fd; - rec->progname = argv[0 ]; -atexit (record__sig_exit);signal (SIGCHLD , sig_handler);signal (SIGINT , sig_handler);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 44/54 perf tools: Add refcnt into struct mem_info
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It's passed along several hists entries in --hierarchy mode, so it's better we keep track of it.
The current fail I see is that it gets removed in hierarchy --mem-mode mode, where it's shared in the different hierarchies, but removed from the template hist entry, so the report crashes.
--- tools/perf/util/hist.c | 4 ++-- tools/perf/util/machine.c | 2 +- tools/perf/util/symbol.c | 22 ++++++++++++++++++++++ tools/perf/util/symbol.h | 19 ++++++++++++++++--- 4 files changed, 41 insertions(+), 6 deletions(-)
tools/perf/util/hist.c +2 -2
@@ -536,7 +536,7 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,* This mem info was allocated from sample__resolve_mem * and will not be used anymore. */ -zfree (&entry->mem_info); +mem_info__zput (entry->mem_info);/* If the map of an existing hist_entry has * become out-of-date due to an exec() or
@@ -1139,7 +1139,7 @@ void hist_entry__delete(struct hist_entry *he)if (he->mem_info) {map__zput (he->mem_info->iaddr.map);map__zput (he->mem_info->daddr.map); -zfree (&he->mem_info); +mem_info__zput (he->mem_info); }zfree (&he->stat_acc);
tools/perf/util/machine.c +1 -1
@@ -1697,7 +1697,7 @@ static void ip__resolve_data(struct thread *thread,struct mem_info *sample__resolve_mem (struct perf_sample *sample,struct addr_location *al) { -struct mem_info *mi =zalloc (sizeof (*mi)); +struct mem_info *mi =mem_info__new ();if (!mi)return NULL ;
tools/perf/util/symbol.c +22 -0
@@ -2221,3 +2221,25 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,free (bf);return 0 ; } + +struct mem_info *mem_info__get (struct mem_info *mi) +{ +if (mi) +refcount_inc (&mi->refcnt); +return mi; +} + +void mem_info__put (struct mem_info *mi) +{ +if (mi &&refcount_dec_and_test (&mi->refcnt)) +free (mi); +} + +struct mem_info *mem_info__new (void ) +{ +struct mem_info *mi =zalloc (sizeof (*mi)); + +if (mi) +refcount_set (&mi->refcnt,1 ); +return mi; +}
tools/perf/util/symbol.h +16 -3
@@ -200,9 +200,10 @@ struct branch_info { };struct mem_info { -struct addr_map_symbol iaddr; -struct addr_map_symbol daddr; -union perf_mem_data_src data_src; +struct addr_map_symbol iaddr; +struct addr_map_symbol daddr; +union perf_mem_data_src data_src; +refcount_t refcnt; };struct addr_location {
@@ -389,4 +390,16 @@ int sdt_notes__get_count(struct list_head *start);#define SDT_NOTE_NAME "stapsdt"#define NR_ADDR 3 +struct mem_info *mem_info__new (void ); +struct mem_info *mem_info__get (struct mem_info *mi); +void mem_info__put (struct mem_info *mi); + +static inline void __mem_info__zput (struct mem_info **mi) +{ +mem_info__put (*mi); + *mi =NULL ; +} + +#define mem_info__zput (mi) __mem_info__zput(&mi) +#endif /* __PERF_SYMBOL */
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 45/54 perf c2c: Use mem_info refcnt logic
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Switch to refcnt logic instead of duplicating mem_info objects. No functional change, just saving some memory.
--- tools/perf/builtin-c2c.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
tools/perf/builtin-c2c.c +11 -13
@@ -237,9 +237,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,if (mi ==NULL )return -ENOMEM ; - mi_dup =memdup (mi,sizeof (*mi)); -if (!mi_dup) - goto free_mi; +/* +* The mi object is released in hists__add_entry_ops, +* if it gets sorted out into existing data, so we need +* to take the copy now. +*/ + mi_dup =mem_info__get (mi);c2c_decode_stats (&stats, mi);
@@ -247,7 +250,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, &al,NULL ,NULL , mi, sample, true);if (he ==NULL ) - goto free_mi_dup; + goto free_mi; c2c_he = container_of(he, struct c2c_hist_entry, he);c2c_add_stats (&c2c_he->stats, &stats);
@@ -272,19 +275,15 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, mi = mi_dup; - mi_dup =memdup (mi,sizeof (*mi)); -if (!mi_dup) - goto free_mi; - c2c_hists =he__get_c2c_hists (he, c2c.cl_sort,2 );if (!c2c_hists) - goto free_mi_dup; + goto free_mi; he =hists__add_entry_ops (&c2c_hists->hists, &c2c_entry_ops, &al,NULL ,NULL , mi, sample, true);if (he ==NULL ) - goto free_mi_dup; + goto free_mi; c2c_he = container_of(he, struct c2c_hist_entry, he);c2c_add_stats (&c2c_he->stats, &stats);
@@ -303,10 +302,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,addr_location__put (&al);return ret; -free_mi_dup: -free (mi_dup); free_mi: -free (mi); +mem_info__put (mi_dup); +mem_info__put (mi); ret = -ENOMEM ; goto out; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 46/54 perf tools: Add MEM_TOPOLOGY feature to perf data file
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding MEM_TOPOLOGY feature to perf data file,
that will carry physical memory map and its
node assignments.
The format of data in MEM_TOPOLOGY is as follows:
0 - version | for future changes 8 - block_size_bytes | /sys/devices/system/memory/block_size_bytes 16 - count | number of nodes
For each node we store map of physical indexes for each node:
32 - node id | node index
40 - size | size of bitmap
48 - bitmap | bitmap of memory indexes that belongs to node
| /sys/devices/system/node/node<NODE>/memory<INDEX>The MEM_TOPOLOGY could be displayed with following report command:
$ perf report --header-only -I ... # memory nodes (nr 1, block size 0x8000000): # 0 [7G]: 0-23,32-69
--- tools/include/linux/bitmap.h | 2 +- tools/perf/util/env.h | 9 ++ tools/perf/util/header.c | 305 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/header.h | 1 + 4 files changed, 316 insertions(+), 1 deletion(-)
tools/include/linux/bitmap.h +1 -1
@@ -98,7 +98,7 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)/** * bitmap_alloc - Allocate bitmap -* @nr: Bit to set +* @nbits: Number of bits */ static inline unsigned long *bitmap_alloc (int nbits) {
tools/perf/util/env.h +9 -0
@@ -27,6 +27,12 @@ struct numa_node {struct cpu_map *map; }; +struct memory_node { +u64 node; +u64 size; +unsigned long *set; +}; +struct perf_env {char *hostname;char *os_release;
@@ -43,6 +49,7 @@ struct perf_env {int nr_sibling_cores;int nr_sibling_threads;int nr_numa_nodes; +int nr_memory_nodes;int nr_pmu_mappings;int nr_groups;char *cmdline;
@@ -54,6 +61,8 @@ struct perf_env {struct cpu_cache_level *caches;int caches_cnt;struct numa_node *numa_nodes; +struct memory_node *memory_nodes; +unsigned long long memory_bsize; };extern struct perf_env perf_env;
tools/perf/util/header.c +305 -0
353 lines not on this page · raw message
tools/perf/util/header.h +1 -0
@@ -36,6 +36,7 @@ enum {HEADER_STAT ,HEADER_CACHE ,HEADER_SAMPLE_TIME , +HEADER_MEM_TOPOLOGY ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 47/54 perf tools: Update tags with .cpp files
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
We have some .cpp files, make ctags/cscope aware of them.
--- tools/perf/Makefile.perf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +3 -3
@@ -708,15 +708,15 @@ TAG_FILES= ../../include/uapi/linux/perf_event.h TAGS: $(QUIET_GEN)$(RM) TAGS; \ - $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs etags -a $(TAG_FILES) + $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs etags -a $(TAG_FILES) tags: $(QUIET_GEN)$(RM) tags; \ - $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs ctags -a $(TAG_FILES) + $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs ctags -a $(TAG_FILES) cscope: $(QUIET_GEN)$(RM) cscope*; \ - $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs cscope -b $(TAG_FILES) + $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs cscope -b $(TAG_FILES) ### Testing rules
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 48/54 perf build: Add llvm/clang/cxx make tests into FEATURE_TESTS_EXTRA
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
So we can see the status when we build perf, like:
$ make LIBCLANGLLVM=1 VF=1 ... cxx: [ on ] ... llvm: [ on ] ... llvm-version: [ on ] ... clang: [ on ]
--- tools/build/Makefile.feature | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/build/Makefile.feature +5 -1
@@ -82,7 +82,11 @@ FEATURE_TESTS_EXTRA := \ liberty-z \ libunwind-debug-frame \ libunwind-debug-frame-arm \ - libunwind-debug-frame-aarch64 + libunwind-debug-frame-aarch64 \ + cxx \ + llvm \ + llvm-version \ + clang FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 49/54 perf build: Add llvm/clang make targets to FILES
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
So they can follow the OUTPUT variable setup as the rest of the features.
--- tools/build/feature/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/build/feature/Makefile +4 -1
@@ -54,7 +54,10 @@ FILES= \ test-jvmti.bin \ test-sched_getcpu.bin \ test-setns.bin \ - test-libopencsd.bin + test-libopencsd.bin \ + test-clang.bin \ + test-llvm.bin \ + test-llvm-version.bin FILES := $(addprefix $(OUTPUT),$(FILES))
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 50/54 perf build: Force llvm/clang test compile output to .make.output
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
So we can see the output of feature compile in following files:
tools/build/feature/test-llvm.make.output tools/build/feature/test-llvm-version.make.output tools/build/feature/test-clang.make.output
--- tools/build/feature/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/build/feature/Makefile +6 -3
@@ -260,11 +260,13 @@ $(OUTPUT)test-llvm.bin: -I$(shell $(LLVM_CONFIG) --includedir) \ -L$(shell $(LLVM_CONFIG) --libdir) \ $(shell $(LLVM_CONFIG) --libs Core BPF) \ - $(shell $(LLVM_CONFIG) --system-libs) + $(shell $(LLVM_CONFIG) --system-libs) \ + > $(@:.bin=.make.output) 2>&1 $(OUTPUT)test-llvm-version.bin: $(BUILDXX) -std=gnu++11 \ - -I$(shell $(LLVM_CONFIG) --includedir) + -I$(shell $(LLVM_CONFIG) --includedir) \ + > $(@:.bin=.make.output) 2>&1 $(OUTPUT)test-clang.bin: $(BUILDXX) -std=gnu++11 \
@@ -274,7 +276,8 @@ $(OUTPUT)test-clang.bin: -lclangFrontend -lclangEdit -lclangLex \ -lclangAST -Wl,--end-group \ $(shell $(LLVM_CONFIG) --libs Core option) \ - $(shell $(LLVM_CONFIG) --system-libs) + $(shell $(LLVM_CONFIG) --system-libs) \ + > $(@:.bin=.make.output) 2>&1 -include $(OUTPUT)*.d
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 51/54 perf report: Provide libtraceevent with a kernel symbol resolver
In reply to Arnaldo Carvalho de MeloFrom: Wang YanQing <[email protected]>
So that beautifiers wanting to resolve kernel function addresses to names can do its work, and when we use "perf report" for output of "perf kmem record", we will get kernel symbol output.
This patch affect the output of "perf report" for the record data generated by "perf kmem record" looks like below:
Before patch:
0.01% call_site=ffffffff814e5828 ptr=0x99bb000 bytes_req=3616 bytes_alloc=4096 gfp_flags=GFP_ATOMIC 0.01% call_site=ffffffff81370b87 ptr=0x428a3060 bytes_req=32 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO
After patch:
0.01% (aa_alloc_task_context+0x27) call_site=ffffffff81370b87 ptr=0x428a3060 bytes_req=32 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO 0.01% (__tty_buffer_request_room+0x88) call_site=ffffffff814e5828 ptr=0x99bb000 bytes_req=3616 bytes_alloc=4096 gfp_flags=GFP_ATOMIC
--- tools/perf/builtin-report.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/builtin-report.c +9 -0
@@ -1348,6 +1348,15 @@ int cmd_report(int argc, const char **argv) report.range_num =1 ; } +if (session->tevent.pevent && +pevent_set_function_resolver (session->tevent.pevent, + machine__resolve_kernel_addr, + &session->machines.host) <0 ) { +pr_err ("%s: failed to set libtraceevent function resolver\n" , + __func__); +return -1 ; + } +sort__setup_elide (stdout); ret =__cmd_report (&report);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 52/54 perf annotate: Support to display the IPC/Cycle in TUI mode
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Unlike the perf report interactive annotate mode, the perf annotate doesn't display the IPC/Cycle even if branch info is recorded in perf data file.
perf record -b ...
perf annotate function
It should show IPC/cycle, but it doesn't.
This patch lets perf annotate support the displaying of IPC/Cycle if branch info is in perf data.
For example,
perf annotate compute_flag
Percent│ IPC Cycle
│
│
│ Disassembly of section .text:
│
│ 0000000000400640 <compute_flag>:
│ compute_flag():
│ volatile int count;
│ static unsigned int s_randseed;
│
│ __attribute__((noinline))
│ int compute_flag()
│ {
22.96 │1.18 584 sub $0x8,%rsp
│ int i;
│
│ i = rand() % 2;
23.02 │1.18 1 → callq rand@plt
│
│ return i;
27.05 │3.37 mov %eax,%edx
│ }
│3.37 add $0x8,%rsp
│ {
│ int i;
│
│ i = rand() % 2;
│
│ return i;
│3.37 shr $0x1f,%edx
│3.37 add %edx,%eax
│3.37 and $0x1,%eax
│3.37 sub %edx,%eax
│ }
26.97 │3.37 2 ← retqNote that, this patch only supports TUI mode. For stdio, now it just keeps original behavior. Will support it in a follow-up patch.
$ perf annotate compute_flag --stdio
Percent | Source code & Disassembly of div for cycles:ppp (7993 samples)
------------------------------------------------------------------------------
:
:
:
: Disassembly of section .text:
:
: 0000000000400640 <compute_flag>:
: compute_flag():
: volatile int count;
: static unsigned int s_randseed;
:
: __attribute__((noinline))
: int compute_flag()
: {
0.29 : 400640: sub $0x8,%rsp # +100.00%
: int i;
:
: i = rand() % 2;
42.93 : 400644: callq 400490 <rand@plt> # -100.00% (p:100.00%)
:
: return i;
0.10 : 400649: mov %eax,%edx # +100.00%
: }
0.94 : 40064b: add $0x8,%rsp
: {
: int i;
:
: i = rand() % 2;
:
: return i;
27.02 : 40064f: shr $0x1f,%edx
0.15 : 400652: add %edx,%eax
1.24 : 400654: and $0x1,%eax
2.08 : 400657: sub %edx,%eax
: }
25.26 : 400659: retq # -100.00% (p:100.00%)--- tools/perf/builtin-annotate.c | 88 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 6 deletions(-)
tools/perf/builtin-annotate.c +82 -6
@@ -44,6 +44,7 @@ struct perf_annotate {bool full_paths;bool print_line;bool skip_missing; +bool has_br_stack;const char *sym_hist_filter;const char *cpu_list;DECLARE_BITMAP (cpu_bitmap,MAX_NR_CPUS );
@@ -146,16 +147,73 @@ static void process_branch_stack(struct branch_stack *bs, struct addr_location *free (bi); } +static int hist_iter__branch_callback (struct hist_entry_iter *iter, +struct addr_location *al__maybe_unused , +bool single__maybe_unused , +void *arg__maybe_unused ) +{ +struct hist_entry *he = iter->he; +struct branch_info *bi; +struct perf_sample *sample = iter->sample; +struct perf_evsel *evsel = iter->evsel; +int err; + +hist__account_cycles (sample->branch_stack, al, sample, false); + + bi = he->branch_info; + err =addr_map_symbol__inc_samples (&bi->from, sample, evsel->idx); + +if (err) + goto out; + + err =addr_map_symbol__inc_samples (&bi->to, sample, evsel->idx); + +out: +return err; +} + +static int process_branch_callback (struct perf_evsel *evsel, +struct perf_sample *sample, +struct addr_location *al__maybe_unused , +struct perf_annotate *ann, +struct machine *machine) +{ +struct hist_entry_iter iter = { + .evsel = evsel, + .sample = sample, + .add_entry_cb = hist_iter__branch_callback, + .hide_unresolved = symbol_conf.hide_unresolved, + .ops = &hist_iter_branch, + }; + +struct addr_location a; +int ret; + +if (machine__resolve (machine, &a, sample) <0 ) +return -1 ; + +if (a.sym ==NULL ) +return 0 ; + +if (a.map !=NULL ) + a.map->dso->hit =1 ; + + ret =hist_entry_iter__add (&iter, &a,PERF_MAX_STACK_DEPTH , ann); +return ret; +} +static int perf_evsel__add_sample (struct perf_evsel *evsel,struct perf_sample *sample,struct addr_location *al, -struct perf_annotate *ann) +struct perf_annotate *ann, +struct machine *machine) {struct hists *hists =evsel__hists (evsel);struct hist_entry *he;int ret; -if (ann->sym_hist_filter !=NULL && +if ((!ann->has_br_stack || !ui__has_annotation ()) && + ann->sym_hist_filter !=NULL && (al->sym ==NULL ||strcmp (ann->sym_hist_filter, al->sym->name) !=0 )) {/* We're only interested in a symbol named sym_hist_filter */
@@ -178,6 +236,9 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,*/ process_branch_stack (sample->branch_stack, al, sample); +if (ann->has_br_stack &&ui__has_annotation ()) +return process_branch_callback (evsel, sample, al, ann, machine); + he =hists__add_entry (hists, al,NULL ,NULL ,NULL , sample, true);if (he ==NULL )return -ENOMEM ;
@@ -206,7 +267,8 @@ static int process_sample_event(struct perf_tool *tool,if (ann->cpu_list && !test_bit (sample->cpu, ann->cpu_bitmap)) goto out_put; -if (!al.filtered &&perf_evsel__add_sample (evsel, sample, &al, ann)) { +if (!al.filtered && +perf_evsel__add_sample (evsel, sample, &al, ann, machine)) {pr_warning ("problem incrementing symbol count, " "skipping event\n" ); ret =-1 ;
@@ -238,6 +300,10 @@ static void hists__find_annotations(struct hists *hists,if (he->ms.sym ==NULL || he->ms.map->dso->annotate_warned) goto find_next; +if (ann->sym_hist_filter && + (strcmp (he->ms.sym->name, ann->sym_hist_filter) !=0 )) + goto find_next; + notes =symbol__annotation (he->ms.sym);if (notes->src ==NULL ) { find_next:
@@ -269,6 +335,7 @@ static void hists__find_annotations(struct hists *hists, nd =rb_next (nd); }else if (use_browser ==1 ) { key =hist_entry__tui_annotate (he, evsel,NULL ); +switch (key) {case -1 :if (!ann->skip_missing)
@@ -489,6 +556,9 @@ int cmd_annotate(int argc, const char **argv)if (annotate.session ==NULL )return -1 ; + annotate.has_br_stack =perf_header__has_feat (&annotate.session->header, +HEADER_BRANCH_STACK ); + ret =symbol__annotation_init ();if (ret <0 ) goto out_delete;
@@ -499,9 +569,6 @@ int cmd_annotate(int argc, const char **argv)if (ret <0 ) goto out_delete; -if (setup_sorting (NULL ) <0 ) -usage_with_options (annotate_usage, options); -if (annotate.use_stdio) use_browser =0 ;else if (annotate.use_tui)
@@ -511,6 +578,15 @@ int cmd_annotate(int argc, const char **argv)setup_browser (true); +if (use_browser ==1 && annotate.has_br_stack) { + sort__mode =SORT_MODE__BRANCH ; +if (setup_sorting (annotate.session->evlist) <0 ) +usage_with_options (annotate_usage, options); + }else { +if (setup_sorting (NULL ) <0 ) +usage_with_options (annotate_usage, options); + } + ret =__cmd_annotate (&annotate); out_delete:
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 53/54 perf annotate: Handle s390 PC relative load and store instruction.
In reply to Arnaldo Carvalho de MeloFrom: Thomas Richter <[email protected]>
S390 has several load and store instructions with target operand addressing relative to the program counter, for example lrl, lgrl, strl, stgrl.
These instructions are handled similar to x86. Objdump output displays those instructions as:
9595c: c4 2d 00 09 9c 54 lgrl %r7,1c8540 <mp_+0x60>
This output is parsed (like on x86) and perf annotate shows those lines as:
lgrl %r7,mp_+0x60
This patch handles the s390 specific instruction parsing for PC relative load and store instructions.
--- tools/perf/arch/s390/annotate/instructions.c | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
tools/perf/arch/s390/annotate/instructions.c +63 -0
@@ -52,6 +52,61 @@ static struct ins_ops s390_call_ops = { .scnprintf = call__scnprintf, }; +static int s390_mov__parse (struct arch *arch__maybe_unused , +struct ins_operands *ops, +struct map *map__maybe_unused ) +{ +char *s =strchr (ops->raw,',' ), *target, *endptr; + +if (s ==NULL ) +return -1 ; + + *s ='\0' ; + ops->source.raw =strdup (ops->raw); + *s =',' ; + +if (ops->source.raw ==NULL ) +return -1 ; + + target = ++s; + ops->target.raw =strdup (target); +if (ops->target.raw ==NULL ) + goto out_free_source; + + ops->target.addr =strtoull (target, &endptr,16 ); +if (endptr == target) + goto out_free_target; + + s =strchr (endptr,'<' ); +if (s ==NULL ) + goto out_free_target; + endptr =strchr (s +1 ,'>' ); +if (endptr ==NULL ) + goto out_free_target; + + *endptr ='\0' ; + ops->target.name =strdup (s +1 ); + *endptr ='>' ; +if (ops->target.name ==NULL ) + goto out_free_target; + +return 0 ; + +out_free_target: +zfree (&ops->target.raw); +out_free_source: +zfree (&ops->source.raw); +return -1 ; +} + +static int mov__scnprintf (struct ins *ins,char *bf,size_t size, +struct ins_operands *ops); + +static struct ins_ops s390_mov_ops = { + .parse = s390_mov__parse, + .scnprintf = mov__scnprintf, +}; +static struct ins_ops *s390__associate_ins_ops (struct arch *arch,const char *name) {struct ins_ops *ops =NULL ;
@@ -68,6 +123,14 @@ static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *na ops = &s390_call_ops;if (!strcmp (name,"br" )) ops = &ret_ops; +/* override load/store relative to PC */ +if (!strcmp (name,"lrl" ) || + !strcmp (name,"lgrl" ) || + !strcmp (name,"lgfrl" ) || + !strcmp (name,"llgfrl" ) || + !strcmp (name,"strl" ) || + !strcmp (name,"stgrl" )) + ops = &s390_mov_ops;if (ops)arch__associate_ins_ops (arch, name, ops);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 54/54 perf tools: Update quipper information
In reply to Arnaldo Carvalho de MeloFrom: Stephane Eranian <[email protected]>
This patch updates the links to the Quipper library. It is now available from GitHub and has been updated.
--- tools/perf/Documentation/perf.data-file-format.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
tools/perf/Documentation/perf.data-file-format.txt +1 -6
@@ -485,10 +485,5 @@ in pmu-tools parser. This allows to read perf.data from python and dump it. quipper The quipper C++ parser is available at -https://chromium.googlesource.com/chromiumos/platform2 +http://github.com/google/perf_data_converter/tree/master/src/quipper -It is under the chromiumos-wide-profiling/ subdirectory. This library can -convert a perf data file to a protobuf and vice versa. - -Unfortunately this parser tends to be many versions behind and may not be able -to parse data files generated by recent perf.
Signature · 1 line
2.14.3
Quoted 212 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
3f986eefc89c528bf2d398a6dc3637b743a7139e:Merge branch 'perf/urgent' into perf/core, to resolve conflict (2018-03-07 09:23:12 +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-20180308for you to fetch changes up to
2427b432e63b4b911100f717c48289195b7a7d62:perf tools: Update quipper information (2018-03-08 11:30:54 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:- Support to display the IPC/Cycle in 'annotate' TUI, for systems where this info can be obtained, like Intel's >= Skylake (Jin Yao)
- Support wildcards on PMU name in dynamic PMU events (Agustin Vega-Frias)
- Display pmu name when printing unmerged events in stat (Agustin Vega-Frias)
- Auto-merge PMU events created by prefix or glob match (Agustin Vega-Frias)
- Fix s390 'call' operations target function annotation (Thomas Richter)
- Handle s390 PC relative load and store instruction in the augmented 'annotate', code, used so far in the TUI modes of 'perf report' and 'perf annotate' (Thomas Richter)
- Provide libtraceevent with a kernel symbol resolver, so that symbols in tracepoint fields can be resolved when showing them in tools such as 'perf report' (Wang YanQing)
- Refactor the cgroups code to look more like other code in
tools/perf, using cgroup__{put,get} for refcount operations instead of its open-coded equivalent, breaking larger functions, etc (Arnaldo Carvalho de Melo)- Implement support for the -G/--cgroup target in 'perf trace', allowing strace like tracing (plus other events, backtraces, etc) for cgroups (Arnaldo Carvalho de Melo)
- Update thread shortname in 'perf sched map' when the thread's COMM changes (Changbin Du)
- refcount 'struct
mem_info', for better sharing it over several users, avoid duplicating structs and fixing crashes related to use after free (Jiri Olsa)- Display perf.data version, offsets in 'perf report --header' (Jiri Olsa)
- Record the machine's memory topology information in a perf.data feature section, to be used by tools such as 'perf c2c' (Jiri Olsa)
- Fix output of forced groups in the header for 'perf report' --stdio and --tui (Jiri Olsa)
- Better support llvm, clang, cxx make tests in the build process (Jiri Olsa)
- Streamline the 'struct
perf_mmap' methods, storing some info in the struct instead of passing it via various methods, shortening its signatures (Kan Liang)- Update the quipper perf.data parser library site information (Stephane Eranian)
- Correct perf's man pages title markers for asciidoctor (Takashi Iwai)
- Intel PT fixes and refactorings paving the way for implementing support for AUX area sampling (Adrian Hunter)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (13):
perf record: Combine some auxtrace initialization into a single function perf auxtrace: Add missing parameters from kernel-doc comments perf auxtrace: Rename some buffer-queuing functions
perf auxtrace: Makeauxtrace_queues__add_buffer()returnbuffer_ptrperf intel-pt: Fix overlap detection to identify consecutive buffers correctly perf intel-pt: Fixsync_switch
perf intel-pt: Fix error recovery from missing TIP packet
perf intel-pt: Fix timestamp following overflow
perf intel-pt/bts: Inauxtrace_record__init_intel()evlist is never NULL perf intel-pt: Get rid ofintel_pt_use_buffer_pid_tid()
perf intel-pt: Tidyold_bufferhandling inintel_pt_get_trace()perf intel-pt: Remove a check for sampling mode
perf intel-pt: Adjust overlap-checking to support sampling modeAgustin Vega-Frias (3):
perf pmu: Support wildcards on pmu name in dynamic pmu events perf pmu: Display pmu name when printing unmerged events in stat perf pmu: Auto-merge PMU events created by prefix or glob matchArnaldo Carvalho de Melo (11):
perf cgroup: Remove misplaced__maybe_unused
perf cgroup: Rename 'structcgroup_sel' to 'struct cgroup' perf cgroup: Introducecgroup__delete()
perf cgroup: Renameclose_cgroup()tocgroup__put()perf cgroup: Introducecgroup__get()
perf cgroup: Introducefind_cgroup()method
perf cgroup: Introducecgroup__new()out of open coded equivalent perf cgroup: Addevlist__findnew_cgroup()
perf cgroup: Addevlist__add_default_cgroup()
perf cgroup: Make the cgroup name be const char *
perf trace: Support setting cgroups as targetsChangbin Du (2):
perf sched: Movethread::shortnametothread_runtimeperf sched map: Re-annotate shortname if thread comm changedJin Yao (1):
perf annotate: Support to display the IPC/Cycle in TUI modeJiri Olsa (11):
perf report: Fix the output for stdio events list
perf report: Display perf.data header info
perf record: Move machine variable down the function perf record: Remove progname from struct record
perf tools: Add refcnt into structmem_info
perf c2c: Usemem_inforefcnt logic
perf tools: AddMEM_TOPOLOGYfeature to perf data file perf tools: Update tags with .cpp files
perf build: Add llvm/clang/cxx make tests intoFEATURE_TESTS_EXTRAperf build: Add llvm/clang make targets to FILES
perf build: Force llvm/clang test compile output to .make.outputKan Liang (8):
perf evlist: Store 'overwrite' in structperf_mmapperf mmap: Store mmap scope in structperf_mmap()perf mmap: Use the stored scope data inperf_mmap__push()perf mmap: Use the stored data inperf_mmap__read_event()perf mmap: Use stored 'overwrite' inperf_mmap__consume()perf mmap: Simplifyperf_mmap__consume()
perf mmap: Simplifyperf_mmap__read_event()perf mmap: Simplifyperf_mmap__read_init()Stephane Eranian (1):
perf tools: Update quipper informationTakashi Iwai (1):
perf tools: Correct title markers for asciidoctorThomas Richter (2):
perf annotate: Fix s390 target function disassembly perf annotate: Handle s390 PC relative load and store instruction.Wang YanQing (1):
perf report: Provide libtraceevent with a kernel symbol resolvertools/build/Makefile.feature | 6 +- tools/build/feature/Makefile | 14 +- tools/include/linux/bitmap.h | 2 +- tools/perf/Documentation/perf-data.txt | 2 +- tools/perf/Documentation/perf-ftrace.txt | 2 +- tools/perf/Documentation/perf-kallsyms.txt | 2 +- tools/perf/Documentation/perf-list.txt | 8 +- tools/perf/Documentation/perf-sched.txt | 2 +- tools/perf/Documentation/perf-script-perl.txt | 2 +- tools/perf/Documentation/perf-stat.txt | 17 ++ tools/perf/Documentation/perf-trace.txt | 25 ++ tools/perf/Documentation/perf.data-file-format.txt | 7 +- tools/perf/Makefile.perf | 6 +- tools/perf/arch/s390/annotate/instructions.c | 116 +++++++- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 7 +- tools/perf/arch/x86/util/auxtrace.c | 14 +- tools/perf/builtin-annotate.c | 88 +++++- tools/perf/builtin-c2c.c | 24 +- tools/perf/builtin-kvm.c | 9 +- tools/perf/builtin-record.c | 45 +-- tools/perf/builtin-report.c | 26 +- tools/perf/builtin-sched.c | 133 ++++++--- tools/perf/builtin-stat.c | 29 +- tools/perf/builtin-top.c | 7 +- tools/perf/builtin-trace.c | 57 +++- tools/perf/tests/backward-ring-buffer.c | 5 +- tools/perf/tests/bpf.c | 5 +- tools/perf/tests/code-reading.c | 7 +- tools/perf/tests/keep-tracking.c | 7 +- tools/perf/tests/mmap-basic.c | 7 +- tools/perf/tests/openat-syscall-tp-fields.c | 7 +- tools/perf/tests/perf-record.c | 7 +- tools/perf/tests/sw-clock.c | 7 +- tools/perf/tests/switch-tracking.c | 7 +- tools/perf/tests/task-exit.c | 7 +- tools/perf/ui/browsers/hists.c | 5 +- tools/perf/util/annotate.c | 2 +- tools/perf/util/auxtrace.c | 37 ++- tools/perf/util/auxtrace.h | 2 + tools/perf/util/cgroup.c | 111 +++++--- tools/perf/util/cgroup.h | 13 +- tools/perf/util/env.h | 9 + tools/perf/util/evlist.c | 8 +- tools/perf/util/evsel.c | 23 +- tools/perf/util/evsel.h | 6 +- tools/perf/util/header.c | 312 ++++++++++++++++++++- tools/perf/util/header.h | 1 + tools/perf/util/hist.c | 4 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 64 ++--- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 +- tools/perf/util/intel-pt.c | 110 ++++---- tools/perf/util/machine.c | 2 +- tools/perf/util/mmap.c | 63 ++--- tools/perf/util/mmap.h | 16 +- tools/perf/util/parse-events.c | 21 +-
Quoted 8 lines
tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.l | 2 +- tools/perf/util/parse-events.y | 18 +- tools/perf/util/python.c | 7 +- tools/perf/util/symbol.c | 22 ++ tools/perf/util/symbol.h | 19 +- tools/perf/util/thread.h | 1 - 62 files changed, 1197 insertions(+), 401 deletions(-)
Pulled, thanks a lot Arnaldo!
Ingo